- #1446: Adds field for sports and hobbies -JAC
- #1535: Moves and displays skills with mentoring informations -JAC
+ * Search:
+ - #1284: If a country is chosen, only proposes its cities -JAC
+
* XnetGrp:
- #1525: Fixes broken page on erroneous group page edition -JAC
- #1530: Enables reminder for xnet accounts -JAC
* @param $text Text to autocomplete
* @return PlIterator over the results
*/
- static public function getAutoComplete($type, $text)
+ static public function getAutoComplete($type, $text, $sub_id = null)
{
if (!array_key_exists($type, self::$enumerations)) {
self::init($type);
}
$obj = self::$enumerations[$type];
if ($obj->capabilities & DirEnumeration::HAS_AUTOCOMP) {
- return call_user_func(array($obj, 'getAutoComplete'), $text);
+ return call_user_func_array(array($obj, 'getAutoComplete'), array($text, $sub_id));
} else {
return array();
}
/** Builds a list of query parts for searching @$text in @$field :
* field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%'
*/
- private function mkTests($field, $text)
+ protected function mkTests($field, $text)
{
$tests = array();
$tests[] = $field . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $text);
}
// {{{ function getAutoComplete
- public function getAutoComplete($text)
+ public function getAutoComplete($text, $sub_id = null)
{
$text = str_replace(array('%', '_'), '', $text);
{
protected $where = 'WHERE FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)';
protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)';
+
+ // {{{ function getAutoComplete
+ public function getAutoComplete($text, $sub_id = null)
+ {
+ if (is_null($sub_id)) {
+ return parent::getAutoComplete($text);
+ } else {
+ $tests = $this->mkTests('pace1.long_name', $text);
+ $where .= '(' . implode(' OR ', $tests) . ')';
+ $query = "SELECT pace1.id AS id, pace1.long_name AS field, COUNT(DISTINCT(pac1.pid)) AS nb
+ FROM profile_addresses_components_enum AS pace1
+ INNER JOIN profile_addresses_components AS pac1 ON (pac1.component_id = pace1.id)
+ INNER JOIN profile_addresses_components AS pac2 ON (pac1.pid = pac2.pid AND pac1.jobid = pac2.jobid AND pac1.id = pac2.id
+ AND pac1.groupid = pac2.groupid AND pac1.type = pac2.type)
+ INNER JOIN profile_addresses_components_enum AS pace2 ON (pac2.component_id = pace2.id AND FIND_IN_SET('country', pace2.types))
+ WHERE pace2.id = {?} AND FIND_IN_SET('locality', pace1.types) AND pac1.type = 'home' AND " . $where . "
+ GROUP BY pace1.long_name";
+ return XDB::fetchAllAssoc($query, $sub_id);
+ }
+ }
+ // }}}
+
}
class DE_Sublocalities extends DE_AddressesComponents
protected $idfield = 'profile_job_term_enum.jtid';
// {{{ function getAutoComplete
- public function getAutoComplete($text)
+ public function getAutoComplete($text, $sub_id = null)
{
$tokens = JobTerms::tokenize($text.'%');
if (count($tokens) == 0) {
var baseurl = $.plURL('search/');
var address_types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'locality', 'postal_code');
var address_types_count = address_types.length;
+var autocomplete_sub = {'country': 'locality_text'};
function load_advanced_search(request)
{
function select_autocomplete(name, id)
{
var field_name = name.replace(/_text$/, '');
+ if (autocomplete_sub[field_name] != null) {
+ $(".autocomplete[name='" + autocomplete_sub[field_name] + "']").autocomplete('option', 'source', baseurl + 'autocomplete/' + autocomplete_sub[field_name] + '/' + id);
+ }
// just display field as valid if field is not a text field for a list
if (field_name == name) {
$("select[name='locality_text']").attr('value', '');
}
+ if (autocomplete_sub[prev_type] != null) {
+ $(".autocomplete[name='" + autocomplete_sub[prev_type] + "']").autocomplete('option', 'source', baseurl + 'autocomplete/' + autocomplete_sub[prev_type] + '/' + value);
+ }
+
$('#' + next_list).load(baseurl + 'list/' + next_type, { previous:prev_type, value:value }, function() {
$("select[name='" + next_type + "']").attr('value', '');
if ($("select[name='" + next_type + "']").children('option').size() > 1) {
return $item['field'] . ' (' . $item['nb'] . ' camarade' . ($item['nb'] > 1 ? 's' : '') . ')';
}
- function handler_autocomplete($page, $type = null)
+ function handler_autocomplete($page, $type = null, $sub_id = null)
{
// Autocompletion : according to type required, return
// a list of results matching with the number of matches.
if (!$q) {
exit();
}
+ if (!is_null($sub_id)) {
+ $query = $q . "\t" . $sub_id;
+ } else {
+ $query = $q;
+ }
// Try to look in cached results.
$cached = false;
$cache = XDB::query('SELECT result
FROM search_autocomplete
WHERE name = {?} AND query = {?} AND generated > NOW() - INTERVAL 1 DAY',
- $type, $q);
+ $type, $query);
if ($cache->numRows() > 0) {
$cached = true;
exit();
}
- $list = DirEnum::getAutoComplete($enums[$type], $q);
+ if (is_null($sub_id)) {
+ $list = DirEnum::getAutoComplete($enums[$type], $q);
+ } else {
+ $list = DirEnum::getAutoComplete($enums[$type], $q, $sub_id);
+ }
$to_cache = '';
foreach ($list as &$item) {
$to_cache .= $item['field'] . "\t" . $item['nb'] . "\t" . $item['id'] . "\n";
XDB::query('INSERT INTO search_autocomplete (name, query, result, generated)
VALUES ({?}, {?}, {?}, NOW())
ON DUPLICATE KEY UPDATE result = VALUES(result), generated = VALUES(generated)',
- $type, $q, $to_cache);
+ $type, $query, $to_cache);
}
echo json_encode($list);
exit();