Example #1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         $rows = [];
         foreach ($this->_wallPostList as $row) {
             $rows[] = [$row->target_type, $row->target_id, $this->id, $row->personal];
         }
         if ($rows) {
             return Yii::$app->db->createCommand()->batchInsert(WallPost::tableName(), ['target_type', 'target_id', 'wall_id', 'personal'], $rows)->execute();
         }
     }
 }
 public function actionWall($id = null)
 {
     /**
      * @var $userView User
      */
     $userView = $id && \Yii::$app->user->identity != $id ? User::findOne($id) : \Yii::$app->user->identity;
     if (!$userView) {
         throw new NotFoundHttpException();
     }
     $collection = new ActiveDataProvider();
     $collection->pagination->pageSize = 12;
     $criteria = ['and', 'wall.id=wall_post.wall_id', ['=', 'target_type', WallPost::TARGET_TYPE_USER], ['=', 'target_id', $userView->id]];
     if (!$userView->isMy()) {
         $criteria[] = ['=', 'personal', 0];
     }
     $collection->query = Wall::find()->select('wall.*')->innerJoin(WallPost::tableName(), $criteria)->orderBy('wall.id DESC');
     return $this->renderCollection($collection);
 }