mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 13:03:50 +00:00
fix transform to activity
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user