Skip to content

Commit 62457d5

Browse files
authored
Merge pull request #14 from lnNgyn1/release-1.4
Release 1.4
2 parents 9245077 + b7f8e23 commit 62457d5

18 files changed

Lines changed: 1066 additions & 828 deletions

.php-cs-fixer.dist.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

33
$fileHeaderComment = <<<COMMENT
4-
This file is part of the "Custom CSS Bundle" for Kimai.
5-
All rights reserved by Kevin Papst (www.kevinpapst.de).
4+
This file is part of the "PeriodInsertBundle" for Kimai.
65
76
For the full copyright and license information, please view the LICENSE
87
file that was distributed with this source code.

Controller/PeriodInsertController.php

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
use App\Entity\Timesheet;
1515
use App\Timesheet\TimesheetService;
1616
use App\Utils\PageSetup;
17+
use App\Validator\ValidationFailedException;
1718
use KimaiPlugin\PeriodInsertBundle\Entity\PeriodInsert;
18-
use KimaiPlugin\PeriodInsertBundle\Form\PeriodInsertType;
19+
use KimaiPlugin\PeriodInsertBundle\Form\PeriodInsertForm;
1920
use KimaiPlugin\PeriodInsertBundle\Repository\PeriodInsertRepository;
2021
use Symfony\Component\Form\FormInterface;
2122
use Symfony\Component\HttpFoundation\Request;
@@ -25,93 +26,76 @@
2526

2627
#[Route(path: '/period_insert')]
2728
#[IsGranted('period_insert')]
28-
class PeriodInsertController extends AbstractController
29+
final class PeriodInsertController extends AbstractController
2930
{
3031
public function __construct(
3132
protected PeriodInsertRepository $repository,
32-
protected TimesheetService $service,
33+
protected TimesheetService $timesheetService,
3334
protected SystemConfiguration $configuration
34-
) {
35+
)
36+
{
3537
}
3638

39+
/**
40+
* @param Request $request
41+
* @return Response
42+
*/
3743
#[Route(path: '', name: 'period_insert', methods: ['GET', 'POST'])]
3844
public function indexAction(Request $request): Response
3945
{
40-
$entry = $this->service->createNewTimesheet($this->getUser(), $request);
46+
$timesheet = $this->timesheetService->createNewTimesheet($this->getUser(), $request);
4147

42-
$entity = $this->repository->getTimesheet();
43-
$entity->setUser($this->getUser());
48+
$periodInsert = new PeriodInsert();
49+
$periodInsert->setUser($this->getUser());
50+
if (!$this->timesheetService->getActiveTrackingMode()->canEditBegin()) {
51+
$periodInsert->setBeginTime($timesheet->getBegin());
52+
}
4453

45-
$form = $this->getInsertForm($entity, $entry);
54+
$form = $this->getInsertForm($periodInsert, $timesheet);
4655
$form->handleRequest($request);
4756

4857
if ($form->isSubmitted() && $form->isValid()) {
49-
/** @var PeriodInsert $entity */
50-
$entity = $form->getData();
51-
if ($this->service->getActiveTrackingMode()->getId() === 'duration_fixed_begin') {
52-
$entity->setBeginTime($entry->getBegin());
53-
}
54-
$entity->setFields();
55-
56-
if (($dayToInsert = $this->repository->findDayToInsert($entity)) === '') {
57-
$this->flashError('Could not find a day to insert in the given time range.');
58-
}
59-
else if ($this->repository->checkFutureTime($entity, $dayToInsert)) {
60-
$this->flashError('The time range cannot be in the future.');
61-
}
62-
else if ($this->repository->checkZeroDuration($entity)) {
63-
$this->flashError('Duration cannot be zero.');
64-
}
65-
else if (($overlap = $this->repository->checkOverlappingTimeEntries($entity)) !== '') {
66-
$this->flashError('You already have an entry on ' . $overlap . '.');
67-
}
68-
else if (($message = $this->repository->checkBudgetOverbooked($entity)) !== '') {
69-
$this->flashError($message);
70-
}
71-
else {
72-
try {
73-
$this->repository->saveTimesheet($entity);
74-
$this->flashSuccess('action.update.success');
75-
76-
return $this->redirectToRoute('period_insert');
77-
} catch (\Exception $ex) {
78-
$this->flashUpdateException($ex);
79-
}
58+
try {
59+
$this->repository->savePeriodInsert($periodInsert);
60+
$this->flashSuccess('action.update.success');
61+
62+
return $this->redirectToRoute('period_insert');
63+
} catch (ValidationFailedException $ex) {
64+
$this->handleFormUpdateException($ex, $form);
8065
}
8166
}
8267

8368
return $this->render('@PeriodInsert/index.html.twig', [
8469
'page_setup' => $this->createPageSetup(),
8570
'route_back' => 'timesheet',
86-
'entity' => $entity,
71+
'period_insert' => $periodInsert,
8772
'form' => $form->createView(),
8873
]);
8974
}
9075

9176
/**
92-
* @param PeriodInsert $entity
93-
* @param Timesheet $entry
77+
* @param PeriodInsert $periodInsert
78+
* @param Timesheet $timesheet
9479
* @return FormInterface
9580
*/
96-
protected function getInsertForm(PeriodInsert $entity, Timesheet $entry): FormInterface
81+
private function getInsertForm(PeriodInsert $periodInsert, Timesheet $timesheet): FormInterface
9782
{
98-
return $this->createForm(PeriodInsertType::class, $entity, [
83+
return $this->createForm(PeriodInsertForm::class, $periodInsert, [
9984
'action' => $this->generateUrl('period_insert'),
100-
'include_user' => $this->isGranted('ROLE_SUPER_ADMIN'),
101-
'include_rate' => $this->isGranted('edit_rate', $entry),
102-
'include_billable' => $this->isGranted('edit_billable', $entry),
103-
'include_exported' => $this->isGranted('edit_export', $entry),
104-
'allow_begin_datetime' => $this->service->getActiveTrackingMode()->canEditBegin(),
85+
'include_user' => $this->isGranted('create_other_timesheet'),
86+
'include_rate' => $this->isGranted('edit_rate', $timesheet),
87+
'include_billable' => $this->isGranted('edit_billable', $timesheet),
88+
'include_exported' => $this->isGranted('edit_export', $timesheet),
89+
'allow_begin_datetime' => $this->timesheetService->getActiveTrackingMode()->canEditBegin(),
10590
'duration_minutes' => $this->configuration->getTimesheetIncrementDuration(),
10691
'timezone' => $this->getDateTimeFactory()->getTimezone()->getName(),
107-
'customer' => true,
10892
]);
10993
}
11094

11195
/**
11296
* @return PageSetup
11397
*/
114-
protected function createPageSetup(): PageSetup
98+
private function createPageSetup(): PageSetup
11599
{
116100
$page = new PageSetup('periodinsert.title');
117101
$page->setHelp('https://www.kimai.org/store/lnngyn-period-insert-bundle.html');

DependencyInjection/PeriodInsertExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Loader;
1616
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1717

18-
class PeriodInsertExtension extends Extension implements PrependExtensionInterface
18+
final class PeriodInsertExtension extends Extension implements PrependExtensionInterface
1919
{
2020
/**
2121
* @param array $configs
@@ -28,6 +28,9 @@ public function load(array $configs, ContainerBuilder $container): void
2828
$loader->load('services.yaml');
2929
}
3030

31+
/**
32+
* @param ContainerBuilder $container
33+
*/
3134
public function prepend(ContainerBuilder $container): void
3235
{
3336
/*

0 commit comments

Comments
 (0)