allow switching user displayed in calendar (#3314)
This commit is contained in:
@@ -11,8 +11,12 @@ namespace App\Controller;
|
||||
|
||||
use App\Calendar\CalendarService;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\User;
|
||||
use App\Form\CalendarForm;
|
||||
use App\Timesheet\TrackingModeService;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
@@ -24,20 +28,43 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
class CalendarController extends AbstractController
|
||||
{
|
||||
private $calendarService;
|
||||
private $configuration;
|
||||
private $service;
|
||||
|
||||
public function __construct(CalendarService $calendarService)
|
||||
public function __construct(CalendarService $calendarService, SystemConfiguration $configuration, TrackingModeService $service)
|
||||
{
|
||||
$this->calendarService = $calendarService;
|
||||
$this->configuration = $configuration;
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", name="calendar", methods={"GET"})
|
||||
* @Route(path="/{profile}", name="calendar_user", methods={"GET"})
|
||||
*/
|
||||
public function userCalendar(SystemConfiguration $configuration, TrackingModeService $service)
|
||||
public function userCalendar(Request $request): Response
|
||||
{
|
||||
$mode = $service->getActiveMode();
|
||||
$form = null;
|
||||
$profile = $this->getUser();
|
||||
|
||||
if ($this->isGranted('view_other_timesheet')) {
|
||||
$form = $this->createFormForGetRequest(CalendarForm::class, ['user' => $profile], [
|
||||
'action' => $this->generateUrl('calendar'),
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$values = $form->getData();
|
||||
if ($values['user'] instanceof User) {
|
||||
$profile = $values['user'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mode = $this->service->getActiveMode();
|
||||
$factory = $this->getDateTimeFactory();
|
||||
$defaultStart = $factory->createDateTime($configuration->getTimesheetDefaultBeginTime());
|
||||
$defaultStart = $factory->createDateTime($this->configuration->getTimesheetDefaultBeginTime());
|
||||
|
||||
$config = $this->calendarService->getConfiguration();
|
||||
|
||||
@@ -46,16 +73,18 @@ class CalendarController extends AbstractController
|
||||
|
||||
if ($mode->canEditBegin()) {
|
||||
try {
|
||||
$dragAndDrop = $this->calendarService->getDragAndDropResources($this->getUser());
|
||||
$dragAndDrop = $this->calendarService->getDragAndDropResources($profile);
|
||||
} catch (\Exception $ex) {
|
||||
$this->logException($ex);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('calendar/user.html.twig', [
|
||||
'form' => ($form === null ? null : $form->createView()),
|
||||
'user' => $profile,
|
||||
'config' => $config,
|
||||
'dragAndDrop' => $dragAndDrop,
|
||||
'google' => $this->calendarService->getGoogleSources($this->getUser()),
|
||||
'google' => $this->calendarService->getGoogleSources($profile),
|
||||
'now' => $factory->createDateTime(),
|
||||
'defaultStartTime' => $defaultStart->format('h:i:s'),
|
||||
'is_punch_mode' => $isPunchMode,
|
||||
|
||||
@@ -23,10 +23,9 @@ use App\Form\MultiUpdate\MultiUpdateTableDTO;
|
||||
use App\Form\MultiUpdate\TimesheetMultiUpdate;
|
||||
use App\Form\MultiUpdate\TimesheetMultiUpdateDTO;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\TimesheetPreCreateForm;
|
||||
use App\Form\Toolbar\TimesheetExportToolbarForm;
|
||||
use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\TagRepository;
|
||||
use App\Repository\TimesheetRepository;
|
||||
@@ -147,48 +146,14 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getTags(TagRepository $tagRepository, $tagNames)
|
||||
{
|
||||
$tags = [];
|
||||
if (!\is_array($tagNames)) {
|
||||
$tagNames = explode(',', $tagNames);
|
||||
}
|
||||
foreach ($tagNames as $tagName) {
|
||||
$tag = $tagRepository->findTagByName($tagName);
|
||||
if (!$tag) {
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
}
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository): Response
|
||||
protected function create(Request $request, string $renderTemplate): Response
|
||||
{
|
||||
$entry = $this->service->createNewTimesheet($this->getUser());
|
||||
|
||||
if ($request->query->get('project')) {
|
||||
$project = $projectRepository->find($request->query->get('project'));
|
||||
$entry->setProject($project);
|
||||
}
|
||||
|
||||
if ($request->query->get('activity')) {
|
||||
$activity = $activityRepository->find($request->query->get('activity'));
|
||||
$entry->setActivity($activity);
|
||||
}
|
||||
|
||||
if ($request->query->get('description')) {
|
||||
$description = $request->query->get('description');
|
||||
$entry->setDescription($description);
|
||||
}
|
||||
|
||||
if ($request->query->get('tags')) {
|
||||
foreach ($this->getTags($tagRepository, $request->query->get('tags')) as $tag) {
|
||||
$entry->addTag($tag);
|
||||
}
|
||||
}
|
||||
$preForm = $this->createFormForGetRequest(TimesheetPreCreateForm::class, $entry, [
|
||||
'include_user' => $this->includeUserInForms('create'),
|
||||
]);
|
||||
$preForm->submit($request->query->all(), false);
|
||||
|
||||
$this->service->prepareNewTimesheet($entry, $request);
|
||||
$createForm = $this->getCreateForm($entry);
|
||||
|
||||
@@ -13,9 +13,6 @@ use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Export\ServiceExport;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TagRepository;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -90,9 +87,9 @@ class TimesheetController extends TimesheetAbstractController
|
||||
* @Route(path="/create", name="timesheet_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_own_timesheet')")
|
||||
*/
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository): Response
|
||||
public function createAction(Request $request): Response
|
||||
{
|
||||
return $this->create($request, 'timesheet/edit.html.twig', $projectRepository, $activityRepository, $tagRepository);
|
||||
return $this->create($request, 'timesheet/edit.html.twig');
|
||||
}
|
||||
|
||||
protected function getCreateForm(Timesheet $entry): FormInterface
|
||||
|
||||
@@ -18,10 +18,7 @@ use App\Export\ServiceExport;
|
||||
use App\Form\Model\MultiUserTimesheet;
|
||||
use App\Form\TimesheetAdminEditForm;
|
||||
use App\Form\TimesheetMultiUserEditForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\TagRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
@@ -83,9 +80,9 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
* @Route(path="/create", name="admin_timesheet_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_other_timesheet')")
|
||||
*/
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository): Response
|
||||
public function createAction(Request $request): Response
|
||||
{
|
||||
return $this->create($request, 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository, $tagRepository);
|
||||
return $this->create($request, 'timesheet-team/edit.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user