changeTpl('include/jobterms.branch.tpl', NO_SKIN); $subTerms = self::getSubTerms(Env::v('jtid'), $filter, Env::v('text_filter')); $page->assign('subTerms', $subTerms); switch ($filter) { case self::ONLY_JOBS: $page->assign('filter', 'camarade'); break; case self::ONLY_MENTORS: $page->assign('filter', 'mentor'); break; } $page->assign('jtid', Env::v('jtid')); $page->assign('text_filter', Env::v('text_filter')); $page->assign('attrfunc', Env::v('attrfunc')); $page->assign('treeid', Env::v('treeid')); } static public function jsAddTree($platalpage, $domElement = '.term_tree', $treeid = '', $attrfunc = '') { return '$("'.addslashes($domElement).'").jstree({ "core" : {"strings":{"loading":"Chargement ..."}}, "plugins" : ["themes","json_data"], "themes" : { "url" : $.plURL("css/jstree.css") }, "json_data" : { "ajax" : { "url" : $.plURL("'.addslashes($platalpage).'"), "data" : function(nod) { var jtid = 0; if (nod != -1) { jtid = nod.attr("id").replace(/^.*_([0-9]+)$/, "$1"); } return { "jtid" : jtid, "treeid" : "'.addslashes($treeid).'", "attrfunc" : "'.addslashes($attrfunc).'" } } }} });'; } /** * Extract search token from term * @param $term a utf-8 string that can contain any char * @return an array of elementary tokens */ static public function tokenize($term) { $term = mb_strtoupper(replace_accent($term)); $term = str_replace(array('/', ',', '(', ')', '"', '&', '»', '«'), ' ', $term); $tokens = explode(' ', $term); static $not_tokens = array('ET','AND','DE','DES','DU','D\'','OU','L\'','LA','LE','LES','PAR','AU','AUX','EN','SUR','UN','UNE','IN'); foreach ($tokens as &$t) { $t = preg_replace(array('/^-+/','/-+$/'), '', $t); if (substr($t, 1, 1) == '\'' && in_array(substr($t, 0, 2), $not_tokens)) { $t = substr($t, 2); } if (strlen($t) == 1 || in_array($t, $not_tokens)) { $t = false; continue; } } return array_filter($tokens); } /** * Create the INNER JOIN query to restrict search to some job terms * @param $tokens an array of the job terms to look for (LIKE comp) * @param $table_alias the alias or name of the table with a jtid field to restrict * @param $table_field the name of the field to restrict in table_alias, usually jtid * @return a partial SQL query */ static public function token_join_query(array $tokens, $table_alias, $table_field = 'jtid') { $joins = ''; $i = 0; foreach ($tokens as $t) { ++$i; $joins .= ' INNER JOIN profile_job_term_search AS s'.$i.' ON(s'.$i.'.jtid = '.$table_alias.'.'.$table_field.' AND s'.$i.'.search LIKE '.XDB::escape($t).')'; } return $joins; } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>