diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index a89b1d67c..6cfc106fb 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -21,6 +21,7 @@ use Chill\ActivityBundle\Repository\ActivityTypeRepository; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Repository\LocationRepository; +use Chill\MainBundle\Repository\UserRepositoryInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Privacy\PrivacyEvent; @@ -70,6 +71,8 @@ final class ActivityController extends AbstractController private ThirdPartyRepository $thirdPartyRepository; + private UserRepositoryInterface $userRepository; + public function __construct( ActivityACLAwareRepositoryInterface $activityACLAwareRepository, ActivityTypeRepository $activityTypeRepository, @@ -82,7 +85,8 @@ final class ActivityController extends AbstractController EntityManagerInterface $entityManager, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, - SerializerInterface $serializer + SerializerInterface $serializer, + UserRepositoryInterface $userRepository ) { $this->activityACLAwareRepository = $activityACLAwareRepository; $this->activityTypeRepository = $activityTypeRepository; @@ -96,6 +100,7 @@ final class ActivityController extends AbstractController $this->eventDispatcher = $eventDispatcher; $this->logger = $logger; $this->serializer = $serializer; + $this->userRepository = $userRepository; } /** @@ -366,7 +371,7 @@ final class ActivityController extends AbstractController if ($request->query->has('activityData')) { $activityData = $request->query->get('activityData'); - if (array_key_exists('durationTime', $activityData)) { + if (array_key_exists('durationTime', $activityData) && $activityType->getDurationTimeVisible() > 0) { $durationTimeInMinutes = $activityData['durationTime']; $hours = floor($durationTimeInMinutes / 60); $minutes = $durationTimeInMinutes % 60; @@ -385,26 +390,35 @@ final class ActivityController extends AbstractController } } - if (array_key_exists('personsId', $activityData)) { + if (array_key_exists('personsId', $activityData) && $activityType->getPersonsVisible() > 0) { foreach ($activityData['personsId'] as $personId) { $concernedPerson = $this->personRepository->find($personId); $entity->addPerson($concernedPerson); } } - if (array_key_exists('professionalsId', $activityData)) { + if (array_key_exists('professionalsId', $activityData) && $activityType->getThirdPartiesVisible() > 0) { foreach ($activityData['professionalsId'] as $professionalsId) { $professional = $this->thirdPartyRepository->find($professionalsId); $entity->addThirdParty($professional); } } - if (array_key_exists('location', $activityData)) { + if (array_key_exists('usersId', $activityData) && $activityType->getUsersVisible() > 0) { + foreach ($activityData['usersId'] as $userId) { + $user = $this->userRepository->find($userId); + if (null !== $user) { + $entity->addUser($user); + } + } + } + + if (array_key_exists('location', $activityData) && $activityType->getLocationVisible() > 0) { $location = $this->locationRepository->find($activityData['location']); $entity->setLocation($location); } - if (array_key_exists('comment', $activityData)) { + if (array_key_exists('comment', $activityData) && $activityType->getCommentVisible() > 0) { $comment = new CommentEmbeddable(); $comment->setComment($activityData['comment']); $comment->setUserId($this->getUser()->getid()); diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 1f01832fc..0c748cccb 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -31,6 +31,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -308,6 +309,50 @@ class CalendarController extends AbstractController ]); } + /** + * @Route("/{_locale}/calendar/calendar/{id}/to-activity", name="chill_calendar_calendar_to_activity") + */ + public function toActivity(Request $request, Calendar $calendar): RedirectResponse + { + $personsId = array_map( + static fn (Person $p): int => $p->getId(), + $calendar->getPersons()->toArray() + ); + + $professionalsId = array_map( + static fn (ThirdParty $thirdParty): ?int => $thirdParty->getId(), + $calendar->getProfessionals()->toArray() + ); + + $usersId = array_map( + static fn (User $user): ?int => $user->getId(), + array_merge($calendar->getUsers()->toArray(), [$calendar->getMainUser()]) + ); + + $durationTime = $calendar->getEndDate()->diff($calendar->getStartDate()); + $durationTimeInMinutes = $durationTime->days * 1440 + $durationTime->h * 60 + $durationTime->i; + + $activityData = [ + 'calendarId' => $calendar->getId(), + 'personsId' => $personsId, + 'professionalsId' => $professionalsId, + 'usersId' => $usersId, + 'date' => $calendar->getStartDate()->format('Y-m-d'), + 'durationTime' => $durationTimeInMinutes, + 'location' => $calendar->getLocation() ? $calendar->getLocation()->getId() : null, + 'comment' => $calendar->getComment()->getComment(), + ]; + + return $this->redirectToRoute( + 'chill_activity_activity_new', + [ + 'accompanying_period_id' => $calendar->getAccompanyingPeriod()->getId(), + 'activityData' => $activityData, + 'returnPath' => $request->query->get('returnPath', null), + ] + ); + } + /** * Show a calendar item. * diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig index cdd6a096a..1407f5855 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig @@ -125,6 +125,13 @@