get_input('field'), 'results' => array( ) ); $voc = waramu_getCombinedVocabulary($field); array_multisort($voc, SORT_NUMERIC, SORT_DESC); // populate results with up to $limit values // adding all values where something starts with a $value foreach ( $voc as $v => $c ) { //print $v. " ".$c."
"; if ( mb_substr($v, 0, mb_strlen($value)) == $value) { $res['results'][] = array($v, $v." (".$c.")"); } if ( count($res['results']) > $limit-1 ) { break; } } // if there is still room, add values where // something contains $value if ( count($res['results']) < $limit ) { foreach ( $voc as $v => $c ) { if ( mb_strpos($v, $value, 1) ) { // just to be sure, we're checking if it's not already in results. $exists = false; foreach ( $res['results'] as $rv => $rc ) { if ( $rc[0] == $v ) { $exists = true; } } if ( !$exists ) { $res['results'][] = array($v, $v." (".$c.")"); } } if ( count($res['results']) > $limit-1 ) { break; } } } echo json_encode($res); } if ( $field == 'creator' || $field == 'vauthor' ) { $voc = array(); global $CONFIG; $creators = get_data("SELECT user_guid, COUNT(user_guid) as user_count FROM elggkoolielu_waramu_resources GROUP BY user_guid;"); foreach ($creators as $creator){ $ue = get_entity($creator->user_guid); if (strtolower(substr($ue->username,0,strlen($value))) == strtolower($value) || strtolower(substr($ue->name,0,strlen($value))) == strtolower($value)) { if ( $field == 'creator' ) { $voc []= array($ue->username,$ue->name." (".$creator->user_count.")"); } if ( $field == 'vauthor' ) { $voc []= array($ue->name,$ue->name." (".$creator->user_count.")"); } } if ( count($voc) > $limit-1 ) { break; } } $res = array('field' => get_input('field'), 'results' => $voc ); echo json_encode($res); } } ?>