From 105b3fbde16d6087c8da999af63844e2e1b5eed8 Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Sun, 13 Aug 2017 22:27:12 +0300 Subject: [PATCH 01/11] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d296c5..c1523cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ -Comments module for Yii2 -======================== +

+ + + +

Yii2 Comments Extension

+
+

This module provide a comments managing system for Yii2 application. From 9600e84d9beebd2df9d46e10f969caface52c7ad Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Sun, 13 Aug 2017 22:29:02 +0300 Subject: [PATCH 02/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1523cf..619bf27 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

-This module provide a comments managing system for Yii2 application. +This module provides a comments managing system. [![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-comments/v/stable)](https://packagist.org/packages/yii2mod/yii2-comments) [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-comments/downloads)](https://packagist.org/packages/yii2mod/yii2-comments) From b91abd31b3490318b358a90722fa98e2bdc3057c Mon Sep 17 00:00:00 2001 From: igor-chepurnoi Date: Mon, 14 Aug 2017 09:43:58 +0300 Subject: [PATCH 03/11] update tests configuration --- .travis.yml | 4 +--- composer.json | 8 +++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0db8b8..eeca0b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,14 +10,12 @@ sudo: false cache: directories: - $HOME/.composer/cache - - vendor install: - travis_retry composer self-update && composer --version - - travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0" - export PATH="$HOME/.composer/vendor/bin:$PATH" - travis_retry composer install --prefer-dist --no-interaction script: - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff - - phpunit --verbose $PHPUNIT_FLAGS + - phpunit --verbose diff --git a/composer.json b/composer.json index 6e6b432..6cef27a 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,11 @@ "psr-4": { "yii2mod\\comments\\": "" } - } + }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org/" + } + ] } From ee7e92ebe8d79c66f5ef225ca8e9bcd9986fd6ed Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Sun, 27 Aug 2017 11:44:31 +0300 Subject: [PATCH 04/11] Added scrutinizer badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 619bf27..5a8a459 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ This module provides a comments managing system. [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-comments/downloads)](https://packagist.org/packages/yii2mod/yii2-comments) [![License](https://poser.pugx.org/yii2mod/yii2-comments/license)](https://packagist.org/packages/yii2mod/yii2-comments) [![Build Status](https://travis-ci.org/yii2mod/yii2-comments.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-comments) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/?branch=master) Installation ------------ From 2083417bfeab2661d62a924b92ec374ab083f1af Mon Sep 17 00:00:00 2001 From: igor-chepurnoi Date: Fri, 8 Sep 2017 15:57:10 +0300 Subject: [PATCH 05/11] fix #75 --- .travis.yml | 2 +- composer.json | 3 ++- models/CommentModel.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index eeca0b5..7d61992 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,4 @@ install: script: - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff - - phpunit --verbose + - vendor/bin/phpunit --verbose diff --git a/composer.json b/composer.json index 6cef27a..e12b108 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "paulzi/yii2-adjacency-list": "^2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.0" + "friendsofphp/php-cs-fixer": "~2.0", + "phpunit/phpunit": "~6.0" }, "autoload": { "psr-4": { diff --git a/models/CommentModel.php b/models/CommentModel.php index 2ec6081..1378205 100644 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -168,7 +168,7 @@ public static function find() public function beforeSave($insert) { if (parent::beforeSave($insert)) { - if ($this->parentId > 0) { + if ($this->parentId > 0 && $this->isNewRecord) { $parentNodeLevel = static::find()->select('level')->where(['id' => $this->parentId])->scalar(); $this->level += $parentNodeLevel; } From 36b012b88c9f81cfc84a80eb3f5b2af6d49a72f1 Mon Sep 17 00:00:00 2001 From: Robert Natkay Date: Wed, 27 Sep 2017 14:04:50 +0200 Subject: [PATCH 06/11] skip the validation of parentId on deletion --- controllers/DefaultController.php | 1 + models/CommentModel.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index fe15098..9404a4e 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -131,6 +131,7 @@ public function actionCreate($entity) public function actionDelete($id) { $commentModel = $this->findModel($id); + $commentModel->setScenario(CommentModel::SCENARIO_MODERATION); $event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]); $this->trigger(self::EVENT_BEFORE_DELETE, $event); diff --git a/models/CommentModel.php b/models/CommentModel.php index 1378205..2e0f246 100644 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -42,6 +42,8 @@ class CommentModel extends ActiveRecord { use ModuleTrait; + const SCENARIO_MODERATION = 'moderation'; + /** * @var null|array|ActiveRecord[] comment children */ @@ -67,7 +69,7 @@ public function rules() ['status', 'default', 'value' => Status::APPROVED], ['status', 'in', 'range' => Status::getConstantsByName()], ['level', 'default', 'value' => 1], - ['parentId', 'validateParentID'], + ['parentId', 'validateParentID', 'except'=>static::SCENARIO_MODERATION], [['entityId', 'parentId', 'status', 'level'], 'integer'], ]; } From 238c3ca7cee5d4bc67d15f14f1920eb5659c0d4f Mon Sep 17 00:00:00 2001 From: Robert Natkay Date: Wed, 27 Sep 2017 14:04:50 +0200 Subject: [PATCH 07/11] skip the validation of parentId on deletion --- controllers/DefaultController.php | 5 +++-- controllers/ManageController.php | 2 +- models/CommentModel.php | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index fe15098..4dd673a 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -131,6 +131,7 @@ public function actionCreate($entity) public function actionDelete($id) { $commentModel = $this->findModel($id); + $commentModel->setScenario(CommentModel::SCENARIO_MODERATION); $event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]); $this->trigger(self::EVENT_BEFORE_DELETE, $event); @@ -157,7 +158,7 @@ public function actionDelete($id) protected function findModel($id) { $commentModel = $this->getModule()->commentModelClass; - if (($model = $commentModel::findOne($id)) !== null) { + if (null !== ($model = $commentModel::findOne($id))) { return $model; } else { throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.')); @@ -176,7 +177,7 @@ protected function findModel($id) protected function getCommentAttributesFromEntity($entity) { $decryptEntity = Yii::$app->getSecurity()->decryptByKey(utf8_decode($entity), $this->getModule()->id); - if ($decryptEntity !== false) { + if (false !== $decryptEntity) { return Json::decode($decryptEntity); } diff --git a/controllers/ManageController.php b/controllers/ManageController.php index 0d980c2..d803cda 100644 --- a/controllers/ManageController.php +++ b/controllers/ManageController.php @@ -142,7 +142,7 @@ protected function findModel($id) { $commentModel = $this->getModule()->commentModelClass; - if (($model = $commentModel::findOne($id)) !== null) { + if (null !== ($model = $commentModel::findOne($id))) { return $model; } else { throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.')); diff --git a/models/CommentModel.php b/models/CommentModel.php index 1378205..4f7efc7 100644 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -42,6 +42,8 @@ class CommentModel extends ActiveRecord { use ModuleTrait; + const SCENARIO_MODERATION = 'moderation'; + /** * @var null|array|ActiveRecord[] comment children */ @@ -67,7 +69,7 @@ public function rules() ['status', 'default', 'value' => Status::APPROVED], ['status', 'in', 'range' => Status::getConstantsByName()], ['level', 'default', 'value' => 1], - ['parentId', 'validateParentID'], + ['parentId', 'validateParentID', 'except' => static::SCENARIO_MODERATION], [['entityId', 'parentId', 'status', 'level'], 'integer'], ]; } @@ -77,7 +79,7 @@ public function rules() */ public function validateParentID($attribute) { - if ($this->{$attribute} !== null) { + if (null !== $this->{$attribute}) { $parentCommentExist = static::find() ->approved() ->andWhere([ From 057c958340707fd71e878203b6dc96d37d763877 Mon Sep 17 00:00:00 2001 From: Robert Natkay Date: Sat, 7 Oct 2017 19:05:09 +0200 Subject: [PATCH 08/11] skip the validation of parentId on deletion --- Module.php | 2 +- migrations/m010101_100001_init_comment.php | 2 +- migrations/m161109_092304_rename_comment_table.php | 4 ++-- views/manage/index.php | 2 +- views/manage/update.php | 4 ++-- widgets/views/_form.php | 2 +- widgets/views/_list.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Module.php b/Module.php index 2cb579d..3c497ac 100644 --- a/Module.php +++ b/Module.php @@ -38,7 +38,7 @@ public function init() { parent::init(); - if ($this->userIdentityClass === null) { + if (null === $this->userIdentityClass) { $this->userIdentityClass = Yii::$app->getUser()->identityClass; } } diff --git a/migrations/m010101_100001_init_comment.php b/migrations/m010101_100001_init_comment.php index e1290a6..cf4126e 100644 --- a/migrations/m010101_100001_init_comment.php +++ b/migrations/m010101_100001_init_comment.php @@ -14,7 +14,7 @@ public function up() { $tableOptions = null; - if ($this->db->driverName === 'mysql') { + if ('mysql' === $this->db->driverName) { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; } diff --git a/migrations/m161109_092304_rename_comment_table.php b/migrations/m161109_092304_rename_comment_table.php index 914d0d3..cbd6740 100644 --- a/migrations/m161109_092304_rename_comment_table.php +++ b/migrations/m161109_092304_rename_comment_table.php @@ -6,14 +6,14 @@ class m161109_092304_rename_comment_table extends Migration { public function up() { - if (Yii::$app->db->schema->getTableSchema('{{%comment}}') === null) { + if (null === Yii::$app->db->schema->getTableSchema('{{%comment}}')) { $this->renameTable('{{%Comment}}', '{{%comment}}'); } } public function down() { - if (Yii::$app->db->schema->getTableSchema('{{%Comment}}') === null) { + if (null === Yii::$app->db->schema->getTableSchema('{{%Comment}}')) { $this->renameTable('{{%comment}}', '{{%Comment}}'); } } diff --git a/views/manage/index.php b/views/manage/index.php index f6f7c6c..245f232 100644 --- a/views/manage/index.php +++ b/views/manage/index.php @@ -16,7 +16,7 @@ ?>
-

title) ?>

+

title); ?>

