예제 #1
0
 /**
  * @param CreateLesson $command
  * @return Lesson
  */
 public function createFromCommand(CreateLesson $command)
 {
     if (get_class($command) === UpdateLesson::class) {
         return $this->lessonRepository->find($command->id);
     }
     return new Lesson($this->idGenerator->generate(), $command->title, $command->description, $command->address, $command->city, null, null, $command->workshop, $command->event);
 }
예제 #2
0
 public function search(SearchFilter $filter, $page = 1, $limit = 10)
 {
     // get workshop and lessons filtered separately
     $workshops = $this->workshopRepository->findForCriteria($filter);
     $lessons = $this->lessonsRepository->findForCriteria($filter);
     // get all lessons for found workshops
     if (count($workshops) > 0) {
         $lessonsFromWorkshops = $this->lessonsRepository->findByWorkshopIds(array_unique(array_column($workshops, "id")));
         $lessons = array_unique(array_merge($lessons, $lessonsFromWorkshops), SORT_REGULAR);
     }
     // get all workshops for found lessons
     if (count($lessons) > 0) {
         $workshopsFromLessons = $this->workshopRepository->findByIds(array_unique(array_column($lessons, "workshop_id")));
         $workshops = array_unique(array_merge($workshops, $workshopsFromLessons), SORT_REGULAR);
     }
     // join of the lessons and workshops
     $result = array_map(function ($workshopArray) use($lessons) {
         $workshopArray["lessons"] = array_values(array_filter($lessons, function ($lessonArray) use($workshopArray) {
             return $lessonArray["workshop_id"] == $workshopArray["id"];
         }));
         return $workshopArray;
     }, $workshops);
     $this->pagination = $this->paginator->paginate($result, $page, $limit);
     $this->results = $result;
     return $this;
 }
예제 #3
0
 /**
  * @param UpdateWorkshop $command
  * @throws Exception
  */
 public function handle(UpdateWorkshop $command)
 {
     /** @var Workshop $workshop */
     $workshop = $this->workshopRepository->findOneById($command->id);
     $workshop->updateWithCommand($command);
     $workshop->updateSlug($this->slugGenerator->generate($workshop));
     $command->lessons;
     foreach ($workshop->getLessons() as $existingLesson) {
         if (!in_array($existingLesson, $command->lessons)) {
             $this->lessonRepository->remove($existingLesson);
             $workshop->getLessons()->removeElement($existingLesson);
         }
     }
     $this->workshopRepository->update($workshop);
 }