Esempio n. 1
0
function autocomplete_search_users($term, $storage_url)
{
    $Profiles = new Application_Model_Profiles();
    // quote
    $search_term = $Profiles->getDefaultAdapter()->quote("%{$term}%");
    if (Zend_Auth::getInstance()->hasIdentity()) {
        $user_id = (int) Zend_Auth::getInstance()->getIdentity()->id;
        $join = "LEFT JOIN connections c ON c.follow_id = p.id AND c.user_id = " . $user_id;
        $order = "ORDER BY c.created_on DESC, p.type DESC";
    } else {
        $join = "";
        $order = "ORDER BY p.type DESC";
    }
    $sql = "\n\tSELECT\n\tp.name AS label,\n\tp.screen_name AS name,\n\tp.avatar as avatar\n\t\n\tFROM profiles p\n\t{$join}\n\t\n\tWHERE p.is_hidden = 0\n\tAND (p.activationkey = 'activated' OR p.type != 'user')\n\tAND (p.name like {$search_term} OR p.screen_name like {$search_term})\n\t\n\t{$order}\n\t\n\tLIMIT 5\n\t";
    $result = $Profiles->getDefaultAdapter()->fetchAll($sql);
    if (!$result) {
        die;
    }
    foreach ($result as &$user) {
        $user['link'] = Application_Plugin_Common::getFullBaseUrl() . '/' . $user['label'];
        $user['avatar'] = $storage_url . $user['avatar'];
    }
    echo json_encode($result);
    // stop view render
    die;
}