コード例 #1
0
 /**
  * Subscribing the thread of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionAdd($id = null)
 {
     if (!Yii::$app->request->isAjax) {
         return $this->redirect(['default/index']);
     }
     $data = ['error' => 1, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Error while adding this subscription!'), ['class' => 'text-danger'])];
     if (Yii::$app->user->isGuest) {
         $data['msg'] = Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Please sign in to subscribe to this thread'), ['class' => 'text-info']);
     }
     if (is_numeric($id) && $id > 0) {
         $subscription = Subscription::find()->where(['thread_id' => $id, 'user_id' => User::loggedId()])->limit(1)->one();
         if (!empty($subscription)) {
             $data['msg'] = Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are already subscribed to this thread.'), ['class' => 'text-info']);
         } else {
             if (Subscription::add((int) $id)) {
                 $data = ['error' => 0, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', 'You have subscribed to this thread!'), ['class' => 'text-success'])];
             }
         }
     }
     return Json::encode($data);
 }