/** * Возвращает объект модели отзыва * @return Model * @throws \yii\base\InvalidConfigException */ public function getModel() { if (is_null($this->_model)) { $this->_model = Yii::createObject(['class' => Model::className(), 'scenario' => Model::SCENARIO_INSERT, 'model' => $this->modelClass, 'item_id' => $this->itemId, 'source_model' => is_null($this->sourceModelClass) ? $this->modelClass : $this->sourceModelClass, 'source_item_id' => is_null($this->sourceItemId) ? $this->itemId : $this->sourceItemId]); } return $this->_model; }
/** * @inheritdoc * @param Review $model */ public function create($model) { if (empty($model->model) or empty($model->item_id) or empty($model->source_model) or empty($model->source_item_id)) { return false; } $exists = Review::find()->byItem($model->item_id, $model->model)->bySourceItem($model->source_item_id, $model->source_model)->count(); return !$exists; }
/** * Возвращает объект провайдера данных * @return object|ActiveDataProvider * @throws \yii\base\InvalidConfigException */ public function getDataProvider() { if (is_null($this->_dataProvider)) { $query = Review::find()->published()->byItem($this->itemId, $this->modelClass); if (is_callable($this->queryModifier)) { $func = $this->queryModifier; $func($query); } $config = ArrayHelper::merge($this->dataProviderConfig, ['class' => ActiveDataProvider::className(), 'query' => $query]); $this->_dataProvider = Yii::createObject($config); $this->_dataProvider->pagination->pageSize = $this->pageSize; $this->_dataProvider->sort->defaultOrder = $this->orderBy; } return $this->_dataProvider; }
/** * @inheritdoc */ public function actions() { return ['comment' => ['class' => actions\CommentAdd::className(), 'modelClass' => Comments::className()], 'review' => ['class' => actions\ReviewAdd::className(), 'modelClass' => Review::className()], 'feedback' => ['class' => actions\Feedback::className(), 'modelClass' => FeedbackForm::className()]]; }
<?php use app\modules\main\models; return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/main/migrations']]], 'modules' => ['main' => ['class' => app\modules\main\Main::className(), 'controllerNamespace' => 'app\\modules\\main\\controllers', 'components' => ['tagsConverter' => \common\components\TagsConverter::className(), 'sphinxUrlService' => \app\modules\main\components\SphinxUrlService::className(), 'sitemap' => ["class" => \app\modules\main\sitemap\Sitemap::className(), "definition" => [['class' => 'app\\modules\\main\\models\\Pages', 'urlCreate' => function ($model) { return Yii::$app->urlManager->createUrl(['/main/pages/index', 'model' => $model]); }]]], 'config' => ['class' => \app\modules\main\components\Config::className()], 'treeFinder' => ['class' => \common\components\TreeFinder::className()], 'blocksProvider' => ['class' => \app\modules\main\components\BlocksProvider::className()]], 'modules' => ['admin' => ['class' => app\modules\main\modules\admin\Admin::className(), 'controllerNamespace' => 'app\\modules\\main\\modules\\admin\\controllers', 'menuItems' => function () { return [['label' => Yii::t('main/app', 'Main module'), 'icon' => 'glyphicon glyphicon-home', 'items' => [['label' => Yii::t('main/app', 'Pages'), 'url' => ['/admin/main/pages'], "permission" => ["listModels", ["model" => Yii::createObject(models\Pages::className())]]], ['label' => Yii::t('main/app', 'Menu'), 'url' => ['/admin/main/menu'], "permission" => ["listModels", ["model" => Yii::createObject(models\Menu::className())]]], ['label' => Yii::t('main/app', 'Users'), 'url' => ['/admin/main/user'], "permission" => ["listModels", ["model" => Yii::createObject(models\User::className())]]], ['label' => Yii::t('main/app', 'FileManager'), 'url' => ['/admin/main/file-manager'], "permission" => ["fileManager"]], ['label' => Yii::t('main/app', 'Templates'), 'url' => ['/admin/main/template'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Includes'), 'url' => ['/admin/main/includes'], "permission" => ["listModels", ["model" => Yii::createObject(models\Includes::className())]]], ['label' => Yii::t('main/app', 'Include Groups'), 'url' => ['/admin/main/include-group'], "permission" => ["listModels", ["model" => Yii::createObject(models\IncludeGroup::className())]]], ['label' => Yii::t('main/app', 'Comments'), 'url' => ['/admin/main/comments'], "permission" => ["listModels", ["model" => Yii::createObject(models\Comments::className())]]], ['label' => Yii::t('main/app', 'Reviews'), 'url' => ['/admin/main/review'], "permission" => ["listModels", ["model" => Yii::createObject(models\Review::className())]]], ['label' => Yii::t('main/app', 'Tools'), 'url' => ['/admin/main/tools'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Permission'), 'url' => ['/admin/main/permission'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Config'), 'url' => ['/admin/main/config'], "permission" => ["rootAccess"]]]]]; }]]]], 'components' => ['i18n' => ['translations' => ['main/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/main/messages', 'fileMap' => ['main/app' => 'app.php']]]], 'urlManager' => ['rules' => ['user/<action:[A-z0-9_-]+>' => 'main/user/<action>', 'user' => 'main/user/profile', ['class' => '\\app\\modules\\main\\components\\PageUrlRule']]]]];
/** * Действия * @return array */ public function actions() { $class = Review::className(); return ['index' => ['class' => crud\Admin::className(), 'modelClass' => $class], 'create' => ['class' => crud\Create::className(), 'modelClass' => $class], 'update' => ['class' => crud\Update::className(), 'modelClass' => $class], 'view' => ['class' => crud\View::className(), 'modelClass' => $class], 'delete' => ['class' => crud\Delete::className(), 'modelClass' => $class], 'groupdelete' => ['class' => crud\GroupDelete::className(), 'modelClass' => $class], 'editable' => ['class' => crud\XEditable::className(), 'modelClass' => $class]]; }
/** * Связь с отзывами * @return Review[] */ public function getReviews() { return $this->hasMany(Review::className(), ['item_id' => 'id'])->where(['model' => get_class()]); }