From d2a364eea85d49c357024ca34b73fc10ceac6970 Mon Sep 17 00:00:00 2001 From: quentin Date: Wed, 1 Jul 2020 14:10:43 +0200 Subject: [PATCH 1/2] NEW get all child recursively --- htdocs/core/class/commonobject.class.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5f9582a475f..03b220f314a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2525,10 +2525,11 @@ abstract class CommonObject /** * Get children of line * - * @param int $id Id of parent line - * @return array Array with list of children lines id + * @param int $id Id of parent line + * @param int $includealltree 0 = 1st level child, 1 = All level child + * @return array Array with list of children lines id */ - public function getChildrenOfLine($id) + public function getChildrenOfLine($id, $includealltree = 0) { $rows = array(); @@ -2541,16 +2542,14 @@ abstract class CommonObject $resql = $this->db->query($sql); if ($resql) { - $i = 0; - $num = $this->db->num_rows($resql); - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $rows[$i] = $row[0]; - $i++; + if($this->db->num_rows($resql) > 0) { + while($row = $this->db->fetch_row($resql)) { + + $rows[] = $row[0]; + if (!empty($includealltree)) $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree); + } } } - return $rows; } From a44f5376dafc665f1bb8fb2962e6a389853d895c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Jul 2020 00:27:30 +0200 Subject: [PATCH 2/2] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 03b220f314a..a2f3d1159e5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2542,9 +2542,8 @@ abstract class CommonObject $resql = $this->db->query($sql); if ($resql) { - if($this->db->num_rows($resql) > 0) { - while($row = $this->db->fetch_row($resql)) { - + if ($this->db->num_rows($resql) > 0) { + while ($row = $this->db->fetch_row($resql)) { $rows[] = $row[0]; if (!empty($includealltree)) $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree); }