admin/emails/broken: remove trailing spaces after email addresses
[platal.git] / classes / jobterms.php
index 418bfc9..b17033c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -46,21 +46,34 @@ class JobTerms {
             $table = 'profile_mentor_term';
             break;
         }
+        // we are in a tree looking for certain job terms:
+        $countingterms = false;
         if ($table) {
             $count = ', COUNT(DISTINCT j.pid) AS nb';
             $join = ' INNER JOIN  profile_job_term_relation AS r2 ON (r2.jtid_1 = e.jtid)
                       INNER JOIN  '.$table.' AS j ON (j.jtid = r2.jtid_2)';
+            $countingterms = 'j.jtid';
         } else {
             $count = $join = '';
         }
         if (!empty($token_filter)) {
             $join .= ' INNER JOIN  profile_job_term_relation AS rtf ON (rtf.jtid_1 = e.jtid) '.
                 self::token_join_query(self::tokenize($token_filter), 'rtf', 'jtid_2');
+            if (!$countingterms) {
+                $countingterms = 'rtf.jtid_2';
+            }
+        }
+        if (!$countingterms) {
+            $select_leaf = 'IF(r_subbranch.jtid_1 IS NULL,1,0)';
+            $join .= ' LEFT JOIN  profile_job_term_relation AS r_subbranch ON (r_subbranch.jtid_1 = e.jtid AND r_subbranch.computed = "original") ';
+        } else {
+            // branches that have counting terms different that
+            // main branch will have subbranches
+            $select_leaf = 'MIN('.$countingterms.' = e.jtid)';
         }
-        return XDB::iterator('SELECT  e.jtid, e.name, e.full_name'.$count.', IF(rf.jtid_1 IS NULL, 1, 0) AS leaf
+        return XDB::iterator('SELECT  e.jtid, e.name, e.full_name'.$count.', '.$select_leaf.' AS leaf
                                 FROM  profile_job_term_enum AS e
                           INNER JOIN  profile_job_term_relation AS r ON (r.jtid_2 = e.jtid)'.$join.'
-                          LEFT JOIN   profile_job_term_relation AS rf ON (rf.jtid_1 = e.jtid AND rf.computed = "original")
                                WHERE  r.jtid_1 = {?} AND r.computed = "original"
                             GROUP BY  e.jtid
                             ORDER BY  e.name',
@@ -81,7 +94,7 @@ class JobTerms {
      * subbranches, keeping only the one containing this text in its title or in the title of one of
      * its subbranches.
      */
-    static public function ajaxGetBranch(&$page, $filter = self::ALL) {
+    static public function ajaxGetBranch($page, $filter = self::ALL) {
         pl_content_headers('application/json');
         $page->changeTpl('include/jobterms.branch.tpl', NO_SKIN);
         $subTerms = self::getSubTerms(Env::v('jtid'), $filter, Env::v('text_filter'));
@@ -104,9 +117,9 @@ class JobTerms {
         return '$("'.addslashes($domElement).'").jstree({
             "core" : {"strings":{"loading":"Chargement ..."}},
             "plugins" : ["themes","json_data"],
-            "themes" : { "url" : platal_baseurl + "css/jstree.css" },
+            "themes" : { "url" : $.plURL("css/jstree.css") },
             "json_data" : { "ajax" : {
-                "url" : platal_baseurl + "'.addslashes($platalpage).'",
+                "url" : $.plURL("'.addslashes($platalpage).'"),
                 "data" : function(nod) {
                     var jtid = 0;
                     if (nod != -1) {
@@ -163,5 +176,5 @@ class JobTerms {
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>