コード例 #1
0
ファイル: User.php プロジェクト: sergiimazurok/koziuck
 public static function getFavorMe($userId, $limit, $contentId, $contentType)
 {
     if ($contentId) {
         $favorId = (new Query())->select('id')->from('favorites')->where(['id_' . $contentType => $contentId])->scalar();
     }
     $favor_photos = (new Query())->select(['f.id as f_id', 'CONCAT("photo") as content_type', 'p.date as content_date', 'CONCAT("/photo", p.id) as content_src', 'p.name as favor_name', 'p.id as favor_id', 'p.src as favor_src', 'f.date as favor_date', 'u.id as favor_user_id', 'u.sex as favor_user_sex', 'u.name as favor_user_name', 'u.avatar as favor_user_avatar', 'p.erotic AS erotic'])->from('favorites f')->innerJoin('photos p', 'f.id_photo=p.id')->innerJoin('user u', 'u.id=f.id_user')->where(['f.id_author' => $userId, 'f.id_article' => 0])->andWhere(['<', 'p.time_closed', time()]);
     $favor_articles = (new Query())->select(['f.id as f_id', 'CONCAT("article") as content_type', 'a.date as content_date', 'CONCAT("/article/", a.url) as content_src', 'a.name as favor_name', 'a.id as favor_id', 'a.thumbnail as favor_src', 'f.date as favor_date', 'u.id as favor_user_id', 'u.sex as favor_user_sex', 'u.name as favor_user_name', 'u.avatar as favor_user_avatar'])->from('favorites f')->innerJoin('articles a', 'f.id_article=a.id')->innerJoin('user u', 'u.id=f.id_user')->where(['f.id_author' => $userId, 'f.id_photo' => 0])->andWhere(['<', 'a.time_closed', time()]);
     $all_favor = $favor_photos->union($favor_articles, true);
     $sql = (new Query())->from(['af' => $all_favor])->orderBy('af.f_id DESC')->limit($limit);
     if ($contentId) {
         $sql->andWhere(['<', 'af.f_id', $favorId]);
     }
     $all_favor = $sql->all();
     foreach ($all_favor as &$favor) {
         if ($favor['content_type'] == 'photo') {
             Photo::getWebPath($favor['favor_src'], $favor['content_date']);
         } else {
             Blog::getWebPath($favor['favor_src']);
         }
         self::getDateContent($favor['favor_date']);
     }
     return $all_favor;
 }