/**
  * @param PageEleveurBranch|null $branch
  * @return PageEleveur
  */
 private function fromBranch(PageEleveurBranch $branch = null)
 {
     $pageEleveur = new PageEleveur();
     $pageEleveur->setId($branch->getId());
     $pageEleveur->setOwner($branch->getOwner());
     $pageEleveur->setSlug($branch->getSlug());
     $pageEleveur->setHead($branch->getCommit()->getId());
     $pageEleveur->setNom($branch->getCommit()->getNom());
     $pageEleveur->setDescription($branch->getCommit()->getDescription());
     $pageEleveur->setEspeces($branch->getCommit()->getEspeces());
     $pageEleveur->setRaces($branch->getCommit()->getRaces());
     $pageEleveur->setLieu($branch->getCommit()->getLieu());
     /*
      * Le tri permet de retourner une PE dans le bon ordre même si
      * le commit a été fait dans un mauvais ordre.
      */
     $arrayCollection = $branch->getCommit()->getAnimaux()->toArray();
     usort($arrayCollection, function (PageAnimalBranch $a, PageAnimalBranch $b) {
         return $b->getCreatedAt()->getTimestamp() - $a->getCreatedAt()->getTimestamp();
     });
     $animaux = [];
     /** @var PageAnimalBranch $pageAnimalBranch */
     foreach ($arrayCollection as $pageAnimalBranch) {
         $animaux[] = PageAnimalService::fromBranch($pageAnimalBranch);
     }
     $pageEleveur->setAnimaux($animaux);
     $actualites = $branch->getCommit()->getActualites()->toArray();
     usort($actualites, function (Actualite $a, Actualite $b) {
         return $b->getDate()->getTimestamp() - $a->getDate()->getTimestamp();
     });
     $pageEleveur->setActualites($actualites);
     return $pageEleveur;
 }
Exemple #2
0
 public function addAnimal()
 {
     /** @var PageAnimalService $pageAnimalService */
     $pageAnimalService = $this->client->getContainer()->get('zigotoo.page_animal');
     if (count($this->pageEleveur->getAnimaux()) === 0) {
         $this->pageEleveur->setAnimaux([]);
     }
     $animaux = $this->pageEleveur->getAnimaux();
     array_push($animaux, $pageAnimalService->create($this->user));
     $this->pageEleveur->setAnimaux($animaux);
     /** @var PageEleveurService $pageEleveurService */
     $pageEleveurService = $this->client->getContainer()->get('zigotoo.page_eleveur');
     $this->pageEleveur = $pageEleveurService->commit($this->user, $this->pageEleveur);
     return $this;
 }