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:
Egils Consulting 2020-08-07 23:17:43 +02:00 committed by GitHub
parent 6f7b65d9f2
commit 9f130aa2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}
}