コード例 #1
0
ファイル: Search.php プロジェクト: sergiimazurok/koziuck
 public static function searchClubs($name, $author, $limit, $contentId)
 {
     if ($contentId) {
         $contentRating = (new Query())->select(['rating'])->from('clubs')->where(['id' => $contentId])->scalar();
     }
     $sql = (new Query())->select(['c.id AS club_id', 'c.name AS club_name', 'c.date AS club_date', 'c.user_count AS club_user_count', 'c.photo_count AS club_photo_count', 'u.name AS club_author', 'u.id AS club_id_author', 'c.background as club_background', 'c.img_src as club_img_src'])->from('clubs c')->where(['<', 'c.time_closed', time()])->filterWhere(['like', 'c.name', $name])->innerJoin('user u', 'c.id_author = u.id')->AndFilterWhere(['like', 'u.name', $author])->limit($limit)->orderBy('c.rating DESC');
     if ($contentId) {
         $sql->andWhere(['<', 'c.rating', $contentRating]);
     }
     $clubs = $sql->all();
     return Club::formatClubDate($clubs);
 }