2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
25 const ONLY_JOBS
= 'jobs';
26 const ONLY_MENTORS
= 'mentors';
28 static public function getSubTerms($parent_jtid, $filter = self
::ALL
) {
35 $table = 'profile_job_term';
37 case self
::ONLY_MENTORS
:
38 $table = 'profile_mentor_term';
42 $count = ', COUNT(DISTINCT j.pid) AS nb';
43 $join = ' INNER JOIN profile_job_term_relation AS r2 ON (r2.jtid_1 = e.jtid)
44 INNER JOIN '.$table.' AS j ON (j.jtid = r2.jtid_2)';
48 return XDB
::iterator('SELECT e.jtid, e.name, e.full_name'.$count.', IF(rf.jtid_1 IS NULL, 1, 0) AS leaf
49 FROM profile_job_term_enum AS e
50 INNER JOIN profile_job_term_relation AS r ON (r.jtid_2 = e.jtid)'.$join.'
51 LEFT JOIN profile_job_term_relation AS rf ON (rf.jtid_1 = e.jtid AND rf.computed = "original")
52 WHERE r.jtid_1 = {?} AND r.computed = "original"
59 * Display a JSon page containing the sub-branches of a branch in the job terms tree.
60 * @param $page the Platal page
61 * @param $filter filter helps to display only jobterms that are contained in jobs or in mentors
63 * @param Env::i('jtid') job term id of the parent branch, if none trunk will be used
64 * @param Env::v('attrfunc') the name of a javascript function that will be called when a branch
66 * @param Env::v('treeid') tree id that will be given as first argument of attrfunc function
67 * the second argument will be the chosen job term id and the third one the chosen job's full name.
69 static public function ajaxGetBranch(&$page, $filter = self
::ALL
) {
70 pl_content_headers('application/json');
71 $page->changeTpl('include/jobterms.branch.tpl', NO_SKIN
);
72 $subTerms = self
::getSubTerms(Env
::v('jtid'), $filter);
73 $page->assign('subTerms', $subTerms);
76 $page->assign('filter', 'camarade');
78 case self
::ONLY_MENTORS
:
79 $page->assign('filter', 'mentor');
82 $page->assign('jtid', Env
::v('jtid'));
83 $page->assign('attrfunc', Env
::v('attrfunc'));
84 $page->assign('treeid', Env
::v('treeid'));
87 static public function jsAddTree($platalpage, $domElement = '.term_tree', $treeid = '', $attrfunc = '') {
88 return '$("'.addslashes($domElement).'").jstree({
89 "core" : {"strings":{"loading":"Chargement ..."}},
90 "plugins" : ["themes","json_data"],
91 "themes" : { "url" : platal_baseurl + "css/jstree.css" },
92 "json_data" : { "ajax" : {
93 "url" : platal_baseurl + "'.addslashes($platalpage).'",
94 "data" : function(nod) {
97 jtid = nod.attr("id").replace(/^.*_([0-9]+)$/, "$1");
99 return { "jtid" : jtid, "treeid" : "'.addslashes($treeid).'", "attrfunc" : "'.addslashes($attrfunc).'" }
105 * Extract search token from term
106 * @param $term a utf-8 string that can contain any char
107 * @param an array of elementary tokens
109 static public function tokenize($term)
111 $term = mb_strtoupper(replace_accent($term));
112 $term = str_replace(array('/', ',', '(', ')', '"', '&', '»', '«'), ' ', $term);
113 $tokens = explode(' ', $term);
114 static $not_tokens = array('ET','AND','DE','DES','DU','D\'','OU','L\'','LA','LE','LES','PAR','AU','AUX','EN','SUR','UN','UNE','IN');
115 foreach ($tokens as &$t) {
116 $t = preg_replace(array('/^-+/','/-+$/'), '', $t);
117 if (substr($t, 1, 1) == '\'' && in_array(substr($t, 0, 2), $not_tokens)) {
120 if (strlen($t) == 1 ||
in_array($t, $not_tokens)) {
125 return array_filter($tokens);
129 * Create the INNER JOIN query to restrict search to some job terms
130 * @param $tokens an array of the job terms to look for (LIKE comp)
131 * @param $table_alias the alias or name of the table with a jtid field to restrict
132 * @return a partial SQL query
134 static public function token_join_query(array $tokens, $table_alias) {
137 foreach ($tokens as $t) {
139 $joins .= ' INNER JOIN profile_job_term_search AS s'.$i.' ON(s'.$i.'.jtid = '.$table_alias.'.jtid AND s'.$i.'.search LIKE '.XDB
::escape($t).')';
145 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: