tag_repository = $tag_repository; $this->track_repository = $track_repository; $this->track_question_template_repository = $track_question_template_repository; $this->file_uploader = $file_uploader; } /** * @param Summit $summit * @param array $data * @return PresentationCategory * @throws EntityNotFoundException * @throws ValidationException */ public function addTrack(Summit $summit, array $data) { $track = $this->tx_service->transaction(function () use ($summit, $data) { if (!empty($data['code'])) { $former_track = $summit->getPresentationCategoryByCode(trim($data['code'])); if (!is_null($former_track)) throw new ValidationException(sprintf("track id %s already has code %s assigned on summit id %s", $former_track->getId(), $data['code'], $summit->getId())); } $former_track = $summit->getPresentationCategoryByTitle($data['name']); if (!is_null($former_track)) throw new ValidationException(sprintf("track id %s already has title %s assigned on summit id %s", $former_track->getId(), $data['name'], $summit->getId())); $track = PresentationCategoryFactory::build($summit, $data); if(isset($data['allowed_tags'])){ foreach($data['allowed_tags'] as $tag_value) { $tackTagGroupAllowedTag = $summit->getAllowedTagOnTagTrackGroup($tag_value); if(is_null($tackTagGroupAllowedTag)){ throw new ValidationException( sprintf("allowed_tags : tag value %s is not allowed on current track tag groups for summit %s", $tag_value, $summit->getId()) ); } $track->addAllowedTag($tackTagGroupAllowedTag->getTag()); } } $summit->addPresentationCategory($track); return $track; }); Event::fire(new TrackInserted($track->getSummitId(), $track->getId())); return $track; } /** * @param Summit $summit * @param int $track_id * @param array $data * @return PresentationCategory * @throws EntityNotFoundException * @throws ValidationException */ public function updateTrack(Summit $summit, $track_id, array $data) { return $this->tx_service->transaction(function () use ($summit, $track_id, $data) { $track = $summit->getPresentationCategory($track_id); if (is_null($track)) throw new EntityNotFoundException ( sprintf("track id %s does not belong to summit id %s", $track_id, $summit->getId()) ); if (isset($data['code']) && !empty($data['code'])) { $former_track = $summit->getPresentationCategoryByCode($data['code']); if (!is_null($former_track) && $former_track->getId() != $track_id) throw new ValidationException(sprintf("track id %s already has code %s assigned on summit id %s", $former_track->getId(), $data['code'], $summit->getId())); } if (isset($data['name'])) { $former_track = $summit->getPresentationCategoryByTitle($data['name']); if (!is_null($former_track) && $former_track->getId() != $track_id) throw new ValidationException(sprintf("track id %s already has title %s assigned on summit id %s", $former_track->getId(), $data['name'], $summit->getId())); } $track = PresentationCategoryFactory::populate($track, $data); if(isset($data['allowed_tags'])){ $track->clearAllowedTags(); foreach($data['allowed_tags'] as $tag_value) { $tackTagGroupAllowedTag = $summit->getAllowedTagOnTagTrackGroup($tag_value); if(is_null($tackTagGroupAllowedTag)){ throw new ValidationException( sprintf("allowed_tags : tag value %s is not allowed on current track tag groups for summit %s", $tag_value, $summit->getId()) ); } $track->addAllowedTag($tackTagGroupAllowedTag->getTag()); } } Event::fire(new TrackUpdated($track->getSummitId(), $track->getId())); return $track; }); } /** * @param Summit $summit * @param int $track_id * @return void * @throws EntityNotFoundException * @throws ValidationException */ public function deleteTrack(Summit $summit, $track_id) { return $this->tx_service->transaction(function () use ($summit, $track_id) { $track = $summit->getPresentationCategory($track_id); if (is_null($track)) throw new EntityNotFoundException ( sprintf("track id %s does not belong to summit id %s", $track_id, $summit->getId()) ); $summit_events = $track->getRelatedPublishedSummitEventsIds(); if(count($summit_events) > 0){ throw new ValidationException ( sprintf("track id %s could not be deleted bc its assigned to published events on summit id %s", $track_id, $summit->getId()) ); } Event::fire(new TrackDeleted($track->getSummitId(), $track->getId())); $this->track_repository->delete($track); }); } /** * @param Summit $from_summit * @param Summit $to_summit * @return PresentationCategory[] * @throws EntityNotFoundException * @throws ValidationException */ public function copyTracks(Summit $from_summit, Summit $to_summit) { $added_tracks = $this->tx_service->transaction(function () use ($from_summit, $to_summit) { if($from_summit->getId() == $to_summit->getId()){ throw new ValidationException ( trans ( 'validation_errors.SummitTrackService.copyTracks.SameSummit' ) ); } $added_tracks = []; foreach($from_summit->getPresentationCategories() as $track_2_copy){ $former_track = $to_summit->getPresentationCategoryByTitle($track_2_copy->getTitle()); if(!is_null($former_track)) continue; $former_track = $to_summit->getPresentationCategoryByCode($track_2_copy->getCode()); if(!is_null($former_track)) continue; $data = [ 'name' => $track_2_copy->getTitle(), 'code' => $track_2_copy->getCode(), 'color' => $track_2_copy->getColor(), 'description' => $track_2_copy->getDescription(), 'session_count' => $track_2_copy->getSessionCount(), 'alternate_count' => $track_2_copy->getAlternateCount(), 'lightning_count' => $track_2_copy->getLightningCount(), 'lightning_alternate_count' => $track_2_copy->getLightningAlternateCount(), 'voting_visible' => $track_2_copy->isVotingVisible(), 'chair_visible' => $track_2_copy->isChairVisible(), ]; $new_track = PresentationCategoryFactory::build($to_summit, $data); $to_summit->addPresentationCategory($new_track); $added_tracks[] = $new_track; } return $added_tracks; }); foreach ($added_tracks as $track){ Event::fire(new TrackInserted($track->getSummitId(), $track->getId())); } return $added_tracks; } /** * @param int $track_id * @param int $question_id * @return void * @throws EntityNotFoundException * @throws ValidationException */ public function addTrackExtraQuestion($track_id, $question_id) { return $this->tx_service->transaction(function() use($track_id, $question_id){ $track = $this->track_repository->getById($track_id); if(is_null($track)) throw new EntityNotFoundException( trans ( 'not_found_errors.SummitTrackService.addTrackExtraQuestion.TrackNotFound', ['track_id' => $track_id ] ) ); $track_question_template = $this->track_question_template_repository->getById($question_id); if(is_null($track_question_template)) throw new EntityNotFoundException( trans ( 'not_found_errors.SummitTrackService.addTrackExtraQuestion.QuestionNotFound', ['question_id' => $question_id ] ) ); $track->addExtraQuestion($track_question_template); }); } /** * @param int $track_id * @param int $question_id * @return void * @throws EntityNotFoundException * @throws ValidationException */ public function removeTrackExtraQuestion($track_id, $question_id) { return $this->tx_service->transaction(function() use($track_id, $question_id){ $track = $this->track_repository->getById($track_id); if(is_null($track)) throw new EntityNotFoundException( trans ( 'not_found_errors.SummitTrackService.removeTrackExtraQuestion.TrackNotFound', ['track_id' => $track_id ] ) ); $track_question_template = $this->track_question_template_repository->getById($question_id); if(is_null($track_question_template)) throw new EntityNotFoundException( trans ( 'not_found_errors.SummitTrackService.removeTrackExtraQuestion.QuestionNotFound', ['question_id' => $question_id ] ) ); $track->removeExtraQuestion($track_question_template); }); } /** * @inheritDoc */ public function addTrackIcon(Summit $summit, $track_id, UploadedFile $file, $max_file_size = 10485760) { return $this->tx_service->transaction(function () use ($summit, $track_id, $file, $max_file_size) { $allowed_extensions = ['png', 'jpg', 'jpeg', 'gif']; $track = $summit->getPresentationCategory($track_id); if (is_null($track) || !$track instanceof PresentationCategory) { throw new EntityNotFoundException('track not found on summit!'); } if (!in_array($file->extension(), $allowed_extensions)) { throw new ValidationException("file does not has a valid extension ('png','jpg','jpeg','gif')."); } if ($file->getSize() > $max_file_size) { throw new ValidationException(sprintf("file exceeds max_file_size (%s MB).", ($max_file_size / 1024) / 1024)); } $file = $this->file_uploader->build($file, 'summit-track-icon', true); $track->setIcon($file); return $file; }); } /** * @inheritDoc */ public function removeTrackIcon(Summit $summit, $track_id): void { $this->tx_service->transaction(function () use ($summit, $track_id) { $track = $summit->getPresentationCategory($track_id); if (is_null($track) || !$track instanceof PresentationCategory) { throw new EntityNotFoundException('track not found on summit!'); } $track->clearIcon(); }); } }