コード例 #1
0
ファイル: SiteController.php プロジェクト: wwcao/group8
 /**
  * Help function to search database for the groups
  * that the current logged-in user joined
  * 
  * @return ['myGroups'=>ActiveRecord, 'pagenation'=>Pagination]
  */
 private function searchGroups($keywords)
 {
     //TODO: Check out this functions correctly
     $username = $this->getUser()->username;
     $reserved = ['where', 'interest', 'interests', 'when', 'where'];
     $likecondition = '';
     foreach ($keywords as $x) {
         if ($x == '' || in_array(strtolower($x), $reserved)) {
             continue;
         }
         $likecondition .= "description like '%" . $x . "%' OR ";
     }
     if ($likecondition == '') {
         return ['Groups' => []];
     }
     $likecondition = substr($likecondition, 0, -4);
     $q_joinTbles = "select a.* from (select * from groups where l_user!='{$username}' and status!='c') a LEFT JOIN (select * from groupmembers where m_user!='{$username}') b on a.l_user=b.l_user and a.groupname=b.groupname";
     $queryGroups = Groups::findBySql("select * from ({$q_joinTbles}) c where {$likecondition} order by create_date desc limit 10");
     $queryGroups->select('*');
     $groups = $queryGroups->all();
     return ['Groups' => $groups];
 }