enhanced plugin support (#634)
- refactored admin controller and templates - plugin support for entity actions - changed column mail to email in customer table - refactored theme events
This commit is contained in:
@@ -16,6 +16,7 @@ use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Timesheet\Util;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Connection;
|
||||
@@ -177,18 +178,9 @@ class KimaiImporterCommand extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
// pre-load all data to make sure we can fully import everything
|
||||
$users = null;
|
||||
$customer = null;
|
||||
$projects = null;
|
||||
$activities = null;
|
||||
$records = null;
|
||||
$activityToProject = null;
|
||||
$fixedRates = null;
|
||||
$rates = null;
|
||||
|
||||
$bytesStart = memory_get_usage(true);
|
||||
|
||||
// pre-load all data to make sure we can fully import everything
|
||||
try {
|
||||
$users = $this->fetchAllFromImport('users');
|
||||
} catch (\Exception $ex) {
|
||||
@@ -965,7 +957,7 @@ class KimaiImporterCommand extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
$duration = $oldRecord['end'] - $oldRecord['start'];
|
||||
$duration = (int) ($oldRecord['end'] - $oldRecord['start']);
|
||||
|
||||
// ----------------------- unknown user, damned missing data integrity in Kimai v1 -----------------------
|
||||
if (!isset($this->users[$oldRecord['userID']])) {
|
||||
@@ -1021,9 +1013,9 @@ class KimaiImporterCommand extends Command
|
||||
if ($timesheet->getFixedRate() !== null) {
|
||||
$timesheet->setRate($timesheet->getFixedRate());
|
||||
} elseif ($timesheet->getHourlyRate() !== null) {
|
||||
$hourlyRate = $timesheet->getHourlyRate();
|
||||
$rate = (float) $hourlyRate * ($duration / 3600);
|
||||
$timesheet->setRate(round($rate, 2));
|
||||
$hourlyRate = (float) $timesheet->getHourlyRate();
|
||||
$rate = Util::calculateRate($hourlyRate, $duration);
|
||||
$timesheet->setRate($rate);
|
||||
}
|
||||
|
||||
$user = $this->users[$oldRecord['userID']];
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Constants;
|
||||
use App\Controller\AbstractController;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
@@ -38,11 +36,10 @@ class AboutController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(path="", name="about", methods={"GET"})
|
||||
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
public function indexAction()
|
||||
{
|
||||
$phpInfo = $this->getPhpInfo();
|
||||
unset($phpInfo[0]);
|
||||
@@ -74,7 +71,7 @@ class AboutController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/system.html.twig', [
|
||||
return $this->render('about/system.html.twig', [
|
||||
'modules' => get_loaded_extensions(),
|
||||
'dotenv' => [
|
||||
'APP_ENV' => getenv('APP_ENV'),
|
||||
@@ -10,19 +10,28 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Form\ActivityEditForm;
|
||||
use App\Form\Toolbar\ActivityToolbarForm;
|
||||
use App\Form\Type\ActivityType;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Controller used to manage activity contents in the public part of the site.
|
||||
* Controller used to manage activities in the admin part of the site.
|
||||
*
|
||||
* @Security("is_granted('ROLE_USER')")
|
||||
* @Route(path="/admin/activity")
|
||||
* @Security("is_granted('view_activity')")
|
||||
*/
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return ActivityRepository
|
||||
* @return \App\Repository\ActivityRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
@@ -30,18 +39,190 @@ class ActivityController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* The flyout to render recent activities and quick-start new recordings.
|
||||
* @Route(path="/", defaults={"page": 1}, name="admin_activity", methods={"GET"})
|
||||
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_activity_paginated", methods={"GET"})
|
||||
* @Cache(smaxage="10")
|
||||
* @Security("is_granted('view_activity')")
|
||||
*
|
||||
* @return Response
|
||||
* @param int $page
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function recentActivitiesAction()
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$entries = $this->getRepository()->getRecentActivities($user, new \DateTime('-1 year'));
|
||||
$query = new ActivityQuery();
|
||||
$query
|
||||
->setOrderBy('name')
|
||||
->setExclusiveVisibility(true)
|
||||
->setPage($page)
|
||||
;
|
||||
|
||||
$form = $this->getToolbarForm($query);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var ActivityQuery $query */
|
||||
$query = $form->getData();
|
||||
}
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('activity/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'showFilter' => $form->isSubmitted(),
|
||||
'toolbarForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_activity_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_activity')")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
return $this->renderActivityForm(new Activity(), $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit", name="admin_activity_edit", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', activity)")
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction(Activity $activity, Request $request)
|
||||
{
|
||||
return $this->renderActivityForm($activity, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/delete", name="admin_activity_delete", methods={"GET", "POST"})
|
||||
* @Security("is_granted('delete', activity)")
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteAction(Activity $activity, Request $request)
|
||||
{
|
||||
$stats = $this->getRepository()->getActivityStatistics($activity);
|
||||
|
||||
$deleteForm = $this->createFormBuilder()
|
||||
->add('activity', ActivityType::class, [
|
||||
'label' => 'label.activity',
|
||||
'query_builder' => function (ActivityRepository $repo) use ($activity) {
|
||||
$query = new ActivityQuery();
|
||||
$query
|
||||
->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER)
|
||||
->setProject($activity->getProject())
|
||||
->setOrderGlobalsFirst(true)
|
||||
->addIgnoredEntity($activity)
|
||||
->setGlobalsOnly(null === $activity->getProject())
|
||||
;
|
||||
|
||||
return $repo->findByQuery($query);
|
||||
},
|
||||
'required' => false,
|
||||
])
|
||||
->setAction($this->generateUrl('admin_activity_delete', ['id' => $activity->getId()]))
|
||||
->setMethod('POST')
|
||||
->getForm();
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if (0 == $stats->getRecordAmount() || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
try {
|
||||
$this->getRepository()->deleteActivity($activity, $deleteForm->get('activity')->getData());
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (ORMException $ex) {
|
||||
$this->flashError('action.delete.error');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_activity');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'navbar/recent-activities.html.twig',
|
||||
['entries' => $entries]
|
||||
'activity/delete.html.twig',
|
||||
[
|
||||
'activity' => $activity,
|
||||
'stats' => $stats,
|
||||
'form' => $deleteForm->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function renderActivityForm(Activity $activity, Request $request)
|
||||
{
|
||||
$editForm = $this->createEditForm($activity);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($activity);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
if ($editForm->has('create_more') && $editForm->get('create_more')->getData() === true) {
|
||||
$newActivity = new Activity();
|
||||
$newActivity->setProject($activity->getProject());
|
||||
$editForm = $this->createEditForm($newActivity);
|
||||
$editForm->get('create_more')->setData(true);
|
||||
$activity = $newActivity;
|
||||
} else {
|
||||
return $this->redirectToRoute('admin_activity');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'activity/edit.html.twig',
|
||||
[
|
||||
'activity' => $activity,
|
||||
'form' => $editForm->createView()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActivityQuery $query
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getToolbarForm(ActivityQuery $query)
|
||||
{
|
||||
return $this->createForm(ActivityToolbarForm::class, $query, [
|
||||
'action' => $this->generateUrl('admin_activity', [
|
||||
'page' => $query->getPage(),
|
||||
]),
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createEditForm(Activity $activity)
|
||||
{
|
||||
if ($activity->getId() === null) {
|
||||
$url = $this->generateUrl('admin_activity_create');
|
||||
} else {
|
||||
$url = $this->generateUrl('admin_activity_edit', ['id' => $activity->getId()]);
|
||||
}
|
||||
|
||||
return $this->createForm(ActivityEditForm::class, $activity, [
|
||||
'action' => $url,
|
||||
'method' => 'POST'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\Activity;
|
||||
use App\Form\ActivityEditForm;
|
||||
use App\Form\Toolbar\ActivityToolbarForm;
|
||||
use App\Form\Type\ActivityType;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Controller used to manage activities in the admin part of the site.
|
||||
*
|
||||
* @Route(path="/admin/activity")
|
||||
* @Security("is_granted('view_activity')")
|
||||
*/
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return \App\Repository\ActivityRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getDoctrine()->getRepository(Activity::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", defaults={"page": 1}, name="admin_activity", methods={"GET"})
|
||||
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_activity_paginated", methods={"GET"})
|
||||
* @Cache(smaxage="10")
|
||||
* @Security("is_granted('view_activity')")
|
||||
*
|
||||
* @param int $page
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
$query = new ActivityQuery();
|
||||
$query
|
||||
->setOrderBy('name')
|
||||
->setExclusiveVisibility(true)
|
||||
->setPage($page)
|
||||
;
|
||||
|
||||
$form = $this->getToolbarForm($query);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var ActivityQuery $query */
|
||||
$query = $form->getData();
|
||||
}
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('admin/activity.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'showFilter' => $form->isSubmitted(),
|
||||
'toolbarForm' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/create", name="admin_activity_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_activity')")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
return $this->renderActivityForm(new Activity(), $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit", name="admin_activity_edit", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', activity)")
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function editAction(Activity $activity, Request $request)
|
||||
{
|
||||
return $this->renderActivityForm($activity, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/delete", name="admin_activity_delete", methods={"GET", "POST"})
|
||||
* @Security("is_granted('delete', activity)")
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteAction(Activity $activity, Request $request)
|
||||
{
|
||||
$stats = $this->getRepository()->getActivityStatistics($activity);
|
||||
|
||||
$deleteForm = $this->createFormBuilder()
|
||||
->add('activity', ActivityType::class, [
|
||||
'label' => 'label.activity',
|
||||
'query_builder' => function (ActivityRepository $repo) use ($activity) {
|
||||
$query = new ActivityQuery();
|
||||
$query
|
||||
->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER)
|
||||
->setProject($activity->getProject())
|
||||
->setOrderGlobalsFirst(true)
|
||||
->addIgnoredEntity($activity)
|
||||
->setGlobalsOnly(null === $activity->getProject())
|
||||
;
|
||||
|
||||
return $repo->findByQuery($query);
|
||||
},
|
||||
'required' => false,
|
||||
])
|
||||
->setAction($this->generateUrl('admin_activity_delete', ['id' => $activity->getId()]))
|
||||
->setMethod('POST')
|
||||
->getForm();
|
||||
|
||||
$deleteForm->handleRequest($request);
|
||||
|
||||
if (0 == $stats->getRecordAmount() || ($deleteForm->isSubmitted() && $deleteForm->isValid())) {
|
||||
try {
|
||||
$this->getRepository()->deleteActivity($activity, $deleteForm->get('activity')->getData());
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (ORMException $ex) {
|
||||
$this->flashError('action.delete.error');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_activity');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'admin/activity_delete.html.twig',
|
||||
[
|
||||
'activity' => $activity,
|
||||
'stats' => $stats,
|
||||
'form' => $deleteForm->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function renderActivityForm(Activity $activity, Request $request)
|
||||
{
|
||||
$editForm = $this->createEditForm($activity);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($activity);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
if ($editForm->has('create_more') && $editForm->get('create_more')->getData() === true) {
|
||||
$newActivity = new Activity();
|
||||
$newActivity->setProject($activity->getProject());
|
||||
$editForm = $this->createEditForm($newActivity);
|
||||
$editForm->get('create_more')->setData(true);
|
||||
$activity = $newActivity;
|
||||
} else {
|
||||
return $this->redirectToRoute('admin_activity');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'admin/activity_edit.html.twig',
|
||||
[
|
||||
'activity' => $activity,
|
||||
'form' => $editForm->createView()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActivityQuery $query
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getToolbarForm(ActivityQuery $query)
|
||||
{
|
||||
return $this->createForm(ActivityToolbarForm::class, $query, [
|
||||
'action' => $this->generateUrl('admin_activity', [
|
||||
'page' => $query->getPage(),
|
||||
]),
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createEditForm(Activity $activity)
|
||||
{
|
||||
if ($activity->getId() === null) {
|
||||
$url = $this->generateUrl('admin_activity_create');
|
||||
} else {
|
||||
$url = $this->generateUrl('admin_activity_edit', ['id' => $activity->getId()]);
|
||||
}
|
||||
|
||||
return $this->createForm(ActivityEditForm::class, $activity, [
|
||||
'action' => $url,
|
||||
'method' => 'POST'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\Customer;
|
||||
use App\Form\CustomerEditForm;
|
||||
use App\Form\Toolbar\CustomerToolbarForm;
|
||||
@@ -23,7 +22,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Controller used to manage activities in the admin part of the site.
|
||||
* Controller used to manage customer in the admin part of the site.
|
||||
*
|
||||
* @Route(path="/admin/customer")
|
||||
* @Security("is_granted('view_customer')")
|
||||
@@ -78,7 +77,7 @@ class CustomerController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('admin/customer.html.twig', [
|
||||
return $this->render('customer/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'showFilter' => $form->isSubmitted(),
|
||||
@@ -158,7 +157,7 @@ class CustomerController extends AbstractController
|
||||
return $this->redirectToRoute('admin_customer');
|
||||
}
|
||||
|
||||
return $this->render('admin/customer_delete.html.twig', [
|
||||
return $this->render('customer/delete.html.twig', [
|
||||
'customer' => $customer,
|
||||
'stats' => $stats,
|
||||
'form' => $deleteForm->createView(),
|
||||
@@ -186,7 +185,7 @@ class CustomerController extends AbstractController
|
||||
return $this->redirectToRoute('admin_customer');
|
||||
}
|
||||
|
||||
return $this->render('admin/customer_edit.html.twig', [
|
||||
return $this->render('customer/edit.html.twig', [
|
||||
'customer' => $customer,
|
||||
'form' => $editForm->createView()
|
||||
]);
|
||||
60
src/Controller/NavbarController.php
Normal file
60
src/Controller/NavbarController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\ActivityRepository;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Controller used to manage navigation-bar contents.
|
||||
*
|
||||
* @Security("is_granted('ROLE_USER')")
|
||||
*/
|
||||
class NavbarController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var ActivityRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @param ActivityRepository $repository
|
||||
*/
|
||||
public function __construct(ActivityRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActivityRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* The flyout to render recent activities and quick-start new recordings.
|
||||
*
|
||||
* @return Response
|
||||
* @throws \Doctrine\ORM\Query\QueryException
|
||||
*/
|
||||
public function recentActivitiesAction()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$entries = $this->getRepository()->getRecentActivities($user, new \DateTime('-1 year'));
|
||||
|
||||
return $this->render(
|
||||
'navbar/recent-activities.html.twig',
|
||||
['entries' => $entries]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Form\ProjectEditForm;
|
||||
@@ -69,7 +68,7 @@ class ProjectController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Project::class)->findByQuery($query);
|
||||
|
||||
return $this->render('admin/project.html.twig', [
|
||||
return $this->render('project/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'showFilter' => $form->isSubmitted(),
|
||||
@@ -145,7 +144,7 @@ class ProjectController extends AbstractController
|
||||
return $this->redirectToRoute('admin_project');
|
||||
}
|
||||
|
||||
return $this->render('admin/project_delete.html.twig', [
|
||||
return $this->render('project/delete.html.twig', [
|
||||
'project' => $project,
|
||||
'stats' => $stats,
|
||||
'form' => $deleteForm->createView(),
|
||||
@@ -181,7 +180,7 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/project_edit.html.twig', [
|
||||
return $this->render('project/edit.html.twig', [
|
||||
'project' => $project,
|
||||
'form' => $editForm->createView()
|
||||
]);
|
||||
@@ -238,7 +238,7 @@ class TimesheetController extends AbstractController
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('timesheet_paginated', ['page' => $request->get('page')]);
|
||||
return $this->redirectToRoute('timesheet_paginated', ['page' => $request->get('page', 1)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -103,11 +103,11 @@ trait TimesheetControllerTrait
|
||||
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute($redirectRoute, ['page' => $request->get('page')]);
|
||||
return $this->redirectToRoute($redirectRoute, ['page' => $request->get('page', 1)]);
|
||||
}
|
||||
|
||||
return $this->render($renderTemplate, [
|
||||
'entry' => $entry,
|
||||
'timesheet' => $entry,
|
||||
'form' => $editForm->createView(),
|
||||
]);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ trait TimesheetControllerTrait
|
||||
}
|
||||
|
||||
return $this->render($renderTemplate, [
|
||||
'entry' => $entry,
|
||||
'timesheet' => $entry,
|
||||
'form' => $createForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Controller\TimesheetControllerTrait;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Toolbar\TimesheetToolbarForm;
|
||||
@@ -26,7 +24,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
* @Route(path="/team/timesheet")
|
||||
* @Security("is_granted('view_other_timesheet')")
|
||||
*/
|
||||
class TimesheetController extends AbstractController
|
||||
class TimesheetTeamController extends AbstractController
|
||||
{
|
||||
use TimesheetControllerTrait;
|
||||
|
||||
@@ -60,7 +58,7 @@ class TimesheetController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('admin/timesheet.html.twig', [
|
||||
return $this->render('timesheet-team/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'page' => $query->getPage(),
|
||||
'query' => $query,
|
||||
@@ -101,7 +99,7 @@ class TimesheetController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('admin/timesheet_export.html.twig', [
|
||||
return $this->render('timesheet-team/export.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
]);
|
||||
@@ -129,7 +127,7 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function editAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
return $this->edit($entry, $request, 'admin_timesheet_paginated', 'admin/timesheet_edit.html.twig');
|
||||
return $this->edit($entry, $request, 'admin_timesheet_paginated', 'timesheet-team/edit.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +139,7 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
return $this->create($request, 'admin_timesheet', 'admin/timesheet_edit.html.twig');
|
||||
return $this->create($request, 'admin_timesheet', 'timesheet-team/edit.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +162,7 @@ class TimesheetController extends AbstractController
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_timesheet_paginated', ['page' => $request->get('page')]);
|
||||
return $this->redirectToRoute('admin_timesheet_paginated', ['page' => $request->get('page', 1)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -7,9 +7,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Form\Toolbar\UserToolbarForm;
|
||||
@@ -74,7 +73,7 @@ class UserController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->findByQuery($query);
|
||||
|
||||
return $this->render('admin/user.html.twig', [
|
||||
return $this->render('user/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'showFilter' => $form->isSubmitted(),
|
||||
@@ -119,7 +118,7 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'admin/user_edit.html.twig',
|
||||
'user/edit.html.twig',
|
||||
[
|
||||
'user' => $user,
|
||||
'form' => $editForm->createView()
|
||||
@@ -159,7 +158,7 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'admin/user_delete.html.twig',
|
||||
'user/delete.html.twig',
|
||||
[
|
||||
'user' => $userToDelete,
|
||||
'stats' => $stats,
|
||||
@@ -23,6 +23,8 @@ use Faker\Generator;
|
||||
*
|
||||
* Execute this command to load the data:
|
||||
* bin/console doctrine:fixtures:load
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CustomerFixtures extends Fixture
|
||||
{
|
||||
@@ -32,7 +34,7 @@ class CustomerFixtures extends Fixture
|
||||
public const MAX_BUDGET = 100000;
|
||||
public const MIN_GLOBAL_ACTIVITIES = 5;
|
||||
public const MAX_GLOBAL_ACTIVITIES = 50;
|
||||
public const MIN_PROJECTS_PER_CUSTOMER = 1;
|
||||
public const MIN_PROJECTS_PER_CUSTOMER = 2;
|
||||
public const MAX_PROJECTS_PER_CUSTOMER = 25;
|
||||
public const MIN_ACTIVITIES_PER_PROJECT = 0;
|
||||
public const MAX_ACTIVITIES_PER_PROJECT = 25;
|
||||
@@ -48,6 +50,7 @@ class CustomerFixtures extends Fixture
|
||||
for ($c = 1; $c <= $amountCustomers; $c++) {
|
||||
$visibleCustomer = 0 != $c % 5;
|
||||
$customer = $this->createCustomer($faker, $visibleCustomer);
|
||||
$manager->persist($customer);
|
||||
|
||||
$projectForCustomer = rand(self::MIN_PROJECTS_PER_CUSTOMER, self::MAX_PROJECTS_PER_CUSTOMER);
|
||||
for ($p = 1; $p <= $projectForCustomer; $p++) {
|
||||
@@ -63,8 +66,6 @@ class CustomerFixtures extends Fixture
|
||||
}
|
||||
}
|
||||
|
||||
$manager->persist($customer);
|
||||
|
||||
$manager->flush();
|
||||
$manager->clear();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ use Faker\Generator;
|
||||
*
|
||||
* Execute this command to load the data:
|
||||
* $ php bin/console doctrine:fixtures:load
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class InvoiceFixtures extends Fixture
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Timesheet\Util;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
@@ -25,6 +26,8 @@ use Faker\Factory;
|
||||
*
|
||||
* Execute this command to load the data:
|
||||
* bin/console doctrine:fixtures:load
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class TimesheetFixtures extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
@@ -181,11 +184,12 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface
|
||||
$end = $end->modify('+ ' . (rand(self::MIN_MINUTES_PER_ENTRY, self::MAX_MINUTES_PER_ENTRY)) . ' minutes');
|
||||
|
||||
$duration = $end->getTimestamp() - $start->getTimestamp();
|
||||
$rate = $user->getPreferenceValue(UserPreference::HOURLY_RATE);
|
||||
$hourlyRate = (float) $user->getPreferenceValue(UserPreference::HOURLY_RATE);
|
||||
$rate = Util::calculateRate($hourlyRate, $duration);
|
||||
|
||||
$entry
|
||||
->setEnd($end)
|
||||
->setRate(round(($duration / 3600) * $rate))
|
||||
->setRate($rate)
|
||||
->setDuration($duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
*
|
||||
* Execute this command to load the data:
|
||||
* $ php bin/console doctrine:fixtures:load
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class UserFixtures extends Fixture
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Doctrine;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration as BaseAbstractMigration;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@@ -50,6 +51,55 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
|
||||
return getenv('DATABASE_PREFIX') . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function preUp(Schema $schema): void
|
||||
{
|
||||
$this->abortIfPlatformNotSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function preDown(Schema $schema): void
|
||||
{
|
||||
$this->abortIfPlatformNotSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort the migration is the current platform is not supported.
|
||||
*
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function abortIfPlatformNotSupported()
|
||||
{
|
||||
$platform = $this->getPlatform();
|
||||
if (!in_array($platform, ['sqlite', 'mysql'])) {
|
||||
$this->abortIf(true, 'Unsupported database platform: ' . $platform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function isPlatformSqlite()
|
||||
{
|
||||
return ($this->getPlatform() === 'sqlite');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function isPlatformMysql()
|
||||
{
|
||||
return ($this->getPlatform() === 'mysql');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws DBALException
|
||||
@@ -84,7 +134,7 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
|
||||
protected function addSqlDropIndex($indexName, $tableName)
|
||||
{
|
||||
$dropSql = 'DROP INDEX ' . $indexName;
|
||||
if ($this->getPlatform() === 'mysql') {
|
||||
if (!$this->isPlatformSqlite()) {
|
||||
$dropSql .= ' ON ' . $tableName;
|
||||
}
|
||||
$this->addSql($dropSql);
|
||||
|
||||
@@ -15,6 +15,16 @@ use Doctrine\DBAL\Events;
|
||||
|
||||
class SqliteSessionInitSubscriber implements EventSubscriber
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
Events::postConnect,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConnectionEventArgs $args
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
@@ -24,14 +34,7 @@ class SqliteSessionInitSubscriber implements EventSubscriber
|
||||
if ('sqlite' !== strtolower($args->getDatabasePlatform()->getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args->getConnection()->executeUpdate('PRAGMA foreign_keys = ON;');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [Events::postConnect];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace App\Doctrine;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Timesheet\CalculatorInterface;
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
|
||||
/**
|
||||
* A listener to make sure all Timesheet entries will have a proper duration.
|
||||
@@ -26,7 +26,6 @@ class TimesheetSubscriber implements EventSubscriber
|
||||
protected $calculator;
|
||||
|
||||
/**
|
||||
* TimesheetSubscriber constructor.
|
||||
* @param iterable $calculators
|
||||
*/
|
||||
public function __construct(iterable $calculators)
|
||||
@@ -48,38 +47,43 @@ class TimesheetSubscriber implements EventSubscriber
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'prePersist',
|
||||
'preUpdate',
|
||||
Events::onFlush,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PreUpdateEventArgs $args
|
||||
* @param OnFlushEventArgs $args
|
||||
*/
|
||||
public function preUpdate(PreUpdateEventArgs $args)
|
||||
public function onFlush(OnFlushEventArgs $args)
|
||||
{
|
||||
$this->calculateFields($args);
|
||||
}
|
||||
$em = $args->getEntityManager();
|
||||
$uow = $em->getUnitOfWork();
|
||||
$meta = $em->getClassMetadata(Timesheet::class);
|
||||
|
||||
/**
|
||||
* @param LifecycleEventArgs $args
|
||||
*/
|
||||
public function prePersist(LifecycleEventArgs $args)
|
||||
{
|
||||
$this->calculateFields($args);
|
||||
}
|
||||
foreach ($uow->getScheduledEntityUpdates() as $entity) {
|
||||
if (!($entity instanceof Timesheet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LifecycleEventArgs $args
|
||||
*/
|
||||
protected function calculateFields(LifecycleEventArgs $args)
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
|
||||
if (!($entity instanceof Timesheet)) {
|
||||
return;
|
||||
$this->calculateFields($entity);
|
||||
$uow->recomputeSingleEntityChangeSet($meta, $entity);
|
||||
}
|
||||
|
||||
foreach ($uow->getScheduledEntityInsertions() as $entity) {
|
||||
if (!($entity instanceof Timesheet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->calculateFields($entity);
|
||||
$uow->recomputeSingleEntityChangeSet($meta, $entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $entity
|
||||
*/
|
||||
protected function calculateFields(Timesheet $entity)
|
||||
{
|
||||
foreach ($this->calculator as $calculator) {
|
||||
$calculator->calculate($entity);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Activity
|
||||
*
|
||||
* @ORM\Table(name="activities")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ActivityRepository")
|
||||
*/
|
||||
@@ -71,7 +69,7 @@ class Activity
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="fixed_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $fixedRate = null;
|
||||
@@ -79,7 +77,7 @@ class Activity
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="hourly_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
|
||||
@@ -13,8 +13,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Customer
|
||||
*
|
||||
* @ORM\Table(name="customers")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
|
||||
*/
|
||||
@@ -130,9 +128,9 @@ class Customer
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="mail", type="string", length=255, nullable=true)
|
||||
* @ORM\Column(name="email", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $mail;
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -152,7 +150,7 @@ class Customer
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="fixed_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $fixedRate = null;
|
||||
@@ -160,7 +158,7 @@ class Customer
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="hourly_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
@@ -443,9 +441,9 @@ class Customer
|
||||
* @param string $mail
|
||||
* @return Customer
|
||||
*/
|
||||
public function setMail($mail)
|
||||
public function setEmail($mail)
|
||||
{
|
||||
$this->mail = $mail;
|
||||
$this->email = $mail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -455,9 +453,9 @@ class Customer
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMail()
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->mail;
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Project
|
||||
*
|
||||
* @ORM\Table(name="projects")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
|
||||
*/
|
||||
@@ -73,7 +71,7 @@ class Project
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="budget", type="decimal", precision=10, scale=2, nullable=false)
|
||||
* @ORM\Column(name="budget", type="float", precision=10, scale=2, nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $budget = 0.00;
|
||||
@@ -88,7 +86,7 @@ class Project
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="fixed_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $fixedRate = null;
|
||||
@@ -96,7 +94,7 @@ class Project
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="hourly_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
|
||||
@@ -13,8 +13,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Timesheet entity.
|
||||
*
|
||||
* @ORM\Table(
|
||||
* name="timesheet",
|
||||
* indexes={
|
||||
@@ -109,7 +107,7 @@ class Timesheet
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="rate", type="decimal", precision=10, scale=2, nullable=false)
|
||||
* @ORM\Column(name="rate", type="float", precision=10, scale=2, nullable=false)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $rate = 0.00;
|
||||
@@ -117,7 +115,7 @@ class Timesheet
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="fixed_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="fixed_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $fixedRate = null;
|
||||
@@ -125,7 +123,7 @@ class Timesheet
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="hourly_rate", type="decimal", precision=10, scale=2, nullable=true)
|
||||
* @ORM\Column(name="hourly_rate", type="float", precision=10, scale=2, nullable=true)
|
||||
* @Assert\GreaterThanOrEqual(0)
|
||||
*/
|
||||
private $hourlyRate = null;
|
||||
@@ -211,7 +209,7 @@ class Timesheet
|
||||
|
||||
if (null === $end) {
|
||||
$this->duration = 0;
|
||||
$this->rate = 0;
|
||||
$this->rate = 0.00;
|
||||
} else {
|
||||
$this->timezone = $end->getTimezone()->getName();
|
||||
}
|
||||
@@ -298,8 +296,6 @@ class Timesheet
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
* @return Timesheet
|
||||
*/
|
||||
@@ -311,8 +307,6 @@ class Timesheet
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
@@ -321,8 +315,6 @@ class Timesheet
|
||||
}
|
||||
|
||||
/**
|
||||
* Set rate
|
||||
*
|
||||
* @param float $rate
|
||||
* @return Timesheet
|
||||
*/
|
||||
@@ -334,8 +326,6 @@ class Timesheet
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRate()
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace App\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ThemeEvent extends Event
|
||||
{
|
||||
@@ -23,23 +22,22 @@ class ThemeEvent extends Event
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $content = '';
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $payload = null;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param User $user
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Request $request, User $user)
|
||||
public function __construct(User $user, $payload = null)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->user = $user;
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,14 +48,6 @@ class ThemeEvent extends Event
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
*/
|
||||
public function getRequest(): Request
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -76,4 +66,22 @@ class ThemeEvent extends Event
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $payload
|
||||
* @return ThemeEvent
|
||||
*/
|
||||
public function setPayload($payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ abstract class AbstractSpreadsheetRenderer
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.activity'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.description'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.exported'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.hourly_rate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.fixed_rate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.hourlyRate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.fixedRate'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.duration'));
|
||||
$sheet->setCellValueByColumnAndRow($recordsHeaderColumn++, $recordsHeaderRow, $this->translator->trans('label.rate'));
|
||||
|
||||
|
||||
@@ -96,12 +96,12 @@ class ActivityEditForm extends AbstractType
|
||||
|
||||
$builder
|
||||
->add('fixedRate', MoneyType::class, [
|
||||
'label' => 'label.fixed_rate',
|
||||
'label' => 'label.fixedRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', MoneyType::class, [
|
||||
'label' => 'label.hourly_rate',
|
||||
'label' => 'label.hourlyRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
|
||||
@@ -42,7 +42,7 @@ class CustomerEditForm extends AbstractType
|
||||
'label' => 'label.name',
|
||||
])
|
||||
->add('number', TextType::class, [
|
||||
'label' => 'label.customer_number',
|
||||
'label' => 'label.number',
|
||||
'required' => false,
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
@@ -81,7 +81,7 @@ class CustomerEditForm extends AbstractType
|
||||
'required' => false,
|
||||
'attr' => ['icon' => 'mobile'],
|
||||
])
|
||||
->add('mail', EmailType::class, [
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'label.email',
|
||||
'required' => false,
|
||||
])
|
||||
@@ -93,12 +93,12 @@ class CustomerEditForm extends AbstractType
|
||||
'label' => 'label.timezone',
|
||||
])
|
||||
->add('fixedRate', MoneyType::class, [
|
||||
'label' => 'label.fixed_rate',
|
||||
'label' => 'label.fixedRate',
|
||||
'required' => false,
|
||||
'currency' => $customer->getCurrency() ?? false,
|
||||
])
|
||||
->add('hourlyRate', MoneyType::class, [
|
||||
'label' => 'label.hourly_rate',
|
||||
'label' => 'label.hourlyRate',
|
||||
'required' => false,
|
||||
'currency' => $customer->getCurrency() ?? false,
|
||||
])
|
||||
|
||||
@@ -52,7 +52,7 @@ class ProjectEditForm extends AbstractType
|
||||
'required' => false,
|
||||
])
|
||||
->add('orderNumber', TextType::class, [
|
||||
'label' => 'label.order_number',
|
||||
'label' => 'label.orderNumber',
|
||||
'required' => false,
|
||||
])
|
||||
->add('customer', CustomerType::class, [
|
||||
@@ -62,12 +62,12 @@ class ProjectEditForm extends AbstractType
|
||||
},
|
||||
])
|
||||
->add('fixedRate', MoneyType::class, [
|
||||
'label' => 'label.fixed_rate',
|
||||
'label' => 'label.fixedRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', MoneyType::class, [
|
||||
'label' => 'label.hourly_rate',
|
||||
'label' => 'label.hourlyRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
|
||||
@@ -265,12 +265,12 @@ class TimesheetEditForm extends AbstractType
|
||||
if ($options['include_rate']) {
|
||||
$builder
|
||||
->add('fixedRate', MoneyType::class, [
|
||||
'label' => 'label.fixed_rate',
|
||||
'label' => 'label.fixedRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', MoneyType::class, [
|
||||
'label' => 'label.hourly_rate',
|
||||
'label' => 'label.hourlyRate',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
]);
|
||||
|
||||
@@ -16,6 +16,8 @@ use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Adds the exported column to the timesheet table
|
||||
*
|
||||
* @version 0.8
|
||||
*/
|
||||
final class Version20190124004014 extends AbstractMigration
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@ use Doctrine\DBAL\Schema\Schema;
|
||||
/**
|
||||
* Adds the timezone column to the timesheet table
|
||||
* See https://github.com/kevinpapst/kimai2/pull/372 for further information.
|
||||
*
|
||||
* @version 0.8
|
||||
*/
|
||||
final class Version20190201150324 extends AbstractMigration
|
||||
{
|
||||
|
||||
@@ -16,6 +16,8 @@ use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Cleanup the user_preferences table from old configs.
|
||||
*
|
||||
* @version 0.9
|
||||
*/
|
||||
final class Version20190219200020 extends AbstractMigration
|
||||
{
|
||||
|
||||
141
src/Migrations/Version20190305152308.php
Normal file
141
src/Migrations/Version20190305152308.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Doctrine\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* - rename mail to email in customer table
|
||||
* - introducing foreign keys in SQLite tables
|
||||
* - converts all decimal to float values, as decimals are treated as string in PHP:
|
||||
* https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#decimal
|
||||
*
|
||||
* @version 0.9
|
||||
*/
|
||||
final class Version20190305152308 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$customers = $this->getTableName('customers');
|
||||
$projects = $this->getTableName('projects');
|
||||
$activities = $this->getTableName('activities');
|
||||
$timesheet = $this->getTableName('timesheet');
|
||||
$users = $this->getTableName('users');
|
||||
|
||||
if ($this->isPlatformSqlite()) {
|
||||
// first backup of ALL tables
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B181C06096');
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B18D93D649');
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B1166D1F9C');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_timesheet AS SELECT id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported FROM ' . $timesheet);
|
||||
|
||||
$this->addSql('DROP INDEX IDX_8811FE1C166D1F9C');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_activities AS SELECT id, project_id, name, comment, visible, fixed_rate, hourly_rate FROM ' . $activities);
|
||||
|
||||
$this->addSql('DROP INDEX IDX_407F12069395C3F3');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_projects AS SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM ' . $projects);
|
||||
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_customers AS SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone, fixed_rate, hourly_rate FROM ' . $customers);
|
||||
|
||||
// now we can drop and re-create the tables
|
||||
$this->addSql('DROP TABLE ' . $customers);
|
||||
$this->addSql('CREATE TABLE ' . $customers . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL COLLATE BINARY, number VARCHAR(50) DEFAULT NULL COLLATE BINARY, comment CLOB DEFAULT NULL COLLATE BINARY, visible BOOLEAN NOT NULL, company VARCHAR(255) DEFAULT NULL COLLATE BINARY, contact VARCHAR(255) DEFAULT NULL COLLATE BINARY, address CLOB DEFAULT NULL COLLATE BINARY, country VARCHAR(2) NOT NULL COLLATE BINARY, currency VARCHAR(3) NOT NULL COLLATE BINARY, phone VARCHAR(255) DEFAULT NULL COLLATE BINARY, fax VARCHAR(255) DEFAULT NULL COLLATE BINARY, mobile VARCHAR(255) DEFAULT NULL COLLATE BINARY, email VARCHAR(255) DEFAULT NULL COLLATE BINARY, homepage VARCHAR(255) DEFAULT NULL COLLATE BINARY, timezone VARCHAR(255) NOT NULL COLLATE BINARY, fixed_rate DOUBLE PRECISION DEFAULT NULL, hourly_rate DOUBLE PRECISION DEFAULT NULL)');
|
||||
$this->addSql('INSERT INTO ' . $customers . ' (id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, email, homepage, timezone, fixed_rate, hourly_rate) SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone, fixed_rate, hourly_rate FROM __temp__kimai2_customers');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_customers');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $projects);
|
||||
$this->addSql('CREATE TABLE ' . $projects . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, customer_id INTEGER NOT NULL, name VARCHAR(255) NOT NULL COLLATE BINARY, order_number CLOB DEFAULT NULL COLLATE BINARY, comment CLOB DEFAULT NULL COLLATE BINARY, visible BOOLEAN NOT NULL, budget DOUBLE PRECISION NOT NULL, fixed_rate DOUBLE PRECISION DEFAULT NULL, hourly_rate DOUBLE PRECISION DEFAULT NULL, CONSTRAINT FK_407F12069395C3F3 FOREIGN KEY (customer_id) REFERENCES ' . $customers . ' (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO ' . $projects . ' (id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate) SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM __temp__kimai2_projects');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_projects');
|
||||
$this->addSql('CREATE INDEX IDX_407F12069395C3F3 ON ' . $projects . ' (customer_id)');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $activities);
|
||||
$this->addSql('CREATE TABLE ' . $activities . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, project_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL COLLATE BINARY, comment CLOB DEFAULT NULL COLLATE BINARY, visible BOOLEAN NOT NULL, fixed_rate DOUBLE PRECISION DEFAULT NULL, hourly_rate DOUBLE PRECISION DEFAULT NULL, CONSTRAINT FK_8811FE1C166D1F9C FOREIGN KEY (project_id) REFERENCES ' . $projects . ' (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO ' . $activities . ' (id, project_id, name, comment, visible, fixed_rate, hourly_rate) SELECT id, project_id, name, comment, visible, fixed_rate, hourly_rate FROM __temp__kimai2_activities');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_activities');
|
||||
$this->addSql('CREATE INDEX IDX_8811FE1C166D1F9C ON ' . $activities . ' (project_id)');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $timesheet);
|
||||
$this->addSql('CREATE TABLE ' . $timesheet . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user INTEGER NOT NULL, activity_id INTEGER NOT NULL, project_id INTEGER NOT NULL, start_time DATETIME NOT NULL --(DC2Type:datetime)
|
||||
, timezone VARCHAR(64) NOT NULL COLLATE BINARY, duration INTEGER DEFAULT NULL, description CLOB DEFAULT NULL COLLATE BINARY, exported BOOLEAN NOT NULL, end_time DATETIME DEFAULT NULL --(DC2Type:datetime)
|
||||
, rate DOUBLE PRECISION NOT NULL, fixed_rate DOUBLE PRECISION DEFAULT NULL, hourly_rate DOUBLE PRECISION DEFAULT NULL, CONSTRAINT FK_4F60C6B18D93D649 FOREIGN KEY (user) REFERENCES ' . $users . ' (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4F60C6B181C06096 FOREIGN KEY (activity_id) REFERENCES ' . $activities . ' (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4F60C6B1166D1F9C FOREIGN KEY (project_id) REFERENCES ' . $projects . ' (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO ' . $timesheet . ' (id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported) SELECT id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported FROM __temp__kimai2_timesheet');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_timesheet');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B181C06096 ON ' . $timesheet . ' (activity_id)');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B18D93D649 ON ' . $timesheet . ' (user)');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B1166D1F9C ON ' . $timesheet . ' (project_id)');
|
||||
} else {
|
||||
$this->addSql('ALTER TABLE ' . $activities . ' CHANGE fixed_rate fixed_rate DOUBLE PRECISION DEFAULT NULL, CHANGE hourly_rate hourly_rate DOUBLE PRECISION DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $customers . ' CHANGE mail email VARCHAR(255) DEFAULT NULL, CHANGE fixed_rate fixed_rate DOUBLE PRECISION DEFAULT NULL, CHANGE hourly_rate hourly_rate DOUBLE PRECISION DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $projects . ' CHANGE budget budget DOUBLE PRECISION NOT NULL, CHANGE fixed_rate fixed_rate DOUBLE PRECISION DEFAULT NULL, CHANGE hourly_rate hourly_rate DOUBLE PRECISION DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $timesheet . ' CHANGE rate rate DOUBLE PRECISION NOT NULL, CHANGE fixed_rate fixed_rate DOUBLE PRECISION DEFAULT NULL, CHANGE hourly_rate hourly_rate DOUBLE PRECISION DEFAULT NULL');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$customers = $this->getTableName('customers');
|
||||
$projects = $this->getTableName('projects');
|
||||
$activities = $this->getTableName('activities');
|
||||
$timesheet = $this->getTableName('timesheet');
|
||||
|
||||
if ($this->isPlatformSqlite()) {
|
||||
// first backup of ALL tables
|
||||
$this->addSql('DROP INDEX IDX_8811FE1C166D1F9C');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_activities AS SELECT id, project_id, name, comment, visible, fixed_rate, hourly_rate FROM ' . $activities);
|
||||
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_customers AS SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, email, homepage, timezone, fixed_rate, hourly_rate FROM ' . $customers);
|
||||
|
||||
$this->addSql('DROP INDEX IDX_407F12069395C3F3');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_projects AS SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM ' . $projects);
|
||||
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B1166D1F9C');
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B18D93D649');
|
||||
$this->addSql('DROP INDEX IDX_4F60C6B181C06096');
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__kimai2_timesheet AS SELECT id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported FROM ' . $timesheet);
|
||||
|
||||
// now we can drop and re-create the tables
|
||||
$this->addSql('DROP TABLE ' . $activities);
|
||||
$this->addSql('CREATE TABLE ' . $activities . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, project_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL)');
|
||||
$this->addSql('INSERT INTO ' . $activities . ' (id, project_id, name, comment, visible, fixed_rate, hourly_rate) SELECT id, project_id, name, comment, visible, fixed_rate, hourly_rate FROM __temp__kimai2_activities');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_activities');
|
||||
$this->addSql('CREATE INDEX IDX_8811FE1C166D1F9C ON ' . $activities . ' (project_id)');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $customers);
|
||||
$this->addSql('CREATE TABLE ' . $customers . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, number VARCHAR(50) DEFAULT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL, company VARCHAR(255) DEFAULT NULL, contact VARCHAR(255) DEFAULT NULL, address CLOB DEFAULT NULL, country VARCHAR(2) NOT NULL, currency VARCHAR(3) NOT NULL, phone VARCHAR(255) DEFAULT NULL, fax VARCHAR(255) DEFAULT NULL, mobile VARCHAR(255) DEFAULT NULL, mail VARCHAR(255) DEFAULT NULL, homepage VARCHAR(255) DEFAULT NULL, timezone VARCHAR(255) NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL)');
|
||||
$this->addSql('INSERT INTO ' . $customers . ' (id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone, fixed_rate, hourly_rate) SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, email, homepage, timezone, fixed_rate, hourly_rate FROM __temp__kimai2_customers');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_customers');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $projects);
|
||||
$this->addSql('CREATE TABLE ' . $projects . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, customer_id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, order_number CLOB DEFAULT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL, budget NUMERIC(10, 2) NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL)');
|
||||
$this->addSql('INSERT INTO ' . $projects . ' (id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate) SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM __temp__kimai2_projects');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_projects');
|
||||
$this->addSql('CREATE INDEX IDX_407F12069395C3F3 ON ' . $projects . ' (customer_id)');
|
||||
|
||||
$this->addSql('DROP TABLE ' . $timesheet);
|
||||
$this->addSql('CREATE TABLE ' . $timesheet . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user INTEGER NOT NULL, activity_id INTEGER NOT NULL, project_id INTEGER NOT NULL, start_time DATETIME NOT NULL --(DC2Type:datetime)
|
||||
, timezone VARCHAR(64) NOT NULL, duration INTEGER DEFAULT NULL, description CLOB DEFAULT NULL, exported BOOLEAN NOT NULL, end_time DATETIME DEFAULT NULL --(DC2Type:datetime)
|
||||
, rate NUMERIC(10, 2) NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL)');
|
||||
$this->addSql('INSERT INTO ' . $timesheet . ' (id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported) SELECT id, user, activity_id, project_id, start_time, end_time, timezone, duration, description, rate, fixed_rate, hourly_rate, exported FROM __temp__kimai2_timesheet');
|
||||
$this->addSql('DROP TABLE __temp__kimai2_timesheet');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B1166D1F9C ON ' . $timesheet . ' (project_id)');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B18D93D649 ON ' . $timesheet . ' (user)');
|
||||
$this->addSql('CREATE INDEX IDX_4F60C6B181C06096 ON ' . $timesheet . ' (activity_id)');
|
||||
} else {
|
||||
$this->addSql('ALTER TABLE ' . $activities . ' CHANGE fixed_rate fixed_rate NUMERIC(10, 2) DEFAULT NULL, CHANGE hourly_rate hourly_rate NUMERIC(10, 2) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $customers . ' CHANGE email mail VARCHAR(255) DEFAULT NULL, CHANGE fixed_rate fixed_rate NUMERIC(10, 2) DEFAULT NULL, CHANGE hourly_rate hourly_rate NUMERIC(10, 2) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $projects . ' CHANGE budget budget NUMERIC(10, 2) NOT NULL, CHANGE fixed_rate fixed_rate NUMERIC(10, 2) DEFAULT NULL, CHANGE hourly_rate hourly_rate NUMERIC(10, 2) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE ' . $timesheet . ' CHANGE rate rate NUMERIC(10, 2) NOT NULL, CHANGE fixed_rate fixed_rate NUMERIC(10, 2) DEFAULT NULL, CHANGE hourly_rate hourly_rate NUMERIC(10, 2) DEFAULT NULL');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,14 +53,14 @@ class ActivityQuery extends ProjectQuery
|
||||
*/
|
||||
public function isGlobalsOnly(): bool
|
||||
{
|
||||
return $this->globalsOnly;
|
||||
return (bool) $this->globalsOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $globalsOnly
|
||||
* @return ActivityQuery
|
||||
*/
|
||||
public function setGlobalsOnly(bool $globalsOnly)
|
||||
public function setGlobalsOnly($globalsOnly)
|
||||
{
|
||||
$this->globalsOnly = $globalsOnly;
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ class TimesheetRepository extends AbstractRepository
|
||||
switch ($type) {
|
||||
case self::STATS_QUERY_ACTIVE:
|
||||
return count($this->getActiveEntries($user));
|
||||
break;
|
||||
|
||||
case self::STATS_QUERY_MONTHLY:
|
||||
return $this->getMonthlyStats($user, $begin, $end);
|
||||
break;
|
||||
|
||||
case self::STATS_QUERY_DURATION:
|
||||
$what = 'SUM(t.duration)';
|
||||
break;
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Timesheet\Calculator;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Timesheet\CalculatorInterface;
|
||||
use App\Timesheet\Util;
|
||||
|
||||
/**
|
||||
* Implementation to calculate the rate for a timesheet record.
|
||||
@@ -54,8 +55,8 @@ class RateCalculator implements CalculatorInterface
|
||||
$hourlyRate = $this->findHourlyRate($record);
|
||||
$factor = $this->getRateFactor($record);
|
||||
|
||||
$hourlyRate = (float) $hourlyRate * $factor;
|
||||
$rate = (float) $hourlyRate * ($record->getDuration() / 3600);
|
||||
$hourlyRate = (float) ($hourlyRate * $factor);
|
||||
$rate = Util::calculateRate($hourlyRate, $record->getDuration());
|
||||
|
||||
$record->setHourlyRate($hourlyRate);
|
||||
$record->setRate($rate);
|
||||
|
||||
31
src/Timesheet/Util.php
Normal file
31
src/Timesheet/Util.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Timesheet;
|
||||
|
||||
/**
|
||||
* A static helper class for re-usable functionality.
|
||||
*/
|
||||
class Util
|
||||
{
|
||||
/**
|
||||
* Calculates the rate for a hourly rate and a given duration in seconds.
|
||||
*
|
||||
* @param float $hourlyRate
|
||||
* @param int $seconds
|
||||
* @return float
|
||||
*/
|
||||
public static function calculateRate(float $hourlyRate, int $seconds): float
|
||||
{
|
||||
$rate = (float) ($hourlyRate * ($seconds / 3600));
|
||||
$rate = round($rate, 2);
|
||||
|
||||
return $rate;
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,13 @@ namespace App\Twig;
|
||||
|
||||
use App\Utils\LocaleSettings;
|
||||
use DateTime;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* Date specific twig extensions
|
||||
*/
|
||||
class DateExtensions extends \Twig_Extension
|
||||
class DateExtensions extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var LocaleSettings|null
|
||||
@@ -30,6 +31,10 @@ class DateExtensions extends \Twig_Extension
|
||||
* @var string
|
||||
*/
|
||||
protected $dateTimeFormat = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dateTimeTypeFormat = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -56,6 +61,7 @@ class DateExtensions extends \Twig_Extension
|
||||
new TwigFilter('month_name', [$this, 'monthName']),
|
||||
new TwigFilter('date_short', [$this, 'dateShort']),
|
||||
new TwigFilter('date_time', [$this, 'dateTime']),
|
||||
new TwigFilter('date_full', [$this, 'dateTimeFull']),
|
||||
new TwigFilter('date_format', [$this, 'dateFormat']),
|
||||
new TwigFilter('time', [$this, 'time']),
|
||||
new TwigFilter('hour24', [$this, 'hour24']),
|
||||
@@ -88,6 +94,28 @@ class DateExtensions extends \Twig_Extension
|
||||
return date_format($date, $this->dateTimeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @return string
|
||||
*/
|
||||
public function dateTimeFull(DateTime $date)
|
||||
{
|
||||
if (null === $this->dateTimeTypeFormat) {
|
||||
$this->dateTimeTypeFormat = $this->localeSettings->getDateTimeTypeFormat();
|
||||
}
|
||||
|
||||
$formatter = new \IntlDateFormatter(
|
||||
$this->localeSettings->getLocale(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
date_default_timezone_get(),
|
||||
\IntlDateFormatter::GREGORIAN,
|
||||
$this->dateTimeTypeFormat
|
||||
);
|
||||
|
||||
return $formatter->format($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param string $format
|
||||
|
||||
163
src/Twig/EntityExtensions.php
Normal file
163
src/Twig/EntityExtensions.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* Entity specific twig extensions.
|
||||
* Should be used with caution, as they can trigger a lot of DB queries.
|
||||
*/
|
||||
class EntityExtensions extends AbstractExtension
|
||||
{
|
||||
private const UNKNOWN_NAME = '-unknown-';
|
||||
|
||||
/**
|
||||
* @var UserRepository|null
|
||||
*/
|
||||
private $users = null;
|
||||
/**
|
||||
* @var CustomerRepository|null
|
||||
*/
|
||||
private $customers = null;
|
||||
/**
|
||||
* @var ProjectRepository|null
|
||||
*/
|
||||
private $projects = null;
|
||||
/**
|
||||
* @var ActivityRepository|null
|
||||
*/
|
||||
private $activities = null;
|
||||
|
||||
/**
|
||||
* @param UserRepository $users
|
||||
* @param CustomerRepository $customers
|
||||
* @param ProjectRepository $projects
|
||||
* @param ActivityRepository $activities
|
||||
*/
|
||||
public function __construct(UserRepository $users, CustomerRepository $customers, ProjectRepository $projects, ActivityRepository $activities)
|
||||
{
|
||||
$this->users = $users;
|
||||
$this->customers = $customers;
|
||||
$this->projects = $projects;
|
||||
$this->activities = $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('user', [$this, 'getUser']),
|
||||
new TwigFilter('customer', [$this, 'getCustomer']),
|
||||
new TwigFilter('project', [$this, 'getProject']),
|
||||
new TwigFilter('activity', [$this, 'getActivity']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|User $user
|
||||
* @param bool $allowEmpty
|
||||
* @return User|null
|
||||
*/
|
||||
public function getUser($user, $allowEmpty = true)
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
$entity = $this->users->getById($user);
|
||||
|
||||
if (null === $entity) {
|
||||
$entity = $this->users->loadUserByUsername($user);
|
||||
}
|
||||
|
||||
if (null === $entity && false === $allowEmpty) {
|
||||
$entity = new User();
|
||||
$entity->setUsername(self::UNKNOWN_NAME);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|Customer $customer
|
||||
* @param bool $allowEmpty
|
||||
* @return Customer|null
|
||||
*/
|
||||
public function getCustomer($customer, $allowEmpty = true)
|
||||
{
|
||||
if ($customer instanceof Customer) {
|
||||
return $customer;
|
||||
}
|
||||
|
||||
$entity = $this->customers->getById($customer);
|
||||
|
||||
if (null === $entity && false === $allowEmpty) {
|
||||
$entity = new Customer();
|
||||
$entity->setName(self::UNKNOWN_NAME);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|Project $project
|
||||
* @param bool $allowEmpty
|
||||
* @return Project|null
|
||||
*/
|
||||
public function getProject($project, $allowEmpty = true)
|
||||
{
|
||||
if ($project instanceof Project) {
|
||||
return $project;
|
||||
}
|
||||
|
||||
$entity = $this->projects->getById($project);
|
||||
|
||||
if (null === $entity && false === $allowEmpty) {
|
||||
$entity = new Project();
|
||||
$entity->setName(self::UNKNOWN_NAME);
|
||||
$entity->setCustomer((new Customer())->setName(self::UNKNOWN_NAME));
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|Activity $activity
|
||||
* @param bool $allowEmpty
|
||||
* @return Activity|null
|
||||
*/
|
||||
public function getActivity($activity, $allowEmpty = true)
|
||||
{
|
||||
if ($activity instanceof Activity) {
|
||||
return $activity;
|
||||
}
|
||||
|
||||
$entity = $this->activities->getById($activity);
|
||||
|
||||
if (null === $entity && false === $allowEmpty) {
|
||||
$entity = new Activity();
|
||||
$entity->setName(self::UNKNOWN_NAME);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
@@ -7,27 +7,43 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\ThemeEvent;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use App\Security\CurrentUser;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class EventController extends Controller
|
||||
class EventExtensions extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function __construct(EventDispatcherInterface $dispatcher)
|
||||
public function __construct(EventDispatcherInterface $dispatcher, CurrentUser $user)
|
||||
{
|
||||
$this->eventDispatcher = $dispatcher;
|
||||
$this->user = $user->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('trigger', [$this, 'triggerEvent']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,19 +65,19 @@ class EventController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $eventName
|
||||
* @return ThemeEvent|Response
|
||||
* @param mixed $payload
|
||||
* @return ThemeEvent
|
||||
*/
|
||||
public function trigger(Request $request, string $event)
|
||||
public function triggerEvent(string $eventName, $payload = null)
|
||||
{
|
||||
if (!$this->hasListener($event)) {
|
||||
return new Response();
|
||||
$themeEvent = new ThemeEvent($this->user, $payload);
|
||||
|
||||
if ($this->hasListener($eventName)) {
|
||||
$this->getDispatcher()->dispatch($eventName, $themeEvent);
|
||||
}
|
||||
|
||||
$themeEvent = new ThemeEvent($request, $this->getUser());
|
||||
$this->getDispatcher()->dispatch($event, $themeEvent);
|
||||
|
||||
return new Response($themeEvent->getContent());
|
||||
return $themeEvent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,12 +16,14 @@ use App\Utils\LocaleSettings;
|
||||
use NumberFormatter;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Multiple Twig extensions: filters and functions
|
||||
*/
|
||||
class Extensions extends \Twig_Extension
|
||||
class Extensions extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var LocaleSettings
|
||||
@@ -98,6 +100,7 @@ class Extensions extends \Twig_Extension
|
||||
'xlsx' => 'fas fa-file-excel',
|
||||
'on' => 'fas fa-toggle-on',
|
||||
'off' => 'fas fa-toggle-off',
|
||||
'audit' => 'fas fa-history',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -132,12 +135,26 @@ class Extensions extends \Twig_Extension
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFunction('locales', [$this, 'getLocales']),
|
||||
new \Twig_SimpleFunction('is_visible_column', [$this, 'isColumnVisible']),
|
||||
new \Twig_SimpleFunction('is_datatable_configured', [$this, 'isDatatableConfigured']),
|
||||
new TwigFunction('locales', [$this, 'getLocales']),
|
||||
new TwigFunction('is_visible_column', [$this, 'isColumnVisible']),
|
||||
new TwigFunction('is_datatable_configured', [$this, 'isDatatableConfigured']),
|
||||
new TwigFunction('class_name', [$this, 'getClassName']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return null|string
|
||||
*/
|
||||
public function getClassName($object)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return get_class($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dataTable
|
||||
* @param string $size
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Utils\Markdown;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* A twig extension to handle markdown parser.
|
||||
*/
|
||||
class MarkdownExtension extends \Twig_Extension
|
||||
class MarkdownExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var Markdown
|
||||
|
||||
@@ -152,7 +152,7 @@ class LocaleSettings
|
||||
*/
|
||||
public function isTwentyFourHours(?string $locale = null): bool
|
||||
{
|
||||
return $this->getConfigByLocaleAndKey('24_hours', $locale);
|
||||
return (bool) $this->getConfigByLocaleAndKey('24_hours', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\Timesheet as TimesheetEntity;
|
||||
use App\Validator\Constraints\Timesheet as TimesheetConstraint;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
@@ -59,7 +59,7 @@ class TimesheetValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $value
|
||||
* @param TimesheetEntity $value
|
||||
* @param Constraint $constraint
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
@@ -68,7 +68,7 @@ class TimesheetValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\Timesheet');
|
||||
}
|
||||
|
||||
if (!is_object($value) || !($value instanceof Timesheet)) {
|
||||
if (!is_object($value) || !($value instanceof TimesheetEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,10 +78,10 @@ class TimesheetValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $timesheet
|
||||
* @param TimesheetEntity $timesheet
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function validatePermissions(Timesheet $timesheet, ExecutionContextInterface $context)
|
||||
protected function validatePermissions(TimesheetEntity $timesheet, ExecutionContextInterface $context)
|
||||
{
|
||||
// special case that would otherwise need to be validated in several controllers:
|
||||
// an entry is edited and the end date is removed (or duration deleted) would restart the record,
|
||||
@@ -102,10 +102,10 @@ class TimesheetValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $timesheet
|
||||
* @param TimesheetEntity $timesheet
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function validateBeginAndEnd(Timesheet $timesheet, ExecutionContextInterface $context)
|
||||
protected function validateBeginAndEnd(TimesheetEntity $timesheet, ExecutionContextInterface $context)
|
||||
{
|
||||
if (null === $timesheet->getBegin()) {
|
||||
$context->buildViolation('You must submit a begin date.')
|
||||
@@ -135,10 +135,10 @@ class TimesheetValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $timesheet
|
||||
* @param TimesheetEntity $timesheet
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function validateActivityAndProject(Timesheet $timesheet, ExecutionContextInterface $context)
|
||||
protected function validateActivityAndProject(TimesheetEntity $timesheet, ExecutionContextInterface $context)
|
||||
{
|
||||
if (null === ($activity = $timesheet->getActivity())) {
|
||||
$context->buildViolation('A timesheet must have an activity.')
|
||||
|
||||
Reference in New Issue
Block a user