Esempio n. 1
0
 /**
  * Gets number of user subscribed threads with new posts.
  * @return integer
  */
 public function getSubscriptionsCount()
 {
     $cache = Cache::getInstance()->getElement('user.subscriptions', $this->id);
     if ($cache === false) {
         $cache = (new Query())->from(Subscription::tableName())->where(['user_id' => $this->id, 'post_seen' => Subscription::POST_NEW])->count();
         Cache::getInstance()->setElement('user.subscriptions', $this->id, $cache);
     }
     return $cache;
 }
Esempio n. 2
0
 /**
  * Showing the subscriptions.
  * @return string|\yii\web\Response
  */
 public function actionSubscriptions()
 {
     $postData = Yii::$app->request->post();
     if ($postData) {
         $selection = !empty($postData['selection']) ? $postData['selection'] : [];
         try {
             if (!empty($selection)) {
                 Yii::$app->db->createCommand()->delete(Subscription::tableName(), ['id' => $selection, 'user_id' => User::loggedId()])->execute();
                 $this->success(Yii::t('podium/flash', 'Subscription list has been updated.'));
             }
         } catch (Exception $e) {
             Log::error($e->getMessage(), null, __METHOD__);
             $this->error(Yii::t('podium/flash', 'Sorry! There was an error while unsubscribing the thread list.'));
         }
         return $this->refresh();
     }
     return $this->render('subscriptions', ['dataProvider' => (new Subscription())->search(Yii::$app->request->get())]);
 }
Esempio n. 3
0
 /**
  * Removes threads' subscriptions of given IDs.
  * @param array $threads threads' IDs
  * @return boolean
  * @since 0.2
  */
 public static function remove($threads = [])
 {
     try {
         if (!empty($threads)) {
             Yii::$app->db->createCommand()->delete(Subscription::tableName(), ['id' => $threads, 'user_id' => User::loggedId()])->execute();
             return true;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }