Exemple #1
0
 public static function getComments($user_id, $type, $limit, $contentId, $contentType)
 {
     if ($contentId) {
         $date = (new Query())->select('date_time')->from('comments_' . $contentType)->where(['id' => $contentId])->scalar();
     }
     if ($type == 'user') {
         $articles_id = false;
         $photos_id = false;
         $club_photos_id = false;
     } else {
         $articles_id = Blog::getAllArticlesIdByAuthor($user_id);
         $photos_id = Photo::getAllPhotosIdByAuthor($user_id);
         $club_photos_id = ClubPhoto::getAllClubPhotosIdByAuthor($user_id);
     }
     $comment_blog_query = CommentsBlog::getCommentsQuery($user_id, $type, $articles_id);
     $comment_photo_query = CommentsPhoto::getCommentsQuery($user_id, $type, $photos_id);
     $comment_club_query = CommentsClub::getCommentsQuery($user_id, $type, $club_photos_id);
     $all_comments = $comment_blog_query->union($comment_photo_query, true)->union($comment_club_query, true);
     $sql = (new Query())->from(['ac' => $all_comments])->limit($limit)->orderBy('comment_date_time desc');
     if ($contentId) {
         $sql->andWhere(['<', 'comment_date_time', $date]);
     }
     $all_comments = $sql->all();
     foreach ($all_comments as &$comment) {
         self::DateCommentsInCorrectFormat($comment);
     }
     return $all_comments;
 }
Exemple #2
0
 public static function viewPhotoClub($photo_id)
 {
     if (!Yii::$app->user->isGuest) {
         $cookies_req = Yii::$app->request->cookies;
         $cookies_res = Yii::$app->response->cookies;
         $photo_views = $cookies_req->getValue('photo_club_views');
         $photo_views = explode('|', $photo_views);
         if (!in_array($photo_id, $photo_views)) {
             $photo_views[] = $photo_id;
             $cookies_res->add(new Cookie(['name' => 'photo_club_views', 'value' => implode('|', $photo_views), 'expire' => time() + 86400 * 30]));
             ClubPhoto::updateViews1($photo_id);
         }
     }
 }
Exemple #3
0
 public static function likePhotoClub()
 {
     $post = Yii::$app->request->post();
     $response = [];
     if (Yii::$app->user->isGuest) {
         $response['error'] = 'Ви не авторизовані!';
     } else {
         if (!ClubPhoto::checkLikePhoto($post['photo_id'], Yii::$app->user->getId())) {
             ClubPhoto::likePhoto($post['photo_id'], Yii::$app->user->getId());
             $response['success'] = '+';
         } else {
             ClubPhoto::disLikePhoto($post['photo_id'], Yii::$app->user->getId());
             $response['success'] = '-';
         }
         $response['cnt_likes'] = ClubPhoto::getCountLikes($post['photo_id']);
     }
     echo json_encode($response);
 }
 public function actionGetLastPhoto()
 {
     $request = Yii::$app->request;
     $clubId = $request->post('clubId');
     $offset = $request->post('offset');
     $limit = $request->post('limit');
     $photos = ClubPhoto::getPhotos($clubId, $limit, $offset);
     echo json_encode(['photos' => $photos]);
 }
 public function actionDelete()
 {
     $post = Yii::$app->request->post();
     $photoId = $post['photoId'];
     $type = $post['type'];
     if (Yii::$app->user->isGuest) {
         return json_encode(['status' => 'error']);
     }
     if ($type == 'photo') {
         if (Photo::deletePhoto($photoId)) {
             $response['status'] = 'ok';
         } else {
             $response['status'] = 'error';
         }
     } else {
         if (ClubPhoto::deletePhoto($photoId)) {
             $response['status'] = 'ok';
         } else {
             $response['status'] = 'error';
         }
     }
     echo json_encode($response);
 }