/**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         //если модератор исправил текст сообщения пользователя, ставим moderator = true
         $oldComment = $this->findOne($this->id);
         if ($this->scenario == 'admin-update' && $oldComment->content !== $this->content) {
             $this->moderator = true;
         }
         return true;
     } else {
         return false;
     }
 }
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             if (!$this->author_id) {
                 $this->author_id = Yii::$app->user->id;
             }
             if (!$this->status_id) {
                 $this->status_id = self::STATUS_ACTIVE;
             }
         }
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['model_class' => 'id']);
 }
 /**
  * Возвращаем последний комментарий пользователя
  * @param int $idUser
  * @param $model
  * @param $status
  * @param bool|int|array $idParent - FALSE - не учитывает родителя
  * @return array|null|ActiveRecord
  * @internal param $model
  */
 public static function lastUserComment($idUser, $model, $status, $idParent = false)
 {
     $modelId = Model::find()->select('id')->where(['name' => $model::className()])->scalar();
     $comment = Comment::find()->where(['author_id' => $idUser, 'status_id' => $status, 'model_class' => $modelId, 'model_id' => $model->id])->orderBy('created_at DESC')->limit(1)->asArray();
     if ($idParent !== false) {
         $comment->andWhere(['parent_id' => $idParent]);
     }
     return $comment->one();
 }