|
@@ -543,39 +543,39 @@ class Categorie
|
|
|
return ($n[0] > 0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * Load this->motherof that is array(id_son=>id_parent, ...)
|
|
|
- *
|
|
|
- * @return int <0 if KO, >0 if OK
|
|
|
- */
|
|
|
- private function load_motherof()
|
|
|
- {
|
|
|
- global $conf;
|
|
|
-
|
|
|
- $this->motherof=array();
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load this->motherof that is array(id_son=>id_parent, ...)
|
|
|
+ *
|
|
|
+ * @return int <0 if KO, >0 if OK
|
|
|
+ */
|
|
|
+ private function load_motherof()
|
|
|
+ {
|
|
|
+ global $conf;
|
|
|
+
|
|
|
+ $this->motherof=array();
|
|
|
+
|
|
|
// Load array[child]=parent
|
|
|
- $sql = "SELECT fk_parent as id_parent, rowid as id_son";
|
|
|
- $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
|
|
|
- $sql.= " WHERE fk_parent != 0";
|
|
|
- $sql.= " AND entity = ".$conf->entity;
|
|
|
-
|
|
|
- dol_syslog(get_class($this)."::load_motherof sql=".$sql);
|
|
|
- $resql = $this->db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- while ($obj= $this->db->fetch_object($resql))
|
|
|
- {
|
|
|
- $this->motherof[$obj->id_son]=$obj->id_parent;
|
|
|
- }
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dol_print_error($this->db);
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ $sql = "SELECT fk_parent as id_parent, rowid as id_son";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
|
|
|
+ $sql.= " WHERE fk_parent != 0";
|
|
|
+ $sql.= " AND entity = ".$conf->entity;
|
|
|
+
|
|
|
+ dol_syslog(get_class($this)."::load_motherof sql=".$sql);
|
|
|
+ $resql = $this->db->query($sql);
|
|
|
+ if ($resql)
|
|
|
+ {
|
|
|
+ while ($obj= $this->db->fetch_object($resql))
|
|
|
+ {
|
|
|
+ $this->motherof[$obj->id_son]=$obj->id_parent;
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dol_print_error($this->db);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -596,8 +596,8 @@ class Categorie
|
|
|
{
|
|
|
$this->cats = array();
|
|
|
|
|
|
- // Init this->motherof that is array(id_son=>id_parent, ...)
|
|
|
- $this->load_motherof();
|
|
|
+ // Init this->motherof that is array(id_son=>id_parent, ...)
|
|
|
+ $this->load_motherof();
|
|
|
|
|
|
// Init $this->cats array
|
|
|
$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.fk_parent"; // Distinct reduce pb with old tables with duplicates
|
|
@@ -695,7 +695,7 @@ class Categorie
|
|
|
$i++; $cursor_categ=$this->motherof[$cursor_categ];
|
|
|
}
|
|
|
//print 'Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].'<br>'."\n";
|
|
|
-
|
|
|
+
|
|
|
// We count number of _ to have level
|
|
|
$this->cats[$id_categ]['level']=dol_strlen(preg_replace('/[^_]/i','',$this->cats[$id_categ]['fullpath']));
|
|
|
|