Пример #1
0
 /**
  * @param $exhibitionId
  * @param Carbon $since
  * @param Carbon|null $until
  * @return ScheduleCollection
  */
 public function findByExhibitionAndDateInterval($exhibitionId, Carbon $since = null, Carbon $until = null)
 {
     if ($since === null) {
         $schedules = $this->schedule->where('exhibition_id', $exhibitionId)->get();
         return new ScheduleCollection($schedules->all());
     }
     $schedules = $this->find($since, $until, $exhibitionId);
     return $schedules;
 }
Пример #2
0
 /**
  * @param array $data
  * @return Exhibition
  */
 public function createAndSave(array $data)
 {
     $exhibition = isset($data['id']) ? Exhibition::find($data['id']) : new Exhibition();
     if (isset($data['exhibition_film']['id'])) {
         $exhibitionFilm = ExhibitionFilm::find($data['exhibition_film']['id']);
     } else {
         $exhibitionFilm = new ExhibitionFilm();
     }
     $exhibitionFilm->film_id = $data['exhibition_film']['film']['id'];
     $exhibitionFilm->save();
     $exhibition->exhibitionFilm()->associate($exhibitionFilm);
     $exhibition->notes = isset($data['notes']) ? $data['notes'] : '';
     if (isset($data['icon']['id'])) {
         $exhibition->type_id = $data['icon']['id'];
     } else {
         $exhibition->type_id = null;
     }
     $exhibition->save();
     Schedule::where('exhibition_id', $exhibition->id)->delete();
     $schedules = array_reduce($data['schedules'], function ($schedules, $rawSchedule) {
         $schedule = new Schedule();
         $schedule->entry = $rawSchedule['entry'];
         $schedule->auditorium_id = $rawSchedule['auditorium']['id'];
         $schedules[] = $schedule;
         return $schedules;
     }, []);
     $exhibition->schedules()->saveMany($schedules);
     return Exhibition::findOrFail($exhibition->id);
 }