Commit faff2c48bfd09f5ee437dc3d513eb8ed4665c2b0
1 parent
2ac6a2f4
Artbox comment created
Showing
30 changed files
with
969 additions
and
617 deletions
Show diff stats
| 1 | +# Change Log | ||
| 2 | +All notable changes to this project will be documented in this file. | ||
| 3 | + | ||
| 4 | +## 1.0.0 - 2017-03-21 | ||
| 5 | +### Added | ||
| 6 | +- This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG. | ||
| 7 | +- Added initial Artbox Comment extension. | ||
| 0 | \ No newline at end of file | 8 | \ No newline at end of file |
| 1 | +The Yii framework is free software. It is released under the terms of | ||
| 2 | +the following BSD License. | ||
| 3 | + | ||
| 4 | +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) | ||
| 5 | +All rights reserved. | ||
| 6 | + | ||
| 7 | +Redistribution and use in source and binary forms, with or without | ||
| 8 | +modification, are permitted provided that the following conditions | ||
| 9 | +are met: | ||
| 10 | + | ||
| 11 | + * Redistributions of source code must retain the above copyright | ||
| 12 | + notice, this list of conditions and the following disclaimer. | ||
| 13 | + * Redistributions in binary form must reproduce the above copyright | ||
| 14 | + notice, this list of conditions and the following disclaimer in | ||
| 15 | + the documentation and/or other materials provided with the | ||
| 16 | + distribution. | ||
| 17 | + * Neither the name of Yii Software LLC nor the names of its | ||
| 18 | + contributors may be used to endorse or promote products derived | ||
| 19 | + from this software without specific prior written permission. | ||
| 20 | + | ||
| 21 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 22 | +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 23 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 24 | +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 25 | +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 26 | +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 27 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 28 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 29 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 30 | +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 31 | +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 32 | +POSSIBILITY OF SUCH DAMAGE. |
Module.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment; | 3 | + namespace artbox\webcomment; |
| 4 | 4 | ||
| 5 | - use artweb\artbox\comment\models\CommentModel; | ||
| 6 | - use artweb\artbox\comment\models\RatingModel; | 5 | + use artbox\webcomment\models\CommentModel; |
| 6 | + use artbox\webcomment\models\RatingModel; | ||
| 7 | use Yii; | 7 | use Yii; |
| 8 | + use yii\base\InvalidConfigException; | ||
| 8 | use yii\console\Application; | 9 | use yii\console\Application; |
| 9 | - | 10 | + |
| 10 | /** | 11 | /** |
| 11 | * Class Module | 12 | * Class Module |
| 13 | + * | ||
| 12 | * @package artweb\artbox\comment | 14 | * @package artweb\artbox\comment |
| 13 | */ | 15 | */ |
| 14 | class Module extends \yii\base\Module | 16 | class Module extends \yii\base\Module |
| @@ -20,39 +22,44 @@ | @@ -20,39 +22,44 @@ | ||
| 20 | public static $name = 'artbox-comment'; | 22 | public static $name = 'artbox-comment'; |
| 21 | 23 | ||
| 22 | /** | 24 | /** |
| 23 | - * User identity class, default to artweb\artbox\comment\models\User | 25 | + * User identity class, default to artbox\order\models\Customer |
| 26 | + * | ||
| 24 | * @var string|null | 27 | * @var string|null |
| 25 | */ | 28 | */ |
| 26 | - public $userIdentityClass = NULL; | 29 | + public $userIdentityClass = null; |
| 27 | 30 | ||
| 28 | /** | 31 | /** |
| 29 | - * Comment model class, default to artweb\artbox\comment\modules\models\CommentModel | 32 | + * Comment model class, default to artbox\webcomment\modules\models\CommentModel |
| 33 | + * | ||
| 30 | * @var string comment model class | 34 | * @var string comment model class |
| 31 | */ | 35 | */ |
| 32 | - public $commentModelClass = NULL; | ||
| 33 | - | ||
| 34 | - public $ratingModelClass = NULL; | 36 | + public $commentModelClass = null; |
| 37 | + | ||
| 38 | + public $ratingModelClass = null; | ||
| 35 | 39 | ||
| 36 | /** | 40 | /** |
| 37 | * This namespace will be used to load controller classes by prepending it to the controller | 41 | * This namespace will be used to load controller classes by prepending it to the controller |
| 38 | * class name. | 42 | * class name. |
| 43 | + * | ||
| 39 | * @var string the namespace that controller classes are in. | 44 | * @var string the namespace that controller classes are in. |
| 40 | */ | 45 | */ |
| 41 | - public $controllerNamespace = 'artweb\artbox\comment\controllers'; | 46 | + public $controllerNamespace = 'artbox\webcomment\controllers'; |
| 42 | 47 | ||
| 43 | /** | 48 | /** |
| 44 | * @var \yii\db\Connection DB connection, default to \Yii::$app->db | 49 | * @var \yii\db\Connection DB connection, default to \Yii::$app->db |
| 45 | */ | 50 | */ |
| 46 | - public $db = NULL; | 51 | + public $db = null; |
| 47 | 52 | ||
| 48 | /** | 53 | /** |
| 49 | * Key, used to encrypt and decrypt comment service data. | 54 | * Key, used to encrypt and decrypt comment service data. |
| 55 | + * | ||
| 50 | * @var string Encryption key | 56 | * @var string Encryption key |
| 51 | */ | 57 | */ |
| 52 | public static $encryptionKey = 'artbox-comment'; | 58 | public static $encryptionKey = 'artbox-comment'; |
| 53 | 59 | ||
| 54 | /** | 60 | /** |
| 55 | * Whether to enable comment rating or not. | 61 | * Whether to enable comment rating or not. |
| 62 | + * | ||
| 56 | * @var bool | 63 | * @var bool |
| 57 | */ | 64 | */ |
| 58 | public static $enableRating = true; | 65 | public static $enableRating = true; |
| @@ -66,22 +73,34 @@ | @@ -66,22 +73,34 @@ | ||
| 66 | */ | 73 | */ |
| 67 | public function init() | 74 | public function init() |
| 68 | { | 75 | { |
| 69 | - if($this->commentModelClass === NULL) { | 76 | + if ($this->commentModelClass === null) { |
| 70 | $this->commentModelClass = CommentModel::className(); | 77 | $this->commentModelClass = CommentModel::className(); |
| 71 | } | 78 | } |
| 72 | - if(self::$enableRating && $this->ratingModelClass === NULL) { | 79 | + if (self::$enableRating && $this->ratingModelClass === null) { |
| 73 | $this->ratingModelClass = RatingModel::className(); | 80 | $this->ratingModelClass = RatingModel::className(); |
| 74 | } | 81 | } |
| 75 | - if(\Yii::$app instanceof Application) { | ||
| 76 | - $this->controllerNamespace = 'artweb\artbox\comment\commands'; | ||
| 77 | - } elseif($this->userIdentityClass === NULL) { | 82 | + if (\Yii::$app instanceof Application) { |
| 83 | + $this->controllerNamespace = 'artbox\webcomment\commands'; | ||
| 84 | + } elseif ($this->userIdentityClass === null) { | ||
| 78 | $this->userIdentityClass = Yii::$app->getUser()->identityClass; | 85 | $this->userIdentityClass = Yii::$app->getUser()->identityClass; |
| 79 | } | 86 | } |
| 80 | - if($this->db === NULL) { | 87 | + if ($this->db === null) { |
| 81 | $this->db = \Yii::$app->db; | 88 | $this->db = \Yii::$app->db; |
| 82 | } | 89 | } |
| 83 | - Yii::setAlias('@artbox-comment', __DIR__); | 90 | + if (!Yii::getAlias('@artbox/webcomment', false)) { |
| 91 | + Yii::setAlias('@artbox/webcomment', __DIR__); | ||
| 92 | + } | ||
| 84 | parent::init(); | 93 | parent::init(); |
| 85 | } | 94 | } |
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Prompt to register current module | ||
| 98 | + * | ||
| 99 | + * @throws \yii\base\InvalidConfigException | ||
| 100 | + */ | ||
| 101 | + public static function registerMe() | ||
| 102 | + { | ||
| 103 | + throw new InvalidConfigException(\Yii::t('artbox-comment', 'Register artbox-comment module')); | ||
| 104 | + } | ||
| 86 | 105 | ||
| 87 | } | 106 | } |
| 1 | +Artbox Comment | ||
| 2 | +=============================== | ||
| 3 | + | ||
| 4 | +Artbox Comment is an extension for working with comments developed by Artweb written with [Yii 2 framework](http://www.yiiframework.com/). | ||
| 5 | + | ||
| 6 | +Comment extension includes functionality for creating and maintaining comments on the website. | ||
| 7 | + | ||
| 8 | +This extension works with Artbox Core application and enough to add fully functional comment system to the website. | ||
| 9 | + | ||
| 10 | +To prepare your application you should run migrations: | ||
| 11 | + | ||
| 12 | + php yii migrate --migationPath=vendor/artweb/artbox-webcomment/migrations | ||
| 13 | + | ||
| 14 | +DIRECTORY STRUCTURE | ||
| 15 | +------------------- | ||
| 16 | + | ||
| 17 | +``` | ||
| 18 | +assets contains AssetBundles | ||
| 19 | +behaviors contains Behaviors classes | ||
| 20 | +components contains custom Classes, which don't belong to other groups | ||
| 21 | +controllers contains controllers for core models | ||
| 22 | +helpers contains helper classes to manipulate, for example static files | ||
| 23 | + and HTML | ||
| 24 | +messages contains translations for core strings | ||
| 25 | +migrations contains migrations, which should be applied after extension | ||
| 26 | + installation | ||
| 27 | +models contains core models | ||
| 28 | +views contains views files for core controllers | ||
| 29 | +web contains assets and other files, which should be web available | ||
| 30 | +widgets contains widgets | ||
| 31 | +``` |
assets/CommentAsset.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\assets; | 3 | + namespace artbox\webcomment\assets; |
| 4 | 4 | ||
| 5 | use yii\web\AssetBundle; | 5 | use yii\web\AssetBundle; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * Class CommentAsset | 8 | * Class CommentAsset |
| 9 | - * @package artweb\artbox\comment\assets | ||
| 10 | */ | 9 | */ |
| 11 | class CommentAsset extends AssetBundle | 10 | class CommentAsset extends AssetBundle |
| 12 | { | 11 | { |
| @@ -14,7 +13,7 @@ | @@ -14,7 +13,7 @@ | ||
| 14 | /** | 13 | /** |
| 15 | * @inheritdoc | 14 | * @inheritdoc |
| 16 | */ | 15 | */ |
| 17 | - public $sourcePath = '@artbox-comment/resources'; | 16 | + public $sourcePath = '@artbox/webcomment/resources'; |
| 18 | 17 | ||
| 19 | /** | 18 | /** |
| 20 | * @inheritdoc | 19 | * @inheritdoc |
behaviors/CommentBehavior.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\behaviors; | 3 | + namespace artbox\webcomment\behaviors; |
| 4 | 4 | ||
| 5 | - use artweb\artbox\comment\models\CommentModel; | ||
| 6 | - use artweb\artbox\comment\models\interfaces\RatingCacheInterface; | 5 | + use artbox\webcomment\models\CommentModel; |
| 6 | + use artbox\webcomment\models\interfaces\RatingCacheInterface; | ||
| 7 | use yii\base\Behavior; | 7 | use yii\base\Behavior; |
| 8 | use yii\base\InvalidConfigException; | 8 | use yii\base\InvalidConfigException; |
| 9 | + use yii\base\InvalidParamException; | ||
| 9 | use yii\db\ActiveQuery; | 10 | use yii\db\ActiveQuery; |
| 10 | use yii\db\ActiveRecord; | 11 | use yii\db\ActiveRecord; |
| 11 | 12 | ||
| @@ -14,7 +15,7 @@ | @@ -14,7 +15,7 @@ | ||
| 14 | * | 15 | * |
| 15 | * @property ActiveQuery $averageRating | 16 | * @property ActiveQuery $averageRating |
| 16 | * @property CommentModel[] $comments | 17 | * @property CommentModel[] $comments |
| 17 | - * @package artweb\artbox\comment\behaviors | 18 | + * @package artbox\webcomment\behaviors |
| 18 | */ | 19 | */ |
| 19 | class CommentBehavior extends Behavior | 20 | class CommentBehavior extends Behavior |
| 20 | { | 21 | { |
| @@ -46,7 +47,7 @@ | @@ -46,7 +47,7 @@ | ||
| 46 | public function attach($owner) | 47 | public function attach($owner) |
| 47 | { | 48 | { |
| 48 | if ($this->cacheRating) { | 49 | if ($this->cacheRating) { |
| 49 | - if (empty( $this->cacheModelName ) || !is_string($this->cacheModelName)) { | 50 | + if (empty($this->cacheModelName) || !is_string($this->cacheModelName)) { |
| 50 | throw new InvalidConfigException( | 51 | throw new InvalidConfigException( |
| 51 | 'To use rating cache you must set $cacheModelName where to store it' | 52 | 'To use rating cache you must set $cacheModelName where to store it' |
| 52 | ); | 53 | ); |
| @@ -67,7 +68,7 @@ | @@ -67,7 +68,7 @@ | ||
| 67 | * | 68 | * |
| 68 | * @return string | 69 | * @return string |
| 69 | */ | 70 | */ |
| 70 | - public function getCacheModelName():string | 71 | + public function getCacheModelName(): string |
| 71 | { | 72 | { |
| 72 | return $this->cacheModelName; | 73 | return $this->cacheModelName; |
| 73 | } | 74 | } |
| @@ -84,10 +85,8 @@ | @@ -84,10 +85,8 @@ | ||
| 84 | 85 | ||
| 85 | /** | 86 | /** |
| 86 | * Get model to hold rating cache | 87 | * Get model to hold rating cache |
| 87 | - * | ||
| 88 | - * @return \artweb\artbox\comment\models\interfaces\RatingCacheInterface | ||
| 89 | */ | 88 | */ |
| 90 | - public function getCacheModel():RatingCacheInterface | 89 | + public function getCacheModel(): RatingCacheInterface |
| 91 | { | 90 | { |
| 92 | return $this->cacheModel; | 91 | return $this->cacheModel; |
| 93 | } | 92 | } |
| @@ -95,7 +94,7 @@ | @@ -95,7 +94,7 @@ | ||
| 95 | /** | 94 | /** |
| 96 | * Set model to hold cache | 95 | * Set model to hold cache |
| 97 | * | 96 | * |
| 98 | - * @param \artweb\artbox\comment\models\interfaces\RatingCacheInterface|null $value | 97 | + * @param \artbox\webcomment\models\interfaces\RatingCacheInterface|null $value |
| 99 | */ | 98 | */ |
| 100 | private function setCacheModel(RatingCacheInterface $value = null) | 99 | private function setCacheModel(RatingCacheInterface $value = null) |
| 101 | { | 100 | { |
| @@ -133,13 +132,19 @@ | @@ -133,13 +132,19 @@ | ||
| 133 | * @var ActiveRecord $owner | 132 | * @var ActiveRecord $owner |
| 134 | */ | 133 | */ |
| 135 | $owner = $this->owner; | 134 | $owner = $this->owner; |
| 136 | - $pk = $owner->primaryKey()[ 0 ]; | 135 | + $pkKeys = $owner->primaryKey(); |
| 136 | + if (!empty($pkKeys)) { | ||
| 137 | + $pkKey = $pkKeys[ 0 ]; | ||
| 138 | + } else { | ||
| 139 | + throw new InvalidParamException('Entity must have primary key.'); | ||
| 140 | + } | ||
| 141 | + $pk = $owner->getAttribute($pkKey); | ||
| 137 | $query = $owner->hasMany(CommentModel::className(), [ 'entity_id' => $pk ]) | 142 | $query = $owner->hasMany(CommentModel::className(), [ 'entity_id' => $pk ]) |
| 138 | ->where( | 143 | ->where( |
| 139 | [ | 144 | [ |
| 140 | - 'artbox_comment.entity' => $owner::className(), | ||
| 141 | - 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, | ||
| 142 | - 'artbox_comment.artbox_comment_pid' => null, | 145 | + 'artbox_comment.entity' => $owner::className(), |
| 146 | + 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, | ||
| 147 | + 'artbox_comment.parent_id' => null, | ||
| 143 | ] | 148 | ] |
| 144 | ); | 149 | ); |
| 145 | return $query; | 150 | return $query; |
| @@ -180,7 +185,7 @@ | @@ -180,7 +185,7 @@ | ||
| 180 | } | 185 | } |
| 181 | $averageRating = $this->getAverageRating() | 186 | $averageRating = $this->getAverageRating() |
| 182 | ->one(); | 187 | ->one(); |
| 183 | - if (!empty( $averageRating )) { | 188 | + if (!empty($averageRating)) { |
| 184 | $averageRating->setValue($average); | 189 | $averageRating->setValue($average); |
| 185 | } else { | 190 | } else { |
| 186 | /** | 191 | /** |
behaviors/ParentBehavior.php
| 1 | <?php | 1 | <?php |
| 2 | - namespace artweb\artbox\comment\behaviors; | ||
| 3 | 2 | ||
| 4 | - use artweb\artbox\comment\models\CommentModel; | 3 | + namespace artbox\webcomment\behaviors; |
| 4 | + | ||
| 5 | + use artbox\webcomment\models\CommentModel; | ||
| 5 | use yii\base\Behavior; | 6 | use yii\base\Behavior; |
| 6 | - use yii\base\Event; | ||
| 7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
| 8 | 8 | ||
| 9 | class ParentBehavior extends Behavior | 9 | class ParentBehavior extends Behavior |
| @@ -17,24 +17,24 @@ | @@ -17,24 +17,24 @@ | ||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | - * @param Event $event | 20 | + * After validate event |
| 21 | */ | 21 | */ |
| 22 | - public function afterValidate($event) | 22 | + public function afterValidate() |
| 23 | { | 23 | { |
| 24 | /** | 24 | /** |
| 25 | * @var CommentModel $owner | 25 | * @var CommentModel $owner |
| 26 | */ | 26 | */ |
| 27 | $owner = $this->owner; | 27 | $owner = $this->owner; |
| 28 | - if(!empty( $owner->artbox_comment_pid )) { | 28 | + if (!empty($owner->parent_id)) { |
| 29 | /** | 29 | /** |
| 30 | * @var CommentModel $parent | 30 | * @var CommentModel $parent |
| 31 | */ | 31 | */ |
| 32 | $parent = CommentModel::find() | 32 | $parent = CommentModel::find() |
| 33 | - ->where([ 'artbox_comment_id' => $owner->artbox_comment_pid ]) | 33 | + ->where([ 'id' => $owner->parent_id ]) |
| 34 | ->one(); | 34 | ->one(); |
| 35 | - if(!empty( $parent->artbox_comment_pid )) { | ||
| 36 | - $owner->related_id = $owner->artbox_comment_pid; | ||
| 37 | - $owner->artbox_comment_pid = $parent->artbox_comment_pid; | 35 | + if (!empty($parent->parent_id)) { |
| 36 | + $owner->related_id = $owner->parent_id; | ||
| 37 | + $owner->parent_id = $parent->parent_id; | ||
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
composer.json
| 1 | { | 1 | { |
| 2 | - "name": "artweb/artbox-comment", | ||
| 3 | - "description": "Yii2 light-weight CMS", | 2 | + "name": "artweb/artbox-webcomment", |
| 3 | + "description": "Artbox comment extension", | ||
| 4 | "license": "BSD-3-Clause", | 4 | "license": "BSD-3-Clause", |
| 5 | "minimum-stability": "dev", | 5 | "minimum-stability": "dev", |
| 6 | "type": "yii2-extension", | 6 | "type": "yii2-extension", |
| 7 | "require": { | 7 | "require": { |
| 8 | - "php": ">=5.4", | ||
| 9 | - "yiisoft/yii2": "*", | ||
| 10 | - "artweb/artbox": "dev-master" | 8 | + "php": ">=7.0", |
| 9 | + "yiisoft/yii2": "~2.0", | ||
| 10 | + "artweb/artbox-core": "~0.0.1" | ||
| 11 | }, | 11 | }, |
| 12 | "autoload": { | 12 | "autoload": { |
| 13 | "psr-4": { | 13 | "psr-4": { |
| 14 | - "artweb\\artbox\\comment\": "" | 14 | + "artbox\\webcomment\": "" |
| 15 | } | 15 | } |
| 16 | } | 16 | } |
| 17 | } | 17 | } |
| 18 | \ No newline at end of file | 18 | \ No newline at end of file |
controllers/DefaultController.php
| 1 | <?php | 1 | <?php |
| 2 | - namespace artweb\artbox\comment\controllers; | ||
| 3 | 2 | ||
| 4 | - use artweb\artbox\comment\models\CommentModel; | ||
| 5 | - use artweb\artbox\comment\models\RatingModel; | ||
| 6 | - use artweb\artbox\comment\Module; | 3 | + namespace artbox\webcomment\controllers; |
| 4 | + | ||
| 5 | + use artbox\webcomment\models\CommentModel; | ||
| 6 | + use artbox\webcomment\models\RatingModel; | ||
| 7 | + use artbox\webcomment\Module; | ||
| 7 | use yii\filters\AccessControl; | 8 | use yii\filters\AccessControl; |
| 8 | use yii\filters\VerbFilter; | 9 | use yii\filters\VerbFilter; |
| 9 | use yii\helpers\Json; | 10 | use yii\helpers\Json; |
| @@ -16,6 +17,7 @@ | @@ -16,6 +17,7 @@ | ||
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| 18 | * Returns a list of behaviors that this component should behave as. | 19 | * Returns a list of behaviors that this component should behave as. |
| 20 | + * | ||
| 19 | * @return array | 21 | * @return array |
| 20 | */ | 22 | */ |
| 21 | public function behaviors() | 23 | public function behaviors() |
| @@ -49,41 +51,53 @@ | @@ -49,41 +51,53 @@ | ||
| 49 | * | 51 | * |
| 50 | * @param string $entity | 52 | * @param string $entity |
| 51 | * | 53 | * |
| 52 | - * @return array|null|Response | 54 | + * @return array|null|\yii\web\Response |
| 55 | + * @throws \yii\base\InvalidConfigException | ||
| 53 | */ | 56 | */ |
| 54 | public function actionCreate(string $entity) | 57 | public function actionCreate(string $entity) |
| 55 | { | 58 | { |
| 56 | \Yii::$app->response->format = Response::FORMAT_JSON; | 59 | \Yii::$app->response->format = Response::FORMAT_JSON; |
| 57 | /* @var $module Module */ | 60 | /* @var $module Module */ |
| 58 | $module = \Yii::$app->getModule(Module::$name); | 61 | $module = \Yii::$app->getModule(Module::$name); |
| 62 | + if (!$module) { | ||
| 63 | + Module::registerMe(); | ||
| 64 | + } | ||
| 59 | $entity_data_json = \Yii::$app->getSecurity() | 65 | $entity_data_json = \Yii::$app->getSecurity() |
| 60 | ->decryptByKey($entity, $module::$encryptionKey); | 66 | ->decryptByKey($entity, $module::$encryptionKey); |
| 61 | - if($entity_data_json != false) { | 67 | + if ($entity_data_json != false) { |
| 62 | $entity_data = Json::decode($entity_data_json); | 68 | $entity_data = Json::decode($entity_data_json); |
| 63 | $commentModelClass = $module->commentModelClass; | 69 | $commentModelClass = $module->commentModelClass; |
| 64 | /** | 70 | /** |
| 65 | * @var CommentModel $model | 71 | * @var CommentModel $model |
| 66 | */ | 72 | */ |
| 67 | - $model = new $commentModelClass([ | ||
| 68 | - 'scenario' => \Yii::$app->user->getIsGuest() ? $commentModelClass::SCENARIO_GUEST : $commentModelClass::SCENARIO_USER, | ||
| 69 | - ]); | ||
| 70 | - if($model->load(\Yii::$app->request->post())) { | 73 | + $model = new $commentModelClass( |
| 74 | + [ | ||
| 75 | + 'scenario' => \Yii::$app->user->getIsGuest( | ||
| 76 | + ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER, | ||
| 77 | + ] | ||
| 78 | + ); | ||
| 79 | + if ($model->load(\Yii::$app->request->post())) { | ||
| 71 | $model->setAttributes($entity_data); | 80 | $model->setAttributes($entity_data); |
| 72 | - if($model->save()) { | ||
| 73 | - if(empty( $model->artbox_comment_pid ) && $module::$enableRating) { | 81 | + if ($model->save()) { |
| 82 | + if (empty($model->parent_id) && $module::$enableRating) { | ||
| 74 | $ratingModelClass = $module->ratingModelClass; | 83 | $ratingModelClass = $module->ratingModelClass; |
| 75 | /** | 84 | /** |
| 76 | * @var RatingModel $rating | 85 | * @var RatingModel $rating |
| 77 | */ | 86 | */ |
| 78 | - $rating = new $ratingModelClass([ | ||
| 79 | - 'model' => $model::className(), | ||
| 80 | - 'model_id' => $model->primaryKey, | ||
| 81 | - ]); | ||
| 82 | - if($rating->load(\Yii::$app->request->post())) { | 87 | + $rating = new $ratingModelClass( |
| 88 | + [ | ||
| 89 | + 'model' => $model::className(), | ||
| 90 | + 'model_id' => $model->primaryKey, | ||
| 91 | + ] | ||
| 92 | + ); | ||
| 93 | + if ($rating->load(\Yii::$app->request->post())) { | ||
| 83 | $rating->save(); | 94 | $rating->save(); |
| 84 | } | 95 | } |
| 85 | } | 96 | } |
| 86 | - \Yii::$app->session->setFlash('artbox_comment_success', \Yii::t('artbox-comment', 'Comment posted')); | 97 | + \Yii::$app->session->setFlash( |
| 98 | + 'artbox_comment_success', | ||
| 99 | + \Yii::t('artbox-comment', 'Comment posted') | ||
| 100 | + ); | ||
| 87 | return [ 'status' => 'success' ]; | 101 | return [ 'status' => 'success' ]; |
| 88 | } else { | 102 | } else { |
| 89 | return [ | 103 | return [ |
| @@ -104,20 +118,23 @@ | @@ -104,20 +118,23 @@ | ||
| 104 | * | 118 | * |
| 105 | * @param integer $id Comment ID | 119 | * @param integer $id Comment ID |
| 106 | * | 120 | * |
| 107 | - * @return string Comment text | 121 | + * @return array Comment text |
| 108 | */ | 122 | */ |
| 109 | public function actionDelete($id) | 123 | public function actionDelete($id) |
| 110 | { | 124 | { |
| 111 | \Yii::$app->response->format = Response::FORMAT_JSON; | 125 | \Yii::$app->response->format = Response::FORMAT_JSON; |
| 112 | $model = $this->findModel($id); | 126 | $model = $this->findModel($id); |
| 113 | - if($model->deleteComment()) { | 127 | + if ($model->deleteComment()) { |
| 114 | return [ | 128 | return [ |
| 115 | 'status' => 'success', | 129 | 'status' => 'success', |
| 116 | - 'message' => \Yii::t('yii2mod.comments', 'Comment has been deleted.'), | 130 | + 'message' => \Yii::t('artbox-comment', 'Comment has been deleted.'), |
| 117 | ]; | 131 | ]; |
| 118 | } else { | 132 | } else { |
| 119 | \Yii::$app->response->setStatusCode(500); | 133 | \Yii::$app->response->setStatusCode(500); |
| 120 | - return \Yii::t('yii2mod.comments', 'Comment has not been deleted. Please try again!'); | 134 | + return [ |
| 135 | + 'status' => 'error', | ||
| 136 | + 'message' => \Yii::t('artbox-comment', 'Comment has not been deleted. Please try again!'), | ||
| 137 | + ]; | ||
| 121 | } | 138 | } |
| 122 | } | 139 | } |
| 123 | 140 | ||
| @@ -126,17 +143,26 @@ | @@ -126,17 +143,26 @@ | ||
| 126 | * | 143 | * |
| 127 | * @param integer|array $id Comment ID | 144 | * @param integer|array $id Comment ID |
| 128 | * | 145 | * |
| 129 | - * @return CommentModel | ||
| 130 | - * @throws NotFoundHttpException | 146 | + * @return \artbox\webcomment\models\CommentModel |
| 147 | + * @throws \yii\base\InvalidConfigException | ||
| 148 | + * @throws \yii\web\NotFoundHttpException | ||
| 131 | */ | 149 | */ |
| 132 | protected function findModel(int $id): CommentModel | 150 | protected function findModel(int $id): CommentModel |
| 133 | { | 151 | { |
| 152 | + /** | ||
| 153 | + * @var Module $module | ||
| 154 | + */ | ||
| 155 | + $module = \Yii::$app->getModule(Module::$name); | ||
| 156 | + if (!$module) { | ||
| 157 | + Module::registerMe(); | ||
| 158 | + } | ||
| 134 | /** @var CommentModel $model */ | 159 | /** @var CommentModel $model */ |
| 135 | - $commentModelClass = \Yii::$app->getModule(Module::$name)->commentModelClass; | ||
| 136 | - if(( $model = $commentModelClass::findOne($id) ) !== NULL) { | ||
| 137 | - return $model; | ||
| 138 | - } else { | ||
| 139 | - throw new NotFoundHttpException(\Yii::t('yii2mod.comments', 'The requested page does not exist.')); | 160 | + $commentModelClass = $module->commentModelClass; |
| 161 | + if (method_exists($commentModelClass, 'findOne')) { | ||
| 162 | + if ($model = $commentModelClass::findOne($id) !== null) { | ||
| 163 | + return $model; | ||
| 164 | + } | ||
| 140 | } | 165 | } |
| 166 | + throw new NotFoundHttpException(\Yii::t('artbox-comment', 'The requested page does not exist.')); | ||
| 141 | } | 167 | } |
| 142 | } | 168 | } |
| 143 | \ No newline at end of file | 169 | \ No newline at end of file |
controllers/ManageController.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\controllers; | 3 | + namespace artbox\webcomment\controllers; |
| 4 | 4 | ||
| 5 | - use artweb\artbox\comment\models\CommentModel; | ||
| 6 | - use artweb\artbox\comment\models\CommentModelSearch; | ||
| 7 | - use artweb\artbox\comment\Module; | 5 | + use artbox\webcomment\models\CommentModel; |
| 6 | + use artbox\webcomment\models\CommentModelSearch; | ||
| 7 | + use artbox\webcomment\Module; | ||
| 8 | use Yii; | 8 | use Yii; |
| 9 | use yii\filters\VerbFilter; | 9 | use yii\filters\VerbFilter; |
| 10 | use yii\web\Controller; | 10 | use yii\web\Controller; |
| @@ -42,9 +42,16 @@ | @@ -42,9 +42,16 @@ | ||
| 42 | */ | 42 | */ |
| 43 | public function actionIndex() | 43 | public function actionIndex() |
| 44 | { | 44 | { |
| 45 | + /** | ||
| 46 | + * @var Module $module | ||
| 47 | + */ | ||
| 48 | + $module = \Yii::$app->getModule(Module::$name); | ||
| 49 | + if (!$module) { | ||
| 50 | + Module::registerMe(); | ||
| 51 | + } | ||
| 45 | $searchModel = new CommentModelSearch(); | 52 | $searchModel = new CommentModelSearch(); |
| 46 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | 53 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
| 47 | - $commentModel = Yii::$app->getModule(Module::$name)->commentModelClass; | 54 | + $commentModel = $module->commentModelClass; |
| 48 | 55 | ||
| 49 | return $this->render( | 56 | return $this->render( |
| 50 | 'index', | 57 | 'index', |
| @@ -67,10 +74,11 @@ | @@ -67,10 +74,11 @@ | ||
| 67 | public function actionUpdate($id) | 74 | public function actionUpdate($id) |
| 68 | { | 75 | { |
| 69 | $model = $this->findModel($id); | 76 | $model = $this->findModel($id); |
| 77 | + $model->scenario = $model::SCENARIO_ADMIN; | ||
| 70 | 78 | ||
| 71 | if ($model->load(Yii::$app->request->post()) && $model->save()) { | 79 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 72 | Yii::$app->session->setFlash( | 80 | Yii::$app->session->setFlash( |
| 73 | - 'artbox_comment_success', /*Yii::t('yii2mod.comments', 'Comment has been saved.')*/ | 81 | + 'artbox_comment_success', |
| 74 | 'Comment has been saved.' | 82 | 'Comment has been saved.' |
| 75 | ); | 83 | ); |
| 76 | return $this->redirect([ 'index' ]); | 84 | return $this->redirect([ 'index' ]); |
| @@ -84,12 +92,23 @@ | @@ -84,12 +92,23 @@ | ||
| 84 | ); | 92 | ); |
| 85 | 93 | ||
| 86 | } | 94 | } |
| 87 | - | 95 | + |
| 96 | + /** | ||
| 97 | + * Answer to particular comment from backend | ||
| 98 | + * | ||
| 99 | + * @param $id | ||
| 100 | + * | ||
| 101 | + * @return string|\yii\web\Response | ||
| 102 | + */ | ||
| 88 | public function actionAnswer($id) | 103 | public function actionAnswer($id) |
| 89 | { | 104 | { |
| 90 | $model = $this->findModel($id); | 105 | $model = $this->findModel($id); |
| 91 | - | ||
| 92 | - $answer = new CommentModel(); | 106 | + |
| 107 | + $answer = new CommentModel( | ||
| 108 | + [ | ||
| 109 | + 'scenario' => CommentModel::SCENARIO_ADMIN_ANSWER, | ||
| 110 | + ] | ||
| 111 | + ); | ||
| 93 | 112 | ||
| 94 | if ($answer->load(Yii::$app->request->post()) && $answer->save()) { | 113 | if ($answer->load(Yii::$app->request->post()) && $answer->save()) { |
| 95 | Yii::$app->session->setFlash( | 114 | Yii::$app->session->setFlash( |
| @@ -138,11 +157,11 @@ | @@ -138,11 +157,11 @@ | ||
| 138 | */ | 157 | */ |
| 139 | protected function findModel($id) | 158 | protected function findModel($id) |
| 140 | { | 159 | { |
| 141 | - if (( $model = CommentModel::findOne($id) ) !== NULL) { | 160 | + if (( $model = CommentModel::findOne($id) ) !== null) { |
| 142 | return $model; | 161 | return $model; |
| 143 | } else { | 162 | } else { |
| 144 | - throw new NotFoundHttpException(/*Yii::t('yii2mod.comments', 'The requested page does not exist.')*/ | ||
| 145 | - 'The requested page does not exist.' | 163 | + throw new NotFoundHttpException( |
| 164 | + \Yii::t('artbox-comment', 'The requested page does not exist.') | ||
| 146 | ); | 165 | ); |
| 147 | } | 166 | } |
| 148 | } | 167 | } |
migrations/m160724_162347_artbox_comment.php
| @@ -10,43 +10,40 @@ | @@ -10,43 +10,40 @@ | ||
| 10 | $this->createTable( | 10 | $this->createTable( |
| 11 | '{{%artbox_comment}}', | 11 | '{{%artbox_comment}}', |
| 12 | [ | 12 | [ |
| 13 | - 'artbox_comment_id' => $this->primaryKey(), | ||
| 14 | - 'text' => $this->text() | ||
| 15 | - ->notNull(), | ||
| 16 | - 'user_id' => $this->integer(), | ||
| 17 | - 'username' => $this->string(), | ||
| 18 | - 'email' => $this->string(), | ||
| 19 | - 'created_at' => $this->integer() | ||
| 20 | - ->notNull(), | ||
| 21 | - 'updated_at' => $this->integer() | ||
| 22 | - ->notNull(), | ||
| 23 | - 'deleted_at' => $this->integer(), | ||
| 24 | - 'status' => $this->integer() | ||
| 25 | - ->notNull() | ||
| 26 | - ->defaultValue(1), | ||
| 27 | - 'artbox_comment_pid' => $this->integer(), | ||
| 28 | - 'related_id' => $this->integer(), | ||
| 29 | - 'ip' => $this->string() | ||
| 30 | - ->notNull(), | ||
| 31 | - 'info' => $this->text(), | 13 | + 'id' => $this->primaryKey(), |
| 14 | + 'text' => $this->text() | ||
| 15 | + ->notNull(), | ||
| 16 | + 'customer_id' => $this->integer(), | ||
| 17 | + 'username' => $this->string(), | ||
| 18 | + 'email' => $this->string(), | ||
| 19 | + 'created_at' => $this->integer() | ||
| 20 | + ->notNull(), | ||
| 21 | + 'updated_at' => $this->integer() | ||
| 22 | + ->notNull(), | ||
| 23 | + 'deleted_at' => $this->integer(), | ||
| 24 | + 'status' => $this->integer() | ||
| 25 | + ->notNull() | ||
| 26 | + ->defaultValue(1), | ||
| 27 | + 'parent_id' => $this->integer(), | ||
| 28 | + 'related_id' => $this->integer(), | ||
| 29 | + 'ip' => $this->string() | ||
| 30 | + ->notNull(), | ||
| 31 | + 'info' => $this->text(), | ||
| 32 | + 'entity' => $this->string() | ||
| 33 | + ->notNull() | ||
| 34 | + ->defaultValue(''), | ||
| 35 | + 'entity_id' => $this->integer() | ||
| 36 | + ->notNull() | ||
| 37 | + ->defaultValue(1), | ||
| 32 | ] | 38 | ] |
| 33 | ); | 39 | ); |
| 34 | 40 | ||
| 35 | $this->addForeignKey( | 41 | $this->addForeignKey( |
| 36 | - 'user_id_user', | 42 | + 'parent_id_artbox_comment', |
| 37 | '{{%artbox_comment}}', | 43 | '{{%artbox_comment}}', |
| 38 | - 'user_id', | ||
| 39 | - 'customer', | ||
| 40 | - 'id', | ||
| 41 | - 'CASCADE', | ||
| 42 | - 'CASCADE' | ||
| 43 | - ); | ||
| 44 | - $this->addForeignKey( | ||
| 45 | - 'artbox_comment_pid_artbox_comment', | ||
| 46 | - '{{%artbox_comment}}', | ||
| 47 | - 'artbox_comment_pid', | 44 | + 'parent_id', |
| 48 | 'artbox_comment', | 45 | 'artbox_comment', |
| 49 | - 'artbox_comment_id', | 46 | + 'id', |
| 50 | 'CASCADE', | 47 | 'CASCADE', |
| 51 | 'CASCADE' | 48 | 'CASCADE' |
| 52 | ); | 49 | ); |
| @@ -55,7 +52,7 @@ | @@ -55,7 +52,7 @@ | ||
| 55 | '{{%artbox_comment}}', | 52 | '{{%artbox_comment}}', |
| 56 | 'related_id', | 53 | 'related_id', |
| 57 | 'artbox_comment', | 54 | 'artbox_comment', |
| 58 | - 'artbox_comment_id', | 55 | + 'id', |
| 59 | 'CASCADE', | 56 | 'CASCADE', |
| 60 | 'CASCADE' | 57 | 'CASCADE' |
| 61 | ); | 58 | ); |
| @@ -63,10 +60,10 @@ | @@ -63,10 +60,10 @@ | ||
| 63 | $this->createTable( | 60 | $this->createTable( |
| 64 | '{{%artbox_like}}', | 61 | '{{%artbox_like}}', |
| 65 | [ | 62 | [ |
| 66 | - 'artbox_like_id' => $this->primaryKey(), | 63 | + 'id' => $this->primaryKey(), |
| 67 | 'artbox_comment_id' => $this->integer() | 64 | 'artbox_comment_id' => $this->integer() |
| 68 | ->notNull(), | 65 | ->notNull(), |
| 69 | - 'user_id' => $this->integer(), | 66 | + 'customer_id' => $this->integer(), |
| 70 | 'created_at' => $this->integer() | 67 | 'created_at' => $this->integer() |
| 71 | ->notNull(), | 68 | ->notNull(), |
| 72 | 'is_like' => $this->integer() | 69 | 'is_like' => $this->integer() |
| @@ -80,17 +77,16 @@ | @@ -80,17 +77,16 @@ | ||
| 80 | '{{%artbox_like}}', | 77 | '{{%artbox_like}}', |
| 81 | 'artbox_comment_id', | 78 | 'artbox_comment_id', |
| 82 | 'artbox_comment', | 79 | 'artbox_comment', |
| 83 | - 'artbox_comment_id', | 80 | + 'id', |
| 84 | 'CASCADE', | 81 | 'CASCADE', |
| 85 | 'CASCADE' | 82 | 'CASCADE' |
| 86 | ); | 83 | ); |
| 87 | - $this->addForeignKey('user_id_user', '{{%artbox_like}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE'); | ||
| 88 | $this->createIndex( | 84 | $this->createIndex( |
| 89 | 'artbox_like_unique', | 85 | 'artbox_like_unique', |
| 90 | '{{%artbox_like}}', | 86 | '{{%artbox_like}}', |
| 91 | [ | 87 | [ |
| 92 | 'artbox_comment_id', | 88 | 'artbox_comment_id', |
| 93 | - 'user_id', | 89 | + 'customer_id', |
| 94 | 'is_like', | 90 | 'is_like', |
| 95 | ], | 91 | ], |
| 96 | true | 92 | true |
| @@ -100,11 +96,9 @@ | @@ -100,11 +96,9 @@ | ||
| 100 | 96 | ||
| 101 | public function down() | 97 | public function down() |
| 102 | { | 98 | { |
| 103 | - $this->dropForeignKey('user_id_user', '{{%artbox_comment}}'); | ||
| 104 | - $this->dropForeignKey('artbox_comment_pid_artbox_comment', '{{%artbox_comment}}'); | 99 | + $this->dropForeignKey('parent_id_artbox_comment', '{{%artbox_comment}}'); |
| 105 | $this->dropForeignKey('related_id_artbox_comment', '{{%artbox_comment}}'); | 100 | $this->dropForeignKey('related_id_artbox_comment', '{{%artbox_comment}}'); |
| 106 | $this->dropForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}'); | 101 | $this->dropForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}'); |
| 107 | - $this->dropForeignKey('user_id_user', '{{%artbox_like}}'); | ||
| 108 | $this->dropIndex('artbox_like_unique', '{{%artbox_like}}'); | 102 | $this->dropIndex('artbox_like_unique', '{{%artbox_like}}'); |
| 109 | $this->dropTable('{{%artbox_comment}}'); | 103 | $this->dropTable('{{%artbox_comment}}'); |
| 110 | $this->dropTable('{{%artbox_like}}'); | 104 | $this->dropTable('{{%artbox_like}}'); |
migrations/m160726_092634_add_entity_fields.php deleted
| 1 | -<?php | ||
| 2 | - | ||
| 3 | - use yii\db\Migration; | ||
| 4 | - | ||
| 5 | - class m160726_092634_add_entity_fields extends Migration | ||
| 6 | - { | ||
| 7 | - | ||
| 8 | - public function up() | ||
| 9 | - { | ||
| 10 | - $this->addColumn('{{%artbox_comment}}', 'entity', $this->string() | ||
| 11 | - ->notNull() | ||
| 12 | - ->defaultValue('')); | ||
| 13 | - $this->addColumn('{{%artbox_comment}}', 'entity_id', $this->integer() | ||
| 14 | - ->notNull() | ||
| 15 | - ->defaultValue(1)); | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - public function down() | ||
| 19 | - { | ||
| 20 | - $this->dropColumn('{{%artbox_comment}}', 'entity'); | ||
| 21 | - $this->dropColumn('{{%artbox_comment}}', 'entity_id'); | ||
| 22 | - } | ||
| 23 | - } |
migrations/m160726_211227_create_artbox_comment_rating.php
| @@ -10,33 +10,23 @@ | @@ -10,33 +10,23 @@ | ||
| 10 | $this->createTable( | 10 | $this->createTable( |
| 11 | '{{%artbox_comment_rating}}', | 11 | '{{%artbox_comment_rating}}', |
| 12 | [ | 12 | [ |
| 13 | - 'artbox_comment_rating_id' => $this->primaryKey(), | ||
| 14 | - 'created_at' => $this->integer() | ||
| 15 | - ->notNull(), | ||
| 16 | - 'updated_at' => $this->integer() | ||
| 17 | - ->notNull(), | ||
| 18 | - 'user_id' => $this->integer(), | ||
| 19 | - 'value' => $this->float(), | ||
| 20 | - 'model' => $this->string() | ||
| 21 | - ->notNull(), | ||
| 22 | - 'model_id' => $this->integer() | ||
| 23 | - ->notNull(), | 13 | + 'id' => $this->primaryKey(), |
| 14 | + 'created_at' => $this->integer() | ||
| 15 | + ->notNull(), | ||
| 16 | + 'updated_at' => $this->integer() | ||
| 17 | + ->notNull(), | ||
| 18 | + 'customer_id' => $this->integer(), | ||
| 19 | + 'value' => $this->float(), | ||
| 20 | + 'model' => $this->string() | ||
| 21 | + ->notNull(), | ||
| 22 | + 'model_id' => $this->integer() | ||
| 23 | + ->notNull(), | ||
| 24 | ] | 24 | ] |
| 25 | ); | 25 | ); |
| 26 | - $this->addForeignKey( | ||
| 27 | - 'user_id_user', | ||
| 28 | - '{{%artbox_comment_rating}}', | ||
| 29 | - 'user_id', | ||
| 30 | - 'customer', | ||
| 31 | - 'id', | ||
| 32 | - 'CASCADE', | ||
| 33 | - 'CASCADE' | ||
| 34 | - ); | ||
| 35 | } | 26 | } |
| 36 | 27 | ||
| 37 | public function down() | 28 | public function down() |
| 38 | { | 29 | { |
| 39 | - $this->dropForeignKey('user_id_user', '{{%artbox_comment_rating}}'); | ||
| 40 | $this->dropTable('{{%artbox_comment_rating}}'); | 30 | $this->dropTable('{{%artbox_comment_rating}}'); |
| 41 | } | 31 | } |
| 42 | } | 32 | } |
migrations/order-to-comment/m170525_095043_order_to_comment.php
0 → 100755
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use yii\db\Migration; | ||
| 4 | + | ||
| 5 | + class m170525_095043_order_to_comment extends Migration | ||
| 6 | + { | ||
| 7 | + public function safeUp() | ||
| 8 | + { | ||
| 9 | + $this->addForeignKey( | ||
| 10 | + 'customer_id_customer', | ||
| 11 | + '{{%artbox_comment}}', | ||
| 12 | + 'customer_id', | ||
| 13 | + 'customer', | ||
| 14 | + 'id', | ||
| 15 | + 'CASCADE', | ||
| 16 | + 'CASCADE' | ||
| 17 | + ); | ||
| 18 | + | ||
| 19 | + $this->addForeignKey( | ||
| 20 | + 'customer_id_customer', | ||
| 21 | + '{{%artbox_like}}', | ||
| 22 | + 'customer_id', | ||
| 23 | + 'customer', | ||
| 24 | + 'id', | ||
| 25 | + 'CASCADE', | ||
| 26 | + 'CASCADE' | ||
| 27 | + ); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public function safeDown() | ||
| 31 | + { | ||
| 32 | + $this->dropForeignKey('customer_id_customer', '{{%artbox_comment}}'); | ||
| 33 | + $this->dropForeignKey('customer_id_customer', '{{%artbox_like}}'); | ||
| 34 | + } | ||
| 35 | + } |
migrations/order-to-comment/m170525_095044_order_to_rating.php
0 → 100755
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + use yii\db\Migration; | ||
| 4 | + | ||
| 5 | + class m170525_095044_order_to_rating extends Migration | ||
| 6 | + { | ||
| 7 | + public function safeUp() | ||
| 8 | + { | ||
| 9 | + $this->addForeignKey( | ||
| 10 | + 'customer_id_customer', | ||
| 11 | + '{{%artbox_comment_rating}}', | ||
| 12 | + 'customer_id', | ||
| 13 | + 'customer', | ||
| 14 | + 'id', | ||
| 15 | + 'CASCADE', | ||
| 16 | + 'CASCADE' | ||
| 17 | + ); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public function safeDown() | ||
| 21 | + { | ||
| 22 | + $this->dropForeignKey('customer_id_customer', '{{%artbox_comment_rating}}'); | ||
| 23 | + | ||
| 24 | + } | ||
| 25 | + } |
models/CommentModel.php
| 1 | <?php | 1 | <?php |
| 2 | - namespace artweb\artbox\comment\models; | ||
| 3 | 2 | ||
| 4 | - use artweb\artbox\comment\behaviors\ParentBehavior; | ||
| 5 | - use artweb\artbox\comment\models\interfaces\CommentInterface; | ||
| 6 | - use artweb\artbox\ecommerce\models\Product; | 3 | + namespace artbox\webcomment\models; |
| 4 | + | ||
| 5 | + use artbox\webcomment\behaviors\ParentBehavior; | ||
| 6 | + use artbox\webcomment\models\interfaces\CommentInterface; | ||
| 7 | use yii\behaviors\AttributeBehavior; | 7 | use yii\behaviors\AttributeBehavior; |
| 8 | use yii\behaviors\BlameableBehavior; | 8 | use yii\behaviors\BlameableBehavior; |
| 9 | use yii\behaviors\TimestampBehavior; | 9 | use yii\behaviors\TimestampBehavior; |
| 10 | use yii\data\ActiveDataProvider; | 10 | use yii\data\ActiveDataProvider; |
| 11 | use yii\db\ActiveRecord; | 11 | use yii\db\ActiveRecord; |
| 12 | - use yii\helpers\Html; | ||
| 13 | - use yii\helpers\VarDumper; | ||
| 14 | 12 | ||
| 15 | /** | 13 | /** |
| 16 | * Class CommentModel | 14 | * Class CommentModel |
| 17 | * | 15 | * |
| 18 | - * @property int $artbox_comment_id | ||
| 19 | - * @property string $text | ||
| 20 | - * @property int $user_id | ||
| 21 | - * @property string $username | ||
| 22 | - * @property string $email | ||
| 23 | - * @property int $created_at | ||
| 24 | - * @property int $updated_at | ||
| 25 | - * @property int $deleted_at | ||
| 26 | - * @property int $status | ||
| 27 | - * @property int $artbox_comment_pid | ||
| 28 | - * @property int $related_id | ||
| 29 | - * @property string $ip | ||
| 30 | - * @property string $info | ||
| 31 | - * @property string $entity | ||
| 32 | - * @property int $entity_id | ||
| 33 | - * @package artweb\artbox\comment\models | ||
| 34 | - * @property ActiveRecord $entityModel | ||
| 35 | - * @property string $link | 16 | + * @property int $id |
| 17 | + * @property string $text | ||
| 18 | + * @property int $customer_id | ||
| 19 | + * @property string $username | ||
| 20 | + * @property string $email | ||
| 21 | + * @property int $created_at | ||
| 22 | + * @property int $updated_at | ||
| 23 | + * @property int $deleted_at | ||
| 24 | + * @property int $status | ||
| 25 | + * @property int $parent_id | ||
| 26 | + * @property int $related_id | ||
| 27 | + * @property string $ip | ||
| 28 | + * @property string $info | ||
| 29 | + * @property string $entity | ||
| 30 | + * @property int $entity_id | ||
| 31 | + * @property ActiveRecord $entityModel | ||
| 32 | + * @property string $link | ||
| 33 | + * @property \artbox\webcomment\models\CommentModel[] $children | ||
| 34 | + * @property \artbox\order\models\Customer $customer | ||
| 36 | */ | 35 | */ |
| 37 | class CommentModel extends ActiveRecord implements CommentInterface | 36 | class CommentModel extends ActiveRecord implements CommentInterface |
| 38 | { | 37 | { |
| @@ -43,11 +42,16 @@ | @@ -43,11 +42,16 @@ | ||
| 43 | 42 | ||
| 44 | const SCENARIO_USER = 'user'; | 43 | const SCENARIO_USER = 'user'; |
| 45 | const SCENARIO_GUEST = 'guest'; | 44 | const SCENARIO_GUEST = 'guest'; |
| 45 | + const SCENARIO_ADMIN = 'admin'; | ||
| 46 | + const SCENARIO_ADMIN_ANSWER = 'admin'; | ||
| 46 | 47 | ||
| 47 | public $encryptedEntity; | 48 | public $encryptedEntity; |
| 48 | 49 | ||
| 49 | public $entityId; | 50 | public $entityId; |
| 50 | - | 51 | + |
| 52 | + /** | ||
| 53 | + * @inheritdoc | ||
| 54 | + */ | ||
| 51 | public function scenarios() | 55 | public function scenarios() |
| 52 | { | 56 | { |
| 53 | $scenarios = parent::scenarios(); | 57 | $scenarios = parent::scenarios(); |
| @@ -55,7 +59,7 @@ | @@ -55,7 +59,7 @@ | ||
| 55 | 'text', | 59 | 'text', |
| 56 | 'entity', | 60 | 'entity', |
| 57 | 'entity_id', | 61 | 'entity_id', |
| 58 | - 'artbox_comment_pid', | 62 | + 'parent_id', |
| 59 | 'status', | 63 | 'status', |
| 60 | ]; | 64 | ]; |
| 61 | $scenarios[ self::SCENARIO_GUEST ] = [ | 65 | $scenarios[ self::SCENARIO_GUEST ] = [ |
| @@ -66,14 +70,32 @@ | @@ -66,14 +70,32 @@ | ||
| 66 | 'email', | 70 | 'email', |
| 67 | 'status', | 71 | 'status', |
| 68 | ]; | 72 | ]; |
| 73 | + $scenarios[ self::SCENARIO_ADMIN ] = [ | ||
| 74 | + 'text', | ||
| 75 | + 'status', | ||
| 76 | + ]; | ||
| 77 | + $scenarios[ self::SCENARIO_ADMIN_ANSWER ] = [ | ||
| 78 | + 'text', | ||
| 79 | + 'parent_id', | ||
| 80 | + 'customer_id', | ||
| 81 | + 'entity', | ||
| 82 | + 'entity_id', | ||
| 83 | + 'status', | ||
| 84 | + ]; | ||
| 69 | return $scenarios; | 85 | return $scenarios; |
| 70 | } | 86 | } |
| 71 | - | 87 | + |
| 88 | + /** | ||
| 89 | + * @inheritdoc | ||
| 90 | + */ | ||
| 72 | public static function tableName() | 91 | public static function tableName() |
| 73 | { | 92 | { |
| 74 | return '{{%artbox_comment}}'; | 93 | return '{{%artbox_comment}}'; |
| 75 | } | 94 | } |
| 76 | - | 95 | + |
| 96 | + /** | ||
| 97 | + * @inheritdoc | ||
| 98 | + */ | ||
| 77 | public function rules() | 99 | public function rules() |
| 78 | { | 100 | { |
| 79 | return [ | 101 | return [ |
| @@ -82,16 +104,10 @@ | @@ -82,16 +104,10 @@ | ||
| 82 | 'text', | 104 | 'text', |
| 83 | 'entity', | 105 | 'entity', |
| 84 | 'entity_id', | 106 | 'entity_id', |
| 85 | - ], | ||
| 86 | - 'required', | ||
| 87 | - ], | ||
| 88 | - [ | ||
| 89 | - [ | ||
| 90 | 'username', | 107 | 'username', |
| 91 | 'email', | 108 | 'email', |
| 92 | ], | 109 | ], |
| 93 | 'required', | 110 | 'required', |
| 94 | - 'on' => self::SCENARIO_GUEST, | ||
| 95 | ], | 111 | ], |
| 96 | [ | 112 | [ |
| 97 | [ | 113 | [ |
| @@ -110,7 +126,7 @@ | @@ -110,7 +126,7 @@ | ||
| 110 | [ | 126 | [ |
| 111 | [ | 127 | [ |
| 112 | 'entity_id', | 128 | 'entity_id', |
| 113 | - 'artbox_comment_pid', | 129 | + 'parent_id', |
| 114 | ], | 130 | ], |
| 115 | 'integer', | 131 | 'integer', |
| 116 | ], | 132 | ], |
| @@ -120,14 +136,17 @@ | @@ -120,14 +136,17 @@ | ||
| 120 | 'value' => 0, | 136 | 'value' => 0, |
| 121 | ], | 137 | ], |
| 122 | [ | 138 | [ |
| 123 | - [ 'artbox_comment_pid' ], | 139 | + [ 'parent_id' ], |
| 124 | 'exist', | 140 | 'exist', |
| 125 | - 'targetAttribute' => 'artbox_comment_id', | 141 | + 'targetAttribute' => 'id', |
| 126 | 'skipOnError' => true, | 142 | 'skipOnError' => true, |
| 127 | ], | 143 | ], |
| 128 | ]; | 144 | ]; |
| 129 | } | 145 | } |
| 130 | - | 146 | + |
| 147 | + /** | ||
| 148 | + * @inheritdoc | ||
| 149 | + */ | ||
| 131 | public function behaviors() | 150 | public function behaviors() |
| 132 | { | 151 | { |
| 133 | return [ | 152 | return [ |
| @@ -136,7 +155,7 @@ | @@ -136,7 +155,7 @@ | ||
| 136 | ], | 155 | ], |
| 137 | [ | 156 | [ |
| 138 | 'class' => BlameableBehavior::className(), | 157 | 'class' => BlameableBehavior::className(), |
| 139 | - 'createdByAttribute' => 'user_id', | 158 | + 'createdByAttribute' => 'customer_id', |
| 140 | 'updatedByAttribute' => false, | 159 | 'updatedByAttribute' => false, |
| 141 | ], | 160 | ], |
| 142 | [ | 161 | [ |
| @@ -144,7 +163,7 @@ | @@ -144,7 +163,7 @@ | ||
| 144 | 'attributes' => [ | 163 | 'attributes' => [ |
| 145 | ActiveRecord::EVENT_BEFORE_INSERT => 'ip', | 164 | ActiveRecord::EVENT_BEFORE_INSERT => 'ip', |
| 146 | ], | 165 | ], |
| 147 | - 'value' => function($event) { | 166 | + 'value' => function () { |
| 148 | return \Yii::$app->request->userIP; | 167 | return \Yii::$app->request->userIP; |
| 149 | }, | 168 | }, |
| 150 | ], | 169 | ], |
| @@ -153,58 +172,88 @@ | @@ -153,58 +172,88 @@ | ||
| 153 | ], | 172 | ], |
| 154 | ]; | 173 | ]; |
| 155 | } | 174 | } |
| 156 | - | 175 | + |
| 176 | + /** | ||
| 177 | + * @inheritdoc | ||
| 178 | + */ | ||
| 157 | public function attributeLabels() | 179 | public function attributeLabels() |
| 158 | { | 180 | { |
| 159 | return [ | 181 | return [ |
| 160 | - 'artbox_comment_id' => \Yii::t('artbox-comment', 'ID'), | ||
| 161 | - 'text' => \Yii::t('artbox-comment', 'Text'), | ||
| 162 | - 'user_id' => \Yii::t('artbox-comment', 'User'), | ||
| 163 | - 'username' => \Yii::t('artbox-comment', 'Username'), | ||
| 164 | - 'email' => 'Email', | ||
| 165 | - 'date_add' => \Yii::t('artbox-comment', 'Date add'), | ||
| 166 | - 'updated_at' => \Yii::t('artbox-comment', 'Date update'), | ||
| 167 | - 'deleted_at' => \Yii::t('artbox-comment', 'Date delete'), | ||
| 168 | - 'status' => \Yii::t('artbox-comment', 'Status'), | ||
| 169 | - 'artbox_comment_pid' => \Yii::t('artbox-comment', 'Comment parent'), | ||
| 170 | - 'related_id' => \Yii::t('artbox-comment', 'Comment related'), | ||
| 171 | - 'ip' => 'IP', | ||
| 172 | - 'entity' => \Yii::t('artbox-comment', 'Entity'), | ||
| 173 | - 'info' => \Yii::t('artbox-comment', 'Info'), | ||
| 174 | - 'entity_id' => \Yii::t('artbox-comment', 'Entity ID'), | 182 | + 'id' => \Yii::t('artbox-comment', 'ID'), |
| 183 | + 'text' => \Yii::t('artbox-comment', 'Text'), | ||
| 184 | + 'customer_id' => \Yii::t('artbox-comment', 'User'), | ||
| 185 | + 'username' => \Yii::t('artbox-comment', 'Username'), | ||
| 186 | + 'email' => 'Email', | ||
| 187 | + 'created_at' => \Yii::t('artbox-comment', 'Date add'), | ||
| 188 | + 'updated_at' => \Yii::t('artbox-comment', 'Date update'), | ||
| 189 | + 'deleted_at' => \Yii::t('artbox-comment', 'Date delete'), | ||
| 190 | + 'status' => \Yii::t('artbox-comment', 'Status'), | ||
| 191 | + 'parent_id' => \Yii::t('artbox-comment', 'Comment parent'), | ||
| 192 | + 'related_id' => \Yii::t('artbox-comment', 'Comment related'), | ||
| 193 | + 'ip' => 'IP', | ||
| 194 | + 'entity' => \Yii::t('artbox-comment', 'Entity'), | ||
| 195 | + 'info' => \Yii::t('artbox-comment', 'Info'), | ||
| 196 | + 'entity_id' => \Yii::t('artbox-comment', 'Entity ID'), | ||
| 175 | ]; | 197 | ]; |
| 176 | } | 198 | } |
| 177 | - | 199 | + |
| 200 | + /** | ||
| 201 | + * Set Entity of Comment model | ||
| 202 | + * | ||
| 203 | + * @param string $entity | ||
| 204 | + */ | ||
| 178 | public function setEntity(string $entity) | 205 | public function setEntity(string $entity) |
| 179 | { | 206 | { |
| 180 | $this->entity = $entity; | 207 | $this->entity = $entity; |
| 181 | } | 208 | } |
| 182 | - | 209 | + |
| 210 | + /** | ||
| 211 | + * Get Entity of Comment model | ||
| 212 | + * | ||
| 213 | + * @return string | ||
| 214 | + */ | ||
| 183 | public function getEntity(): string | 215 | public function getEntity(): string |
| 184 | { | 216 | { |
| 185 | return $this->entity; | 217 | return $this->entity; |
| 186 | } | 218 | } |
| 187 | - | 219 | + |
| 220 | + /** | ||
| 221 | + * Get ActiveDataProvider of comments for particular Entity according to its EntityId | ||
| 222 | + * | ||
| 223 | + * @param string $entity Entity name | ||
| 224 | + * @param int $entityId Entity Id | ||
| 225 | + * | ||
| 226 | + * @return \yii\data\ActiveDataProvider | ||
| 227 | + */ | ||
| 188 | public static function getTree(string $entity, int $entityId): ActiveDataProvider | 228 | public static function getTree(string $entity, int $entityId): ActiveDataProvider |
| 189 | { | 229 | { |
| 230 | + $query = self::find() | ||
| 231 | + ->with( | ||
| 232 | + [ | ||
| 233 | + 'children' => function ($query) { | ||
| 234 | + /** | ||
| 235 | + * @var \yii\db\ActiveQuery $query | ||
| 236 | + */ | ||
| 237 | + if (class_exists(self::getCustomerClass())) { | ||
| 238 | + $query->with('customer'); | ||
| 239 | + } | ||
| 240 | + }, | ||
| 241 | + ] | ||
| 242 | + ) | ||
| 243 | + ->where( | ||
| 244 | + [ | ||
| 245 | + 'entity' => $entity, | ||
| 246 | + 'entity_id' => $entityId, | ||
| 247 | + 'status' => self::STATUS_ACTIVE, | ||
| 248 | + 'parent_id' => null, | ||
| 249 | + ] | ||
| 250 | + ); | ||
| 251 | + if (class_exists(self::getCustomerClass())) { | ||
| 252 | + $query->with('customer'); | ||
| 253 | + } | ||
| 190 | return new ActiveDataProvider( | 254 | return new ActiveDataProvider( |
| 191 | [ | 255 | [ |
| 192 | - 'query' => self::find() | ||
| 193 | - ->with( | ||
| 194 | - [ | ||
| 195 | - 'children', | ||
| 196 | - 'user', | ||
| 197 | - 'children.user', | ||
| 198 | - ] | ||
| 199 | - ) | ||
| 200 | - ->where( | ||
| 201 | - [ | ||
| 202 | - 'entity' => $entity, | ||
| 203 | - 'entity_id' => $entityId, | ||
| 204 | - 'status' => 1, | ||
| 205 | - 'artbox_comment_pid' => NULL, | ||
| 206 | - ] | ||
| 207 | - ), | 256 | + 'query' => $query, |
| 208 | 'pagination' => [ | 257 | 'pagination' => [ |
| 209 | 'pageSize' => 20, | 258 | 'pageSize' => 20, |
| 210 | ], | 259 | ], |
| @@ -216,93 +265,128 @@ | @@ -216,93 +265,128 @@ | ||
| 216 | ] | 265 | ] |
| 217 | ); | 266 | ); |
| 218 | } | 267 | } |
| 219 | - | 268 | + |
| 269 | + /** | ||
| 270 | + * Delete comment | ||
| 271 | + * | ||
| 272 | + * @return bool | ||
| 273 | + */ | ||
| 220 | public function deleteComment(): bool | 274 | public function deleteComment(): bool |
| 221 | { | 275 | { |
| 222 | - if (\Yii::$app->user->id != NULL && \Yii::$app->user->id == $this->user_id) { | 276 | + if (!\Yii::$app->user->isGuest && \Yii::$app->user->id == $this->customer_id) { |
| 223 | if ($this->delete()) { | 277 | if ($this->delete()) { |
| 224 | return true; | 278 | return true; |
| 225 | } | 279 | } |
| 226 | } | 280 | } |
| 227 | return false; | 281 | return false; |
| 228 | } | 282 | } |
| 229 | - | 283 | + |
| 284 | + /** | ||
| 285 | + * Set EntityId of Comment model | ||
| 286 | + * | ||
| 287 | + * @param int $entityId | ||
| 288 | + */ | ||
| 230 | public function setEntityId(int $entityId) | 289 | public function setEntityId(int $entityId) |
| 231 | { | 290 | { |
| 232 | $this->entityId = $entityId; | 291 | $this->entityId = $entityId; |
| 233 | } | 292 | } |
| 234 | - | 293 | + |
| 294 | + /** | ||
| 295 | + * Get EntityId of Comment model | ||
| 296 | + * | ||
| 297 | + * @return int | ||
| 298 | + */ | ||
| 235 | public function getEntityId(): int | 299 | public function getEntityId(): int |
| 236 | { | 300 | { |
| 237 | return $this->entityId; | 301 | return $this->entityId; |
| 238 | } | 302 | } |
| 239 | - | 303 | + |
| 304 | + /** | ||
| 305 | + * Get children relation for current comment | ||
| 306 | + * | ||
| 307 | + * @return \yii\db\ActiveQuery | ||
| 308 | + */ | ||
| 240 | public function getChildren() | 309 | public function getChildren() |
| 241 | { | 310 | { |
| 242 | - return $this->hasMany(self::className(), [ 'artbox_comment_pid' => 'artbox_comment_id' ]) | 311 | + return $this->hasMany(self::className(), [ 'parent_id' => 'id' ]) |
| 243 | ->andFilterWhere([ 'status' => self::STATUS_ACTIVE ]) | 312 | ->andFilterWhere([ 'status' => self::STATUS_ACTIVE ]) |
| 244 | ->inverseOf('parent'); | 313 | ->inverseOf('parent'); |
| 245 | } | 314 | } |
| 246 | - | 315 | + |
| 316 | + /** | ||
| 317 | + * Get parent relation for current comment | ||
| 318 | + * | ||
| 319 | + * @return \yii\db\ActiveQuery | ||
| 320 | + */ | ||
| 247 | public function getParent() | 321 | public function getParent() |
| 248 | { | 322 | { |
| 249 | - return $this->hasOne(self::className(), [ 'artbox_comment_id' => 'artbox_comment_pid' ]) | 323 | + return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]) |
| 250 | ->inverseOf('children'); | 324 | ->inverseOf('children'); |
| 251 | } | 325 | } |
| 252 | - | ||
| 253 | - public function getUser() | 326 | + |
| 327 | + /** | ||
| 328 | + * Get customer relation for current comment | ||
| 329 | + * | ||
| 330 | + * @return \yii\db\ActiveQuery | ||
| 331 | + */ | ||
| 332 | + public function getCustomer() | ||
| 254 | { | 333 | { |
| 255 | - $module = \Yii::$app->getModule('artbox-comment'); | ||
| 256 | - return $this->hasOne($module->userIdentityClass, [ 'id' => 'user_id' ]); | 334 | + return $this->hasOne(self::getCustomerClass(), [ 'id' => 'customer_id' ]); |
| 257 | } | 335 | } |
| 258 | - | 336 | + |
| 337 | + /** | ||
| 338 | + * Get rating relation for current model | ||
| 339 | + * | ||
| 340 | + * @return \yii\db\ActiveQuery | ||
| 341 | + */ | ||
| 259 | public function getRating() | 342 | public function getRating() |
| 260 | { | 343 | { |
| 261 | - return $this->hasOne(RatingModel::className(), [ 'model_id' => 'artbox_comment_id' ]) | 344 | + return $this->hasOne(RatingModel::className(), [ 'model_id' => 'id' ]) |
| 262 | ->andWhere( | 345 | ->andWhere( |
| 263 | [ | 346 | [ |
| 264 | 'or', | 347 | 'or', |
| 265 | - [ 'artbox_comment_rating.model' => NULL ], | 348 | + [ 'artbox_comment_rating.model' => null ], |
| 266 | [ 'artbox_comment_rating.model' => self::className() ], | 349 | [ 'artbox_comment_rating.model' => self::className() ], |
| 267 | ] | 350 | ] |
| 268 | ); | 351 | ); |
| 269 | } | 352 | } |
| 270 | - | 353 | + |
| 354 | + /** | ||
| 355 | + * Get entity model for current comment or false if not ActiveRecord | ||
| 356 | + * | ||
| 357 | + * @return ActiveRecord|false | ||
| 358 | + */ | ||
| 271 | public function getEntityModel() | 359 | public function getEntityModel() |
| 272 | { | 360 | { |
| 273 | - $model = call_user_func_array( | ||
| 274 | - [ | ||
| 275 | - $this->entity, | ||
| 276 | - 'findOne', | ||
| 277 | - ], | ||
| 278 | - [ $this->entity_id ] | ||
| 279 | - ); | ||
| 280 | - return $model; | ||
| 281 | - } | ||
| 282 | - | ||
| 283 | - public function getLink() | ||
| 284 | - { | ||
| 285 | - $model = $this->getEntityModel(); | ||
| 286 | - if (empty($model)) { | ||
| 287 | - return Html::a('Страница не найдена', '#'); | ||
| 288 | - } | ||
| 289 | - if (Product::className() == $this->entity) { | ||
| 290 | - return Html::a( | ||
| 291 | - 'Перейти на товар', | ||
| 292 | - \Yii::$app->urlManagerFrontend->createAbsoluteUrl( | ||
| 293 | - [ | ||
| 294 | - 'catalog/product', | ||
| 295 | - 'product' => $model->lang->alias, | ||
| 296 | - 'variant' => $model->variant->sku, | ||
| 297 | - ] | ||
| 298 | - ), | 361 | + if (method_exists($this->entity, 'findOne')) { |
| 362 | + $model = call_user_func_array( | ||
| 299 | [ | 363 | [ |
| 300 | - 'target' => '_blank', | ||
| 301 | - 'data-pjax' => '0', | ||
| 302 | - ] | 364 | + $this->entity, |
| 365 | + 'findOne', | ||
| 366 | + ], | ||
| 367 | + [ $this->entity_id ] | ||
| 303 | ); | 368 | ); |
| 369 | + return $model; | ||
| 370 | + } else { | ||
| 371 | + return false; | ||
| 372 | + } | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + /** | ||
| 376 | + * Get Customer model name | ||
| 377 | + * | ||
| 378 | + * @return string | ||
| 379 | + */ | ||
| 380 | + protected static function getCustomerClass() | ||
| 381 | + { | ||
| 382 | + /** | ||
| 383 | + * @var \artbox\webcomment\Module $module | ||
| 384 | + */ | ||
| 385 | + $module = \Yii::$app->getModule('artbox-comment'); | ||
| 386 | + if ($module) { | ||
| 387 | + return $module->userIdentityClass; | ||
| 304 | } else { | 388 | } else { |
| 305 | - return Html::a('Неизвестная модель', '#'); | 389 | + return 'artbox\order\models\Customer'; |
| 306 | } | 390 | } |
| 307 | } | 391 | } |
| 308 | } | 392 | } |
models/CommentModelSearch.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\models; | 3 | + namespace artbox\webcomment\models; |
| 4 | 4 | ||
| 5 | use yii\base\Model; | 5 | use yii\base\Model; |
| 6 | use yii\data\ActiveDataProvider; | 6 | use yii\data\ActiveDataProvider; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | * CommentModelSearch represents the model behind the search form about | 9 | * CommentModelSearch represents the model behind the search form about |
| 10 | - * `artweb\artbox\comment\models\CommentModel`. | 10 | + * `artbox\webcomment\models\CommentModel`. |
| 11 | */ | 11 | */ |
| 12 | class CommentModelSearch extends CommentModel | 12 | class CommentModelSearch extends CommentModel |
| 13 | { | 13 | { |
| @@ -24,12 +24,12 @@ | @@ -24,12 +24,12 @@ | ||
| 24 | return [ | 24 | return [ |
| 25 | [ | 25 | [ |
| 26 | [ | 26 | [ |
| 27 | - 'artbox_comment_id', | 27 | + 'id', |
| 28 | 'created_at', | 28 | 'created_at', |
| 29 | 'updated_at', | 29 | 'updated_at', |
| 30 | 'deleted_at', | 30 | 'deleted_at', |
| 31 | 'status', | 31 | 'status', |
| 32 | - 'artbox_comment_pid', | 32 | + 'parent_id', |
| 33 | 'related_id', | 33 | 'related_id', |
| 34 | 'entity_id', | 34 | 'entity_id', |
| 35 | ], | 35 | ], |
| @@ -52,7 +52,7 @@ | @@ -52,7 +52,7 @@ | ||
| 52 | ], | 52 | ], |
| 53 | [ | 53 | [ |
| 54 | [ | 54 | [ |
| 55 | - 'user_id', | 55 | + 'customer_id', |
| 56 | 'text', | 56 | 'text', |
| 57 | 'username', | 57 | 'username', |
| 58 | 'email', | 58 | 'email', |
| @@ -64,14 +64,17 @@ | @@ -64,14 +64,17 @@ | ||
| 64 | ], | 64 | ], |
| 65 | ]; | 65 | ]; |
| 66 | } | 66 | } |
| 67 | - | 67 | + |
| 68 | + /** | ||
| 69 | + * @inheritdoc | ||
| 70 | + */ | ||
| 68 | public function attributeLabels() | 71 | public function attributeLabels() |
| 69 | { | 72 | { |
| 70 | return array_merge( | 73 | return array_merge( |
| 71 | parent::attributeLabels(), | 74 | parent::attributeLabels(), |
| 72 | [ | 75 | [ |
| 73 | - 'ratingValue' => 'Рейтинг', | ||
| 74 | - 'childrenCount' => 'Количество ответов', | 76 | + 'ratingValue' => \Yii::t('artbox-comment', 'Рейтинг'), |
| 77 | + 'childrenCount' => \Yii::t('artbox-comment', 'Количество ответов'), | ||
| 75 | ] | 78 | ] |
| 76 | ); | 79 | ); |
| 77 | } | 80 | } |
| @@ -98,7 +101,7 @@ | @@ -98,7 +101,7 @@ | ||
| 98 | ->joinWith( | 101 | ->joinWith( |
| 99 | [ | 102 | [ |
| 100 | 'rating', | 103 | 'rating', |
| 101 | - 'user', | 104 | + 'customer', |
| 102 | ] | 105 | ] |
| 103 | ); | 106 | ); |
| 104 | 107 | ||
| @@ -113,10 +116,9 @@ | @@ -113,10 +116,9 @@ | ||
| 113 | 'asc' => [ 'artbox_comment_rating.value' => SORT_ASC ], | 116 | 'asc' => [ 'artbox_comment_rating.value' => SORT_ASC ], |
| 114 | 'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ], | 117 | 'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ], |
| 115 | ], | 118 | ], |
| 116 | - 'artbox_comment_id', | ||
| 117 | - 'date_add', | 119 | + 'id', |
| 118 | 'text', | 120 | 'text', |
| 119 | - 'user_id', | 121 | + 'customer_id', |
| 120 | 'status', | 122 | 'status', |
| 121 | 'entity', | 123 | 'entity', |
| 122 | 'entity_id', | 124 | 'entity_id', |
| @@ -140,12 +142,12 @@ | @@ -140,12 +142,12 @@ | ||
| 140 | // grid filtering conditions | 142 | // grid filtering conditions |
| 141 | $query->andFilterWhere( | 143 | $query->andFilterWhere( |
| 142 | [ | 144 | [ |
| 143 | - 'artbox_comment_id' => $this->artbox_comment_id, | 145 | + 'id' => $this->id, |
| 144 | 'created_at' => $this->created_at, | 146 | 'created_at' => $this->created_at, |
| 145 | 'updated_at' => $this->updated_at, | 147 | 'updated_at' => $this->updated_at, |
| 146 | 'deleted_at' => $this->deleted_at, | 148 | 'deleted_at' => $this->deleted_at, |
| 147 | 'artbox_comment.status' => $this->status, | 149 | 'artbox_comment.status' => $this->status, |
| 148 | - 'artbox_comment_pid' => $this->artbox_comment_pid, | 150 | + 'parent_id' => $this->parent_id, |
| 149 | 'related_id' => $this->related_id, | 151 | 'related_id' => $this->related_id, |
| 150 | 'entity_id' => $this->entity_id, | 152 | 'entity_id' => $this->entity_id, |
| 151 | ] | 153 | ] |
| @@ -198,26 +200,26 @@ | @@ -198,26 +200,26 @@ | ||
| 198 | 'artbox_comment_rating.value' => $this->ratingValue, | 200 | 'artbox_comment_rating.value' => $this->ratingValue, |
| 199 | ] | 201 | ] |
| 200 | ); | 202 | ); |
| 201 | - | ||
| 202 | - if (!empty( $this->user_id )) { | 203 | + |
| 204 | + if (!empty($this->customer_id)) { | ||
| 203 | $query->andWhere( | 205 | $query->andWhere( |
| 204 | [ | 206 | [ |
| 205 | 'or', | 207 | 'or', |
| 206 | - [ 'artbox_comment.user_id' => (int) $this->user_id ], | 208 | + [ 'artbox_comment.customer_id' => (int) $this->customer_id ], |
| 207 | [ | 209 | [ |
| 208 | 'like', | 210 | 'like', |
| 209 | 'user.username', | 211 | 'user.username', |
| 210 | - $this->user_id, | 212 | + $this->customer_id, |
| 211 | ], | 213 | ], |
| 212 | [ | 214 | [ |
| 213 | 'like', | 215 | 'like', |
| 214 | 'artbox_comment.username', | 216 | 'artbox_comment.username', |
| 215 | - $this->user_id, | 217 | + $this->customer_id, |
| 216 | ], | 218 | ], |
| 217 | [ | 219 | [ |
| 218 | 'like', | 220 | 'like', |
| 219 | 'artbox_comment.email', | 221 | 'artbox_comment.email', |
| 220 | - $this->user_id, | 222 | + $this->customer_id, |
| 221 | ], | 223 | ], |
| 222 | ] | 224 | ] |
| 223 | ); | 225 | ); |
models/LikeModel.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\models; | 3 | + namespace artbox\webcomment\models; |
| 4 | 4 | ||
| 5 | use yii\db\ActiveRecord; | 5 | use yii\db\ActiveRecord; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * Class LikeModel | 8 | * Class LikeModel |
| 9 | - * @package artweb\artbox\comment\models | ||
| 10 | */ | 9 | */ |
| 11 | class LikeModel extends ActiveRecord | 10 | class LikeModel extends ActiveRecord |
| 12 | { | 11 | { |
models/RatingModel.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\models; | 3 | + namespace artbox\webcomment\models; |
| 4 | 4 | ||
| 5 | use Yii; | 5 | use Yii; |
| 6 | use yii\behaviors\BlameableBehavior; | 6 | use yii\behaviors\BlameableBehavior; |
| @@ -10,12 +10,10 @@ | @@ -10,12 +10,10 @@ | ||
| 10 | /** | 10 | /** |
| 11 | * This is the model class for table "artbox_comment_rating". | 11 | * This is the model class for table "artbox_comment_rating". |
| 12 | * | 12 | * |
| 13 | - * @todo Refactor User to Identity | ||
| 14 | - * | ||
| 15 | - * @property integer $artbox_comment_rating_id | 13 | + * @property integer $id |
| 16 | * @property string $created_at | 14 | * @property string $created_at |
| 17 | * @property string $updated_at | 15 | * @property string $updated_at |
| 18 | - * @property integer $user_id | 16 | + * @property integer $customer_id |
| 19 | * @property integer $value | 17 | * @property integer $value |
| 20 | * @property string $model | 18 | * @property string $model |
| 21 | * @property integer $model_id | 19 | * @property integer $model_id |
| @@ -58,7 +56,7 @@ | @@ -58,7 +56,7 @@ | ||
| 58 | ], | 56 | ], |
| 59 | [ | 57 | [ |
| 60 | 'class' => BlameableBehavior::className(), | 58 | 'class' => BlameableBehavior::className(), |
| 61 | - 'createdByAttribute' => 'user_id', | 59 | + 'createdByAttribute' => 'customer_id', |
| 62 | 'updatedByAttribute' => false, | 60 | 'updatedByAttribute' => false, |
| 63 | ], | 61 | ], |
| 64 | ]; | 62 | ]; |
| @@ -70,18 +68,30 @@ | @@ -70,18 +68,30 @@ | ||
| 70 | public function attributeLabels() | 68 | public function attributeLabels() |
| 71 | { | 69 | { |
| 72 | return [ | 70 | return [ |
| 73 | - 'rating_id' => Yii::t('app', 'Rating ID'), | ||
| 74 | - 'date_add' => Yii::t('app', 'Date Add'), | ||
| 75 | - 'updated_at' => Yii::t('app', 'Date Update'), | ||
| 76 | - 'user_id' => Yii::t('app', 'User ID'), | ||
| 77 | - 'entity' => Yii::t('app', 'Entity'), | ||
| 78 | - 'value' => Yii::t('app', 'Value'), | 71 | + 'id' => Yii::t('app', 'Rating ID'), |
| 72 | + 'created_at' => Yii::t('app', 'Date Add'), | ||
| 73 | + 'updated_at' => Yii::t('app', 'Date Update'), | ||
| 74 | + 'customer_id' => Yii::t('app', 'User ID'), | ||
| 75 | + 'entity' => Yii::t('app', 'Entity'), | ||
| 76 | + 'value' => Yii::t('app', 'Value'), | ||
| 79 | ]; | 77 | ]; |
| 80 | } | 78 | } |
| 81 | - | 79 | + |
| 80 | + /** | ||
| 81 | + * Get entity model for current model | ||
| 82 | + * | ||
| 83 | + * @return \yii\db\ActiveQuery|null | ||
| 84 | + */ | ||
| 82 | public function getModel() | 85 | public function getModel() |
| 83 | { | 86 | { |
| 84 | $model = $this->model; | 87 | $model = $this->model; |
| 85 | - return $this->hasOne($model, [ $model::primaryKey() => 'model_id' ]); | 88 | + if (method_exists($model, 'primaryKey')) { |
| 89 | + /** | ||
| 90 | + * @var ActiveRecord $model | ||
| 91 | + */ | ||
| 92 | + return $this->hasOne($model, [ $model::primaryKey()[ 0 ] => 'model_id' ]); | ||
| 93 | + } else { | ||
| 94 | + return null; | ||
| 95 | + } | ||
| 86 | } | 96 | } |
| 87 | } | 97 | } |
models/interfaces/CommentInterface.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\models\interfaces; | 3 | + namespace artbox\webcomment\models\interfaces; |
| 4 | 4 | ||
| 5 | use yii\data\ActiveDataProvider; | 5 | use yii\data\ActiveDataProvider; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * Interface CommentInterface | 8 | * Interface CommentInterface |
| 9 | - * @package artweb\artbox\comment\models\interfaces | ||
| 10 | */ | 9 | */ |
| 11 | interface CommentInterface | 10 | interface CommentInterface |
| 12 | { | 11 | { |
models/interfaces/RatingCacheInterface.php
resources/artbox_comment.js
| @@ -174,8 +174,11 @@ | @@ -174,8 +174,11 @@ | ||
| 174 | var form = $(data.formSelector + '-reply'); | 174 | var form = $(data.formSelector + '-reply'); |
| 175 | var button = this; | 175 | var button = this; |
| 176 | var item = $(button).parents(data.itemContainerSelector); | 176 | var item = $(button).parents(data.itemContainerSelector); |
| 177 | + console.log(item); | ||
| 177 | var item_id = $(item).data('key'); | 178 | var item_id = $(item).data('key'); |
| 178 | - $(form).find('#commentmodel-artbox_comment_pid-reply').val(item_id); | 179 | + $(form) |
| 180 | + .find('#commentmodel-parent_id-reply') | ||
| 181 | + .val(item_id); | ||
| 179 | $(item).find(data.itemReplySelector).append(form); | 182 | $(item).find(data.itemReplySelector).append(form); |
| 180 | } | 183 | } |
| 181 | 184 | ||
| @@ -252,8 +255,11 @@ | @@ -252,8 +255,11 @@ | ||
| 252 | var form = $(data.formSelector + '-reply'); | 255 | var form = $(data.formSelector + '-reply'); |
| 253 | var button = this; | 256 | var button = this; |
| 254 | var item = $(button).parents(data.childContainerSelector); | 257 | var item = $(button).parents(data.childContainerSelector); |
| 258 | + console.log(item); | ||
| 255 | var item_id = $(item).data('key'); | 259 | var item_id = $(item).data('key'); |
| 256 | - $(form).find('#commentmodel-artbox_comment_pid-reply').val(item_id); | 260 | + $(form) |
| 261 | + .find('#commentmodel-parent_id-reply') | ||
| 262 | + .val(item_id); | ||
| 257 | $(item).find(data.childReplySelector).append(form); | 263 | $(item).find(data.childReplySelector).append(form); |
| 258 | } | 264 | } |
| 259 | 265 |
views/artbox_comment_form.php
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | ||
| 3 | - use artweb\artbox\comment\models\RatingModel; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | + use artbox\webcomment\models\RatingModel; | ||
| 4 | use yii\base\Model; | 4 | use yii\base\Model; |
| 5 | use yii\helpers\Html; | 5 | use yii\helpers\Html; |
| 6 | use yii\helpers\Url; | 6 | use yii\helpers\Url; |
| @@ -15,42 +15,54 @@ | @@ -15,42 +15,54 @@ | ||
| 15 | * @var View $this | 15 | * @var View $this |
| 16 | * @var RatingModel|NULL $rating_model | 16 | * @var RatingModel|NULL $rating_model |
| 17 | */ | 17 | */ |
| 18 | - $form = ActiveForm::begin([ | ||
| 19 | - 'id' => $formId, | ||
| 20 | - 'action' => Url::to([ | ||
| 21 | - 'artbox-comment/default/create', | ||
| 22 | - 'entity' => $comment_model->encryptedEntity, | ||
| 23 | - ]), | ||
| 24 | - ]); | 18 | + $form = ActiveForm::begin( |
| 19 | + [ | ||
| 20 | + 'id' => $formId, | ||
| 21 | + 'action' => Url::to( | ||
| 22 | + [ | ||
| 23 | + 'artbox-comment/default/create', | ||
| 24 | + 'entity' => $comment_model->encryptedEntity, | ||
| 25 | + ] | ||
| 26 | + ), | ||
| 27 | + ] | ||
| 28 | + ); | ||
| 25 | ?> | 29 | ?> |
| 26 | - <div class="form-comm-wr"> | ||
| 27 | - <?php | ||
| 28 | - if(!empty( $rating_model )) { | ||
| 29 | - ?> | ||
| 30 | - <div class="input_bl stars-wr_"> | ||
| 31 | - <?php | ||
| 32 | - echo $form->field($rating_model, 'value', [ 'enableClientValidation' => false ]) | ||
| 33 | - ->hiddenInput() | ||
| 34 | - ->label(false); | ||
| 35 | - echo Html::tag('div', '', [ | 30 | + <div class="form-comm-wr"> |
| 31 | + <?php | ||
| 32 | + if (!empty($rating_model)) { | ||
| 33 | + ?> | ||
| 34 | + <div class="input_bl stars-wr_"> | ||
| 35 | + <?php | ||
| 36 | + echo $form->field($rating_model, 'value', [ 'enableClientValidation' => false ]) | ||
| 37 | + ->hiddenInput() | ||
| 38 | + ->label(false); | ||
| 39 | + echo Html::tag( | ||
| 40 | + 'div', | ||
| 41 | + '', | ||
| 42 | + [ | ||
| 36 | 'class' => 'rateit', | 43 | 'class' => 'rateit', |
| 37 | 'data-rateit-backingfld' => '#' . Html::getInputId($rating_model, 'value'), | 44 | 'data-rateit-backingfld' => '#' . Html::getInputId($rating_model, 'value'), |
| 38 | - ]); | ||
| 39 | - ?> | ||
| 40 | - </div> | ||
| 41 | - <?php | ||
| 42 | - } | ||
| 43 | - if(\Yii::$app->user->isGuest) { | ||
| 44 | - echo $form->field($comment_model, 'username', [ 'options' => [ 'class' => 'form-group input_bl' ] ]) | ||
| 45 | - ->textInput(); | ||
| 46 | - echo $form->field($comment_model, 'email', [ 'options' => [ 'class' => 'form-group input_bl' ] ]) | ||
| 47 | - ->textInput(); | ||
| 48 | - } | ||
| 49 | - echo $form->field($comment_model, 'text', [ 'options' => [ 'class' => 'form-group input_bl area_bl' ] ]) | ||
| 50 | - ->textarea(); | ||
| 51 | - echo Html::tag('div', Html::submitButton(Yii::t('artbox-comment', 'Submit')), [ 'class' => 'input_bl submit_btn' ]); | ||
| 52 | - ?> | ||
| 53 | - </div> | 45 | + ] |
| 46 | + ); | ||
| 47 | + ?> | ||
| 48 | + </div> | ||
| 49 | + <?php | ||
| 50 | + } | ||
| 51 | + if (\Yii::$app->user->isGuest) { | ||
| 52 | + echo $form->field($comment_model, 'username', [ 'options' => [ 'class' => 'form-group input_bl' ] ]) | ||
| 53 | + ->textInput(); | ||
| 54 | + echo $form->field($comment_model, 'email', [ 'options' => [ 'class' => 'form-group input_bl' ] ]) | ||
| 55 | + ->textInput(); | ||
| 56 | + } | ||
| 57 | + echo $form->field($comment_model, 'text', [ 'options' => [ 'class' => 'form-group input_bl area_bl' ] ]) | ||
| 58 | + ->textarea(); | ||
| 59 | + echo Html::tag( | ||
| 60 | + 'div', | ||
| 61 | + Html::submitButton(Yii::t('artbox-comment', 'Submit')), | ||
| 62 | + [ 'class' => 'input_bl submit_btn' ] | ||
| 63 | + ); | ||
| 64 | + ?> | ||
| 65 | + </div> | ||
| 54 | <?php | 66 | <?php |
| 55 | ActiveForm::end(); | 67 | ActiveForm::end(); |
| 56 | ?> | 68 | ?> |
| 57 | \ No newline at end of file | 69 | \ No newline at end of file |
views/artbox_comment_item.php
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
| 4 | use yii\helpers\Url; | 4 | use yii\helpers\Url; |
| 5 | use yii\widgets\ListView; | 5 | use yii\widgets\ListView; |
| @@ -12,139 +12,149 @@ | @@ -12,139 +12,149 @@ | ||
| 12 | */ | 12 | */ |
| 13 | ?> | 13 | ?> |
| 14 | <div class="comments-wr"> | 14 | <div class="comments-wr"> |
| 15 | - <div class="artbox_item_info"> | ||
| 16 | - <div class="user-ico"> | ||
| 17 | - <?php | ||
| 18 | - echo Html::img('/img/user-noimage.png'); | ||
| 19 | - ?> | ||
| 20 | - </div> | ||
| 21 | - <div class="user_data" itemprop="datePublished"> | ||
| 22 | - <?php | ||
| 23 | - echo date('d.m.Y', $model->created_at); | ||
| 24 | - ?> | ||
| 25 | - </div> | ||
| 26 | - <div class="user_name" itemprop="author"> | ||
| 27 | - <?php | ||
| 28 | - if(!empty( $model->user )) { | ||
| 29 | - echo $model->user->username; | ||
| 30 | - } else { | ||
| 31 | - echo $model->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')'; | ||
| 32 | - } | ||
| 33 | - ?> | ||
| 34 | - </div> | 15 | + <div class="artbox_item_info"> |
| 16 | + <div class="user-ico"> | ||
| 35 | <?php | 17 | <?php |
| 36 | - if(!empty( $model->rating )) { | ||
| 37 | - ?> | ||
| 38 | - <div class="user_rating" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"> | ||
| 39 | - <span itemprop="worstRating" style="display: none">1</span> | ||
| 40 | - <span itemprop="ratingValue" style="display: none"><?php echo $model->rating->value; ?></span> | ||
| 41 | - <span itemprop="bestRating" style="display: none">5</span> | ||
| 42 | - <div class="rateit" data-rateit-value="<?php echo $model->rating->value; ?>" data-rateit-ispreset="true" data-rateit-readonly="true"></div> | ||
| 43 | - </div> | ||
| 44 | - <?php | ||
| 45 | - } | 18 | + echo Html::img('/img/no-image.png'); |
| 46 | ?> | 19 | ?> |
| 47 | - <div class="user_txt" itemprop="description"> | ||
| 48 | - <?php | ||
| 49 | - echo $model->text; | ||
| 50 | - ?> | ||
| 51 | - </div> | ||
| 52 | </div> | 20 | </div> |
| 53 | - <div class="artbox_item_tools comment-panel"> | 21 | + <div class="user_data" itemprop="datePublished"> |
| 54 | <?php | 22 | <?php |
| 55 | - if(!\Yii::$app->user->isGuest) { | ||
| 56 | - ?> | ||
| 57 | - <a href="" class="btn-comm-answer" data-action="reply">Ответить</a> | ||
| 58 | - <?php | ||
| 59 | - } | ||
| 60 | - if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $model->user_id) { | ||
| 61 | - ?> | ||
| 62 | - <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to([ | ||
| 63 | - 'artbox-comment/default/delete', | ||
| 64 | - 'id' => $model->artbox_comment_id, | ||
| 65 | - ]); ?>">Удалить</a> | ||
| 66 | - <?php | 23 | + echo date('d.m.Y', $model->created_at); |
| 24 | + ?> | ||
| 25 | + </div> | ||
| 26 | + <div class="user_name" itemprop="author"> | ||
| 27 | + <?php | ||
| 28 | + if (!empty($model->customer)) { | ||
| 29 | + echo $model->customer->username; | ||
| 30 | + } else { | ||
| 31 | + echo $model->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')'; | ||
| 67 | } | 32 | } |
| 68 | - // Like / dislike to be done | ||
| 69 | - /* | ||
| 70 | - ?> | ||
| 71 | - <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([ | ||
| 72 | - 'artbox-comment/default/like', | ||
| 73 | - 'id' => $model->artbox_comment_id, | ||
| 74 | - ]); ?>">Like</a> | ||
| 75 | - <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([ | ||
| 76 | - 'artbox-comment/default/dislike', | ||
| 77 | - 'id' => $model->artbox_comment_id, | ||
| 78 | - ]); ?>">Dislike</a> | ||
| 79 | - <?php | ||
| 80 | - */ | ||
| 81 | ?> | 33 | ?> |
| 82 | - <div class="artbox_item_reply"></div> | ||
| 83 | </div> | 34 | </div> |
| 35 | + <?php | ||
| 36 | + if (!empty($model->rating)) { | ||
| 37 | + ?> | ||
| 38 | + <div class="user_rating" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"> | ||
| 39 | + <span itemprop="worstRating" style="display: none">1</span> | ||
| 40 | + <span itemprop="ratingValue" style="display: none"><?php echo $model->rating->value; ?></span> | ||
| 41 | + <span itemprop="bestRating" style="display: none">5</span> | ||
| 42 | + <div class="rateit" data-rateit-value="<?php echo $model->rating->value; ?>" data-rateit-ispreset="true" data-rateit-readonly="true"></div> | ||
| 43 | + </div> | ||
| 44 | + <?php | ||
| 45 | + } | ||
| 46 | + ?> | ||
| 47 | + <div class="user_txt" itemprop="description"> | ||
| 48 | + <?php | ||
| 49 | + echo $model->text; | ||
| 50 | + ?> | ||
| 51 | + </div> | ||
| 52 | + </div> | ||
| 53 | + <div class="artbox_item_tools comment-panel"> | ||
| 54 | + <?php | ||
| 55 | + if (!\Yii::$app->user->isGuest) { | ||
| 56 | + ?> | ||
| 57 | + <a href="" class="btn-comm-answer" data-action="reply"><?php echo \Yii::t( | ||
| 58 | + 'artbox-comment', | ||
| 59 | + 'Ответить' | ||
| 60 | + ); ?></a> | ||
| 61 | + <?php | ||
| 62 | + } | ||
| 63 | + if (!\Yii::$app->user->isGuest && \Yii::$app->user->id == $model->customer_id) { | ||
| 64 | + ?> | ||
| 65 | + <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to( | ||
| 66 | + [ | ||
| 67 | + 'artbox-comment/default/delete', | ||
| 68 | + 'id' => $model->id, | ||
| 69 | + ] | ||
| 70 | + ); ?>"><?php echo \Yii::t('artbox-comment', 'Удалить'); ?></a> | ||
| 71 | + <?php | ||
| 72 | + } | ||
| 73 | + // Like / dislike to be done | ||
| 74 | + /* | ||
| 75 | + ?> | ||
| 76 | + <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([ | ||
| 77 | + 'artbox-comment/default/like', | ||
| 78 | + 'id' => $model->artbox_comment_id, | ||
| 79 | + ]); ?>">Like</a> | ||
| 80 | + <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([ | ||
| 81 | + 'artbox-comment/default/dislike', | ||
| 82 | + 'id' => $model->artbox_comment_id, | ||
| 83 | + ]); ?>">Dislike</a> | ||
| 84 | + <?php | ||
| 85 | + */ | ||
| 86 | + ?> | ||
| 87 | + <div class="artbox_item_reply"></div> | ||
| 88 | + </div> | ||
| 84 | </div> | 89 | </div> |
| 85 | <div class="artbox_children_container"> | 90 | <div class="artbox_children_container"> |
| 86 | <?php | 91 | <?php |
| 87 | - if(!empty( $model->children )) { | ||
| 88 | - foreach($model->children as $index => $child) { | 92 | + if (!empty($model->children)) { |
| 93 | + foreach ($model->children as $index => $child) { | ||
| 89 | ?> | 94 | ?> |
| 90 | - <div class="artbox_child_container comment-answer"> | ||
| 91 | - <div class="artbox_child_info"> | ||
| 92 | - <div class="user-ico"> | ||
| 93 | - <?php | ||
| 94 | - echo Html::img('/img/user-noimage.png'); | ||
| 95 | - ?> | ||
| 96 | - </div> | ||
| 97 | - <div class="user_data"> | ||
| 98 | - <?php | ||
| 99 | - echo date('d.m.Y', $child->created_at); | ||
| 100 | - ?> | ||
| 101 | - </div> | ||
| 102 | - <div class="user_name"> | ||
| 103 | - <?php | ||
| 104 | - if(!empty( $child->user )) { | ||
| 105 | - echo $child->user->username; | ||
| 106 | - } else { | ||
| 107 | - echo $child->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')'; | ||
| 108 | - } | 95 | + <div class="artbox_child_container comment-answer" data-key="<?php echo $child->id; ?>"> |
| 96 | + <div class="artbox_child_info"> | ||
| 97 | + <div class="user-ico"> | ||
| 98 | + <?php | ||
| 99 | + echo Html::img('/img/no-image.png'); | ||
| 100 | + ?> | ||
| 101 | + </div> | ||
| 102 | + <div class="user_data"> | ||
| 103 | + <?php | ||
| 104 | + echo date('d.m.Y', $child->created_at); | ||
| 105 | + ?> | ||
| 106 | + </div> | ||
| 107 | + <div class="user_name"> | ||
| 108 | + <?php | ||
| 109 | + if (!empty($child->customer)) { | ||
| 110 | + echo $child->customer->username; | ||
| 111 | + } else { | ||
| 112 | + echo $child->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')'; | ||
| 113 | + } | ||
| 114 | + ?> | ||
| 115 | + </div> | ||
| 116 | + <div class="user_txt"> | ||
| 117 | + <?php | ||
| 118 | + echo $child->text; | ||
| 119 | + ?> | ||
| 120 | + </div> | ||
| 121 | + </div> | ||
| 122 | + <div class="artbox_child_tools comment-panel"> | ||
| 123 | + <?php | ||
| 124 | + if (!\Yii::$app->user->isGuest) { | ||
| 109 | ?> | 125 | ?> |
| 110 | - </div> | ||
| 111 | - <div class="user_txt"> | 126 | + <a href="" class="btn-comm-answer" data-action="reply"><?php echo \Yii::t( |
| 127 | + 'artbox-comment', | ||
| 128 | + 'Ответить' | ||
| 129 | + ); ?></a> | ||
| 112 | <?php | 130 | <?php |
| 113 | - echo $child->text; | 131 | + } |
| 132 | + if (!\Yii::$app->user->isGuest && \Yii::$app->user->id == $child->customer_id) { | ||
| 114 | ?> | 133 | ?> |
| 115 | - </div> | ||
| 116 | - </div> | ||
| 117 | - <div class="artbox_child_tools comment-panel"> | ||
| 118 | - <?php | ||
| 119 | - if(!\Yii::$app->user->isGuest) { | ||
| 120 | - ?> | ||
| 121 | - <a href="" class="btn-comm-answer" data-action="reply">Ответить</a> | ||
| 122 | - <?php | ||
| 123 | - } | ||
| 124 | - if(!\Yii::$app->user->isGuest && \Yii::$app->user->id == $child->user_id) { | ||
| 125 | - ?> | ||
| 126 | - <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to([ | ||
| 127 | - 'artbox-comment/default/delete', | ||
| 128 | - 'id' => $child->artbox_comment_id, | ||
| 129 | - ]); ?>">Удалить</a> | ||
| 130 | - <?php | ||
| 131 | - } | ||
| 132 | - /* Like /dislike to be done | ||
| 133 | - ?> | ||
| 134 | - <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([ | ||
| 135 | - 'artbox-comment/default/like', | ||
| 136 | - 'id' => $child->artbox_comment_id, | ||
| 137 | - ]); ?>">Like</a> | ||
| 138 | - <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([ | ||
| 139 | - 'artbox-comment/default/dislike', | ||
| 140 | - 'id' => $child->artbox_comment_id, | ||
| 141 | - ]); ?>">Dislike</a> | 134 | + <a href="" class="btn-comm-delete" data-action="delete" data-url="<?php echo Url::to( |
| 135 | + [ | ||
| 136 | + 'artbox-comment/default/delete', | ||
| 137 | + 'id' => $child->id, | ||
| 138 | + ] | ||
| 139 | + ); ?>"><?php echo \Yii::t('artbox-comment', 'Удалить'); ?></a> | ||
| 142 | <?php | 140 | <?php |
| 143 | - */ | 141 | + } |
| 142 | + /* Like /dislike to be done | ||
| 144 | ?> | 143 | ?> |
| 145 | - <div class="artbox_child_reply"></div> | ||
| 146 | - </div> | 144 | + <a href="" class="btn-comm-like" data-action="like" data-url="<?php echo Url::to([ |
| 145 | + 'artbox-comment/default/like', | ||
| 146 | + 'id' => $child->artbox_comment_id, | ||
| 147 | + ]); ?>">Like</a> | ||
| 148 | + <a href="" class="btn-comm-dislike" data-action="dislike" data-url="<?php echo Url::to([ | ||
| 149 | + 'artbox-comment/default/dislike', | ||
| 150 | + 'id' => $child->artbox_comment_id, | ||
| 151 | + ]); ?>">Dislike</a> | ||
| 152 | + <?php | ||
| 153 | + */ | ||
| 154 | + ?> | ||
| 155 | + <div class="artbox_child_reply"></div> | ||
| 147 | </div> | 156 | </div> |
| 157 | + </div> | ||
| 148 | <?php | 158 | <?php |
| 149 | } | 159 | } |
| 150 | } | 160 | } |
views/artbox_comment_list.php
views/artbox_comment_reply.php
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | use yii\base\Model; | 3 | use yii\base\Model; |
| 4 | use yii\helpers\Html; | 4 | use yii\helpers\Html; |
| 5 | use yii\helpers\Url; | 5 | use yii\helpers\Url; |
| @@ -14,14 +14,14 @@ | @@ -14,14 +14,14 @@ | ||
| 14 | * @var View $this | 14 | * @var View $this |
| 15 | */ | 15 | */ |
| 16 | $text_input_id = Html::getInputId($comment_model, 'text') . '-reply'; | 16 | $text_input_id = Html::getInputId($comment_model, 'text') . '-reply'; |
| 17 | - $artbox_comment_pid_input_id = Html::getInputId($comment_model, 'artbox_comment_pid') . '-reply'; | 17 | + $parent_id_input_id = Html::getInputId($comment_model, 'parent_id') . '-reply'; |
| 18 | $text_input_selectors = [ | 18 | $text_input_selectors = [ |
| 19 | 'container' => '.field-' . $text_input_id, | 19 | 'container' => '.field-' . $text_input_id, |
| 20 | 'input' => '#' . $text_input_id, | 20 | 'input' => '#' . $text_input_id, |
| 21 | ]; | 21 | ]; |
| 22 | - $artbox_comment_pid_input_selectors = [ | ||
| 23 | - 'container' => '.field-' . $artbox_comment_pid_input_id, | ||
| 24 | - 'input' => '#' . $artbox_comment_pid_input_id, | 22 | + $parent_id_input_selectors = [ |
| 23 | + 'container' => '.field-' . $parent_id_input_id, | ||
| 24 | + 'input' => '#' . $parent_id_input_id, | ||
| 25 | ]; | 25 | ]; |
| 26 | $form = ActiveForm::begin([ | 26 | $form = ActiveForm::begin([ |
| 27 | 'id' => $formId . '-reply', | 27 | 'id' => $formId . '-reply', |
| @@ -33,10 +33,13 @@ | @@ -33,10 +33,13 @@ | ||
| 33 | ?> | 33 | ?> |
| 34 | <div class="answer-form"> | 34 | <div class="answer-form"> |
| 35 | <?php | 35 | <?php |
| 36 | - echo $form->field($comment_model, 'artbox_comment_pid', [ | ||
| 37 | - 'selectors' => $artbox_comment_pid_input_selectors, | 36 | + echo $form->field( |
| 37 | + $comment_model, | ||
| 38 | + 'parent_id', | ||
| 39 | + [ | ||
| 40 | + 'selectors' => $parent_id_input_selectors, | ||
| 38 | 'inputOptions' => [ | 41 | 'inputOptions' => [ |
| 39 | - 'id' => $artbox_comment_pid_input_id, | 42 | + 'id' => $parent_id_input_id, |
| 40 | 'class' => 'form-control', | 43 | 'class' => 'form-control', |
| 41 | ], | 44 | ], |
| 42 | ]) | 45 | ]) |
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
| 4 | use yii\web\View; | 4 | use yii\web\View; |
| 5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
| @@ -10,14 +10,13 @@ | @@ -10,14 +10,13 @@ | ||
| 10 | * @var CommentModel $answer | 10 | * @var CommentModel $answer |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | - $this->title = 'Ответить на комментарий# ' . $model->artbox_comment_id; | 13 | + $this->title = \Yii::t('artbox-comment', 'Ответить на комментарий') . '# ' . $model->id; |
| 14 | 14 | ||
| 15 | $this->params[ 'breadcrumbs' ][] = [ | 15 | $this->params[ 'breadcrumbs' ][] = [ |
| 16 | - 'label' => 'Комментарии', | 16 | + 'label' => \Yii::t('artbox-comment', 'Комментарии'), |
| 17 | 'url' => [ 'index' ], | 17 | 'url' => [ 'index' ], |
| 18 | ]; | 18 | ]; |
| 19 | $this->params[ 'breadcrumbs' ][] = $this->title; | 19 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 20 | - | ||
| 21 | ?> | 20 | ?> |
| 22 | 21 | ||
| 23 | <div class="comment-answer"> | 22 | <div class="comment-answer"> |
| @@ -26,16 +25,16 @@ | @@ -26,16 +25,16 @@ | ||
| 26 | <div class="form-group"> | 25 | <div class="form-group"> |
| 27 | <?= $form->field($answer, 'text') | 26 | <?= $form->field($answer, 'text') |
| 28 | ->textarea() ?> | 27 | ->textarea() ?> |
| 29 | - | ||
| 30 | - <?= $form->field($answer, 'artbox_comment_pid') | 28 | + |
| 29 | + <?= $form->field($answer, 'parent_id') | ||
| 31 | ->hiddenInput( | 30 | ->hiddenInput( |
| 32 | [ | 31 | [ |
| 33 | - 'value' => $model->artbox_comment_id, | 32 | + 'value' => $model->id, |
| 34 | ] | 33 | ] |
| 35 | ) | 34 | ) |
| 36 | ->label(false) ?> | 35 | ->label(false) ?> |
| 37 | - | ||
| 38 | - <?= $form->field($answer, 'user_id') | 36 | + |
| 37 | + <?= $form->field($answer, 'customer_id') | ||
| 39 | ->hiddenInput( | 38 | ->hiddenInput( |
| 40 | [ | 39 | [ |
| 41 | 'value' => 1, | 40 | 'value' => 1, |
| @@ -60,7 +59,7 @@ | @@ -60,7 +59,7 @@ | ||
| 60 | ->label(false) ?> | 59 | ->label(false) ?> |
| 61 | 60 | ||
| 62 | <?= Html::submitButton( | 61 | <?= Html::submitButton( |
| 63 | - \Yii::t('app', 'Ответить'), | 62 | + \Yii::t('artbox-comment', 'Ответить'), |
| 64 | [ 'class' => 'btn btn-primary' ] | 63 | [ 'class' => 'btn btn-primary' ] |
| 65 | ) ?> | 64 | ) ?> |
| 66 | </div> | 65 | </div> |
views/manage/index.php
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | ||
| 3 | - use artweb\artbox\comment\models\CommentModelSearch; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | + use artbox\webcomment\models\CommentModelSearch; | ||
| 4 | use yii\data\ActiveDataProvider; | 4 | use yii\data\ActiveDataProvider; |
| 5 | use yii\grid\GridView; | 5 | use yii\grid\GridView; |
| 6 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
| @@ -14,17 +14,17 @@ | @@ -14,17 +14,17 @@ | ||
| 14 | * @var string $commentModel | 14 | * @var string $commentModel |
| 15 | * @var View $this | 15 | * @var View $this |
| 16 | */ | 16 | */ |
| 17 | - $this->title = 'Комментарии'; | 17 | + $this->title = \Yii::t('artbox-comment', 'Комментарии'); |
| 18 | 18 | ||
| 19 | $this->params[ 'breadcrumbs' ][] = $this->title; | 19 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 20 | 20 | ||
| 21 | $statuses = [ | 21 | $statuses = [ |
| 22 | - $searchModel::STATUS_ACTIVE => 'Активный', | ||
| 23 | - $searchModel::STATUS_HIDDEN => 'Скрытый', | ||
| 24 | - $searchModel::STATUS_DELETED => 'Удаленный', | 22 | + $searchModel::STATUS_ACTIVE => \Yii::t('artbox-comment', 'Активный'), |
| 23 | + $searchModel::STATUS_HIDDEN => \Yii::t('artbox-comment', 'Скрытый'), | ||
| 24 | + $searchModel::STATUS_DELETED => \Yii::t('artbox-comment', 'Удаленный'), | ||
| 25 | ]; | 25 | ]; |
| 26 | Pjax::begin(); | 26 | Pjax::begin(); |
| 27 | - if (( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != NULL) { | 27 | + if (( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != null) { |
| 28 | echo Html::tag('p', $success); | 28 | echo Html::tag('p', $success); |
| 29 | } | 29 | } |
| 30 | echo GridView::widget( | 30 | echo GridView::widget( |
| @@ -32,19 +32,7 @@ | @@ -32,19 +32,7 @@ | ||
| 32 | 'dataProvider' => $dataProvider, | 32 | 'dataProvider' => $dataProvider, |
| 33 | 'filterModel' => $searchModel, | 33 | 'filterModel' => $searchModel, |
| 34 | 'columns' => [ | 34 | 'columns' => [ |
| 35 | - [ | ||
| 36 | - 'attribute' => 'artbox_comment_id', | ||
| 37 | - 'label' => 'Id', | ||
| 38 | - ], | ||
| 39 | - [ | ||
| 40 | - 'label' => 'url', | ||
| 41 | - 'content' => function (CommentModel $model) { | ||
| 42 | - return $model->getLink(); | ||
| 43 | - }, | ||
| 44 | - ], | ||
| 45 | - [ | ||
| 46 | - 'label' => 'Ссылка', | ||
| 47 | - ], | 35 | + 'id', |
| 48 | [ | 36 | [ |
| 49 | 'attribute' => 'created_at', | 37 | 'attribute' => 'created_at', |
| 50 | 'format' => [ | 38 | 'format' => [ |
| @@ -54,51 +42,70 @@ | @@ -54,51 +42,70 @@ | ||
| 54 | 'filter' => false, | 42 | 'filter' => false, |
| 55 | ], | 43 | ], |
| 56 | [ | 44 | [ |
| 57 | - 'label' => 'Комментарий', | ||
| 58 | - 'content' => function(CommentModel $model) { | 45 | + 'label' => \Yii::t('artbox-comment', 'Комментарий'), |
| 46 | + 'content' => function (CommentModel $model) { | ||
| 59 | return StringHelper::truncate($model->text, 40, '...'); | 47 | return StringHelper::truncate($model->text, 40, '...'); |
| 60 | }, | 48 | }, |
| 61 | ], | 49 | ], |
| 62 | [ | 50 | [ |
| 63 | - 'attribute' => 'user_id', | ||
| 64 | - 'value' => function($model) { | ||
| 65 | - if (!empty($model->user)) { | ||
| 66 | - return $model->user->username . ' (id:' . $model->user->id . ')'; | 51 | + 'attribute' => 'customer_id', |
| 52 | + 'value' => function ($model) { | ||
| 53 | + /** | ||
| 54 | + * @var CommentModel $model | ||
| 55 | + */ | ||
| 56 | + if (!empty($model->customer)) { | ||
| 57 | + return $model->customer->username . ' (id:' . $model->customer->id . ')'; | ||
| 67 | } else { | 58 | } else { |
| 68 | - return $model->username . ' ' . $model->email . ' (Гость)'; | 59 | + return $model->username . ' ' . $model->email . ' (' . \Yii::t( |
| 60 | + 'artbox-comment', | ||
| 61 | + 'Гость' | ||
| 62 | + ) . ')'; | ||
| 69 | } | 63 | } |
| 70 | }, | 64 | }, |
| 71 | ], | 65 | ], |
| 72 | [ | 66 | [ |
| 73 | 'attribute' => 'status', | 67 | 'attribute' => 'status', |
| 74 | 'filter' => $statuses, | 68 | 'filter' => $statuses, |
| 75 | - 'value' => function($model) use ($statuses) { | ||
| 76 | - return $statuses[ $model->status ]; | 69 | + 'value' => function ($model) use ($statuses) { |
| 70 | + /** | ||
| 71 | + * @var CommentModel $model | ||
| 72 | + */ | ||
| 73 | + if (array_key_exists($model->status, $statuses)) { | ||
| 74 | + return $statuses[ $model->status ]; | ||
| 75 | + } else { | ||
| 76 | + return null; | ||
| 77 | + } | ||
| 77 | }, | 78 | }, |
| 78 | ], | 79 | ], |
| 79 | [ | 80 | [ |
| 80 | 'attribute' => 'ratingValue', | 81 | 'attribute' => 'ratingValue', |
| 81 | - 'value' => function($model) { | 82 | + 'value' => function ($model) { |
| 83 | + /** | ||
| 84 | + * @var CommentModel $model | ||
| 85 | + */ | ||
| 82 | if (!empty($model->rating)) { | 86 | if (!empty($model->rating)) { |
| 83 | return $model->rating->value; | 87 | return $model->rating->value; |
| 84 | } | 88 | } |
| 85 | - return NULL; | 89 | + return null; |
| 86 | }, | 90 | }, |
| 87 | ], | 91 | ], |
| 88 | [ | 92 | [ |
| 89 | 'attribute' => 'childrenCount', | 93 | 'attribute' => 'childrenCount', |
| 90 | - 'value' => function($model) { | 94 | + 'value' => function ($model) { |
| 95 | + /** | ||
| 96 | + * @var CommentModel $model | ||
| 97 | + */ | ||
| 91 | return count($model->children); | 98 | return count($model->children); |
| 92 | }, | 99 | }, |
| 93 | ], | 100 | ], |
| 94 | [ | 101 | [ |
| 95 | 'class' => 'yii\grid\ActionColumn', | 102 | 'class' => 'yii\grid\ActionColumn', |
| 96 | 'buttons' => [ | 103 | 'buttons' => [ |
| 97 | - 'answer' => function(string $url) { | 104 | + 'answer' => function (string $url) { |
| 98 | return Html::a(Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-bullhorn' ]), $url); | 105 | return Html::a(Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-bullhorn' ]), $url); |
| 99 | }, | 106 | }, |
| 100 | ], | 107 | ], |
| 101 | - 'template' => \Yii::$app->user->identity->isAdmin() ? '{update} {answer} {delete}' : '{update} {answer}', | 108 | + 'template' => '{update} {answer} {delete}', |
| 102 | ], | 109 | ], |
| 103 | ], | 110 | ], |
| 104 | ] | 111 | ] |
views/manage/update.php
| 1 | <?php | 1 | <?php |
| 2 | - use artweb\artbox\comment\models\CommentModel; | 2 | + use artbox\webcomment\models\CommentModel; |
| 3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
| 4 | use yii\widgets\ActiveForm; | 4 | use yii\widgets\ActiveForm; |
| 5 | 5 | ||
| @@ -7,14 +7,14 @@ | @@ -7,14 +7,14 @@ | ||
| 7 | * @var CommentModel $model | 7 | * @var CommentModel $model |
| 8 | */ | 8 | */ |
| 9 | $statuses = [ | 9 | $statuses = [ |
| 10 | - $model::STATUS_ACTIVE => 'Активный', | ||
| 11 | - $model::STATUS_HIDDEN => 'Скрытый', | ||
| 12 | - $model::STATUS_DELETED => 'Удаленный', | 10 | + $model::STATUS_ACTIVE => \Yii::t('artbox-comment', 'Активный'), |
| 11 | + $model::STATUS_HIDDEN => \Yii::t('artbox-comment', 'Скрытый'), | ||
| 12 | + $model::STATUS_DELETED => \Yii::t('artbox-comment', 'Удаленный'), | ||
| 13 | ]; | 13 | ]; |
| 14 | $form = ActiveForm::begin(); | 14 | $form = ActiveForm::begin(); |
| 15 | echo $form->field($model, 'text') | 15 | echo $form->field($model, 'text') |
| 16 | ->textarea(); | 16 | ->textarea(); |
| 17 | echo $form->field($model, 'status') | 17 | echo $form->field($model, 'status') |
| 18 | ->dropDownList($statuses); | 18 | ->dropDownList($statuses); |
| 19 | - echo Html::submitButton('Обновить'); | 19 | + echo Html::submitButton(\Yii::t('artbox-comment', 'Обновить')); |
| 20 | $form->end(); | 20 | $form->end(); |
| 21 | \ No newline at end of file | 21 | \ No newline at end of file |
widgets/CommentWidget.php
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | - namespace artweb\artbox\comment\widgets; | 3 | + namespace artbox\webcomment\widgets; |
| 4 | 4 | ||
| 5 | - use artweb\artbox\comment\assets\CommentAsset; | ||
| 6 | - use artweb\artbox\comment\models\interfaces\CommentInterface; | ||
| 7 | - use artweb\artbox\comment\models\RatingModel; | ||
| 8 | - use artweb\artbox\comment\Module; | ||
| 9 | - use artweb\artbox\models\Customer; | 5 | + use artbox\webcomment\assets\CommentAsset; |
| 6 | + use artbox\webcomment\models\CommentModel; | ||
| 7 | + use artbox\webcomment\models\interfaces\CommentInterface; | ||
| 8 | + use artbox\webcomment\models\RatingModel; | ||
| 9 | + use artbox\webcomment\Module; | ||
| 10 | use Yii; | 10 | use Yii; |
| 11 | use yii\base\InvalidConfigException; | 11 | use yii\base\InvalidConfigException; |
| 12 | use yii\base\Model; | 12 | use yii\base\Model; |
| @@ -19,20 +19,22 @@ | @@ -19,20 +19,22 @@ | ||
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * Class CommentWidget | 21 | * Class CommentWidget |
| 22 | + * | ||
| 22 | * @property Model $model Model, to which comment attached | 23 | * @property Model $model Model, to which comment attached |
| 23 | - * @package artweb\artbox\comment\widgets | ||
| 24 | */ | 24 | */ |
| 25 | class CommentWidget extends Widget | 25 | class CommentWidget extends Widget |
| 26 | { | 26 | { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * Model, to which comment attached | 29 | * Model, to which comment attached |
| 30 | + * | ||
| 30 | * @var Model Model | 31 | * @var Model Model |
| 31 | */ | 32 | */ |
| 32 | //public $model; | 33 | //public $model; |
| 33 | 34 | ||
| 34 | /** | 35 | /** |
| 35 | * Options | 36 | * Options |
| 37 | + * | ||
| 36 | * @var array | 38 | * @var array |
| 37 | */ | 39 | */ |
| 38 | public $options = [ | 40 | public $options = [ |
| @@ -43,10 +45,11 @@ | @@ -43,10 +45,11 @@ | ||
| 43 | /** | 45 | /** |
| 44 | * @var string the view file that will render comment form. | 46 | * @var string the view file that will render comment form. |
| 45 | */ | 47 | */ |
| 46 | - public $formView = '@artbox-comment/views/artbox_comment_form'; | 48 | + public $formView = '@artbox/webcomment/views/artbox_comment_form'; |
| 47 | 49 | ||
| 48 | /** | 50 | /** |
| 49 | * Form options | 51 | * Form options |
| 52 | + * | ||
| 50 | * @var array | 53 | * @var array |
| 51 | */ | 54 | */ |
| 52 | public $formOptions = [ | 55 | public $formOptions = [ |
| @@ -55,6 +58,7 @@ | @@ -55,6 +58,7 @@ | ||
| 55 | 58 | ||
| 56 | /** | 59 | /** |
| 57 | * Params to be passed to form | 60 | * Params to be passed to form |
| 61 | + * | ||
| 58 | * @var array | 62 | * @var array |
| 59 | */ | 63 | */ |
| 60 | public $formParams = []; | 64 | public $formParams = []; |
| @@ -62,10 +66,11 @@ | @@ -62,10 +66,11 @@ | ||
| 62 | /** | 66 | /** |
| 63 | * @var string the view file that will render comments list. | 67 | * @var string the view file that will render comments list. |
| 64 | */ | 68 | */ |
| 65 | - public $listView = '@artbox-comment/views/artbox_comment_list'; | 69 | + public $listView = '@artbox/webcomment/views/artbox_comment_list'; |
| 66 | 70 | ||
| 67 | /** | 71 | /** |
| 68 | * List options | 72 | * List options |
| 73 | + * | ||
| 69 | * @var array | 74 | * @var array |
| 70 | */ | 75 | */ |
| 71 | public $listOptions = [ | 76 | public $listOptions = [ |
| @@ -74,12 +79,14 @@ | @@ -74,12 +79,14 @@ | ||
| 74 | 79 | ||
| 75 | /** | 80 | /** |
| 76 | * List params | 81 | * List params |
| 82 | + * | ||
| 77 | * @var array | 83 | * @var array |
| 78 | */ | 84 | */ |
| 79 | public $listParams = []; | 85 | public $listParams = []; |
| 80 | 86 | ||
| 81 | /** | 87 | /** |
| 82 | * Reply options | 88 | * Reply options |
| 89 | + * | ||
| 83 | * @var array | 90 | * @var array |
| 84 | */ | 91 | */ |
| 85 | public $replyOptions = [ | 92 | public $replyOptions = [ |
| @@ -89,30 +96,35 @@ | @@ -89,30 +96,35 @@ | ||
| 89 | 96 | ||
| 90 | /** | 97 | /** |
| 91 | * Reply view | 98 | * Reply view |
| 99 | + * | ||
| 92 | * @var string | 100 | * @var string |
| 93 | */ | 101 | */ |
| 94 | - public $replyView = '@artbox-comment/views/artbox_comment_reply'; | 102 | + public $replyView = '@artbox/webcomment/views/artbox_comment_reply'; |
| 95 | 103 | ||
| 96 | /** | 104 | /** |
| 97 | * Comment form ID. If you have multiple forms on the same page, please use unique IDs. | 105 | * Comment form ID. If you have multiple forms on the same page, please use unique IDs. |
| 106 | + * | ||
| 98 | * @var string Form ID | 107 | * @var string Form ID |
| 99 | */ | 108 | */ |
| 100 | public $formId = 'artbox-comment-form'; | 109 | public $formId = 'artbox-comment-form'; |
| 101 | 110 | ||
| 102 | /** | 111 | /** |
| 103 | * Comment list ID. If you have multiple forms on the same page, please use unique IDs. | 112 | * Comment list ID. If you have multiple forms on the same page, please use unique IDs. |
| 113 | + * | ||
| 104 | * @var string List ID | 114 | * @var string List ID |
| 105 | */ | 115 | */ |
| 106 | public $listId = 'artbox-comment-list'; | 116 | public $listId = 'artbox-comment-list'; |
| 107 | 117 | ||
| 108 | /** | 118 | /** |
| 109 | * Item view | 119 | * Item view |
| 120 | + * | ||
| 110 | * @var string | 121 | * @var string |
| 111 | */ | 122 | */ |
| 112 | - public $itemView = '@artbox-comment/views/artbox_comment_item'; | 123 | + public $itemView = '@artbox/webcomment/views/artbox_comment_item'; |
| 113 | 124 | ||
| 114 | /** | 125 | /** |
| 115 | * Item options | 126 | * Item options |
| 127 | + * | ||
| 116 | * @var array | 128 | * @var array |
| 117 | */ | 129 | */ |
| 118 | public $itemOptions = [ | 130 | public $itemOptions = [ |
| @@ -125,24 +137,26 @@ | @@ -125,24 +137,26 @@ | ||
| 125 | /** | 137 | /** |
| 126 | * Entity ID attribute, default to primaryKey() if ActiveRecord and throws exception if not | 138 | * Entity ID attribute, default to primaryKey() if ActiveRecord and throws exception if not |
| 127 | * set | 139 | * set |
| 140 | + * | ||
| 128 | * @var string entity id attribute | 141 | * @var string entity id attribute |
| 129 | */ | 142 | */ |
| 130 | public $entityIdAttribute; | 143 | public $entityIdAttribute; |
| 131 | 144 | ||
| 132 | /** | 145 | /** |
| 133 | * Info to be passed to Comment Model | 146 | * Info to be passed to Comment Model |
| 147 | + * | ||
| 134 | * @var string $info Additional info | 148 | * @var string $info Additional info |
| 135 | */ | 149 | */ |
| 136 | - public $info = NULL; | 150 | + public $info = null; |
| 137 | 151 | ||
| 138 | /** | 152 | /** |
| 139 | * Client options to be passed to JS | 153 | * Client options to be passed to JS |
| 154 | + * | ||
| 140 | * @var array comment widget client options | 155 | * @var array comment widget client options |
| 141 | */ | 156 | */ |
| 142 | public $clientOptions = []; | 157 | public $clientOptions = []; |
| 143 | 158 | ||
| 144 | /** | 159 | /** |
| 145 | - * @todo Check if needed | ||
| 146 | * @var string pjax container id | 160 | * @var string pjax container id |
| 147 | */ | 161 | */ |
| 148 | public $pjaxContainerId; | 162 | public $pjaxContainerId; |
| @@ -151,12 +165,14 @@ | @@ -151,12 +165,14 @@ | ||
| 151 | 165 | ||
| 152 | /** | 166 | /** |
| 153 | * Model fully namespaced classname | 167 | * Model fully namespaced classname |
| 168 | + * | ||
| 154 | * @var string Model namespace | 169 | * @var string Model namespace |
| 155 | */ | 170 | */ |
| 156 | protected $entity; | 171 | protected $entity; |
| 157 | 172 | ||
| 158 | /** | 173 | /** |
| 159 | * Entity ID for attached model | 174 | * Entity ID for attached model |
| 175 | + * | ||
| 160 | * @var integer Entity ID | 176 | * @var integer Entity ID |
| 161 | */ | 177 | */ |
| 162 | protected $entityId; | 178 | protected $entityId; |
| @@ -166,12 +182,14 @@ | @@ -166,12 +182,14 @@ | ||
| 166 | * * Model::className() | 182 | * * Model::className() |
| 167 | * * entityId | 183 | * * entityId |
| 168 | * * info (optional) | 184 | * * info (optional) |
| 185 | + * | ||
| 169 | * @var string encrypted entity key | 186 | * @var string encrypted entity key |
| 170 | */ | 187 | */ |
| 171 | protected $encryptedEntityKey; | 188 | protected $encryptedEntityKey; |
| 172 | 189 | ||
| 173 | /** | 190 | /** |
| 174 | * Parts for widget | 191 | * Parts for widget |
| 192 | + * | ||
| 175 | * @var array $parts | 193 | * @var array $parts |
| 176 | */ | 194 | */ |
| 177 | protected $parts; | 195 | protected $parts; |
| @@ -182,26 +200,28 @@ | @@ -182,26 +200,28 @@ | ||
| 182 | public function init() | 200 | public function init() |
| 183 | { | 201 | { |
| 184 | // Module init | 202 | // Module init |
| 185 | - Yii::$app->getModule(Module::$name); | 203 | + $module = Yii::$app->getModule(Module::$name); |
| 204 | + if (!$module) { | ||
| 205 | + Module::registerMe(); | ||
| 206 | + } | ||
| 186 | // Model init | 207 | // Model init |
| 187 | $model = $this->getModel(); | 208 | $model = $this->getModel(); |
| 188 | - | ||
| 189 | - /** | ||
| 190 | - * @todo Check if needed | ||
| 191 | - */ | ||
| 192 | - if(empty( $this->pjaxContainerId )) { | 209 | + |
| 210 | + if (empty($this->pjaxContainerId)) { | ||
| 193 | $this->pjaxContainerId = 'comment-pjax-container-' . $this->getId(); | 211 | $this->pjaxContainerId = 'comment-pjax-container-' . $this->getId(); |
| 194 | } | 212 | } |
| 195 | 213 | ||
| 196 | $this->entity = $model::className(); | 214 | $this->entity = $model::className(); |
| 197 | // Entity ID init | 215 | // Entity ID init |
| 198 | - if(!empty( $this->entityIdAttribute ) && $this->model->hasProperty($this->entityIdAttribute)) { | 216 | + if (!empty($this->entityIdAttribute) && $this->model->hasProperty($this->entityIdAttribute)) { |
| 199 | $this->entityId = $this->model->{$this->entityIdAttribute}; | 217 | $this->entityId = $this->model->{$this->entityIdAttribute}; |
| 200 | } else { | 218 | } else { |
| 201 | - if($this->model instanceof ActiveRecord && !empty( $this->model->getPrimaryKey() )) { | 219 | + if ($this->model instanceof ActiveRecord && !empty($this->model->getPrimaryKey())) { |
| 202 | $this->entityId = (int) $this->model->getPrimaryKey(); | 220 | $this->entityId = (int) $this->model->getPrimaryKey(); |
| 203 | } else { | 221 | } else { |
| 204 | - throw new InvalidConfigException(/*Yii::t('artbox-comment', 'The "entityIdAttribute" value for widget model cannot be empty.')*/); | 222 | + throw new InvalidConfigException( |
| 223 | + Yii::t('artbox-comment', 'The "entityIdAttribute" value for widget model cannot be empty.') | ||
| 224 | + ); | ||
| 205 | } | 225 | } |
| 206 | } | 226 | } |
| 207 | 227 | ||
| @@ -213,27 +233,38 @@ | @@ -213,27 +233,38 @@ | ||
| 213 | 233 | ||
| 214 | /** | 234 | /** |
| 215 | * Executes the widget. | 235 | * Executes the widget. |
| 236 | + * | ||
| 216 | * @return string the result of widget execution to be outputted. | 237 | * @return string the result of widget execution to be outputted. |
| 217 | */ | 238 | */ |
| 218 | public function run() | 239 | public function run() |
| 219 | { | 240 | { |
| 220 | /* @var Module $module */ | 241 | /* @var Module $module */ |
| 221 | $module = Yii::$app->getModule(Module::$name); | 242 | $module = Yii::$app->getModule(Module::$name); |
| 243 | + if (!$module) { | ||
| 244 | + Module::registerMe(); | ||
| 245 | + } | ||
| 222 | $commentModelClass = $module->commentModelClass; | 246 | $commentModelClass = $module->commentModelClass; |
| 223 | - $commentModel = $this->createModel($commentModelClass, [ | ||
| 224 | - 'entity' => $this->entity, | ||
| 225 | - 'entityId' => $this->entityId, | ||
| 226 | - 'encryptedEntity' => $this->encryptedEntityKey, | ||
| 227 | - 'scenario' => \Yii::$app->user->getIsGuest() ? $commentModelClass::SCENARIO_GUEST : $commentModelClass::SCENARIO_USER, | ||
| 228 | - ]); | ||
| 229 | - if($module::$enableRating) { | 247 | + $commentModel = $this->createModel( |
| 248 | + $commentModelClass, | ||
| 249 | + [ | ||
| 250 | + 'entity' => $this->entity, | ||
| 251 | + 'entityId' => $this->entityId, | ||
| 252 | + 'encryptedEntity' => $this->encryptedEntityKey, | ||
| 253 | + 'scenario' => \Yii::$app->user->getIsGuest( | ||
| 254 | + ) ? CommentModel::SCENARIO_GUEST : CommentModel::SCENARIO_USER, | ||
| 255 | + ] | ||
| 256 | + ); | ||
| 257 | + if ($module::$enableRating) { | ||
| 230 | $ratingModelClass = $module->ratingModelClass; | 258 | $ratingModelClass = $module->ratingModelClass; |
| 231 | $ratingModel = $this->createRating($ratingModelClass); | 259 | $ratingModel = $this->createRating($ratingModelClass); |
| 232 | } else { | 260 | } else { |
| 233 | - $ratingModel = NULL; | 261 | + $ratingModel = null; |
| 262 | + } | ||
| 263 | + if (method_exists($commentModelClass, 'getTree')) { | ||
| 264 | + $comments = $commentModelClass::getTree($this->entity, $this->entityId); | ||
| 265 | + } else { | ||
| 266 | + $comments = []; | ||
| 234 | } | 267 | } |
| 235 | - | ||
| 236 | - $comments = $commentModelClass::getTree($this->entity, $this->entityId); | ||
| 237 | 268 | ||
| 238 | $this->buildParts($commentModel, $comments, $ratingModel); | 269 | $this->buildParts($commentModel, $comments, $ratingModel); |
| 239 | 270 | ||
| @@ -255,16 +286,22 @@ | @@ -255,16 +286,22 @@ | ||
| 255 | 286 | ||
| 256 | /** | 287 | /** |
| 257 | * Get encrypted entity key | 288 | * Get encrypted entity key |
| 289 | + * | ||
| 258 | * @return string | 290 | * @return string |
| 259 | */ | 291 | */ |
| 260 | protected function generateEntityKey() | 292 | protected function generateEntityKey() |
| 261 | { | 293 | { |
| 262 | return Yii::$app->getSecurity() | 294 | return Yii::$app->getSecurity() |
| 263 | - ->encryptByKey(Json::encode([ | ||
| 264 | - 'entity' => $this->entity, | ||
| 265 | - 'entity_id' => $this->entityId, | ||
| 266 | - 'info' => $this->info, | ||
| 267 | - ]), Module::$encryptionKey); | 295 | + ->encryptByKey( |
| 296 | + Json::encode( | ||
| 297 | + [ | ||
| 298 | + 'entity' => $this->entity, | ||
| 299 | + 'entity_id' => $this->entityId, | ||
| 300 | + 'info' => $this->info, | ||
| 301 | + ] | ||
| 302 | + ), | ||
| 303 | + Module::$encryptionKey | ||
| 304 | + ); | ||
| 268 | } | 305 | } |
| 269 | 306 | ||
| 270 | /** | 307 | /** |
| @@ -280,10 +317,12 @@ | @@ -280,10 +317,12 @@ | ||
| 280 | { | 317 | { |
| 281 | $options = array_merge($config, [ 'class' => $className ]); | 318 | $options = array_merge($config, [ 'class' => $className ]); |
| 282 | $object = Yii::createObject($options); | 319 | $object = Yii::createObject($options); |
| 283 | - if($object instanceof CommentInterface) { | 320 | + if ($object instanceof CommentInterface) { |
| 284 | return $object; | 321 | return $object; |
| 285 | } | 322 | } |
| 286 | - throw new InvalidConfigException(/*Yii::t(\'artbox-comment\', \'Comment model must be instance of CommentInterface.\')*/); | 323 | + throw new InvalidConfigException( |
| 324 | + Yii::t('artbox-comment', 'Comment model must be instance of CommentInterface.') | ||
| 325 | + ); | ||
| 287 | } | 326 | } |
| 288 | 327 | ||
| 289 | /** | 328 | /** |
| @@ -299,10 +338,12 @@ | @@ -299,10 +338,12 @@ | ||
| 299 | { | 338 | { |
| 300 | $options = array_merge($config, [ 'class' => $className ]); | 339 | $options = array_merge($config, [ 'class' => $className ]); |
| 301 | $object = Yii::createObject($options); | 340 | $object = Yii::createObject($options); |
| 302 | - if($object instanceof RatingModel) { | 341 | + if ($object instanceof RatingModel) { |
| 303 | return $object; | 342 | return $object; |
| 304 | } | 343 | } |
| 305 | - throw new InvalidConfigException(Yii::t('artbox-comment', 'Comment model must be instance of RatingModel.')); | 344 | + throw new InvalidConfigException( |
| 345 | + Yii::t('artbox-comment', 'Comment model must be instance of RatingModel.') | ||
| 346 | + ); | ||
| 306 | } | 347 | } |
| 307 | 348 | ||
| 308 | /** | 349 | /** |
| @@ -312,36 +353,57 @@ | @@ -312,36 +353,57 @@ | ||
| 312 | * @param ActiveDataProvider $comments | 353 | * @param ActiveDataProvider $comments |
| 313 | * @param null|RatingModel $ratingModel | 354 | * @param null|RatingModel $ratingModel |
| 314 | */ | 355 | */ |
| 315 | - protected function buildParts(CommentInterface $commentModel, ActiveDataProvider $comments, $ratingModel = NULL) | 356 | + protected function buildParts(CommentInterface $commentModel, ActiveDataProvider $comments, $ratingModel = null) |
| 316 | { | 357 | { |
| 317 | $form_options = $this->formOptions; | 358 | $form_options = $this->formOptions; |
| 318 | - $this->parts[ 'form' ] = Html::tag(ArrayHelper::remove($form_options, 'tag', 'div'), $this->render($this->formView, [ | ||
| 319 | - 'comment_model' => $commentModel, | ||
| 320 | - 'form_params' => $this->formParams, | ||
| 321 | - 'model' => $this->getModel(), | ||
| 322 | - 'formId' => $this->formId, | ||
| 323 | - 'rating_model' => $ratingModel, | ||
| 324 | - ]), $form_options); | ||
| 325 | - | ||
| 326 | - if(!\Yii::$app->user->isGuest) { | 359 | + $this->parts[ 'form' ] = Html::tag( |
| 360 | + ArrayHelper::remove($form_options, 'tag', 'div'), | ||
| 361 | + $this->render( | ||
| 362 | + $this->formView, | ||
| 363 | + [ | ||
| 364 | + 'comment_model' => $commentModel, | ||
| 365 | + 'form_params' => $this->formParams, | ||
| 366 | + 'model' => $this->getModel(), | ||
| 367 | + 'formId' => $this->formId, | ||
| 368 | + 'rating_model' => $ratingModel, | ||
| 369 | + ] | ||
| 370 | + ), | ||
| 371 | + $form_options | ||
| 372 | + ); | ||
| 373 | + | ||
| 374 | + if (!\Yii::$app->user->isGuest) { | ||
| 327 | $reply_options = $this->replyOptions; | 375 | $reply_options = $this->replyOptions; |
| 328 | - $this->parts[ 'reply_form' ] = Html::tag(ArrayHelper::remove($reply_options, 'tag', 'div'), $this->render($this->replyView, [ | ||
| 329 | - 'comment_model' => $commentModel, | ||
| 330 | - 'form_params' => $this->formParams, | ||
| 331 | - 'model' => $this->getModel(), | ||
| 332 | - 'formId' => $this->formId, | ||
| 333 | - ]), $reply_options); | 376 | + $this->parts[ 'reply_form' ] = Html::tag( |
| 377 | + ArrayHelper::remove($reply_options, 'tag', 'div'), | ||
| 378 | + $this->render( | ||
| 379 | + $this->replyView, | ||
| 380 | + [ | ||
| 381 | + 'comment_model' => $commentModel, | ||
| 382 | + 'form_params' => $this->formParams, | ||
| 383 | + 'model' => $this->getModel(), | ||
| 384 | + 'formId' => $this->formId, | ||
| 385 | + ] | ||
| 386 | + ), | ||
| 387 | + $reply_options | ||
| 388 | + ); | ||
| 334 | } | 389 | } |
| 335 | 390 | ||
| 336 | $list_options = array_merge($this->listOptions, [ 'id' => $this->listId ]); | 391 | $list_options = array_merge($this->listOptions, [ 'id' => $this->listId ]); |
| 337 | - $this->parts[ 'list' ] = Html::tag(ArrayHelper::remove($list_options, 'tag', 'div'), $this->render($this->listView, [ | ||
| 338 | - 'comment_model' => $commentModel, | ||
| 339 | - 'list_params' => $this->listParams, | ||
| 340 | - 'model' => $this->getModel(), | ||
| 341 | - 'comments' => $comments, | ||
| 342 | - 'item_options' => $this->itemOptions, | ||
| 343 | - 'item_view' => $this->itemView, | ||
| 344 | - ]), $list_options); | 392 | + $this->parts[ 'list' ] = Html::tag( |
| 393 | + ArrayHelper::remove($list_options, 'tag', 'div'), | ||
| 394 | + $this->render( | ||
| 395 | + $this->listView, | ||
| 396 | + [ | ||
| 397 | + 'comment_model' => $commentModel, | ||
| 398 | + 'list_params' => $this->listParams, | ||
| 399 | + 'model' => $this->getModel(), | ||
| 400 | + 'comments' => $comments, | ||
| 401 | + 'item_options' => $this->itemOptions, | ||
| 402 | + 'item_view' => $this->itemView, | ||
| 403 | + ] | ||
| 404 | + ), | ||
| 405 | + $list_options | ||
| 406 | + ); | ||
| 345 | } | 407 | } |
| 346 | 408 | ||
| 347 | /** | 409 | /** |
| @@ -366,9 +428,9 @@ | @@ -366,9 +428,9 @@ | ||
| 366 | 428 | ||
| 367 | public function getModel(): Model | 429 | public function getModel(): Model |
| 368 | { | 430 | { |
| 369 | - if(!empty( $this->model )) { | 431 | + if (!empty($this->model)) { |
| 370 | return $this->model; | 432 | return $this->model; |
| 371 | } | 433 | } |
| 372 | - throw new InvalidConfigException(/*Yii::t(\'artbox-comment\', \'The "model" property must be set.\')*/); | 434 | + throw new InvalidConfigException(Yii::t('artbox-comment', 'The "model" property must be set.')); |
| 373 | } | 435 | } |
| 374 | } | 436 | } |
| 375 | \ No newline at end of file | 437 | \ No newline at end of file |