This commit is contained in:
Laurent Destailleur 2011-08-29 22:52:04 +00:00
parent f0cef509f7
commit 41ada61bdd

View File

@ -56,6 +56,7 @@ class Categorie
/**
* Constructor
*
* @param DB acces base de donnees
* @param id id de la categorie
*/
@ -69,6 +70,7 @@ class Categorie
/**
* Load category into memory from database
*
* @param id id of category
*/
function fetch($id)
@ -78,7 +80,7 @@ class Categorie
$sql.= " WHERE rowid = ".$id;
dol_syslog("Categorie::fetch sql=".$sql);
$resql = $this->db->query ($sql);
$resql = $this->db->query($sql);
if ($resql)
{
$res = $this->db->fetch_array($resql);
@ -94,7 +96,7 @@ class Categorie
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
@ -103,7 +105,7 @@ class Categorie
$sql.= " WHERE fk_categorie_fille = '".$id."'";
dol_syslog("Categorie::fetch sql=".$sql);
$resql = $this->db->query ($sql);
$resql = $this->db->query($sql);
if ($resql)
{
$res = $this->db->fetch_array($resql);
@ -113,13 +115,14 @@ class Categorie
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
}
/**
* Add category into database
*
* @return int -1 : erreur SQL
* -2 : nouvel ID inconnu
* -3 : categorie invalide
@ -159,10 +162,10 @@ class Categorie
//$sql.= ",".$this->parentId;
$sql.= ")";
$res = $this->db->query ($sql);
$res = $this->db->query($sql);
if ($res)
{
$id = $this->db->last_insert_id (MAIN_DB_PREFIX."categorie");
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."categorie");
if ($id > 0)
{
@ -199,6 +202,7 @@ class Categorie
/**
* Update category
*
* @return int 1 : OK
* -1 : SQL error
* -2 : invalid category
@ -284,6 +288,7 @@ class Categorie
/**
* Delete a category from database
*
* @param user Object user that ask to delete
*/
function delete($user)
@ -392,6 +397,7 @@ class Categorie
/**
* Ajout d'une sous-categorie
*
* @param $fille objet categorie
* @return int 1 : OK
* -2 : $fille est deja dans la famille de $this
@ -416,6 +422,7 @@ class Categorie
/**
* Suppression d'une sous-categorie (seulement "desassociation")
*
* @param $fille objet categorie
* @return int 1 : OK
* -3 : categorie ($this ou $fille) invalide
@ -442,10 +449,11 @@ class Categorie
}
/**
* \brief Link an object to the category
* \param obj Object to link to category
* \param type Type of category
* \return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked
* Link an object to the category
*
* @param obj Object to link to category
* @param type Type of category
* @return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked
*/
function add_type($obj,$type)
{
@ -478,9 +486,9 @@ class Categorie
/**
* Suppresion d'un produit de la categorie
* @param $prod est un objet de type produit
* retour : 1 : OK
* -1 : erreur SQL
*
* @param $prod est un objet de type produit
* @return int 1 if OK, -1 if KO
*/
function del_type($obj,$type)
{
@ -568,8 +576,8 @@ class Categorie
/**
* Return category description
*
* @param $cate Category id
* @return string Description
* @param int $cate Category id
* @return string Description
*/
function get_desc ($cate)
{
@ -585,7 +593,7 @@ class Categorie
/**
* La categorie $fille est-elle une fille de cette categorie ?
*
* @param fille Object category
* @param Category $fille Object category
*/
function is_fille ($fille)
{
@ -609,9 +617,10 @@ class Categorie
* label = nom de la categorie
* fulllabel = nom avec chemin complet de la categorie
* fullpath = chemin complet compose des id
* @param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
* @param markafterid Mark all categories after this leaf in category tree.
* @return array Array of categories
*
* @param string $type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
* @param int $markafterid Mark all categories after this leaf in category tree.
* @return array Array of categories
*/
function get_full_arbo($type,$markafterid=0)
{
@ -638,7 +647,7 @@ class Categorie
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
@ -672,7 +681,7 @@ class Categorie
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
@ -714,6 +723,7 @@ class Categorie
/**
* For category id_categ and its childs available in this->cats, define property fullpath and fulllabel
*
* @param id_categ id_categ entry to update
* @param protection Deep counter to avoid infinite loop
*/
@ -764,7 +774,7 @@ class Categorie
}
/**
* \brief Affiche contenu de $this->cats
* Affiche contenu de $this->cats
*/
function debug_cats()
{
@ -783,8 +793,9 @@ class Categorie
/**
* \brief Retourne toutes les categories
* \return array Tableau d'objet Categorie
* Retourne toutes les categories
*
* @return array Tableau d'objet Categorie
*/
function get_all_categories ()
{
@ -809,8 +820,9 @@ class Categorie
}
/**
* \brief Retourne le nombre total de categories
* \return int Nombre de categories
* Retourne le nombre total de categories
*
* @return int Nombre de categories
*/
function get_nb_categories ()
{
@ -831,6 +843,7 @@ class Categorie
/**
* Check if no category with same label already exists for this cat's parent or root and for this cat's type
*
* @return boolean 1 if already exist, 0 otherwise, -1 if error
*/
function already_exists()
@ -878,23 +891,23 @@ class Categorie
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
}
/**
* \brief Retourne les categories de premier niveau (qui ne sont pas filles)
* Retourne les categories de premier niveau (qui ne sont pas filles)
*/
function get_main_categories ()
function get_main_categories()
{
$allcats = $this->get_all_categories ();
$allcats = $this->get_all_categories();
$maincats = array ();
$filles = array ();
$sql = "SELECT fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association";
$res = $this->db->query ($sql);
while ($res = $this->db->fetch_array ($res))
$res = $this->db->query($sql);
while ($res = $this->db->fetch_array($res))
{
$filles[] = $res['fk_categorie_fille'];
}
@ -921,7 +934,7 @@ class Categorie
{
$ways = array ();
foreach ($this->get_all_ways () as $way)
foreach ($this->get_all_ways() as $way)
{
$w = array ();
foreach ($way as $cat)
@ -1000,19 +1013,19 @@ class Categorie
$sql = "SELECT fk_categorie_mere FROM ".MAIN_DB_PREFIX."categorie_association ";
$sql .= "WHERE fk_categorie_fille = ".$this->id;
$res = $this->db->query ($sql);
$res = $this->db->query($sql);
if ($res)
{
while ($cat = $this->db->fetch_array ($res))
while ($cat = $this->db->fetch_array($res))
{
$meres[] = new Categorie ($this->db, $cat['fk_categorie_mere']);
$meres[] = new Categorie($this->db, $cat['fk_categorie_mere']);
}
return $meres;
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
}
@ -1025,9 +1038,9 @@ class Categorie
{
$ways = array ();
foreach ($this->get_meres () as $mere)
foreach ($this->get_meres() as $mere)
{
foreach ($mere->get_all_ways () as $way)
foreach ($mere->get_all_ways() as $way)
{
$w = $way;
$w[] = $this;
@ -1036,7 +1049,7 @@ class Categorie
}
}
if (sizeof ($ways) == 0)
if (count($ways) == 0)
$ways[0][0] = $this;
return $ways;
@ -1044,6 +1057,7 @@ class Categorie
/**
* Return list of categories linked to element of type $type with id $typeid
*
* @param id Id of element
* @param typeid Type id of link (0,1,2,3...)
* @return array List of category objects
@ -1063,19 +1077,19 @@ class Categorie
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid";
$sql.= " WHERE ct.fk_".$table." = ".$id." AND c.type = ".$typeid;
$res = $this->db->query ($sql);
$res = $this->db->query($sql);
if ($res)
{
while ($cat = $this->db->fetch_array ($res))
while ($cat = $this->db->fetch_array($res))
{
$cats[] = new Categorie ($this->db, $cat['fk_categorie']);
$cats[] = new Categorie($this->db, $cat['fk_categorie']);
}
return $cats;
}
else
{
dol_print_error ($this->db);
dol_print_error($this->db);
return -1;
}
}
@ -1102,7 +1116,7 @@ class Categorie
{
if (! $exact)
{
$nom = '%'.str_replace ('*', '%', $nom).'%';
$nom = '%'.str_replace('*', '%', $nom).'%';
}
$sql.= "AND label LIKE '".$nom."'";
}
@ -1111,12 +1125,12 @@ class Categorie
$sql.="AND rowid = '".$id."'";
}
$res = $this->db->query ($sql);
$res = $this->db->query($sql);
if ($res)
{
while ($id = $this->db->fetch_array ($res))
while ($id = $this->db->fetch_array($res))
{
$cats[] = new Categorie ($this->db, $id['rowid']);
$cats[] = new Categorie($this->db, $id['rowid']);
}
return $cats;
@ -1265,8 +1279,9 @@ class Categorie
}
/**
* \brief Efface la photo de la categorie et sa vignette
* \param file Chemin de l'image
* Efface la photo de la categorie et sa vignette
*
* @param file Chemin de l'image
*/
function delete_photo($file)
{
@ -1291,8 +1306,9 @@ class Categorie
}
/**
* \brief Load size of image file
* \param file Path to file
* Load size of image file
*
* @param file Path to file
*/
function get_image_size($file)
{
@ -1310,7 +1326,7 @@ class Categorie
{
global $user,$langs,$conf;
dol_syslog("Categorie::initAsSpecimen");
dol_syslog(get_class($this)."::initAsSpecimen");
// Initialise parametres
$this->id=0;