Commit b82db04a71afede9792efa103ee7452ecda2733c
1 parent
24e8280a
test
Showing
21 changed files
with
948 additions
and
30 deletions
Show diff stats
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\components\rules; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class CommentOwnRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentOwn'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return isset( $params[ 'item' ] ) ? $params[ 'item' ]->user_id == $user : false; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
common/config/main.php
| 1 | <?php | 1 | <?php |
| 2 | -return [ | 2 | + |
| 3 | + return [ | ||
| 3 | 'timeZone' => 'Europe/Kiev', | 4 | 'timeZone' => 'Europe/Kiev', |
| 4 | 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', | 5 | 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', |
| 5 | 'controllerMap' => [ | 6 | 'controllerMap' => [ |
| @@ -38,6 +39,47 @@ return [ | @@ -38,6 +39,47 @@ return [ | ||
| 38 | 'file' => [ | 39 | 'file' => [ |
| 39 | 'class' => 'common\modules\file\Module', | 40 | 'class' => 'common\modules\file\Module', |
| 40 | ], | 41 | ], |
| 42 | + 'comment' => [ | ||
| 43 | + 'class' => 'common\modules\comment\Module', | ||
| 44 | + 'useRbac' => true, | ||
| 45 | + 'rbac' => [ | ||
| 46 | + 'rules' => [ | ||
| 47 | + \common\modules\comment\rbac\ArtboxCommentCreateRule::className(), | ||
| 48 | + \common\modules\comment\rbac\ArtboxCommentDeleteRule::className(), | ||
| 49 | + \common\modules\comment\rbac\ArtboxCommentUpdateRule::className(), | ||
| 50 | + \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule::className(), | ||
| 51 | + \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule::className(), | ||
| 52 | + ], | ||
| 53 | + 'permissions' => [ | ||
| 54 | + [ | ||
| 55 | + 'name' => common\modules\comment\Permissions::CREATE, | ||
| 56 | + 'description' => 'Can create comments', | ||
| 57 | + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentCreateRule())->name, | ||
| 58 | + ], | ||
| 59 | + [ | ||
| 60 | + 'name' => common\modules\comment\Permissions::UPDATE, | ||
| 61 | + 'description' => 'Can update comments', | ||
| 62 | + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateRule())->name, | ||
| 63 | + ], | ||
| 64 | + [ | ||
| 65 | + 'name' => common\modules\comment\Permissions::DELETE, | ||
| 66 | + 'description' => 'Can delete comments', | ||
| 67 | + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteRule())->name, | ||
| 68 | + ], | ||
| 69 | + [ | ||
| 70 | + 'name' => common\modules\comment\Permissions::UPDATE_OWN, | ||
| 71 | + 'description' => 'Can update own comments', | ||
| 72 | + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule())->name, | ||
| 73 | + ], | ||
| 74 | + [ | ||
| 75 | + 'name' => common\modules\comment\Permissions::DELETE_OWN, | ||
| 76 | + 'description' => 'Can delete own comments', | ||
| 77 | + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule())->name, | ||
| 78 | + ], | ||
| 79 | + ], | ||
| 80 | + ], | ||
| 81 | + | ||
| 82 | + ], | ||
| 41 | 83 | ||
| 42 | ], | 84 | ], |
| 43 | 'bootstrap' => [ | 85 | 'bootstrap' => [ |
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment; | ||
| 3 | + | ||
| 4 | + /** | ||
| 5 | + * Class Module | ||
| 6 | + * @package common\modules\comment | ||
| 7 | + */ | ||
| 8 | + class Module extends \yii\base\Module | ||
| 9 | + { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * @var string Module name | ||
| 13 | + */ | ||
| 14 | + public static $moduleName = 'artbox_comment'; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * @var bool Wheather to use Rbac system | ||
| 18 | + * @link http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#rbac | ||
| 19 | + * @see \yii\rbac\ManagerInterface | ||
| 20 | + */ | ||
| 21 | + public $useRbac = false; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Array of RBAC rules and permissions that can be used by install command. | ||
| 25 | + * | ||
| 26 | + * Currently supports associative array, of such view: | ||
| 27 | + * | ||
| 28 | + * <code> | ||
| 29 | + * [ | ||
| 30 | + * 'rules' => [ | ||
| 31 | + * \full\namapaced\ClassName, | ||
| 32 | + * \another\one\ClassName, | ||
| 33 | + * ], | ||
| 34 | + * 'permissions' => [ | ||
| 35 | + * [ | ||
| 36 | + * 'name' => stringName, | ||
| 37 | + * 'description' => descriptionText, | ||
| 38 | + * 'ruleName' => (new \full\namespaced\ClassName())->name (optional) | ||
| 39 | + * ], | ||
| 40 | + * [ | ||
| 41 | + * 'name' => stringName2, | ||
| 42 | + * 'description' => descriptionText2, | ||
| 43 | + * 'ruleName' => (new \another\one\ClassName())->name (optional) | ||
| 44 | + * ], | ||
| 45 | + * ] | ||
| 46 | + * ] | ||
| 47 | + * </code> | ||
| 48 | + * | ||
| 49 | + * @var array | ||
| 50 | + * @see \common\modules\comment\commands\RbacController | ||
| 51 | + */ | ||
| 52 | + public $rbac = []; | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @var \yii\db\Connection Connection to the db | ||
| 56 | + */ | ||
| 57 | + public $db = null; | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * @inheritdoc | ||
| 61 | + */ | ||
| 62 | + public function init() | ||
| 63 | + { | ||
| 64 | + parent::init(); | ||
| 65 | + if(\Yii::$app instanceof \yii\console\Application) { | ||
| 66 | + $this->controllerNamespace = 'common\modules\comment\commands'; | ||
| 67 | + } | ||
| 68 | + if($this->db === null) { | ||
| 69 | + $this->db = \Yii::$app->db; | ||
| 70 | + } elseif(!$this->db instanceof \yii\db\Connection) { | ||
| 71 | + throw new \yii\base\InvalidConfigException('Конфиг db обязан наследоваться от'.\yii\db\Connection::className()); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + } | ||
| 0 | \ No newline at end of file | 75 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment; | ||
| 3 | + | ||
| 4 | + class Permissions | ||
| 5 | + { | ||
| 6 | + | ||
| 7 | + const CREATE = 'artbox_comment.create'; | ||
| 8 | + const UPDATE = 'artbox_comment.update'; | ||
| 9 | + const DELETE = 'artbox_comment.delete'; | ||
| 10 | + const UPDATE_OWN = 'artbox_comment.update_own'; | ||
| 11 | + const DELETE_OWN = 'artbox_comment.delete.own'; | ||
| 12 | + } | ||
| 0 | \ No newline at end of file | 13 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment\commands; | ||
| 3 | + | ||
| 4 | + class RbacController extends \yii\console\Controller | ||
| 5 | + { | ||
| 6 | + | ||
| 7 | + public function actionInstall() | ||
| 8 | + { | ||
| 9 | + /** | ||
| 10 | + * @var \common\modules\comment\Module $module | ||
| 11 | + */ | ||
| 12 | + $module = \Yii::$app->controller->module; | ||
| 13 | + if(!$module->useRbac) { | ||
| 14 | + throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs'); | ||
| 15 | + } | ||
| 16 | + $auth = \Yii::$app->getAuthManager(); | ||
| 17 | + if(!$auth instanceof \yii\rbac\ManagerInterface) { | ||
| 18 | + throw new \yii\base\InvalidConfigException('ManagerInterface is not configured'); | ||
| 19 | + } | ||
| 20 | + if(!empty($module->rbac['rules'])) { | ||
| 21 | + foreach($module->rbac['rules'] as $rule) { | ||
| 22 | + $rule_model = new $rule(); | ||
| 23 | + echo "Creating rule: ".$rule_model->name."\n"; | ||
| 24 | + if($auth->add($rule_model)) { | ||
| 25 | + echo "Successful\n"; | ||
| 26 | + } else { | ||
| 27 | + echo "Failed\n"; | ||
| 28 | + } | ||
| 29 | + unset($rule_model); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + if(!empty($module->rbac['permissions'])) { | ||
| 33 | + foreach($module->rbac['permissions'] as $permission) { | ||
| 34 | + echo "Creating permission: ".$permission['name']."\n"; | ||
| 35 | + if($auth->add(new \yii\rbac\Permission($permission))) { | ||
| 36 | + echo "Successful\n"; | ||
| 37 | + } else { | ||
| 38 | + echo "Failed\n"; | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public function actionUninstall() | ||
| 45 | + { | ||
| 46 | + /** | ||
| 47 | + * @var \common\modules\comment\Module $module | ||
| 48 | + */ | ||
| 49 | + $module = \Yii::$app->controller->module; | ||
| 50 | + if(!$module->useRbac) { | ||
| 51 | + throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs'); | ||
| 52 | + } | ||
| 53 | + $auth = \Yii::$app->getAuthManager(); | ||
| 54 | + if(!$auth instanceof \yii\rbac\ManagerInterface) { | ||
| 55 | + throw new \yii\base\InvalidConfigException('ManagerInterface is not configured'); | ||
| 56 | + } | ||
| 57 | + if(!empty($module->rbac['rules'])) { | ||
| 58 | + foreach($module->rbac['rules'] as $rule) { | ||
| 59 | + $rule_model = new $rule(); | ||
| 60 | + echo "Removing rule: ".$rule_model->name."\n"; | ||
| 61 | + if($auth->remove($rule_model)) { | ||
| 62 | + echo "Successful\n"; | ||
| 63 | + } else { | ||
| 64 | + echo "Failed\n"; | ||
| 65 | + } | ||
| 66 | + unset($rule_model); | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + if(!empty($module->rbac['permissions'])) { | ||
| 70 | + foreach($module->rbac['permissions'] as $permission) { | ||
| 71 | + echo "Removing permission: ".$permission['name']."\n"; | ||
| 72 | + if($auth->remove(new \yii\rbac\Permission($permission))) { | ||
| 73 | + echo "Successful\n"; | ||
| 74 | + } else { | ||
| 75 | + echo "Failed\n"; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + } | ||
| 0 | \ No newline at end of file | 82 | \ No newline at end of file |
common/modules/comment/interfaces/CommentInterface.php
0 → 100644
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment\interfaces; | ||
| 3 | + | ||
| 4 | + interface CommentInterface { | ||
| 5 | + public function load($data, $formName = null); | ||
| 6 | + public function formName(); | ||
| 7 | + public function getComments($entity); | ||
| 8 | + public function postComment($data); | ||
| 9 | + public function deleteComment($comment_id); | ||
| 10 | + public function updateComment($comment_id); | ||
| 11 | + } |
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment\models; | ||
| 3 | + | ||
| 4 | + /** | ||
| 5 | + * Class Comment | ||
| 6 | + * @property bool $guestComment | ||
| 7 | + * @package common\modules\comment\models | ||
| 8 | + */ | ||
| 9 | + class Comment extends \yii\db\ActiveRecord | ||
| 10 | + implements \common\modules\comment\interfaces\CommentInterface | ||
| 11 | + { | ||
| 12 | + | ||
| 13 | + const STATUS_HIDDEN = 0; | ||
| 14 | + const STATUS_DELETED = 2; | ||
| 15 | + const STATUS_ACTIVE = 1; | ||
| 16 | + const STATUS_PERSONAL = 3; | ||
| 17 | + | ||
| 18 | + const SCENARIO_USER = 'user'; | ||
| 19 | + const SCENARIO_GUEST = 'guest'; | ||
| 20 | + | ||
| 21 | + public function rules() | ||
| 22 | + { | ||
| 23 | + return [ | ||
| 24 | + [ | ||
| 25 | + ['text'], | ||
| 26 | + 'required', | ||
| 27 | + ], | ||
| 28 | + [ | ||
| 29 | + ['user_email'], | ||
| 30 | + 'email', | ||
| 31 | + ], | ||
| 32 | + [ | ||
| 33 | + ['user_name'], | ||
| 34 | + 'string', | ||
| 35 | + ], | ||
| 36 | + ]; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public function scenarios() | ||
| 40 | + { | ||
| 41 | + return [ | ||
| 42 | + self::SCENARIO_GUEST => ['user_name', 'user_email', 'text'], | ||
| 43 | + self::SCENARIO_USER => ['text'], | ||
| 44 | + ]; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static function tableName() | ||
| 48 | + { | ||
| 49 | + return '{{%comment}}'; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * @inheritdoc | ||
| 54 | + */ | ||
| 55 | + public function attributeLabels() | ||
| 56 | + { | ||
| 57 | + return [ | ||
| 58 | + 'text' => \Yii::t('app', 'Комментарий'), | ||
| 59 | + 'user_name' => \Yii::t('app', 'Имя'), | ||
| 60 | + 'user_email' => \Yii::t('app', 'Email'), | ||
| 61 | + ]; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public function getGuestComment($entity) | ||
| 65 | + { | ||
| 66 | + return true; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public function getComments($entity) | ||
| 70 | + { | ||
| 71 | + return $this->find()->where(['entity' => $this->entity]); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public function postComment($data) | ||
| 75 | + { | ||
| 76 | + if($this->load($data) && $this->insert($data)) { | ||
| 77 | + $this->clearSafe(); | ||
| 78 | + return true; | ||
| 79 | + } else { | ||
| 80 | + return false; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public function updateComment($comment_id) | ||
| 85 | + { | ||
| 86 | + // TODO: Implement updateComment() method. | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public function deleteComment($comment_id) | ||
| 90 | + { | ||
| 91 | + // TODO: Implement deleteComment() method. | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public function checkCreate($entity) | ||
| 95 | + { | ||
| 96 | + if($this->getGuestComment($entity)) { | ||
| 97 | + return true; | ||
| 98 | + } else { | ||
| 99 | + return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, ['entity' => $entity]); | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + protected function clearSafe($setNew = true) { | ||
| 104 | + $safe = $this->safeAttributes(); | ||
| 105 | + $count = count($safe); | ||
| 106 | + $values = array_fill(0, $count, NULL); | ||
| 107 | + $result = array_combine($safe, $values); | ||
| 108 | + $this->setAttributes($result); | ||
| 109 | + $this->setIsNewRecord($setNew); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + } | ||
| 0 | \ No newline at end of file | 113 | \ No newline at end of file |
common/modules/comment/rbac/ArtboxCommentCreateRule.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\modules\comment\rbac; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class ArtboxCommentCreateRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentCreateArtbox'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return true; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
common/modules/comment/rbac/ArtboxCommentDeleteOwnRule.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\modules\comment\rbac; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class ArtboxCommentDeleteOwnRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentDeleteOwnArtbox'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return true; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
common/modules/comment/rbac/ArtboxCommentDeleteRule.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\modules\comment\rbac; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class ArtboxCommentDeleteRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentDeleteArtbox'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return true; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\modules\comment\rbac; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class ArtboxCommentUpdateOwnRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentUpdateOwnArtbox'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return true; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
common/modules/comment/rbac/ArtboxCommentUpdateRule.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace common\modules\comment\rbac; | ||
| 4 | + | ||
| 5 | + use yii\rbac\Rule; | ||
| 6 | + | ||
| 7 | + class ArtboxCommentUpdateRule extends Rule | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + public $name = 'canCommentUpdateArtbox'; | ||
| 11 | + | ||
| 12 | + public function execute($user, $item, $params) | ||
| 13 | + { | ||
| 14 | + return true; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + } | ||
| 0 | \ No newline at end of file | 18 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + namespace common\modules\comment\widgets; | ||
| 3 | + | ||
| 4 | + use \yii\helpers\ArrayHelper; | ||
| 5 | + use \yii\helpers\Html; | ||
| 6 | + | ||
| 7 | + class CommentWidget extends \yii\base\Widget | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * @var array Parts of widgets that can be rendered | ||
| 12 | + */ | ||
| 13 | + public $parts = []; | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * @var string|\common\modules\comment\models\Comment | ||
| 17 | + */ | ||
| 18 | + public $comment_class; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * @var array | ||
| 22 | + */ | ||
| 23 | + public $class_options = []; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @var bool Wheather to display comment list | ||
| 27 | + */ | ||
| 28 | + public $display_comment_list = true; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * @var bool Wheather to display comment form | ||
| 32 | + */ | ||
| 33 | + public $display_comment_form = true; | ||
| 34 | + | ||
| 35 | + public $display_comment_success = true; | ||
| 36 | + | ||
| 37 | + public $allow_multiple = true; | ||
| 38 | + | ||
| 39 | + public $success_text = "Comment posted successfully"; | ||
| 40 | + | ||
| 41 | + public $list_options = [ | ||
| 42 | + 'tag' => 'div', | ||
| 43 | + 'view' => 'list-comment', | ||
| 44 | + 'class' => 'test-class', | ||
| 45 | + ]; | ||
| 46 | + | ||
| 47 | + public $success_options = [ | ||
| 48 | + 'tag' => 'div', | ||
| 49 | + 'content' => null, | ||
| 50 | + 'class' => 'test-class-success', | ||
| 51 | + ]; | ||
| 52 | + | ||
| 53 | + public $form_options = [ | ||
| 54 | + 'tag' => 'div', | ||
| 55 | + 'view' => 'form-comment', | ||
| 56 | + 'class' => 'test-class-form', | ||
| 57 | + ]; | ||
| 58 | + | ||
| 59 | + protected $isSuccess = false; | ||
| 60 | + | ||
| 61 | + public $entity; | ||
| 62 | + | ||
| 63 | + public $template = "{success}\n{form}\n{list}"; | ||
| 64 | + | ||
| 65 | + public $options = []; | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * @var \yii\data\DataProviderInterface | ||
| 69 | + */ | ||
| 70 | + public $dataProvider; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * @inheritdoc | ||
| 74 | + */ | ||
| 75 | + public function init() | ||
| 76 | + { | ||
| 77 | + parent::init(); | ||
| 78 | + if(is_string($this->comment_class)) { | ||
| 79 | + $this->comment_class = new $this->comment_class($this->class_options); | ||
| 80 | + } elseif(!is_object($this->comment_class)) { | ||
| 81 | + throw new \yii\base\InvalidConfigException(__CLASS__.'->comment_class must be defined as string or object.'); | ||
| 82 | + } | ||
| 83 | + $this->comment_class->entity = $this->entity; | ||
| 84 | + $this->createDataProvider(); | ||
| 85 | + if($this->comment_class->checkCreate($this->entity)) { | ||
| 86 | + $this->handleCreate(); | ||
| 87 | + } | ||
| 88 | + ob_start(); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * @inheritdoc | ||
| 93 | + * @return string | ||
| 94 | + */ | ||
| 95 | + public function run() | ||
| 96 | + { | ||
| 97 | + $content = ob_get_clean(); | ||
| 98 | + $this->createParts(); | ||
| 99 | + return $this->renderWidget(); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public function createParts() { | ||
| 103 | + if($this->display_comment_success && $this->isSuccess) { | ||
| 104 | + $tag = ArrayHelper::remove($this->success_options, 'tag', 'div'); | ||
| 105 | + if(is_callable($this->success_options['content'])) { | ||
| 106 | + $result = call_user_func(ArrayHelper::remove($this->success_options, 'content'), $this->success_text); | ||
| 107 | + } elseif($this->success_options['content'] != NULL) { | ||
| 108 | + $result = Html::encode(ArrayHelper::remove($this->success_options, 'content', $this->success_text)); | ||
| 109 | + } else { | ||
| 110 | + $result = Html::encode($this->success_text); | ||
| 111 | + } | ||
| 112 | + $this->parts['success'] = Html::tag($tag, $result, $this->success_options); | ||
| 113 | + unset($tag, $result); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + if($this->display_comment_list) { | ||
| 117 | + $tag = ArrayHelper::remove($this->list_options, 'tag', 'div'); | ||
| 118 | + $view = ArrayHelper::remove($this->list_options, 'view'); | ||
| 119 | + $this->parts['list'] = Html::tag($tag, $this->renderItems($view), $this->list_options); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + if($this->display_comment_form) { | ||
| 123 | + $tag = ArrayHelper::remove($this->form_options, 'tag', 'div'); | ||
| 124 | + $view = ArrayHelper::remove($this->form_options, 'view'); | ||
| 125 | + $this->parts['form'] = Html::tag($tag, $this->renderForm($view), $this->list_options); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public function createDataProvider() | ||
| 130 | + { | ||
| 131 | + $this->dataProvider = new \yii\data\ActiveDataProvider([ | ||
| 132 | + 'query' => $this->comment_class->getComments($this->entity), | ||
| 133 | + 'pagination' => [ | ||
| 134 | + 'pageSize' => 10, | ||
| 135 | + ], | ||
| 136 | + ]); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public function renderItems($view) { | ||
| 140 | + if(empty($view)) { | ||
| 141 | + throw new \yii\base\InvalidConfigException("list_options[view] must be set"); | ||
| 142 | + } | ||
| 143 | + return $this->render($view, ['dataProvider' => $this->dataProvider]); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public function renderForm($view) { | ||
| 147 | + if(empty($view)) { | ||
| 148 | + throw new \yii\base\InvalidConfigException("form_options[view] must be set"); | ||
| 149 | + } | ||
| 150 | + return $this->render($view, [ | ||
| 151 | + 'model' => $this->comment_class, | ||
| 152 | + 'user' => \Yii::$app->user->identity, | ||
| 153 | + 'dataProvider' => $this->dataProvider, | ||
| 154 | + ]); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public function renderWidget() { | ||
| 158 | + $template = $this->template; | ||
| 159 | + $parts = $this->parts; | ||
| 160 | + $options = $this->options; | ||
| 161 | + $template = preg_replace('/{success}/', ArrayHelper::remove($parts, 'success', ''), $template); | ||
| 162 | + $template = preg_replace('/{list}/', ArrayHelper::remove($parts, 'list', ''), $template); | ||
| 163 | + $template = preg_replace('/{form}/', ArrayHelper::remove($parts, 'form', ''), $template); | ||
| 164 | + $tag = ArrayHelper::remove($options, 'tag', 'div'); | ||
| 165 | + return Html::tag($tag, $template, $options); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + public function handleCreate() | ||
| 169 | + { | ||
| 170 | + $data = \Yii::$app->request->post(); | ||
| 171 | + if($this->comment_class->postComment($data)) { | ||
| 172 | + $this->isSuccess = true; | ||
| 173 | + }; | ||
| 174 | + } | ||
| 175 | + } | ||
| 0 | \ No newline at end of file | 176 | \ No newline at end of file |
common/modules/comment/widgets/views/form-comment.php
0 → 100644
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * @var \common\modules\comment\models\Comment $model | ||
| 4 | + * @var \common\models\User $user | ||
| 5 | + * @var \yii\data\ActiveDataProvider $dataProvider | ||
| 6 | + */ | ||
| 7 | + use yii\widgets\ActiveForm; | ||
| 8 | + use yii\helpers\Html; | ||
| 9 | + | ||
| 10 | +?> | ||
| 11 | +<div class="new-portf-comm-count">Комментарии: <?= $dataProvider->totalCount ?></div> | ||
| 12 | + | ||
| 13 | +<div class="new-portf-add-comm style"> | ||
| 14 | + <?php | ||
| 15 | + $form = ActiveForm::begin(); | ||
| 16 | + ?> | ||
| 17 | + | ||
| 18 | + <?php | ||
| 19 | + if($model->scenario == $model::SCENARIO_GUEST) { | ||
| 20 | + echo $form->field($model, 'user_name', [ | ||
| 21 | + 'options' => [ | ||
| 22 | + 'class' => 'input-blocks-comm', | ||
| 23 | + ], | ||
| 24 | + 'inputOptions' => [ | ||
| 25 | + 'class' => 'custom-input-4', | ||
| 26 | + ], | ||
| 27 | + ])->textInput(); | ||
| 28 | + echo $form->field($model, 'user_email', [ | ||
| 29 | + 'options' => [ | ||
| 30 | + 'class' => 'input-blocks-comm', | ||
| 31 | + ], | ||
| 32 | + 'inputOptions' => [ | ||
| 33 | + 'class' => 'custom-input-4', | ||
| 34 | + ], | ||
| 35 | + ])->textInput(); | ||
| 36 | + } | ||
| 37 | + echo $form->field($model, 'text', [ | ||
| 38 | + 'options' => [ | ||
| 39 | + 'class' => 'input-blocks-comm area-comm', | ||
| 40 | + ], | ||
| 41 | + 'inputOptions' => [ | ||
| 42 | + 'class' => 'custom-area-4', | ||
| 43 | + ], | ||
| 44 | + ])->textarea(); | ||
| 45 | + ?> | ||
| 46 | + <div class="input-blocks-comm-button style"> | ||
| 47 | + <?= Html::submitButton('Добавить комментарий') ?> | ||
| 48 | + </div> | ||
| 49 | + <?php | ||
| 50 | + $form->end(); | ||
| 51 | + ?> | ||
| 52 | +</div> | ||
| 0 | \ No newline at end of file | 53 | \ No newline at end of file |
common/modules/comment/widgets/views/list-comment.php
0 → 100644
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * @var \yii\data\DataProviderInterface $dataProvider | ||
| 4 | + */ | ||
| 5 | +echo \yii\widgets\ListView::widget([ | ||
| 6 | + 'dataProvider' => $dataProvider, | ||
| 7 | + 'itemView' => 'project_comment_view', | ||
| 8 | + 'itemOptions' => [ | ||
| 9 | + 'tag' => false, | ||
| 10 | + ], | ||
| 11 | + 'summary' => '', | ||
| 12 | +]); | ||
| 0 | \ No newline at end of file | 13 | \ No newline at end of file |
common/modules/comment/widgets/views/project_comment_view.php
0 → 100644
| 1 | +<?php | ||
| 2 | + use common\models\User; | ||
| 3 | + use yii\helpers\Html; | ||
| 4 | + | ||
| 5 | + /** | ||
| 6 | + * @var \common\modules\comment\models\Comment $model Current comment model | ||
| 7 | + * @var integer $key ID of current comment | ||
| 8 | + * @var integer $index index of current element according to | ||
| 9 | + * current page, starting from 0 | ||
| 10 | + * @var \yii\widgets\ListView $widget current ListView instance | ||
| 11 | + * @var User $user | ||
| 12 | + */ | ||
| 13 | + $user = NULL; | ||
| 14 | + if(!empty( $model->user_id )) { | ||
| 15 | + $user = User::find() | ||
| 16 | + ->where([ 'id' => $model->user_id ]) | ||
| 17 | + ->with('userInfo') | ||
| 18 | + ->one(); | ||
| 19 | + } | ||
| 20 | +?> | ||
| 21 | +<div class="new-portf-comm-read"> | ||
| 22 | + <div class="style"> | ||
| 23 | + <div class="header-cabinet-foto"> | ||
| 24 | + <?php | ||
| 25 | + if(!empty( $user ) && !empty( $user->userInfo->image )) { | ||
| 26 | + echo "<img src='{$user->userInfo->image}' alt=''>"; | ||
| 27 | + } else { | ||
| 28 | + echo "<img src='/images/ded-ico.png' alt=''>"; | ||
| 29 | + } | ||
| 30 | + ?> | ||
| 31 | + </div> | ||
| 32 | + <div class="new-prof-wrapper-read"> | ||
| 33 | + <div class="new-portf-comm-read-title"> | ||
| 34 | + <?php | ||
| 35 | + if(!empty($user)) { | ||
| 36 | + echo Html::a($user->firstname . ' ' . $user->lastname, [ | ||
| 37 | + 'performer/common', | ||
| 38 | + 'performer_id' => $user->id, | ||
| 39 | + ]); | ||
| 40 | + } else { | ||
| 41 | + echo $model->user_name . '(Гость)'; | ||
| 42 | + } | ||
| 43 | + ?> | ||
| 44 | + </div> | ||
| 45 | + <div class="new-portf-comm-read-rating"> | ||
| 46 | + <div class="rating"> | ||
| 47 | + <!--оценка--> | ||
| 48 | + <input type="hidden" class="val" value="3"/> | ||
| 49 | + <!--количество голосов--> | ||
| 50 | + <input type="hidden" class="votes" value="12"/> | ||
| 51 | + </div> | ||
| 52 | + </div> | ||
| 53 | + <div class="blog-post-date"> | ||
| 54 | + <span></span> | ||
| 55 | + <p><?= date('d.m.Y', strtotime($model->date_add)) ?></p> | ||
| 56 | + </div> | ||
| 57 | + </div> | ||
| 58 | + | ||
| 59 | + <div class="new-portf-answer"> | ||
| 60 | + <?= Html::encode($model->text) ?> | ||
| 61 | + </div> | ||
| 62 | + | ||
| 63 | + </div> | ||
| 64 | + <div class="style"></div> | ||
| 65 | +</div> | ||
| 0 | \ No newline at end of file | 66 | \ No newline at end of file |
composer.json
| @@ -27,7 +27,8 @@ | @@ -27,7 +27,8 @@ | ||
| 27 | "yiisoft/yii2-imagine": "^2.0", | 27 | "yiisoft/yii2-imagine": "^2.0", |
| 28 | "mihaildev/yii2-elfinder": "^1.1", | 28 | "mihaildev/yii2-elfinder": "^1.1", |
| 29 | "kartik-v/yii2-widget-colorinput": "*", | 29 | "kartik-v/yii2-widget-colorinput": "*", |
| 30 | - "2amigos/yii2-transliterator-helper": "*" | 30 | + "2amigos/yii2-transliterator-helper": "*", |
| 31 | + "rmrevin/yii2-comments": "1.4.*" | ||
| 31 | }, | 32 | }, |
| 32 | "require-dev": { | 33 | "require-dev": { |
| 33 | "yiisoft/yii2-codeception": "*", | 34 | "yiisoft/yii2-codeception": "*", |
composer.lock
| @@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
| 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
| 5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
| 6 | ], | 6 | ], |
| 7 | - "hash": "dfde859453134d35dc61fc6825917302", | ||
| 8 | - "content-hash": "ec129e7be083837c52b871f4c8ec7f56", | 7 | + "hash": "67e32b98a5cc37bfa51bc84148316627", |
| 8 | + "content-hash": "706cd7bd8f9339ce92d17c5871da8b8f", | ||
| 9 | "packages": [ | 9 | "packages": [ |
| 10 | { | 10 | { |
| 11 | "name": "2amigos/yii2-transliterator-helper", | 11 | "name": "2amigos/yii2-transliterator-helper", |
| @@ -762,18 +762,23 @@ | @@ -762,18 +762,23 @@ | ||
| 762 | "source": { | 762 | "source": { |
| 763 | "type": "git", | 763 | "type": "git", |
| 764 | "url": "https://github.com/kartik-v/yii2-widget-select2.git", | 764 | "url": "https://github.com/kartik-v/yii2-widget-select2.git", |
| 765 | - "reference": "519241c7360a0470624f24d872741e1ea880de75" | 765 | + "reference": "4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69" |
| 766 | }, | 766 | }, |
| 767 | "dist": { | 767 | "dist": { |
| 768 | "type": "zip", | 768 | "type": "zip", |
| 769 | - "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/519241c7360a0470624f24d872741e1ea880de75", | ||
| 770 | - "reference": "519241c7360a0470624f24d872741e1ea880de75", | 769 | + "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69", |
| 770 | + "reference": "4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69", | ||
| 771 | "shasum": "" | 771 | "shasum": "" |
| 772 | }, | 772 | }, |
| 773 | "require": { | 773 | "require": { |
| 774 | "kartik-v/yii2-krajee-base": "~1.7" | 774 | "kartik-v/yii2-krajee-base": "~1.7" |
| 775 | }, | 775 | }, |
| 776 | "type": "yii2-extension", | 776 | "type": "yii2-extension", |
| 777 | + "extra": { | ||
| 778 | + "branch-alias": { | ||
| 779 | + "dev-master": "2.0.x-dev" | ||
| 780 | + } | ||
| 781 | + }, | ||
| 777 | "autoload": { | 782 | "autoload": { |
| 778 | "psr-4": { | 783 | "psr-4": { |
| 779 | "kartik\\select2\\": "" | 784 | "kartik\\select2\\": "" |
| @@ -802,7 +807,7 @@ | @@ -802,7 +807,7 @@ | ||
| 802 | "widget", | 807 | "widget", |
| 803 | "yii2" | 808 | "yii2" |
| 804 | ], | 809 | ], |
| 805 | - "time": "2016-02-01 02:19:01" | 810 | + "time": "2016-02-17 11:49:30" |
| 806 | }, | 811 | }, |
| 807 | { | 812 | { |
| 808 | "name": "lusitanian/oauth", | 813 | "name": "lusitanian/oauth", |
| @@ -1067,6 +1072,57 @@ | @@ -1067,6 +1072,57 @@ | ||
| 1067 | "time": "2016-01-13 18:15:48" | 1072 | "time": "2016-01-13 18:15:48" |
| 1068 | }, | 1073 | }, |
| 1069 | { | 1074 | { |
| 1075 | + "name": "rmrevin/yii2-comments", | ||
| 1076 | + "version": "1.4.0", | ||
| 1077 | + "source": { | ||
| 1078 | + "type": "git", | ||
| 1079 | + "url": "https://github.com/rmrevin/yii2-comments.git", | ||
| 1080 | + "reference": "9aaf46b0a5c2c3d71b9dafd669ef78810729951f" | ||
| 1081 | + }, | ||
| 1082 | + "dist": { | ||
| 1083 | + "type": "zip", | ||
| 1084 | + "url": "https://api.github.com/repos/rmrevin/yii2-comments/zipball/9aaf46b0a5c2c3d71b9dafd669ef78810729951f", | ||
| 1085 | + "reference": "9aaf46b0a5c2c3d71b9dafd669ef78810729951f", | ||
| 1086 | + "shasum": "" | ||
| 1087 | + }, | ||
| 1088 | + "require": { | ||
| 1089 | + "php": ">=5.4.0", | ||
| 1090 | + "rmrevin/yii2-fontawesome": "~2.10", | ||
| 1091 | + "yiisoft/yii2": "2.0.*" | ||
| 1092 | + }, | ||
| 1093 | + "type": "yii2-extension", | ||
| 1094 | + "extra": { | ||
| 1095 | + "asset-installer-paths": { | ||
| 1096 | + "npm-asset-library": "vendor/npm", | ||
| 1097 | + "bower-asset-library": "vendor/bower" | ||
| 1098 | + } | ||
| 1099 | + }, | ||
| 1100 | + "autoload": { | ||
| 1101 | + "psr-4": { | ||
| 1102 | + "rmrevin\\yii\\module\\Comments\\": "" | ||
| 1103 | + } | ||
| 1104 | + }, | ||
| 1105 | + "notification-url": "https://packagist.org/downloads/", | ||
| 1106 | + "license": [ | ||
| 1107 | + "MIT" | ||
| 1108 | + ], | ||
| 1109 | + "authors": [ | ||
| 1110 | + { | ||
| 1111 | + "name": "Roman Revin", | ||
| 1112 | + "email": "xgismox@gmail.com", | ||
| 1113 | + "homepage": "http://rmrevin.ru/" | ||
| 1114 | + } | ||
| 1115 | + ], | ||
| 1116 | + "description": "Comments module for Yii2", | ||
| 1117 | + "keywords": [ | ||
| 1118 | + "comment", | ||
| 1119 | + "module", | ||
| 1120 | + "widget", | ||
| 1121 | + "yii" | ||
| 1122 | + ], | ||
| 1123 | + "time": "2015-10-05 17:48:21" | ||
| 1124 | + }, | ||
| 1125 | + { | ||
| 1070 | "name": "rmrevin/yii2-fontawesome", | 1126 | "name": "rmrevin/yii2-fontawesome", |
| 1071 | "version": "2.13.0", | 1127 | "version": "2.13.0", |
| 1072 | "source": { | 1128 | "source": { |
| @@ -1177,12 +1233,12 @@ | @@ -1177,12 +1233,12 @@ | ||
| 1177 | "source": { | 1233 | "source": { |
| 1178 | "type": "git", | 1234 | "type": "git", |
| 1179 | "url": "https://github.com/yiisoft/yii2-framework.git", | 1235 | "url": "https://github.com/yiisoft/yii2-framework.git", |
| 1180 | - "reference": "abb6d386b71fe4d30d028c293202223311162dd2" | 1236 | + "reference": "c47257db05de10b0924b1e47c855212b457c69a3" |
| 1181 | }, | 1237 | }, |
| 1182 | "dist": { | 1238 | "dist": { |
| 1183 | "type": "zip", | 1239 | "type": "zip", |
| 1184 | - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/abb6d386b71fe4d30d028c293202223311162dd2", | ||
| 1185 | - "reference": "abb6d386b71fe4d30d028c293202223311162dd2", | 1240 | + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/c47257db05de10b0924b1e47c855212b457c69a3", |
| 1241 | + "reference": "c47257db05de10b0924b1e47c855212b457c69a3", | ||
| 1186 | "shasum": "" | 1242 | "shasum": "" |
| 1187 | }, | 1243 | }, |
| 1188 | "require": { | 1244 | "require": { |
| @@ -1193,7 +1249,7 @@ | @@ -1193,7 +1249,7 @@ | ||
| 1193 | "cebe/markdown": "~1.0.0 | ~1.1.0", | 1249 | "cebe/markdown": "~1.0.0 | ~1.1.0", |
| 1194 | "ext-ctype": "*", | 1250 | "ext-ctype": "*", |
| 1195 | "ext-mbstring": "*", | 1251 | "ext-mbstring": "*", |
| 1196 | - "ezyang/htmlpurifier": "4.6.*", | 1252 | + "ezyang/htmlpurifier": "~4.6", |
| 1197 | "lib-pcre": "*", | 1253 | "lib-pcre": "*", |
| 1198 | "php": ">=5.4.0", | 1254 | "php": ">=5.4.0", |
| 1199 | "yiisoft/yii2-composer": "~2.0.4" | 1255 | "yiisoft/yii2-composer": "~2.0.4" |
| @@ -1263,7 +1319,7 @@ | @@ -1263,7 +1319,7 @@ | ||
| 1263 | "framework", | 1319 | "framework", |
| 1264 | "yii2" | 1320 | "yii2" |
| 1265 | ], | 1321 | ], |
| 1266 | - "time": "2016-02-11 15:39:25" | 1322 | + "time": "2016-02-21 17:08:31" |
| 1267 | }, | 1323 | }, |
| 1268 | { | 1324 | { |
| 1269 | "name": "yiisoft/yii2-bootstrap", | 1325 | "name": "yiisoft/yii2-bootstrap", |
| @@ -1368,12 +1424,12 @@ | @@ -1368,12 +1424,12 @@ | ||
| 1368 | "source": { | 1424 | "source": { |
| 1369 | "type": "git", | 1425 | "type": "git", |
| 1370 | "url": "https://github.com/yiisoft/yii2-imagine.git", | 1426 | "url": "https://github.com/yiisoft/yii2-imagine.git", |
| 1371 | - "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888" | 1427 | + "reference": "d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299" |
| 1372 | }, | 1428 | }, |
| 1373 | "dist": { | 1429 | "dist": { |
| 1374 | "type": "zip", | 1430 | "type": "zip", |
| 1375 | - "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", | ||
| 1376 | - "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", | 1431 | + "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299", |
| 1432 | + "reference": "d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299", | ||
| 1377 | "shasum": "" | 1433 | "shasum": "" |
| 1378 | }, | 1434 | }, |
| 1379 | "require": { | 1435 | "require": { |
| @@ -1408,7 +1464,7 @@ | @@ -1408,7 +1464,7 @@ | ||
| 1408 | "imagine", | 1464 | "imagine", |
| 1409 | "yii2" | 1465 | "yii2" |
| 1410 | ], | 1466 | ], |
| 1411 | - "time": "2015-09-29 10:49:20" | 1467 | + "time": "2016-02-21 23:09:41" |
| 1412 | }, | 1468 | }, |
| 1413 | { | 1469 | { |
| 1414 | "name": "yiisoft/yii2-jui", | 1470 | "name": "yiisoft/yii2-jui", |
| @@ -1545,12 +1601,12 @@ | @@ -1545,12 +1601,12 @@ | ||
| 1545 | "source": { | 1601 | "source": { |
| 1546 | "type": "git", | 1602 | "type": "git", |
| 1547 | "url": "https://github.com/fzaninotto/Faker.git", | 1603 | "url": "https://github.com/fzaninotto/Faker.git", |
| 1548 | - "reference": "772feacf6849bf0114873e2b869bb500fccfd438" | 1604 | + "reference": "2585edbef8b0e7a44c695217c35b16720203d8ee" |
| 1549 | }, | 1605 | }, |
| 1550 | "dist": { | 1606 | "dist": { |
| 1551 | "type": "zip", | 1607 | "type": "zip", |
| 1552 | - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/772feacf6849bf0114873e2b869bb500fccfd438", | ||
| 1553 | - "reference": "772feacf6849bf0114873e2b869bb500fccfd438", | 1608 | + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/2585edbef8b0e7a44c695217c35b16720203d8ee", |
| 1609 | + "reference": "2585edbef8b0e7a44c695217c35b16720203d8ee", | ||
| 1554 | "shasum": "" | 1610 | "shasum": "" |
| 1555 | }, | 1611 | }, |
| 1556 | "require": { | 1612 | "require": { |
| @@ -1587,7 +1643,7 @@ | @@ -1587,7 +1643,7 @@ | ||
| 1587 | "faker", | 1643 | "faker", |
| 1588 | "fixtures" | 1644 | "fixtures" |
| 1589 | ], | 1645 | ], |
| 1590 | - "time": "2016-02-11 12:29:31" | 1646 | + "time": "2016-02-23 12:35:04" |
| 1591 | }, | 1647 | }, |
| 1592 | { | 1648 | { |
| 1593 | "name": "phpspec/php-diff", | 1649 | "name": "phpspec/php-diff", |
| @@ -1674,12 +1730,12 @@ | @@ -1674,12 +1730,12 @@ | ||
| 1674 | "source": { | 1730 | "source": { |
| 1675 | "type": "git", | 1731 | "type": "git", |
| 1676 | "url": "https://github.com/yiisoft/yii2-debug.git", | 1732 | "url": "https://github.com/yiisoft/yii2-debug.git", |
| 1677 | - "reference": "7a28977497e43bf7180a793389e6a5739ec52756" | 1733 | + "reference": "e30ded9067f595b5e6d3536ec1365353b826b300" |
| 1678 | }, | 1734 | }, |
| 1679 | "dist": { | 1735 | "dist": { |
| 1680 | "type": "zip", | 1736 | "type": "zip", |
| 1681 | - "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/7a28977497e43bf7180a793389e6a5739ec52756", | ||
| 1682 | - "reference": "7a28977497e43bf7180a793389e6a5739ec52756", | 1737 | + "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/e30ded9067f595b5e6d3536ec1365353b826b300", |
| 1738 | + "reference": "e30ded9067f595b5e6d3536ec1365353b826b300", | ||
| 1683 | "shasum": "" | 1739 | "shasum": "" |
| 1684 | }, | 1740 | }, |
| 1685 | "require": { | 1741 | "require": { |
| @@ -1713,7 +1769,7 @@ | @@ -1713,7 +1769,7 @@ | ||
| 1713 | "debugger", | 1769 | "debugger", |
| 1714 | "yii2" | 1770 | "yii2" |
| 1715 | ], | 1771 | ], |
| 1716 | - "time": "2015-12-31 16:25:50" | 1772 | + "time": "2016-02-16 08:23:57" |
| 1717 | }, | 1773 | }, |
| 1718 | { | 1774 | { |
| 1719 | "name": "yiisoft/yii2-faker", | 1775 | "name": "yiisoft/yii2-faker", |
| @@ -1768,12 +1824,12 @@ | @@ -1768,12 +1824,12 @@ | ||
| 1768 | "source": { | 1824 | "source": { |
| 1769 | "type": "git", | 1825 | "type": "git", |
| 1770 | "url": "https://github.com/yiisoft/yii2-gii.git", | 1826 | "url": "https://github.com/yiisoft/yii2-gii.git", |
| 1771 | - "reference": "bb0eba84639a99bff6c8bc9e803bd8ac3ab66297" | 1827 | + "reference": "ce42838abcbef076ebaf46147671d518ae69d028" |
| 1772 | }, | 1828 | }, |
| 1773 | "dist": { | 1829 | "dist": { |
| 1774 | "type": "zip", | 1830 | "type": "zip", |
| 1775 | - "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/bb0eba84639a99bff6c8bc9e803bd8ac3ab66297", | ||
| 1776 | - "reference": "bb0eba84639a99bff6c8bc9e803bd8ac3ab66297", | 1831 | + "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/ce42838abcbef076ebaf46147671d518ae69d028", |
| 1832 | + "reference": "ce42838abcbef076ebaf46147671d518ae69d028", | ||
| 1777 | "shasum": "" | 1833 | "shasum": "" |
| 1778 | }, | 1834 | }, |
| 1779 | "require": { | 1835 | "require": { |
| @@ -1813,7 +1869,7 @@ | @@ -1813,7 +1869,7 @@ | ||
| 1813 | "gii", | 1869 | "gii", |
| 1814 | "yii2" | 1870 | "yii2" |
| 1815 | ], | 1871 | ], |
| 1816 | - "time": "2016-02-02 07:11:51" | 1872 | + "time": "2016-02-21 20:39:29" |
| 1817 | } | 1873 | } |
| 1818 | ], | 1874 | ], |
| 1819 | "aliases": [], | 1875 | "aliases": [], |
| 1 | +<?php | ||
| 2 | + namespace console\controllers; | ||
| 3 | + | ||
| 4 | + use common\components\rules\CommentOwnRule; | ||
| 5 | + use yii\console\Controller; | ||
| 6 | + use yii\rbac\Permission; | ||
| 7 | + | ||
| 8 | + class CommentRulesController extends Controller | ||
| 9 | + { | ||
| 10 | + public function actionCreate() { | ||
| 11 | + $auth = \Yii::$app->getAuthManager(); | ||
| 12 | + $commentownrule = new CommentOwnRule(); | ||
| 13 | + $auth->add($commentownrule); | ||
| 14 | + $auth->add(new Permission([ | ||
| 15 | + 'name' => 'Update own comment', | ||
| 16 | + 'ruleName' => $commentownrule->name, | ||
| 17 | + 'description' => 'Can update own comment', | ||
| 18 | + ])); | ||
| 19 | + $auth->add(new Permission([ | ||
| 20 | + 'name' => 'Delete own comment', | ||
| 21 | + 'ruleName' => $commentownrule->name, | ||
| 22 | + 'description' => 'Can delete own comment', | ||
| 23 | + ])); | ||
| 24 | + return 'Success'; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public function actionUpdate() | ||
| 28 | + { | ||
| 29 | + $auth = \Yii::$app->getAuthManager(); | ||
| 30 | + $commentownrule = new CommentOwnRule(); | ||
| 31 | + $auth->add(new Permission([ | ||
| 32 | + 'name' => \rmrevin\yii\module\Comments\Permission::CREATE, | ||
| 33 | + 'description' => 'Can create own comments', | ||
| 34 | + ])); | ||
| 35 | + $auth->add(new Permission([ | ||
| 36 | + 'name' => \rmrevin\yii\module\Comments\Permission::UPDATE, | ||
| 37 | + 'description' => 'Can update all comments', | ||
| 38 | + ])); | ||
| 39 | + $auth->add(new Permission([ | ||
| 40 | + 'name' => \rmrevin\yii\module\Comments\Permission::UPDATE_OWN, | ||
| 41 | + 'ruleName' => $commentownrule->name, | ||
| 42 | + 'description' => 'Can update own comments', | ||
| 43 | + ])); | ||
| 44 | + $auth->add(new Permission([ | ||
| 45 | + 'name' => \rmrevin\yii\module\Comments\Permission::DELETE, | ||
| 46 | + 'description' => 'Can delete all comments', | ||
| 47 | + ])); | ||
| 48 | + $auth->add(new Permission([ | ||
| 49 | + 'name' => \rmrevin\yii\module\Comments\Permission::DELETE_OWN, | ||
| 50 | + 'ruleName' => $commentownrule->name, | ||
| 51 | + 'description' => 'Can delete own comments', | ||
| 52 | + ])); | ||
| 53 | + echo 'ok'; | ||
| 54 | + return 'ok'; | ||
| 55 | + } | ||
| 56 | + } | ||
| 0 | \ No newline at end of file | 57 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +class m160225_143331_comment_test extends Migration | ||
| 6 | +{ | ||
| 7 | + public function up() | ||
| 8 | + { | ||
| 9 | + $this->createTable('{{%comment}}', [ | ||
| 10 | + 'comment_id' => $this->primaryKey(), | ||
| 11 | + 'entity' => $this->string()->notNull(), | ||
| 12 | + 'text' => $this->text()->notNull(), | ||
| 13 | + 'user_id' => $this->integer(), | ||
| 14 | + 'user_name' => $this->string(), | ||
| 15 | + 'user_email' => $this->string(), | ||
| 16 | + 'comment_pid' => $this->integer(), | ||
| 17 | + 'status' => $this->integer(), | ||
| 18 | + 'date_add' => $this->timestamp()->notNull()->defaultExpression('NOW()'), | ||
| 19 | + 'date_update' => $this->timestamp()->notNull()->defaultExpression('NOW()'), | ||
| 20 | + 'date_delete' => $this->timestamp(), | ||
| 21 | + ]); | ||
| 22 | + | ||
| 23 | + $this->addForeignKey('comment_user', '{{%comment}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE'); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public function down() | ||
| 27 | + { | ||
| 28 | + $this->dropForeignKey('comment_user', '{{%comment}}'); | ||
| 29 | + $this->dropTable('{{%comment}}'); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /* | ||
| 33 | + // Use safeUp/safeDown to run migration code within a transaction | ||
| 34 | + public function safeUp() | ||
| 35 | + { | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public function safeDown() | ||
| 39 | + { | ||
| 40 | + } | ||
| 41 | + */ | ||
| 42 | +} |
frontend/views/performer/portfolio-view.php
| @@ -13,7 +13,6 @@ | @@ -13,7 +13,6 @@ | ||
| 13 | 13 | ||
| 14 | $this->title = 'My Yii Application'; | 14 | $this->title = 'My Yii Application'; |
| 15 | ?> | 15 | ?> |
| 16 | - | ||
| 17 | <div class="portfolio-new-page-wrapper style"> | 16 | <div class="portfolio-new-page-wrapper style"> |
| 18 | <div class="new-portfolio-bg style "> | 17 | <div class="new-portfolio-bg style "> |
| 19 | <img src="<?= $portfolio->cover ?>" alt=""/></div> | 18 | <img src="<?= $portfolio->cover ?>" alt=""/></div> |
| @@ -109,6 +108,30 @@ | @@ -109,6 +108,30 @@ | ||
| 109 | ?> | 108 | ?> |
| 110 | </div> | 109 | </div> |
| 111 | 110 | ||
| 111 | + <?php | ||
| 112 | + echo \common\modules\comment\widgets\CommentWidget::widget([ | ||
| 113 | + 'entity' => $portfolio::tableName().'-'.$portfolio->portfolio_id, | ||
| 114 | + 'comment_class' => \common\modules\comment\models\Comment::className(), | ||
| 115 | + 'class_options' => [ | ||
| 116 | + 'scenario' => is_int(\Yii::$app->user->getId())?\common\modules\comment\models\Comment::SCENARIO_USER:\common\modules\comment\models\Comment::SCENARIO_GUEST, | ||
| 117 | + 'user_id' => \Yii::$app->user->getId(), | ||
| 118 | + ], | ||
| 119 | + 'list_options' => [ | ||
| 120 | + 'view' => 'list-comment', | ||
| 121 | + ], | ||
| 122 | + 'form_options' => [ | ||
| 123 | + 'view' => 'form-comment', | ||
| 124 | + 'tag' => false, | ||
| 125 | + ], | ||
| 126 | + 'options' => [ | ||
| 127 | + 'class' => 'new-portf-comments-wr style', | ||
| 128 | + ], | ||
| 129 | + ]); | ||
| 130 | + ?> | ||
| 131 | + | ||
| 132 | + <?php | ||
| 133 | + /* | ||
| 134 | + ?> | ||
| 112 | <div class="new-portf-comments-wr style"> | 135 | <div class="new-portf-comments-wr style"> |
| 113 | <div class="new-portf-comm-count">Комментарии: 3</div> | 136 | <div class="new-portf-comm-count">Комментарии: 3</div> |
| 114 | <div class="new-portf-add-comm style"> | 137 | <div class="new-portf-add-comm style"> |
| @@ -286,6 +309,8 @@ | @@ -286,6 +309,8 @@ | ||
| 286 | 309 | ||
| 287 | </div> | 310 | </div> |
| 288 | </div> | 311 | </div> |
| 312 | + */ | ||
| 313 | + ?> | ||
| 289 | </div> | 314 | </div> |
| 290 | <script> | 315 | <script> |
| 291 | $('.portfolio-new-page-wrapper .rating').rating( | 316 | $('.portfolio-new-page-wrapper .rating').rating( |