add a method to check for the presence of an object in a category

This commit is contained in:
Cédric Salvador 2014-01-10 10:41:19 +01:00
parent 795dcad59f
commit e7f7dd49a5

View File

@ -571,6 +571,27 @@ 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 int $object_id id of the object to search
* @return int nb number of occurrences
*/
function object_exists($field, $category_table, $object_id)
{
$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);
$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);
return -1;
}
}
/**
* Return childs of a category