/** * Handle Ajax call to register unwatching a topic by a user */ public function actionUnwatch() { $json = array('success' => 'yes'); if (isset(\Yii::$app->request->post()['topicId'])) { $object = new BbiiTopicRead(); $model = BbiiTopicRead::find(\Yii::$app->user->identity->id); if ($model !== null) { $object->unserialize($model->data); $object->unsetFollow(\Yii::$app->request->post()['topicId']); $model->data = $object->serialize(); $model->save(); } } echo json_encode($json); \Yii::$app->end(); }
/** * [actionView description] * * @version 2.2.0 * @param [type] $id [description] * @return [type] [description] */ public function actionView($id = null) { $object = new BbiiTopicRead(); $read = BbiiTopicRead::find($id); if (isset(\Yii::$app->request->get()['unwatch']) && ($this->isModerator() || $id == \Yii::$app->user->identity->id)) { if ($read !== null) { $object->unserialize($read->data); foreach (\Yii::$app->request->get()['unwatch'] as $topicId => $val) { $object->unsetFollow($topicId); } $read->data = $object->serialize(); $read->save(); } } if (($this->isModerator() || $id == \Yii::$app->user->identity->id) && isset($read->data)) { if ($read === null) { $in = array(0); } else { $object->unserialize($read->data); $in = array_keys($object->getFollow()); } } else { $in = array(0); } // @todo Need to figure out the Yii2 version of `'with' => 'forum',` for ADP - DJE : 2015-05-15 $dataProvider = new ActiveDataProvider(['pagination' => false, 'query' => BbiiPost::find()->where(['approved' => 1, 'user_id' => \Yii::$app->user->identity->id])->orderBy('create_time DESC')->limit(10)]); // @todo Need to figure out the Yii2 version of `'with' => 'forum',` for ADP - DJE : 2015-05-15 $topicProvider = new ActiveDataProvider(['pagination' => false, 'query' => BbiiTopic::find()->where(['id' => $in])->orderBy('id ASC')]); return $this->render('view', array('dataProvider' => $dataProvider, 'topicProvider' => $topicProvider, 'userData' => BbiiMember::find()->where(['id' => is_numeric($id) ? $id : \Yii::$app->request->get('id')])->one())); }