diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 063207be7d8..4430d835df4 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -11,7 +11,7 @@ * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2016 Charlie Benke * Copyright (C) 2018-2023 Frédéric France - * Copyright (C) 2023 Benjamin Falière + * Copyright (C) 2023-2024 Benjamin Falière * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1159,6 +1159,7 @@ class Categorie extends CommonObject } $this->cats = array(); + $nbcateg = 0; // Init this->motherof that is array(id_son=>id_parent, ...) $this->load_motherof(); @@ -1180,6 +1181,8 @@ class Categorie extends CommonObject $resql = $this->db->query($sql); if ($resql) { $i = 0; + $nbcateg = $this->db->num_rows($resql); + while ($obj = $this->db->fetch_object($resql)) { $this->cats[$obj->rowid]['rowid'] = $obj->rowid; $this->cats[$obj->rowid]['id'] = $obj->rowid; @@ -1201,7 +1204,7 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::get_full_arbo call to buildPathFromId", LOG_DEBUG); foreach ($this->cats as $key => $val) { //print 'key='.$key.'
'."\n"; - $this->buildPathFromId($key, 0); // Process a branch from the root category key (this category has no parent) + $this->buildPathFromId($key, $nbcateg); // Process a branch from the root category key (this category has no parent) } // Include or exclude leaf including $markafterid from tree