X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fsearch.php;h=fc2b811081f2e63282d88176cc5055c65b0c1cce;hb=c9566e01c2add8f12a858abe0fbb0bc6b8e3c0d4;hp=7c2ed2e50c936d1521646fa3a754d61423bba986;hpb=23ccdf38469f803adee2d799a7b4669d7d04834b;p=platal.git diff --git a/modules/search.php b/modules/search.php index 7c2ed2e..fc2b811 100644 --- a/modules/search.php +++ b/modules/search.php @@ -213,12 +213,12 @@ class SearchModule extends PLModule $page->assign('public_directory',0); } - private function format_autocomplete(array $item) + static public function format_autocomplete(array $item) { 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. @@ -237,13 +237,18 @@ class SearchModule extends PLModule 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; @@ -257,7 +262,7 @@ class SearchModule extends PLModule 'nb' => $aux[1], 'id' => $aux[2] ); - $item['value'] = $this->format_autocomplete($item); + $item['value'] = self::format_autocomplete($item); array_push($list, $item); } } @@ -279,11 +284,15 @@ class SearchModule extends PLModule 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"; - $item['value'] = $this->format_autocomplete($item); + $item['value'] = self::format_autocomplete($item); } } @@ -308,7 +317,7 @@ class SearchModule extends PLModule 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(); @@ -405,6 +414,7 @@ class SearchModule extends PLModule $wp->buildCache(); $page->setTitle('Emploi et Carrières'); + $page->addJsLink('jquery.ui.xorg.js'); // Count mentors $res = XDB::query("SELECT count(distinct pid) FROM profile_mentor_term");