예제 #1
0
    public static function getSearchChannels($query)
    {
        $query = trim(urldecode($query));
        if ($query != '') {
            return UserChannel::find_by_sql('SELECT * FROM users_channels
	LEFT OUTER JOIN 
		(SELECT user_channel_id, COUNT(*) AS total_sub FROM subscriptions GROUP BY user_channel_id) 
			AS total_sub
	ON(total_sub.user_channel_id = users_channels.id) 
	
	WHERE name LIKE ? OR description LIKE ? ORDER BY total_sub DESC LIMIT 6', ["%{$query}%", "%{$query}%"]);
        }
    }
예제 #2
0
 public function autocomplete($prefix, $request)
 {
     if (strlen($prefix) >= 3) {
         $channels = UserChannel::find_by_sql("SELECT * FROM users_channels WHERE name LIKE ?", array($prefix . '%'));
         $array = array();
         foreach ($channels as $chan) {
             $array[] = array('user_id' => $chan->owner_id, 'name' => $chan->name, 'avatar' => $chan->avatar);
         }
         return new JsonResponse($array);
     } else {
         return new JsonResponse(array());
     }
 }