10000]); ?> $dataProvider, diff --git a/views/manage/update.php b/views/manage/update.php index a426837..acc1a0e 100644 --- a/views/manage/update.php +++ b/views/manage/update.php @@ -15,7 +15,7 @@ ?>
-

title) ?>

+

title); ?>

@@ -30,7 +30,7 @@ ?> field($model, 'status')->dropDownList(Status::listData()); ?>
- 'btn btn-primary']) ?> + 'btn btn-primary']); ?> 'btn btn-default']); ?>
diff --git a/widgets/views/_form.php b/widgets/views/_form.php index 9130729..957e175 100644 --- a/widgets/views/_form.php +++ b/widgets/views/_form.php @@ -20,7 +20,7 @@ 'validateOnBlur' => false, ]); ?> - field($commentModel, 'content', ['template' => '{input}{error}'])->textarea(['placeholder' => Yii::t('yii2mod.comments', 'Add a comment...'), 'rows' => 4, 'data' => ['comment' => 'content']]) ?> + field($commentModel, 'content', ['template' => '{input}{error}'])->textarea(['placeholder' => Yii::t('yii2mod.comments', 'Add a comment...'), 'rows' => 4, 'data' => ['comment' => 'content']]); ?> field($commentModel, 'parentId', ['template' => '{input}'])->hiddenInput(['data' => ['comment' => 'parent-id']]); ?>
diff --git a/widgets/views/_list.php b/widgets/views/_list.php index 19449c5..b61bbe8 100644 --- a/widgets/views/_list.php +++ b/widgets/views/_list.php @@ -9,7 +9,7 @@ /* @var $maxLevel null|integer comments max level */ ?>
  • -
    +
    getAvatar(), ['alt' => $model->getAuthorName()]); ?>
    From 024e332177ab1411766fcc7bc97f9e683cd99a1f Mon Sep 17 00:00:00 2001 From: "Gustavo G. Andrade" Date: Sat, 27 Oct 2018 19:14:25 -0300 Subject: [PATCH 09/11] Added language pt-BR complete --- messages/pt-BR/yii2mod.comments.php | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 messages/pt-BR/yii2mod.comments.php diff --git a/messages/pt-BR/yii2mod.comments.php b/messages/pt-BR/yii2mod.comments.php new file mode 100644 index 0000000..c53d98e --- /dev/null +++ b/messages/pt-BR/yii2mod.comments.php @@ -0,0 +1,54 @@ + 'ID', + 'Content' => 'Conteúdo', + 'Entity' => 'Entidade', + 'Entity ID' => 'ID da Entidade', + 'Parent ID' => 'ID Pai', + 'Status' => 'Situação', + 'Level' => 'Level', + 'Created by' => 'Criado por', + 'Updated by' => 'Alterado por', + 'Related to' => 'Relacionado por', + 'Url' => 'Url', + 'Created date' => 'Criado em', + 'Updated date' => 'Alterado em', + 'View' => 'Visualizar', + 'Update' => 'Alterar', + 'Delete' => 'Excluir', + 'Reply' => 'Responder', + 'Comments ({0})' => 'Comentários ({0})', + 'Comment cannot be blank.' => 'Comentário não pode ficar em branco.', + 'Comment has not been deleted. Please try again!' => 'Comentário não pode ser excluído. Tente novamente!', + 'Add a comment...' => 'Adicionar Comentário...', + 'Comment' => 'Comentário', + 'Oops, something went wrong. Please try again later.' => 'Oops, algo deu errado. Tente novamente depois.', + 'The requested page does not exist.' => 'Página solicitada não existe.', + 'Comment has been deleted.' => 'Comentário foi excluído.', + 'Comment has been saved.' => 'Comentário foi gravado.', + 'Click here to cancel reply.' => 'Clique aqui para cancelar a resposta.', + 'Comments Management' => 'Gerenciar Comentários', + 'Select Status' => 'Selecionar situação', + 'Select Author' => 'Selecionar Autor', + 'Update Comment: {0}' => 'Alterar Comentário: {0}', + 'Active' => 'Ativo', + 'Deleted' => 'Excluído', + 'Go Back' => 'Voltar', +]; From 8b1145b0edd072b28eb0af988abba8ba3f826857 Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Thu, 31 Oct 2019 13:26:00 +0200 Subject: [PATCH 10/11] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5a8a459..2381f89 100644 --- a/README.md +++ b/README.md @@ -227,3 +227,9 @@ return [ #### Example comments ----- ![Alt text](http://res.cloudinary.com/zfort/image/upload/v1467214676/comments-preview.png "Example comments") + + +## Support us + +Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). +All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff. From 89e5b3f682f532de492a44123cd5418f44ffcc22 Mon Sep 17 00:00:00 2001 From: Igor Chepurnoy Date: Sat, 2 Nov 2019 19:49:55 +0200 Subject: [PATCH 11/11] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2381f89..14ada99 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ This module provides a comments managing system. [![Build Status](https://travis-ci.org/yii2mod/yii2-comments.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-comments) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/?branch=master) +## Support us + +Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). +All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff. + Installation ------------ @@ -227,9 +232,3 @@ return [ #### Example comments ----- ![Alt text](http://res.cloudinary.com/zfort/image/upload/v1467214676/comments-preview.png "Example comments") - - -## Support us - -Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). -All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.