Loading module/Oscar/src/Oscar/Service/ActivityTypeService.php +41 −8 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService } protected function getTreeArray(&$index, $datas, &$children) protected function getTreeArray(&$index, $datas, &$children) :void { if (!array_key_exists($index, $datas)) { return; Loading @@ -203,15 +203,18 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService ]; $index++; if( $index < count($datas) ){ if ($activityType->getLft() + 1 < $activityType->getRgt()) { if( array_key_exists($index, $datas) ){ for ( ; $datas[$index] && $datas[$index]->getLft() > $activityType->getLft() && $datas[$index]->getRgt( ; count($datas) > $index && $datas[$index] && $datas[$index]->getLft() > $activityType->getLft() && $datas[$index]->getRgt( ) - 1 <= $activityType->getRgt(); ) { $this->getTreeArray($index, $datas, $out['children']); } } } } $children[] = $out; } Loading @@ -229,11 +232,41 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService $out = []; $start = 0; $this->getTreeArray($start, $datas, $out); return $out; } /** * Retourne l'enchainement des IDs/label pour chaque type. * ex: 507: [505,506] * ou "587": [ "Fonds structurels europ\u00e9ens", "FEDER Recherche", "Feder Recherche 2014\/2020" ] * @return array */ public function getIdsTreeByLast(bool $returnLabel = false) :array { $output = []; $tree = $this->getActivityTypesTree(true); $tree = $tree[0]; foreach ($tree['children'] as $child){ $this->getIdsTreeByLast_recursive($output, [], $child, $returnLabel); } return $output; } protected function getIdsTreeByLast_recursive( array &$output, array $previous, array $child, bool $returnLabel = false ) :void { $data = $returnLabel ? $child['label'] : $child['id']; if(count($child['children'])){ $previous[] = $data; foreach ($child['children'] as $subChild){ $this->getIdsTreeByLast_recursive($output, $previous, $subChild, $returnLabel); } } else { $previous[] = $data; $output[$child['id']] = $previous; } } public function deleteNode(ActivityType $activityType, $deleteEntity = true): void { $lft = $activityType->getLft(); Loading Loading
module/Oscar/src/Oscar/Service/ActivityTypeService.php +41 −8 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService } protected function getTreeArray(&$index, $datas, &$children) protected function getTreeArray(&$index, $datas, &$children) :void { if (!array_key_exists($index, $datas)) { return; Loading @@ -203,15 +203,18 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService ]; $index++; if( $index < count($datas) ){ if ($activityType->getLft() + 1 < $activityType->getRgt()) { if( array_key_exists($index, $datas) ){ for ( ; $datas[$index] && $datas[$index]->getLft() > $activityType->getLft() && $datas[$index]->getRgt( ; count($datas) > $index && $datas[$index] && $datas[$index]->getLft() > $activityType->getLft() && $datas[$index]->getRgt( ) - 1 <= $activityType->getRgt(); ) { $this->getTreeArray($index, $datas, $out['children']); } } } } $children[] = $out; } Loading @@ -229,11 +232,41 @@ class ActivityTypeService implements UseEntityManager, UseLoggerService $out = []; $start = 0; $this->getTreeArray($start, $datas, $out); return $out; } /** * Retourne l'enchainement des IDs/label pour chaque type. * ex: 507: [505,506] * ou "587": [ "Fonds structurels europ\u00e9ens", "FEDER Recherche", "Feder Recherche 2014\/2020" ] * @return array */ public function getIdsTreeByLast(bool $returnLabel = false) :array { $output = []; $tree = $this->getActivityTypesTree(true); $tree = $tree[0]; foreach ($tree['children'] as $child){ $this->getIdsTreeByLast_recursive($output, [], $child, $returnLabel); } return $output; } protected function getIdsTreeByLast_recursive( array &$output, array $previous, array $child, bool $returnLabel = false ) :void { $data = $returnLabel ? $child['label'] : $child['id']; if(count($child['children'])){ $previous[] = $data; foreach ($child['children'] as $subChild){ $this->getIdsTreeByLast_recursive($output, $previous, $subChild, $returnLabel); } } else { $previous[] = $data; $output[$child['id']] = $previous; } } public function deleteNode(ActivityType $activityType, $deleteEntity = true): void { $lft = $activityType->getLft(); Loading