public function convertKeysForSession(CourseSession $session, $content, $withEventsList = true, User $user = null) { $course = $session->getCourse(); $events = $session->getEvents(); $eventsList = ''; $sessionTrainers = $this->getUsersBySessionAndType($session, CourseSessionUser::TEACHER); $sessionTrainersHtml = ''; if (count($sessionTrainers) > 0) { $sessionTrainersHtml = '<ul>'; foreach ($sessionTrainers as $trainer) { $sessionTrainersHtml .= '<li>' . $trainer->getFirstName() . ' ' . $trainer->getLastName() . '</li>'; } $sessionTrainersHtml .= '</ul>'; } if ($withEventsList && count($events) > 0) { $eventsList = '<ul>'; foreach ($events as $event) { $eventsList .= '<li>' . $event->getName() . ' [' . $event->getStartDate()->format('d/m/Y H:i') . ' -> ' . $event->getEndDate()->format('d/m/Y H:i') . ']'; $location = $event->getLocation(); if (!is_null($location)) { $locationHtml = '<br>' . $location->getStreet() . ', ' . $location->getStreetNumber(); $locationHtml .= $location->getBoxNumber() ? ' / ' . $location->getBoxNumber() : ''; $locationHtml .= '<br>' . $location->getPc() . ' ' . $location->getTown() . '<br>' . $location->getCountry(); $locationHtml .= $location->getPhone() ? '<br>' . $location->getPhone() : ''; $eventsList .= $locationHtml; } $eventsList .= $event->getLocationExtra(); } $eventsList .= '</ul>'; } $now = new \DateTime(); $keys = ['%date%', '%course_title%', '%course_code%', '%course_description%', '%session_name%', '%session_description%', '%session_start%', '%session_end%', '%session_trainers%']; $values = [$now->format('d/m/Y'), $course->getTitle(), $course->getCode(), $course->getDescription(), $session->getName(), $session->getDescription(), $session->getStartDate()->format('d/m/Y'), $session->getEndDate()->format('d/m/Y'), $sessionTrainersHtml]; if ($withEventsList) { $keys[] = '%events_list%'; $values[] = $eventsList; } if (!is_null($user)) { $keys[] = '%first_name%'; $keys[] = '%last_name%'; $values[] = $user->getFirstName(); $values[] = $user->getLastName(); } return str_replace($keys, $values, $content); }