Skip to content

Commit

Permalink
Simplified codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Sep 27, 2024
1 parent 4bbcd3a commit b3861e5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Compatibility: requires minimum Kimai 2.21.0

- Added missing "Documentation" link
- Create with invalid type caused 500: redirect to manage view instead
- Create with invalid type caused 500: redirect to manage view instead
- Simplified codebase

## Version 4.1.0

Expand Down
7 changes: 4 additions & 3 deletions Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ public function update(SharedProjectTimesheet $sharedProject, string $shareKey,
throw $this->createNotFoundException('Project not found');
}

$formClass = $sharedProject->isCustomerSharing() ?
SharedCustomerFormType::class :
SharedProjectFormType::class;
$formClass = SharedProjectFormType::class;
if ($sharedProject->getCustomer() !== null) {
$formClass = SharedCustomerFormType::class;
}

$form = $this->createForm($formClass, $sharedProject, [
'method' => 'POST',
Expand Down
6 changes: 3 additions & 3 deletions Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function indexAction(#[MapEntity(mapping: ['shareKey' => 'shareKey'])] Sh
]);
}

if ($sharedPortal->isCustomerSharing()) {
if ($sharedPortal->getCustomer() !== null) {
return $this->renderCustomerView($sharedPortal, $request);
} else {
return $this->renderProjectView($sharedPortal, $sharedPortal->getProject(), $request);
}

return $this->renderProjectView($sharedPortal, $sharedPortal->getProject(), $request);
}

#[Route(path: '/auth/shared-project-timesheets/customer/{customer}/{shareKey}/project/{project}', methods: ['GET', 'POST'])]
Expand Down
14 changes: 0 additions & 14 deletions Entity/SharedProjectTimesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,10 @@ public function setTimeBudgetStatsVisible(bool $timeBudgetStatsVisible): void

public function getType(): string
{
if ($this->customer !== null && $this->project !== null) {
throw new LogicException('Invalid state: customer and project cannot be filled both');
}

if ($this->customer !== null) {
return static::TYPE_CUSTOMER;
}

return static::TYPE_PROJECT;
}

public function isCustomerSharing(): bool
{
return $this->getType() === static::TYPE_CUSTOMER;
}

public function isProjectSharing(): bool
{
return $this->getType() === static::TYPE_PROJECT;
}
}
4 changes: 2 additions & 2 deletions EventSubscriber/SharedProjectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function onActions(PageActionsEvent $event): void

$event->addEdit($this->path('update_shared_project_timesheets', ['sharedProject' => $sharedProject->getId(), 'shareKey' => $sharedProject->getShareKey()]));

if ($sharedProject->isCustomerSharing()) {
if ($sharedProject->getCustomer() !== null) {
$event->addAction('customer', ['url' => $this->path('customer_details', ['id' => $sharedProject->getCustomer()->getId()])]);
} else {
} elseif ($sharedProject->getProject() !== null) {
$event->addAction('project', ['url' => $this->path('project_details', ['id' => $sharedProject->getProject()->getId()])]);
}

Expand Down
4 changes: 2 additions & 2 deletions Repository/SharedProjectTimesheetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public function findByShareKey(string $shareKey): ?SharedProjectTimesheet
*/
public function getProjects(SharedProjectTimesheet $sharedProject): array
{
if ($sharedProject->isProjectSharing()) {
if ($sharedProject->getProject() !== null) {
return [$sharedProject->getProject()];
}

/** @var ProjectRepository $projectRepository */
$projectRepository = $this->_em->getRepository(Project::class); // @phpstan-ignore-line
$projectRepository = $this->_em->getRepository(Project::class); // @phpstan-ignore varTag.type

$query = new ProjectQuery();
$query->setCustomers([$sharedProject->getCustomer()]);
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/manage/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% if column == 'name' %}
{{ entry.project.name ?? entry.customer.name }}
{% elseif column == 'type' %}
<i class="{% if entry.isCustomerSharing() %}{{ 'customer'|icon(false) }}{% else %}{{ 'project'|icon(false) }}{% endif %}" title="{{ entry.getType() | trans }}"></i>
<i class="{% if entry.getCustomer() != null %}{{ 'customer'|icon(false) }}{% else %}{{ 'project'|icon(false) }}{% endif %}" title="{{ entry.getType() | trans }}"></i>
{% elseif column == 'url' %}
{% if entry.shareKey %}
{% set p_url = url('customer_portal_view', {shareKey: entry.shareKey}) %}
Expand Down
4 changes: 2 additions & 2 deletions Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function getAnnualStats(SharedProjectTimesheet $sharedProject, int $year,
'project' => $limitProject,
'year' => $year,
]);
} elseif ($sharedProject->isProjectSharing()) {
} elseif ($sharedProject->getProject() !== null) {
$queryBuilder = $queryBuilder
->andWhere('t.project = :project')
->setParameters([
Expand Down Expand Up @@ -223,7 +223,7 @@ public function getMonthlyStats(SharedProjectTimesheet $sharedProject, int $year
'year' => $year,
'month' => $month,
]);
} elseif ($sharedProject->isProjectSharing()) {
} elseif ($sharedProject->getProject() !== null) {
$queryBuilder = $queryBuilder
->andWhere('t.project = :project')
->setParameters([
Expand Down

0 comments on commit b3861e5

Please sign in to comment.