From ecfff5636baeb86086ab7b24fb884c8d6a4cf269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 13 Jan 2014 09:27:10 +0100 Subject: [PATCH] rename is_in_cat to containsObject --- htdocs/categories/class/categorie.class.php | 31 +++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 3040ed3176c..7e990e602c9 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -573,22 +573,43 @@ class Categorie /** * check for the presence of an object in a category - * @param string $field table field - * @param string $category_table category table name + * @param string $type object type * @param int $object_id id of the object to search * @return int nb number of occurrences */ - function is_in_cat($field, $category_table, $object_id) + function containsObject($type, $object_id) { + $field = ''; $classname = ''; $category_table = ''; $object_table = ''; + if ($type == 'product') { + $field = 'product'; + } + if ($type == 'customer') { + $field = 'societe'; + } + if ($type == 'supplier') { + $field = 'societe'; + $category_table = 'fournisseur'; + } + if ($type == 'member') { + $field = 'member'; + $category_table = ''; + } + if ($type == 'contact') { + $field = 'socpeople'; + $category_table = 'contact'; + } + if (empty($category_table)) { + $category_table = $field; + } $sql = "SELECT COUNT(*) as nb FROM " . MAIN_DB_PREFIX . "categorie_" . $category_table; $sql .= " WHERE fk_categorie = " . $this->id . " AND fk_" . $field . " = " . $object_id; - dol_syslog(get_class($this)."::product_exists sql=".$sql); + dol_syslog(get_class($this)."::containsObject sql=".$sql); $resql = $this->db->query($sql); if ($resql) { return $this->db->fetch_object($resql)->nb; } else { $this->error=$this->db->error().' sql='.$sql; - dol_syslog(get_class($this)."::get_type ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::containsObject ".$this->error, LOG_ERR); return -1; } }