Exemple #1
0
 public static function getPhotoInfo($id)
 {
     $photo = (new Query())->select(['p.id as photo_id', 'p.name as photo_name', 'l.name as category_name', 'p.src as photo_path', 'p.date as photo_date', 'u.id as user_id', 'u.name as user_name', 'p.views as photo_views', 'p.likes as photo_likes', 'p.comments as photo_comments', 'p.rating_all as photo_rating', 'p.favorites as photo_favorites', 'p.value as photo_value', 'p.time_closed', 'bpa.x1', 'bpa.y1', 'bpa.background_size'])->from('photos p')->innerJoin('level_1 l', 'l.id=p.id_level_1')->innerJoin('user u', 'u.id=p.id_author')->leftJoin('best_photo_area bpa', 'p.id=bpa.photo_id')->where(['p.id' => $id])->one();
     Rating::formRating($photo['photo_rating']);
     $date = explode(' ', $photo['photo_date']);
     $date = explode('-', $date[0]);
     $photo['photo_date'] = $date[2] . ' ' . \Yii::$app->params['month'][$date[1] - 1] . ' ' . $date[0];
     $photo['photo_path'] = '/img/photos/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/original_' . $photo['photo_path'];
     return $photo;
 }
Exemple #2
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);
         }
     }
 }
Exemple #3
0
 public static function likeArticle()
 {
     $post = Yii::$app->request->post();
     $response = [];
     if (Yii::$app->user->isGuest) {
         $response['error'] = 'Ви не авторизовані!';
     } else {
         if (!Blog::checkLikeArticle($post['article_id'], Yii::$app->user->getId())) {
             $response['success'] = '+';
             $response['count-likes'] = Blog::likeArticle($post['article_id'], Yii::$app->user->getId());
             Rating::like($post['article_id'], Rating::ARTICLE, 1);
         } else {
             $response['count-likes'] = Blog::disLikeArticle($post['article_id'], Yii::$app->user->getId());
             $response['success'] = '-';
             Rating::like($post['article_id'], Rating::ARTICLE, -1);
         }
     }
     echo json_encode($response);
 }
 public function actionFavorit()
 {
     $post = Yii::$app->request->post();
     $response = [];
     if (Yii::$app->user->isGuest) {
         $response['error'] = Yii::t('yii', 'Вы не авторизованы!');
     } else {
         if (!Photo::checkFavoritPhoto($post['photo_id'], Yii::$app->user->getId())) {
             Photo::favoritPhoto($post['photo_id'], Yii::$app->user->getId());
             Rating::favor($post['photo_id'], Rating::PHOTO, 1);
             $response['success'] = '+';
         } else {
             Photo::disFavoritPhoto($post['photo_id'], Yii::$app->user->getId());
             Rating::favor($post['photo_id'], Rating::PHOTO, -1);
             $response['success'] = '-';
         }
         $response['cnt_favorite'] = Photo::getCountFavorite($post['photo_id']);
         echo json_encode($response);
     }
 }
Exemple #5
0
 public static function searchArticles($name, $author, $id_level_1, $marks, $limit, $contentId)
 {
     if ($contentId) {
         $contentRating = (new Query())->select(['rating_all'])->from('articles')->where(['id' => $contentId])->scalar();
     }
     $sql = (new Query())->select(['a.name as article_name', 'a.id as article_id', 'a.date as article_date', 'a.text as article_text', 'a.thumbnail as article_img', 'a.likes as article_likes', 'a.views as article_views', 'a.comments as article_comments', 'a.rating_all as article_rating_all', 'a.url as article_url', 'u.name as user_name', 'u.id as user_id'])->from('articles a')->where(['<', 'a.time_closed', time()])->filterWhere(['like', 'a.name', $name])->AndFilterWhere(['=', 'a.id_level_1', $id_level_1])->innerJoin('user u', 'a.id_author = u.id')->AndFilterWhere(['like', 'u.name', $author])->leftJoin('marks_article AS ma', 'ma.id_article = a.id')->leftJoin('marks AS m', 'ma.id_mark = m.id')->AndFilterWhere(['in', 'm.name', $marks])->limit($limit)->orderBy('a.rating_all DESC')->indexBy('article_id')->distinct();
     if ($contentId) {
         $sql->andWhere(['<', 'a.rating_all', $contentRating]);
     }
     $articles = $sql->all();
     foreach ($articles as $k => &$article) {
         $date = explode(' ', $article['article_date']);
         $date = explode('-', $date[0]);
         $article['article_date'] = $date[2] . ' ' . Yii::t('yii', Yii::$app->params['month'][$date[1] - 1]) . ' ' . $date[0];
         Rating::formRating($article['article_rating_all']);
     }
     $nn = [];
     foreach ($articles as $aa) {
         $nn[] = $aa;
     }
     return $nn;
 }
