Exemplo n.º 1
0
 public static function viewArticle($article_id, &$views)
 {
     if (!Yii::$app->user->isGuest) {
         $cookies_req = Yii::$app->request->cookies;
         $cookies_res = Yii::$app->response->cookies;
         $article_views = $cookies_req->getValue('article_views');
         $article_views = explode('|', $article_views);
         if (!in_array($article_id, $article_views)) {
             $article_views[] = $article_id;
             $cookies_res->remove('article_views');
             $cookies_res->add(new Cookie(['name' => 'article_views', 'value' => implode('|', $article_views), 'expire' => time() + 86400 * 30]));
             Blog::updateViews($article_id);
             $views++;
             Rating::view($article_id, Rating::ARTICLE);
         }
     }
 }