New function count_all_categories
This is useful to count the total number of categories e.g. to decide whether to load the full tree or not. It might make most sense to wait with merging until there is code in viewcat.php or index.php using it.
This commit is contained in:
parent
6f7b65d9f2
commit
9f130aa2af
@ -2010,4 +2010,29 @@ class Categorie extends CommonObject
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Count all categories
|
||||
*
|
||||
* @return int Number of categories, -1 on error
|
||||
*/
|
||||
public function count_all_categories()
|
||||
{
|
||||
dol_syslog(get_class($this)."::count_all_categories", LOG_DEBUG);
|
||||
$sql = "SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX."categorie";
|
||||
$sql .= " WHERE entity IN (".getEntity('category').")";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if ($res)
|
||||
{
|
||||
$obj = $this->db->fetch_object($res);
|
||||
return $obj->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user