db */ public $db = null; /** * Key, used to encrypt and decrypt comment service data. * * @var string Encryption key */ public static $encryptionKey = 'artbox-comment'; /** * Whether to enable comment rating or not. * * @var bool */ public $enableRating = true; /** * Whether to enable comment premoderate or not. * * @var bool */ public $enablePremoderate = true; /** * @var string[] $cacheModels */ public $cacheModels = []; /** * Initializes the module. * This method is called after the module is created and initialized with property values * given in configuration. The default implementation will initialize * [[controllerNamespace]] if it is not set. If you override this method, please make sure * you call the parent implementation. */ public function init() { if ($this->commentModelClass === null) { $this->commentModelClass = CommentModel::className(); } if ($this->enableRating && $this->ratingModelClass === null) { $this->ratingModelClass = RatingModel::className(); } if (\Yii::$app instanceof Application) { $this->controllerNamespace = 'artbox\webcomment\commands'; } elseif ($this->userIdentityClass === null) { $this->userIdentityClass = Yii::$app->getUser()->identityClass; } if ($this->db === null) { $this->db = \Yii::$app->db; } if (!Yii::getAlias('@artbox/webcomment', false)) { Yii::setAlias('@artbox/webcomment', __DIR__); } parent::init(); } /** * Prompt to register current module * * @throws \yii\base\InvalidConfigException */ public static function registerMe() { throw new InvalidConfigException(\Yii::t('artbox-comment', 'Register artbox-comment module')); } /** * Rating model factory * * @param $config * * @return \yii\db\ActiveRecord */ public function createRating($config) { /** * @var \yii\db\ActiveRecord $model */ $model = \Yii::createObject( array_merge( [ 'class' => $this->ratingModelClass, ], $config ) ); $behaviors = []; foreach ($this->cacheModels as $cacheModel) { $behaviors[] = \Yii::createObject($cacheModel); } if (!empty($behaviors)) { $model->attachBehaviors($behaviors); } return $model; } }