Exemple #6
0
 public static function getFavoritesArticles($id_user, $limit, $contentId)
 {
     if ($contentId) {
         $favorId = (new Query())->select('f.id')->from('favorites f')->where(['f.id_article' => $contentId, 'f.id_user' => $id_user])->scalar();
     }
     $sql = (new Query())->select(['u.name AS user_name', 'u.id AS user_id', 'a.id AS article_id', 'a.url AS article_url', 'a.date AS article_date', 'a.likes AS article_likes', 'a.views AS article_views', 'a.text AS article_text', 'a.thumbnail AS article_img', 'a.rating_all AS article_rating_all', 'a.comments as article_comments', 'a.time_closed as time_closed'])->from('favorites f')->innerJoin('articles a', 'f.id_article=a.id')->innerJoin('user u', 'f.id_author=u.id')->where('id_user=:id_user', [':id_user' => $id_user])->andWhere(['<', 'a.time_closed', time()])->limit($limit)->orderBy('f.id DESC')->indexBy('article_id');
     if ($contentId) {
         $sql->andWhere('<', 'f.id', $favorId);
     }
     $favor_articles = $sql->all();
     $articles_id = [];
     foreach ($favor_articles as &$article) {
         $articles_id[] = $article['article_id'];
         $article['mylike'] = 0;
         $date = explode('-', explode(" ", $article['article_date'])[0]);
         $article['article_date'] = $date[2] . " " . Yii::t('yii', Yii::$app->params['month'][$date[1]]) . " " . $date[0];
         Rating::formRating($article['article_rating_all']);
     }
     $likes = (new Query())->select(['l.id_article'])->from('likes l')->where(['l.id_article' => $articles_id])->andWhere('l.id_user=:id_user', [':id_user' => $id_user])->column();
     foreach ($likes as $id_likes) {
         $favor_articles[$id_likes]['mylike'] = 1;
     }
     $nn = [];
     foreach ($favor_articles as $fa) {
         $nn[] = $fa;
     }
     return $nn;
 }
 public function actionFavor()
 {
     $request = Yii::$app->request;
     $articaleId = $request->post('article_id');
     $response = [];
     if (!Yii::$app->user->isGuest && Blog::isClosed($articaleId)) {
         if (Blog::ifAvailableArticle($articaleId)) {
             $response['response'] = 1;
             if (Blog::favorArticle($articaleId, Yii::$app->user->getId())) {
                 $response['favorite'] = 1;
                 Rating::favor($articaleId, Rating::ARTICLE, 1);
             } else {
                 $response['favorite'] = 0;
                 Rating::favor($articaleId, Rating::ARTICLE, -1);
             }
         } else {
             $response['response'] = 0;
         }
     } else {
         $response['response'] = 0;
     }
     echo json_encode($response);
 }
 public function actionInfo($id)
 {
     User::getUserInfoOrRedirect($this, $id, $user, $isMyProfile);
     $averageRatingPhoto = Photo::getAverageRatingPhoto($id);
     Rating::formRating($averageRatingPhoto);
     $privacy = User::getPrivacyInformation($id);
     $type_friend = User::getTypeFriend(Yii::$app->user->getId(), $id);
     return $this->render('info', ['user' => $user, 'isMyProfile' => $isMyProfile, 'privacy' => $privacy, 'type_friend' => $type_friend, 'averageRatingPhoto' => $averageRatingPhoto]);
 }
Exemple #9
0
 public static function getPotentialMembersByIdClub($id, $offset, $limit)
 {
     $users = (new Query())->select(['u.name AS user_name', 'u.id AS user_id', 'u.avatar AS user_avatar', 'u.last_visit AS user_last_visit', 'u.sex AS user_sex', 'u.created_at AS user_created_at', 'u.rating AS user_rating', 'u.photos AS user_photos', 'u.comments AS user_comments', 'u.photo_day AS user_photo_day', 'u.photo_week AS user_photo_week', 'u.city AS user_city', 'u.country AS user_country'])->from('user u')->innerJoin('users_clubs uc', 'u.id=uc.id_user')->where('uc.id_club=:id', [':id' => $id])->andWhere('role=0')->offset($offset)->limit($limit)->all();
     foreach ($users as &$user) {
         $date = date('d-m-Y', $user['user_created_at']);
         $date = explode('-', $date);
         $user['user_created_at'] = $date[0] . ' ' . Yii::t('yii', Yii::$app->params['month'][$date[1] - 1]) . ' ' . $date[2];
         Rating::formRating($user['user_rating']);
     }
     return $users;
 }
