From 9f130aa2af4ae5c97c261b391f61c47ab5c1ecc4 Mon Sep 17 00:00:00 2001 From: Egils Consulting Date: Fri, 7 Aug 2020 23:17:43 +0200 Subject: [PATCH 1/3] 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. --- htdocs/categories/class/categorie.class.php | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) 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; + } + } } From fc58d92db4312f74d851e2f412deb1d79ca83391 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 7 Aug 2020 21:20:55 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/categories/class/categorie.class.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 111f3bf8a88..dd1e48b7346 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -2010,7 +2010,7 @@ class Categorie extends CommonObject return ""; } } - + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Count all categories @@ -2019,20 +2019,19 @@ class Categorie extends CommonObject */ public function count_all_categories() { - dol_syslog(get_class($this)."::count_all_categories", LOG_DEBUG); + 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) + if ($res) { - $obj = $this->db->fetch_object($res); - return $obj->count; - } - else - { - dol_print_error($this->db); - return -1; - } + $obj = $this->db->fetch_object($res); + return $obj->count; + } + else { + dol_print_error($this->db); + return -1; + } } } From 8f8f7ecf5dce545ee891630054ab389e8fcf01a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 8 Aug 2020 02:24:01 +0200 Subject: [PATCH 3/3] Update categorie.class.php --- htdocs/categories/class/categorie.class.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index dd1e48b7346..6128ab5e2df 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -2011,27 +2011,24 @@ class Categorie extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Count all categories * * @return int Number of categories, -1 on error */ - public function count_all_categories() + public function countNbOfCategories() { 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').")"; + $sql = "SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX."categorie"; + $sql .= " WHERE entity IN (".getEntity('category').")"; - $res = $this->db->query($sql); - if ($res) - { + $res = $this->db->query($sql); + if ($res) { $obj = $this->db->fetch_object($res); - return $obj->count; - } - else { - dol_print_error($this->db); - return -1; + return $obj->count; + } else { + dol_print_error($this->db); + return -1; } } }