From eb3e1eb8c8365d3b3d1d39f24314ba420255afc2 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 21 Apr 2025 20:36:10 +0200 Subject: page menu et chemin, partie1 --- src/model/entities/Node.php | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'src/model/entities/Node.php') diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index a52a7e6..103163b 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -12,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\Table(name: TABLE_PREFIX . "node")] class Node { + use \Position; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: "integer")] @@ -135,36 +137,7 @@ class Node $this->children[] = $child; $this->sortChildren(false); } - // utiliser $position pour afficher les éléments dans l'ordre - public function sortChildren(bool $reposition = false): void - { - // ordre du tableau des enfants - // inefficace quand des noeuds ont la même position - - // tri par insertion - for($i = 1; $i < count($this->children); $i++) - { - $tmp = $this->children[$i]; - $j = $i - 1; - - // Déplacez les éléments du tableau qui sont plus grands que la clé - // à une position devant leur position actuelle - while ($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) { - $this->children[$j + 1] = $this->children[$j]; - $j = $j - 1; - } - $this->children[$j + 1] = $tmp; - } - - // nouvelles positions - if($reposition){ - $i = 1; - foreach($this->children as $child){ - $child->setPosition($i); - $i++; - } - } - } + public function removeChild(self $child): void { foreach($this->children as $key => $object){ -- cgit v1.2.3