Пример #1
0
 /**
  * Делает комментарий новым
  */
 public function actionAjaxUpdateSetNew()
 {
     if (!isset($_POST['checkboxes'])) {
         return;
     }
     $userID = \Yii::$app->getModule('comments')->getUserID();
     foreach ($_POST['checkboxes'] as $comment_id) {
         $model = new NewComments();
         $model->user_id = $userID;
         $model->comment_id = $comment_id;
         $model->save();
     }
 }
Пример #2
0
 /**
  * Поведение после сохранения
  * @return boolean
  */
 public function afterSave($insert, $changedAttributes)
 {
     //        Yii::$app->end;
     //        parent::afterSave($insert, $changedAttributes);
     //
     if (!$insert) {
         return true;
     }
     //
     if (!($userModelClass = \Yii::$app->getModule('comments')->userModelClass)) {
         return true;
     }
     $userModel = new $userModelClass();
     $userPK = $userModel->tableSchema->primaryKey;
     $userID = \Yii::$app->getModule('comments')->getUserID();
     if (!empty($userID)) {
         $query = $userModel::find(['not in ', 'id', array($userID)]);
     } else {
         $query = $userModel::find();
     }
     foreach ($query->all() as $user) {
         if (!NewComments::find()->where(['user_id' => $user->{$userPK}[0], 'comment_id' => $this->id])->exists()) {
             $newComments = new NewComments();
             $newComments->user_id = $user->{$userPK}[0];
             $newComments->comment_id = $this->id;
             if (!$newComments->save()) {
                 return false;
             }
         }
     }
     return true;
 }