diff --git a/.travis.yml b/.travis.yml index f0db8b8..7d61992 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 + - vendor/bin/phpunit --verbose 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/README.md b/README.md index 8d296c5..14ada99 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,23 @@ -Comments module for Yii2 -======================== +

+ + + +

Yii2 Comments Extension

+
+

-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) [![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) + +## 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 ------------ diff --git a/composer.json b/composer.json index 6e6b432..e12b108 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,18 @@ "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": { "yii2mod\\comments\\": "" } - } + }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org/" + } + ] } 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/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', +]; 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/models/CommentModel.php b/models/CommentModel.php index 2ec6081..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([ @@ -168,7 +170,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; } 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()]); ?>