diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7d3cdfde518..111f3bf8a88 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -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; + } + } }