fix transform to activity

This commit is contained in:
2022-07-01 14:09:46 +02:00
parent 87403e509f
commit 9c1324e9ec
3 changed files with 72 additions and 6 deletions

View File

@@ -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.
*

View File

@@ -125,6 +125,13 @@
</div>
<ul class="record_actions">
{% if is_granted('CHILL_ACTIVITY_CREATE', accompanyingCourse) %}
<li>
<a class="btn btn-create" href="{{ chill_path_add_return_path('chill_calendar_calendar_to_activity', { 'id': calendar.id }) }}">
{{ 'Transform to activity'|trans }}
</a>
</li>
{% endif %}
{% if (calendar.isInvited(app.user)) %}
{% set invite = calendar.inviteForUser(app.user) %}
<li>