Exemple #10
0
 public static function getAllPhotoInfo($id)
 {
     $photo = (new Query())->select(['p.id AS photo_id', 'p.name AS photo_name', 'p.src AS photo_src', 'u.id AS user_id', 'u.name AS user_name', 'u.avatar as user_avatar', 'u.sex as user_sex', 'p.rating_all AS photo_rating_all', 'p.date as photo_date', 'l.url AS category_url', 'l.name AS category_name', 'a.name AS album_name', 'a.id AS album_id', 'p.likes AS photo_likes', 'p.views AS photo_views', 'p.value AS photo_value', 'p.time_closed AS time_closed', 'p.erotic AS erotic'])->from('photos p')->innerJoin('user u', 'u.id = p.id_author')->innerJoin('level_1 l', 'l.id = p.id_level_1')->innerJoin('album a', 'a.id = p.id_album')->where(['p.id' => $id])->one();
     Rating::formRating($photo['photo_rating_all']);
     $marks = (new Query())->select(['m.id as mark_id', 'm.name as mark_name'])->from('marks m')->innerJoin('marks_photo', 'm.id=marks_photo.id_mark')->where(['marks_photo.id_photo' => $id])->all();
     $photo['marks'] = $marks;
     if (count($photo['marks']) == 0) {
         $photo['marks'] = [];
     }
     $favorite = (new Query())->select(['u.name AS user_name', 'u.id AS user_id'])->from('favorites f')->innerJoin('user u', 'f.id_user=u.id')->where('id_photo=' . $id)->all();
     $photo['favorite'] = $favorite;
     self::createUrlByDate($photo, 'original_');
     $date = explode(' ', $photo['photo_date']);
     $date = explode('-', $date[0]);
     $photo['photo_date'] = $date[2] . ' ' . Yii::t('yii', Yii::$app->params['month'][$date[1] - 1]) . ' ' . $date[0];
     $photo['mylike'] = false;
     if (!Yii::$app->user->isGuest) {
         $photo['mylike'] = (new Query())->select('COUNT(1)')->from('likes')->where(['id_photo' => $id, 'id_user' => Yii::$app->user->getId()])->scalar();
     }
     $photo['myfavorite'] = false;
     if (!Yii::$app->user->isGuest) {
         $photo['myfavorite'] = (new Query())->select('COUNT(1)')->from('favorites')->where(['id_photo' => $id, 'id_user' => Yii::$app->user->getId()])->scalar();
     }
     if (Yii::$app->user->isGuest) {
         $photo['estimation'] = null;
     } else {
         $photo['estimation'] = (new Query())->select('e')->from('estimation')->where(['photo_id' => $id, 'user_id' => Yii::$app->user->getId()])->scalar();
     }
     return $photo;
 }
Exemple #11
0
 public static function getInfo($id)
 {
     $res = (new Query())->select(['u.id AS user_id', 'u.avatar as user_avatar', 'u.sex as user_sex', 'u.name as user_name', 'u.country as user_country', 'u.city as user_city', 'u.rating as user_rating', 'CONCAT("1") as user_type'])->from('user u')->where(['u.id' => $id])->one();
     Rating::formRating($res['user_rating']);
     return $res;
 }
Exemple #12
0
 public static function getPhotosByAlbum($album_id, $limit, $contentId, $user_id)
 {
     if ($contentId) {
         $contentRate = (new Query())->select('rating_all')->from('photos')->where(['id' => $contentId])->scalar();
     }
     $sql = (new Query())->select(['p.name AS photo_name', 'p.src AS photo_src', 'p.date AS photo_date', 'p.views AS photo_views', 'p.rating_all AS photo_rating', 'p.id AS photo_id', 'p.likes AS photo_likes', 'p.comments AS photo_comments', 'l.name AS category_name', 'l.url AS category_url'])->from('photos p')->innerJoin('album a', 'p.id_album = a.id')->where(['a.id' => $album_id])->innerJoin('level_1 AS l', 'l.id = p.id_level_1')->indexBy('photo_id')->limit($limit)->orderBy('p.rating_all DESC');
     if ($contentId) {
         $sql->andWhere(['<', 'p.rating_all', $contentRate]);
     }
     $photos = $sql->all();
     if ($user_id == Yii::$app->user->getId()) {
         $isMyPhoto = true;
     } else {
         $isMyPhoto = false;
     }
     $id_photo = [];
     foreach ($photos as $k => &$v) {
         $photos[$k]['isMyPhoto'] = $isMyPhoto;
         $id_photo[] = $k;
         $v['mylike'] = false;
         $data = explode(' ', $v['photo_date']);
         $data = str_replace("-", "/", $data[0]);
         $v['photo_src'] = 'img/photos/' . $data . '/l_' . $v['photo_src'];
         Rating::formRating($v['photo_rating']);
     }
     if (Yii::$app->user->isGuest) {
         $likes = [];
     } else {
         $likes = (new Query())->select(['id_photo'])->from('likes')->where(['id_user' => Yii::$app->user->getId(), 'id_photo' => $id_photo])->column();
     }
     foreach ($likes as $like) {
         if (isset($photos[$like])) {
             $photos[$like]['mylike'] = true;
         }
     }
     $photos = User::dateFormat($photos);
     $nn = [];
     foreach ($photos as $pp) {
         $nn[] = $pp;
     }
     return $nn;
 }