public function run()
 {
     $feedId = \Yii::$app->request->get('feed_id');
     /** @var FeedModel $feed */
     $feed = FeedModel::findOne($feedId);
     if ($feed && $feed->user == \Yii::$app->user->identity->id) {
         NewModel::updateAll(['read' => 1], ['feed' => $feedId, 'read' => 0]);
         \Yii::$app->cache->delete($this->getNewsCacheKey($feedId));
         \Yii::$app->cache->delete($this->getFeedsCacheKey());
     }
     return $this->controller->redirect(['/user/news/list', 'feed_id' => $feedId, 'page' => 1]);
 }
 public function run()
 {
     $feedId = \Yii::$app->request->get('feed_id');
     /** @var FeedModel $feed */
     $feed = FeedModel::findOne($feedId);
     if ($feed && $feed->user == \Yii::$app->user->identity->id) {
         NewModel::deleteAll(['feed' => $feedId]);
         $feed->delete();
         $iconPath = FeedModel::getIconPath($feed->id);
         if (file_exists($iconPath)) {
             unlink($iconPath);
         }
         \Yii::$app->cache->delete($this->getNewsCacheKey($feedId));
         \Yii::$app->cache->delete($this->getFeedsCacheKey());
     }
     return $this->controller->redirect(['/user/news/list', 'feed_id' => '', 'page' => 1]);
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNewsQuery()
 {
     return $this->hasMany(NewModel::className(), ['feed' => 'id']);
 }
 private function getFeedsList()
 {
     if (!($feeds = \Yii::$app->cache->get($this->getFeedsCacheKey()))) {
         $noReadCountQuery = (new Query())->select('COUNT(id)')->from(NewModel::tableName())->where(new Expression('feed = feeds.id'))->andWhere(['read' => 0]);
         $feeds = (new Query())->select(['*', 'no_read_count' => $noReadCountQuery])->from(FeedModel::tableName())->where(['user' => \Yii::$app->user->identity->id])->all();
         $this->injectFeedIcons($feeds);
         \Yii::$app->cache->set($this->getFeedsCacheKey(), $feeds);
     }
     return $feeds;
 }