/** * UpdateWorkshop constructor. * @param Workshop $workshop */ public function __construct(Workshop $workshop) { $this->id = $workshop->getId(); $this->title = $workshop->getTitle(); $this->description = $workshop->getDescription(); $this->startDate = $workshop->getStartDate(); $this->endDate = $workshop->getEndDate(); $this->city = $workshop->getCity(); $this->lessons = $this->convertLessons($workshop->getLessons()); $this->phone = $workshop->getPhone(); $this->url = $workshop->getUrl(); $this->email = $workshop->getEmail(); }
/** * @param Workshop|WorkshopCommandInterface $workshop * @return string */ public function generate($workshop) { if ($workshop instanceof Workshop) { $params = [$workshop->getCity(), $workshop->getTitle()]; } elseif ($workshop instanceof WorkshopCommandInterface) { /** @var CreateWorkshop|UpdateWorkshop $workshop */ $firstLesson = current($workshop->lessons); $params = [$firstLesson->city, $workshop->title]; } $i = 1; do { $slug = sprintf("%s-%d", implode("-", array_map(function ($el) { return strtolower(str_replace(" ", "-", $el)); }, $params)), $i++); } while (!is_null($this->workshopRepository->findOneBySlug($slug))); return $slug; }