detail pages for customers and projects (#1371)
This commit is contained in:
@@ -23,6 +23,10 @@ class ThemeConfiguration implements SystemBundleConfiguration, \ArrayAccess
|
||||
return (bool) $this->find('auto_reload_datatable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently unused, as JS selects are always activated.
|
||||
* @deprecated since 1.7 will be removed with 2.0
|
||||
*/
|
||||
public function getSelectPicker(): string
|
||||
{
|
||||
return (string) $this->find('select_type');
|
||||
|
||||
@@ -11,17 +11,24 @@ namespace App\Controller;
|
||||
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerComment;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Team;
|
||||
use App\Event\CustomerMetaDefinitionEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Form\CustomerCommentForm;
|
||||
use App\Form\CustomerEditForm;
|
||||
use App\Form\CustomerTeamPermissionForm;
|
||||
use App\Form\Toolbar\CustomerToolbarForm;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\CustomerFormTypeQuery;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use App\Repository\TeamRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
@@ -34,42 +41,28 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
* Controller used to manage customer in the admin part of the site.
|
||||
*
|
||||
* @Route(path="/admin/customer")
|
||||
* @Security("is_granted('view_customer')")
|
||||
* @Security("is_granted('view_customer') or is_granted('view_teamlead_customer') or is_granted('view_team_customer')")
|
||||
*/
|
||||
class CustomerController extends AbstractController
|
||||
final class CustomerController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var CustomerRepository
|
||||
*/
|
||||
private $repository;
|
||||
/**
|
||||
* @var FormConfiguration
|
||||
*/
|
||||
private $configuration;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(CustomerRepository $repository, FormConfiguration $configuration, EventDispatcherInterface $dispatcher)
|
||||
public function __construct(CustomerRepository $repository, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->configuration = $configuration;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \App\Repository\CustomerRepository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", defaults={"page": 1}, name="admin_customer", methods={"GET"})
|
||||
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_customer_paginated", methods={"GET"})
|
||||
* @Security("is_granted('view_customer')")
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
@@ -85,7 +78,7 @@ class CustomerController extends AbstractController
|
||||
$query->resetByFormError($form->getErrors());
|
||||
}
|
||||
|
||||
$entries = $this->getRepository()->getPagerfantaForQuery($query);
|
||||
$entries = $this->repository->getPagerfantaForQuery($query);
|
||||
|
||||
return $this->render('customer/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
@@ -99,7 +92,7 @@ class CustomerController extends AbstractController
|
||||
* @param CustomerQuery $query
|
||||
* @return MetaTableTypeInterface[]
|
||||
*/
|
||||
protected function findMetaColumns(CustomerQuery $query): array
|
||||
private function findMetaColumns(CustomerQuery $query): array
|
||||
{
|
||||
$event = new CustomerMetaDisplayEvent($query, CustomerMetaDisplayEvent::CUSTOMER);
|
||||
$this->dispatcher->dispatch($event);
|
||||
@@ -111,16 +104,16 @@ class CustomerController extends AbstractController
|
||||
* @Route(path="/create", name="admin_customer_create", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create_customer')")
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
public function createAction(Request $request, FormConfiguration $configuration)
|
||||
{
|
||||
$timezone = date_default_timezone_get();
|
||||
if (null !== $this->configuration->getCustomerDefaultTimezone()) {
|
||||
$timezone = $this->configuration->getCustomerDefaultTimezone();
|
||||
if (null !== $configuration->getCustomerDefaultTimezone()) {
|
||||
$timezone = $configuration->getCustomerDefaultTimezone();
|
||||
}
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->setCountry($this->configuration->getCustomerDefaultCountry());
|
||||
$customer->setCurrency($this->configuration->getCustomerDefaultCurrency());
|
||||
$customer->setCountry($configuration->getCustomerDefaultCountry());
|
||||
$customer->setCurrency($configuration->getCustomerDefaultCurrency());
|
||||
$customer->setTimezone($timezone);
|
||||
|
||||
return $this->renderCustomerForm($customer, $request);
|
||||
@@ -130,7 +123,7 @@ class CustomerController extends AbstractController
|
||||
* @Route(path="/{id}/permissions", name="admin_customer_permissions", methods={"GET", "POST"})
|
||||
* @Security("is_granted('permissions', customer)")
|
||||
*/
|
||||
public function teamPermissions(Customer $customer, Request $request)
|
||||
public function teamPermissionsAction(Customer $customer, Request $request)
|
||||
{
|
||||
$form = $this->createForm(CustomerTeamPermissionForm::class, $customer, [
|
||||
'action' => $this->generateUrl('admin_customer_permissions', ['id' => $customer->getId()]),
|
||||
@@ -141,11 +134,11 @@ class CustomerController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->saveCustomer($customer);
|
||||
$this->repository->saveCustomer($customer);
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_customer');
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
@@ -157,18 +150,160 @@ class CustomerController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/budget", name="admin_customer_budget", methods={"GET"})
|
||||
* @Security("is_granted('budget', customer)")
|
||||
* @Route(path="/{id}/comment_delete", name="customer_comment_delete", methods={"GET"})
|
||||
* @Security("is_granted('edit', comment.getCustomer()) and is_granted('comments', comment.getCustomer())")
|
||||
*/
|
||||
public function budgetAction(Customer $customer)
|
||||
public function deleteCommentAction(CustomerComment $comment)
|
||||
{
|
||||
$stats = $this->getRepository()->getCustomerStatistics($customer);
|
||||
$customerId = $comment->getCustomer()->getId();
|
||||
|
||||
// TODO sent event with stats
|
||||
try {
|
||||
$this->repository->deleteComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->render('customer/budget.html.twig', [
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customerId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/comment_add", name="customer_comment_add", methods={"POST"})
|
||||
* @Security("is_granted('edit', customer) and is_granted('comments', customer)")
|
||||
*/
|
||||
public function addCommentAction(Customer $customer, Request $request)
|
||||
{
|
||||
$comment = new CustomerComment();
|
||||
$form = $this->getCommentForm($customer, $comment);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->repository->saveComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/comment_pin", name="customer_comment_pin", methods={"GET"})
|
||||
* @Security("is_granted('edit', comment.getCustomer()) and is_granted('comments', comment.getCustomer())")
|
||||
*/
|
||||
public function pinCommentAction(CustomerComment $comment)
|
||||
{
|
||||
$comment->setPinned(!$comment->isPinned());
|
||||
try {
|
||||
$this->repository->saveComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('customer_details', ['id' => $comment->getCustomer()->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/create_team", name="customer_team_create", methods={"GET"})
|
||||
* @Security("is_granted('create_team') and is_granted('permissions', customer)")
|
||||
*/
|
||||
public function createDefaultTeamAction(Customer $customer, TeamRepository $teamRepository)
|
||||
{
|
||||
$defaultTeam = $teamRepository->findOneBy(['name' => $customer->getName()]);
|
||||
if (null !== $defaultTeam) {
|
||||
$this->flashError('action.update.error', ['%reason%' => 'Team already existing']);
|
||||
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
$defaultTeam = new Team();
|
||||
$defaultTeam->setName($customer->getName());
|
||||
$defaultTeam->setTeamLead($this->getUser());
|
||||
$defaultTeam->addCustomer($customer);
|
||||
|
||||
try {
|
||||
$teamRepository->saveTeam($defaultTeam);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/projects/{page}", defaults={"page": 1}, name="customer_projects", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view', customer)")
|
||||
*/
|
||||
public function projectsAction(Customer $customer, int $page, ProjectRepository $projectRepository)
|
||||
{
|
||||
$query = new ProjectQuery();
|
||||
$query->setCurrentUser($this->getUser());
|
||||
$query->setPage($page);
|
||||
$query->setPageSize(5);
|
||||
$query->setCustomer($customer);
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $projectRepository->getPagerfantaForQuery($query);
|
||||
|
||||
return $this->render('customer/embed_projects.html.twig', [
|
||||
'customer' => $customer,
|
||||
'projects' => $entries,
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/details", name="customer_details", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view', customer)")
|
||||
*/
|
||||
public function detailsAction(Customer $customer, TeamRepository $teamRepository)
|
||||
{
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$stats = null;
|
||||
$timezone = null;
|
||||
$defaultTeam = null;
|
||||
$commentForm = null;
|
||||
$attachments = [];
|
||||
$comments = null;
|
||||
$teams = null;
|
||||
$projects = null;
|
||||
|
||||
if ($this->isGranted('edit', $customer)) {
|
||||
$commentForm = $this->getCommentForm($customer, new CustomerComment())->createView();
|
||||
|
||||
if ($this->isGranted('create_team')) {
|
||||
$defaultTeam = $teamRepository->findOneBy(['name' => $customer->getName()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $customer->getTimezone()) {
|
||||
$timezone = new \DateTimeZone($customer->getTimezone());
|
||||
}
|
||||
|
||||
if ($this->isGranted('budget', $customer)) {
|
||||
$stats = $this->repository->getCustomerStatistics($customer);
|
||||
}
|
||||
|
||||
if ($this->isGranted('comments', $customer)) {
|
||||
$comments = $this->repository->getComments($customer);
|
||||
}
|
||||
|
||||
if ($this->isGranted('permissions', $customer) || $this->isGranted('details', $customer) || $this->isGranted('view_team')) {
|
||||
$teams = $customer->getTeams();
|
||||
}
|
||||
|
||||
return $this->render('customer/details.html.twig', [
|
||||
'customer' => $customer,
|
||||
'comments' => $comments,
|
||||
'commentForm' => $commentForm,
|
||||
'attachments' => $attachments,
|
||||
'stats' => $stats,
|
||||
'team' => $defaultTeam,
|
||||
'teams' => $teams,
|
||||
'now' => new \DateTime('now', $timezone),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -187,7 +322,7 @@ class CustomerController extends AbstractController
|
||||
*/
|
||||
public function deleteAction(Customer $customer, Request $request)
|
||||
{
|
||||
$stats = $this->getRepository()->getCustomerStatistics($customer);
|
||||
$stats = $this->repository->getCustomerStatistics($customer);
|
||||
|
||||
$deleteForm = $this->createFormBuilder(null, [
|
||||
'attr' => [
|
||||
@@ -215,7 +350,7 @@ class CustomerController extends AbstractController
|
||||
|
||||
if ($deleteForm->isSubmitted() && $deleteForm->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->deleteCustomer($customer, $deleteForm->get('customer')->getData());
|
||||
$this->repository->deleteCustomer($customer, $deleteForm->get('customer')->getData());
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (ORMException $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
@@ -236,21 +371,18 @@ class CustomerController extends AbstractController
|
||||
* @param Request $request
|
||||
* @return RedirectResponse|Response
|
||||
*/
|
||||
protected function renderCustomerForm(Customer $customer, Request $request)
|
||||
private function renderCustomerForm(Customer $customer, Request $request)
|
||||
{
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($customer);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->saveCustomer($customer);
|
||||
$this->repository->saveCustomer($customer);
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_customer');
|
||||
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
|
||||
} catch (ORMException $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
@@ -262,7 +394,7 @@ class CustomerController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getToolbarForm(CustomerQuery $query): FormInterface
|
||||
private function getToolbarForm(CustomerQuery $query): FormInterface
|
||||
{
|
||||
return $this->createForm(CustomerToolbarForm::class, $query, [
|
||||
'action' => $this->generateUrl('admin_customer', [
|
||||
@@ -272,8 +404,24 @@ class CustomerController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function getCommentForm(Customer $customer, CustomerComment $comment): FormInterface
|
||||
{
|
||||
if (null === $comment->getId()) {
|
||||
$comment->setCustomer($customer);
|
||||
$comment->setCreatedBy($this->getUser());
|
||||
}
|
||||
|
||||
return $this->createForm(CustomerCommentForm::class, $comment, [
|
||||
'action' => $this->generateUrl('customer_comment_add', ['id' => $customer->getId()]),
|
||||
'method' => 'POST',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createEditForm(Customer $customer): FormInterface
|
||||
{
|
||||
$event = new CustomerMetaDefinitionEvent($customer);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
if ($customer->getId() === null) {
|
||||
$url = $this->generateUrl('admin_customer_create');
|
||||
} else {
|
||||
|
||||
@@ -13,16 +13,21 @@ use App\Configuration\FormConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectComment;
|
||||
use App\Entity\Team;
|
||||
use App\Event\ProjectMetaDefinitionEvent;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Form\ProjectCommentForm;
|
||||
use App\Form\ProjectEditForm;
|
||||
use App\Form\ProjectTeamPermissionForm;
|
||||
use App\Form\Toolbar\ProjectToolbarForm;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use App\Repository\Query\ProjectFormTypeQuery;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use App\Repository\TeamRepository;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
@@ -33,12 +38,12 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Controller used to manage projects in the admin part of the site.
|
||||
* Controller used to manage projects.
|
||||
*
|
||||
* @Route(path="/admin/project")
|
||||
* @Security("is_granted('view_project')")
|
||||
* @Security("is_granted('view_project') or is_granted('view_teamlead_project') or is_granted('view_team_project')")
|
||||
*/
|
||||
class ProjectController extends AbstractController
|
||||
final class ProjectController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var ProjectRepository
|
||||
@@ -51,7 +56,7 @@ class ProjectController extends AbstractController
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct(ProjectRepository $repository, FormConfiguration $configuration, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
@@ -60,15 +65,9 @@ class ProjectController extends AbstractController
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
protected function getRepository(): ProjectRepository
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", defaults={"page": 1}, name="admin_project", methods={"GET"})
|
||||
* @Route(path="/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_project_paginated", methods={"GET"})
|
||||
* @Security("is_granted('view_project')")
|
||||
*/
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
@@ -85,7 +84,7 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getRepository()->getPagerfantaForQuery($query);
|
||||
$entries = $this->repository->getPagerfantaForQuery($query);
|
||||
|
||||
return $this->render('project/index.html.twig', [
|
||||
'entries' => $entries,
|
||||
@@ -122,11 +121,11 @@ class ProjectController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->saveProject($project);
|
||||
$this->repository->saveProject($project);
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_project');
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
@@ -154,18 +153,154 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/budget", name="admin_project_budget", methods={"GET"})
|
||||
* @Security("is_granted('budget', project)")
|
||||
* @Route(path="/{id}/comment_delete", name="project_comment_delete", methods={"GET"})
|
||||
* @Security("is_granted('edit', comment.getProject()) and is_granted('comments', comment.getProject())")
|
||||
*/
|
||||
public function budgetAction(Project $project)
|
||||
public function deleteCommentAction(ProjectComment $comment)
|
||||
{
|
||||
$stats = $this->getRepository()->getProjectStatistics($project);
|
||||
$projectId = $comment->getProject()->getId();
|
||||
|
||||
// TODO sent event with stats
|
||||
try {
|
||||
$this->repository->deleteComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->render('project/budget.html.twig', [
|
||||
return $this->redirectToRoute('project_details', ['id' => $projectId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/comment_add", name="project_comment_add", methods={"POST"})
|
||||
* @Security("is_granted('edit', project) and is_granted('comments', project)")
|
||||
*/
|
||||
public function addCommentAction(Project $project, Request $request)
|
||||
{
|
||||
$comment = new ProjectComment();
|
||||
$form = $this->getCommentForm($project, $comment);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->repository->saveComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/comment_pin", name="project_comment_pin", methods={"GET"})
|
||||
* @Security("is_granted('edit', comment.getProject()) and is_granted('comments', comment.getProject())")
|
||||
*/
|
||||
public function pinCommentAction(ProjectComment $comment)
|
||||
{
|
||||
$comment->setPinned(!$comment->isPinned());
|
||||
try {
|
||||
$this->repository->saveComment($comment);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('project_details', ['id' => $comment->getProject()->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/create_team", name="project_team_create", methods={"GET"})
|
||||
* @Security("is_granted('create_team') and is_granted('edit', project)")
|
||||
*/
|
||||
public function createDefaultTeamAction(Project $project, TeamRepository $teamRepository)
|
||||
{
|
||||
$defaultTeam = $teamRepository->findOneBy(['name' => $project->getName()]);
|
||||
if (null !== $defaultTeam) {
|
||||
$this->flashError('action.update.error', ['%reason%' => 'Team already existing']);
|
||||
|
||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||
}
|
||||
|
||||
$defaultTeam = new Team();
|
||||
$defaultTeam->setName($project->getName());
|
||||
$defaultTeam->setTeamLead($this->getUser());
|
||||
$defaultTeam->addProject($project);
|
||||
|
||||
try {
|
||||
$teamRepository->saveTeam($defaultTeam);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/activities/{page}", defaults={"page": 1}, name="project_activities", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view', project)")
|
||||
*/
|
||||
public function activitiesAction(Project $project, int $page, ActivityRepository $activityRepository)
|
||||
{
|
||||
$query = new ActivityQuery();
|
||||
$query->setCurrentUser($this->getUser());
|
||||
$query->setPage($page);
|
||||
$query->setPageSize(5);
|
||||
$query->setProject($project);
|
||||
$query->setExcludeGlobals(true);
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $activityRepository->getPagerfantaForQuery($query);
|
||||
|
||||
return $this->render('project/embed_activities.html.twig', [
|
||||
'project' => $project,
|
||||
'stats' => $stats
|
||||
'activities' => $entries,
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/details", name="project_details", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view', project)")
|
||||
*/
|
||||
public function detailsAction(Project $project, TeamRepository $teamRepository)
|
||||
{
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$stats = null;
|
||||
$defaultTeam = null;
|
||||
$commentForm = null;
|
||||
$attachments = [];
|
||||
$comments = null;
|
||||
$teams = null;
|
||||
|
||||
if ($this->isGranted('edit', $project)) {
|
||||
$commentForm = $this->getCommentForm($project, new ProjectComment())->createView();
|
||||
|
||||
if ($this->isGranted('create_team')) {
|
||||
$defaultTeam = $teamRepository->findOneBy(['name' => $project->getName()]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isGranted('budget', $project)) {
|
||||
$stats = $this->repository->getProjectStatistics($project);
|
||||
}
|
||||
|
||||
if ($this->isGranted('comments', $project)) {
|
||||
$comments = $this->repository->getComments($project);
|
||||
}
|
||||
|
||||
if ($this->isGranted('permissions', $project) || $this->isGranted('details', $project) || $this->isGranted('view_team')) {
|
||||
$teams = $project->getTeams();
|
||||
}
|
||||
|
||||
return $this->render('project/details.html.twig', [
|
||||
'project' => $project,
|
||||
'comments' => $comments,
|
||||
'commentForm' => $commentForm,
|
||||
'attachments' => $attachments,
|
||||
'stats' => $stats,
|
||||
'team' => $defaultTeam,
|
||||
'teams' => $teams,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -184,7 +319,7 @@ class ProjectController extends AbstractController
|
||||
*/
|
||||
public function deleteAction(Project $project, Request $request)
|
||||
{
|
||||
$stats = $this->getRepository()->getProjectStatistics($project);
|
||||
$stats = $this->repository->getProjectStatistics($project);
|
||||
|
||||
$deleteForm = $this->createFormBuilder(null, [
|
||||
'attr' => [
|
||||
@@ -213,9 +348,9 @@ class ProjectController extends AbstractController
|
||||
|
||||
if ($deleteForm->isSubmitted() && $deleteForm->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->deleteProject($project, $deleteForm->get('project')->getData());
|
||||
$this->repository->deleteProject($project, $deleteForm->get('project')->getData());
|
||||
$this->flashSuccess('action.delete.success');
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
|
||||
@@ -234,17 +369,14 @@ class ProjectController extends AbstractController
|
||||
* @param Request $request
|
||||
* @return RedirectResponse|Response
|
||||
*/
|
||||
protected function renderProjectForm(Project $project, Request $request)
|
||||
private function renderProjectForm(Project $project, Request $request)
|
||||
{
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$editForm = $this->createEditForm($project);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
try {
|
||||
$this->getRepository()->saveProject($project);
|
||||
$this->repository->saveProject($project);
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
if ($editForm->has('create_more') && $editForm->get('create_more')->getData() === true) {
|
||||
@@ -254,9 +386,9 @@ class ProjectController extends AbstractController
|
||||
$editForm->get('create_more')->setData(true);
|
||||
$project = $newProject;
|
||||
} else {
|
||||
return $this->redirectToRoute('admin_project');
|
||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||
}
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
@@ -277,8 +409,24 @@ class ProjectController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function getCommentForm(Project $project, ProjectComment $comment): FormInterface
|
||||
{
|
||||
if (null === $comment->getId()) {
|
||||
$comment->setProject($project);
|
||||
$comment->setCreatedBy($this->getUser());
|
||||
}
|
||||
|
||||
return $this->createForm(ProjectCommentForm::class, $comment, [
|
||||
'action' => $this->generateUrl('project_comment_add', ['id' => $project->getId()]),
|
||||
'method' => 'POST',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createEditForm(Project $project): FormInterface
|
||||
{
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$currency = $this->configuration->getCustomerDefaultCurrency();
|
||||
$url = $this->generateUrl('admin_project_create');
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Event\SystemConfigurationEvent;
|
||||
use App\Form\Model\Configuration;
|
||||
use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
|
||||
use App\Form\SystemConfigurationForm;
|
||||
use App\Form\Type\EnhancedSelectboxType;
|
||||
use App\Form\Type\LanguageType;
|
||||
use App\Form\Type\RoundingModeType;
|
||||
use App\Form\Type\SkinType;
|
||||
@@ -293,25 +292,20 @@ class SystemConfigurationController extends AbstractController
|
||||
->setSection(SystemConfigurationModel::SECTION_THEME)
|
||||
->setConfiguration([
|
||||
(new Configuration())
|
||||
->setName('theme.select_type')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(EnhancedSelectboxType::class)
|
||||
->setRequired(false),
|
||||
->setName('theme.autocomplete_chars')
|
||||
->setLabel('theme.autocomplete_chars')
|
||||
->setType(IntegerType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('timesheet.markdown_content')
|
||||
->setLabel('theme.markdown_content')
|
||||
->setType(CheckboxType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('theme.autocomplete_chars')
|
||||
->setLabel('theme.autocomplete_chars')
|
||||
->setType(IntegerType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
// FIXME should that be configurable per user?
|
||||
// TODO should that be configurable per user?
|
||||
/*
|
||||
(new Configuration())
|
||||
->setName('theme.auto_reload_datatable')
|
||||
->setLabel('theme.auto_reload_datatable') // FIXME translation
|
||||
->setLabel('theme.auto_reload_datatable') // TODO translation
|
||||
->setType(CheckboxType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,6 @@ use App\Form\TeamProjectForm;
|
||||
use App\Form\Toolbar\TeamToolbarForm;
|
||||
use App\Repository\Query\TeamQuery;
|
||||
use App\Repository\TeamRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@@ -28,7 +27,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
* @Route(path="/admin/teams")
|
||||
* @Security("is_granted('view_team')")
|
||||
*/
|
||||
class TeamController extends AbstractController
|
||||
final class TeamController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var TeamRepository
|
||||
@@ -93,6 +92,40 @@ class TeamController extends AbstractController
|
||||
return $this->renderEditScreen($team, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit_member", name="admin_team_member", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', team)")
|
||||
*/
|
||||
public function editMemberAction(Team $team, Request $request)
|
||||
{
|
||||
$editForm = $this->createForm(TeamEditForm::class, $team, [
|
||||
'action' => $this->generateUrl('admin_team_member', ['id' => $team->getId()]),
|
||||
'method' => 'POST',
|
||||
]);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
try {
|
||||
// make sure that the teamlead is always part of the team, otherwise permission checks
|
||||
// and filtering might not work as expected!
|
||||
$team->addUser($team->getTeamLead());
|
||||
|
||||
$this->repository->saveTeam($team);
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('team/edit_member.html.twig', [
|
||||
'team' => $team,
|
||||
'form' => $editForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function renderEditScreen(Team $team, Request $request): Response
|
||||
{
|
||||
$customerForm = null;
|
||||
@@ -122,7 +155,7 @@ class TeamController extends AbstractController
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +175,7 @@ class TeamController extends AbstractController
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
@@ -161,7 +194,7 @@ class TeamController extends AbstractController
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
|
||||
} catch (ORMException $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class TeamFixtures extends Fixture implements DependentFixtureInterface
|
||||
public const BATCH_SIZE = 50;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return class-string[]
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface
|
||||
public const BATCH_SIZE = 100;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return class-string[]
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
|
||||
@@ -31,10 +31,10 @@ class Configuration implements ConfigurationInterface
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder('kimai');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
$rootNode = $treeBuilder->getRootNode();
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $treeBuilder->getRootNode();
|
||||
|
||||
$rootNode
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('data_dir')
|
||||
->isRequired()
|
||||
@@ -75,7 +75,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getTimesheetNode()
|
||||
{
|
||||
$builder = new TreeBuilder('timesheet');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -205,7 +205,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getInvoiceNode()
|
||||
{
|
||||
$builder = new TreeBuilder('invoice');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -232,7 +232,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getLanguagesNode()
|
||||
{
|
||||
$builder = new TreeBuilder('languages');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -256,7 +256,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getCalendarNode()
|
||||
{
|
||||
$builder = new TreeBuilder('calendar');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -310,7 +310,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getThemeNode()
|
||||
{
|
||||
$builder = new TreeBuilder('theme');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -326,6 +326,7 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->scalarNode('select_type')
|
||||
->defaultValue('selectpicker')
|
||||
->setDeprecated()
|
||||
->end()
|
||||
->scalarNode('auto_reload_datatable')
|
||||
->defaultFalse()
|
||||
@@ -374,7 +375,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getIndustryNode()
|
||||
{
|
||||
$builder = new TreeBuilder('industry');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -390,7 +391,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getUserNode()
|
||||
{
|
||||
$builder = new TreeBuilder('user');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -411,7 +412,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getWidgetsNode()
|
||||
{
|
||||
$builder = new TreeBuilder('widgets');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -438,7 +439,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getDashboardNode()
|
||||
{
|
||||
$builder = new TreeBuilder('dashboard');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -467,7 +468,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getDefaultsNode()
|
||||
{
|
||||
$builder = new TreeBuilder('defaults');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
@@ -499,7 +500,7 @@ class Configuration implements ConfigurationInterface
|
||||
protected function getPermissionsNode()
|
||||
{
|
||||
$builder = new TreeBuilder('permissions');
|
||||
/** @var ArrayNodeDefinition $rootNode */
|
||||
/** @var ArrayNodeDefinition $node */
|
||||
$node = $builder->getRootNode();
|
||||
|
||||
$node
|
||||
|
||||
31
src/Entity/CommentInterface.php
Normal file
31
src/Entity/CommentInterface.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\Entity;
|
||||
|
||||
interface CommentInterface
|
||||
{
|
||||
public function getId(): ?int;
|
||||
|
||||
public function getMessage(): ?string;
|
||||
|
||||
public function setMessage(string $message);
|
||||
|
||||
public function getCreatedBy(): ?User;
|
||||
|
||||
public function setCreatedBy(User $createdBy);
|
||||
|
||||
public function getCreatedAt(): ?\DateTime;
|
||||
|
||||
public function setCreatedAt(\DateTime $createdAt);
|
||||
|
||||
public function isPinned(): bool;
|
||||
|
||||
public function setPinned(bool $pinned);
|
||||
}
|
||||
104
src/Entity/CommentTableTypeTrait.php
Normal file
104
src/Entity/CommentTableTypeTrait.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
trait CommentTableTypeTrait
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="message", type="text", nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $message;
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\User")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $createdBy;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="created_at", type="datetime", nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $createdAt;
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(name="pinned", type="boolean", nullable=false, options={"default": false})
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $pinned = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMessage(): ?string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMessage(string $message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function getCreatedBy(): ?User
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
public function setCreatedBy(User $createdBy)
|
||||
{
|
||||
$this->createdBy = $createdBy;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?\DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTime $createdAt)
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
}
|
||||
|
||||
public function isPinned(): bool
|
||||
{
|
||||
return $this->pinned;
|
||||
}
|
||||
|
||||
public function setPinned(bool $pinned)
|
||||
{
|
||||
$this->pinned = $pinned;
|
||||
}
|
||||
}
|
||||
49
src/Entity/CustomerComment.php
Normal file
49
src/Entity/CustomerComment.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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 App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="kimai2_customers_comments",
|
||||
* indexes={
|
||||
* @ORM\Index(columns={"customer_id"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class CustomerComment implements CommentInterface
|
||||
{
|
||||
use CommentTableTypeTrait;
|
||||
|
||||
/**
|
||||
* @var Customer
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Customer")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $customer;
|
||||
|
||||
public function setCustomer(Customer $customer): CustomerComment
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomer(): ?Customer
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
}
|
||||
49
src/Entity/ProjectComment.php
Normal file
49
src/Entity/ProjectComment.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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 App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="kimai2_projects_comments",
|
||||
* indexes={
|
||||
* @ORM\Index(columns={"project_id"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ProjectComment implements CommentInterface
|
||||
{
|
||||
use CommentTableTypeTrait;
|
||||
|
||||
/**
|
||||
* @var Project
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Project")
|
||||
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $project;
|
||||
|
||||
public function setProject(Project $project): ProjectComment
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProject(): ?Project
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
}
|
||||
@@ -93,13 +93,13 @@ final class MenuSubscriber implements EventSubscriberInterface
|
||||
$menu->addChild($timesheets);
|
||||
}
|
||||
|
||||
if ($auth->isGranted('view_customer')) {
|
||||
if ($auth->isGranted('view_customer') || $auth->isGranted('view_teamlead_customer') || $auth->isGranted('view_team_customer')) {
|
||||
$customers = new MenuItemModel('customer_admin', 'menu.admin_customer', 'admin_customer', [], $this->getIcon('customer'));
|
||||
$customers->setChildRoutes(['admin_customer_create', 'admin_customer_permissions', 'admin_customer_budget', 'admin_customer_edit', 'admin_customer_delete']);
|
||||
$menu->addChild($customers);
|
||||
}
|
||||
|
||||
if ($auth->isGranted('view_project')) {
|
||||
if ($auth->isGranted('view_project') || $auth->isGranted('view_teamlead_project') || $auth->isGranted('view_team_project')) {
|
||||
$projects = new MenuItemModel('project_admin', 'menu.admin_project', 'admin_project', [], $this->getIcon('project'));
|
||||
$projects->setChildRoutes(['admin_project_permissions', 'admin_project_create', 'admin_project_budget', 'admin_project_edit', 'admin_project_delete']);
|
||||
$menu->addChild($projects);
|
||||
|
||||
@@ -59,7 +59,7 @@ class ActivityEditForm extends AbstractType
|
||||
],
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'label.comment',
|
||||
'label' => 'label.description',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
|
||||
47
src/Form/CustomerCommentForm.php
Normal file
47
src/Form/CustomerCommentForm.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Form;
|
||||
|
||||
use App\Entity\CustomerComment;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CustomerCommentForm extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('message', TextareaType::class, [
|
||||
'label' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => CustomerComment::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_customer_comment',
|
||||
'attr' => [
|
||||
'data-form-event' => 'kimai.customerComment'
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class CustomerEditForm extends AbstractType
|
||||
'required' => false,
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'label.comment',
|
||||
'label' => 'label.description',
|
||||
'required' => false,
|
||||
])
|
||||
->add('company', TextType::class, [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace App\Form\Extension;
|
||||
|
||||
use App\Configuration\ThemeConfiguration;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -20,19 +19,12 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
/**
|
||||
* Converts normal select boxes into javascript enhanced versions.
|
||||
*/
|
||||
class EnhancedChoiceTypeExtension extends AbstractTypeExtension
|
||||
final class EnhancedChoiceTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
public const TYPE_SELECTPICKER = 'selectpicker';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
* @deprecated since 1.7 will be removed with 2.0
|
||||
*/
|
||||
protected $type = null;
|
||||
|
||||
public function __construct(ThemeConfiguration $configuration)
|
||||
{
|
||||
$this->type = $configuration->getSelectPicker();
|
||||
}
|
||||
public const TYPE_SELECTPICKER = 'selectpicker';
|
||||
|
||||
public static function getExtendedTypes(): iterable
|
||||
{
|
||||
@@ -46,10 +38,6 @@ class EnhancedChoiceTypeExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($this->type !== self::TYPE_SELECTPICKER) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($options['selectpicker']) && false === $options['selectpicker']) {
|
||||
return;
|
||||
}
|
||||
|
||||
47
src/Form/ProjectCommentForm.php
Normal file
47
src/Form/ProjectCommentForm.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Form;
|
||||
|
||||
use App\Entity\ProjectComment;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectCommentForm extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('message', TextareaType::class, [
|
||||
'label' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => ProjectComment::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_project_comment',
|
||||
'attr' => [
|
||||
'data-form-event' => 'kimai.projectComment'
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class ProjectEditForm extends AbstractType
|
||||
$entry = $options['data'];
|
||||
$id = $entry->getId();
|
||||
|
||||
if ($id !== null) {
|
||||
if (null !== $entry->getCustomer()) {
|
||||
$customer = $entry->getCustomer();
|
||||
$options['currency'] = $customer->getCurrency();
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class ProjectEditForm extends AbstractType
|
||||
],
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'label.comment',
|
||||
'label' => 'label.description',
|
||||
'required' => false,
|
||||
])
|
||||
->add('orderNumber', TextType::class, [
|
||||
|
||||
65
src/Migrations/Version20200109102138.php
Normal file
65
src/Migrations/Version20200109102138.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Creates comment tables for customers and projects
|
||||
*
|
||||
* @version 1.7
|
||||
*/
|
||||
final class Version20200109102138 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Creates comment tables for customers and projects';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$customerComment = $schema->createTable('kimai2_customers_comments');
|
||||
$customerComment->addColumn('id', 'integer', ['autoincrement' => true, 'notnull' => true]);
|
||||
$customerComment->addColumn('customer_id', 'integer', ['notnull' => true]);
|
||||
$customerComment->addColumn('message', 'text', ['notnull' => true]);
|
||||
$customerComment->addColumn('created_by_id', 'integer', ['notnull' => true]);
|
||||
$customerComment->addColumn('created_at', 'datetime', ['notnull' => true]);
|
||||
$customerComment->addColumn('pinned', 'boolean', ['notnull' => true, 'default' => false]);
|
||||
$customerComment->setPrimaryKey(['id']);
|
||||
$customerComment->addIndex(['customer_id'], 'IDX_A5B142D99395C3F3');
|
||||
$customerComment->addForeignKeyConstraint('kimai2_customers', ['customer_id'], ['id'], ['onDelete' => 'CASCADE'], 'FK_A5B142D99395C3F3');
|
||||
$customerComment->addForeignKeyConstraint('kimai2_users', ['created_by_id'], ['id'], ['onDelete' => 'CASCADE'], 'FK_A5B142D9B03A8386');
|
||||
|
||||
$projectComment = $schema->createTable('kimai2_projects_comments');
|
||||
$projectComment->addColumn('id', 'integer', ['autoincrement' => true, 'notnull' => true]);
|
||||
$projectComment->addColumn('project_id', 'integer', ['notnull' => true]);
|
||||
$projectComment->addColumn('message', 'text', ['notnull' => true]);
|
||||
$projectComment->addColumn('created_by_id', 'integer', ['notnull' => true]);
|
||||
$projectComment->addColumn('created_at', 'datetime', ['notnull' => true]);
|
||||
$projectComment->addColumn('pinned', 'boolean', ['notnull' => true, 'default' => false]);
|
||||
$projectComment->setPrimaryKey(['id']);
|
||||
$projectComment->addIndex(['project_id'], 'IDX_29A23638166D1F9C');
|
||||
$projectComment->addForeignKeyConstraint('kimai2_projects', ['project_id'], ['id'], ['onDelete' => 'CASCADE'], 'FK_29A23638166D1F9C');
|
||||
$projectComment->addForeignKeyConstraint('kimai2_users', ['created_by_id'], ['id'], ['onDelete' => 'CASCADE'], 'FK_29A23638B03A8386');
|
||||
|
||||
$this->addSql('DELETE from kimai2_configuration WHERE name = "theme.select_type"');
|
||||
$this->addSql('DELETE from kimai2_roles_permissions WHERE permission = "delete_other_profile"');
|
||||
$this->addSql('DELETE from kimai2_roles_permissions WHERE permission = "delete_own_profile"');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$schema->dropTable('kimai2_projects_comments');
|
||||
$schema->dropTable('kimai2_customers_comments');
|
||||
}
|
||||
}
|
||||
@@ -294,12 +294,15 @@ class ActivityRepository extends EntityRepository
|
||||
if ($query->isGlobalsOnly()) {
|
||||
$where->add($qb->expr()->isNull('a.project'));
|
||||
} elseif (null !== $query->getProject()) {
|
||||
$where->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('a.project', ':project'),
|
||||
$qb->expr()->isNull('a.project')
|
||||
)
|
||||
$orX = $qb->expr()->orX(
|
||||
$qb->expr()->eq('a.project', ':project')
|
||||
);
|
||||
|
||||
if (!$query->isExcludeGlobals()) {
|
||||
$orX->add($qb->expr()->isNull('a.project'));
|
||||
}
|
||||
|
||||
$where->add($orX);
|
||||
$qb->setParameter('project', $query->getProject());
|
||||
} elseif (null !== $query->getCustomer()) {
|
||||
$where->add('p.customer = :customer');
|
||||
@@ -343,6 +346,11 @@ class ActivityRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
// this will make sure, that we do not accidentally create results with multiple rows
|
||||
// => which would result in a wrong LIMIT / pagination results
|
||||
// the second group by is needed due to SQL standard (even though logically not really required for this query)
|
||||
$qb->addGroupBy('a.id')->addGroupBy($orderBy);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
@@ -352,6 +360,7 @@ class ActivityRepository extends EntityRepository
|
||||
$qb
|
||||
->resetDQLPart('select')
|
||||
->resetDQLPart('orderBy')
|
||||
->resetDQLPart('groupBy')
|
||||
->select($qb->expr()->countDistinct('a.id'))
|
||||
;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerComment;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
@@ -208,9 +209,13 @@ class CustomerRepository extends EntityRepository
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('c')
|
||||
$qb
|
||||
->select('c')
|
||||
->from(Customer::class, 'c')
|
||||
->orderBy('c.' . $query->getOrderBy(), $query->getOrder());
|
||||
;
|
||||
|
||||
$orderBy = 'c.' . $query->getOrderBy();
|
||||
$qb->orderBy($orderBy, $query->getOrder());
|
||||
|
||||
if (CustomerQuery::SHOW_VISIBLE == $query->getVisibility()) {
|
||||
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
|
||||
@@ -260,6 +265,11 @@ class CustomerRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
// this will make sure, that we do not accidentally create results with multiple rows
|
||||
// => which would result in a wrong LIMIT / pagination results
|
||||
// the second group by is needed due to SQL standard (even though logically not really required for this query)
|
||||
$qb->addGroupBy('c.id')->addGroupBy($orderBy);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
@@ -278,6 +288,7 @@ class CustomerRepository extends EntityRepository
|
||||
$qb
|
||||
->resetDQLPart('select')
|
||||
->resetDQLPart('orderBy')
|
||||
->resetDQLPart('groupBy')
|
||||
->select($qb->expr()->countDistinct('c.id'))
|
||||
;
|
||||
|
||||
@@ -336,4 +347,33 @@ class CustomerRepository extends EntityRepository
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
public function getComments(Customer $customer): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb
|
||||
->select('comments')
|
||||
->from(CustomerComment::class, 'comments')
|
||||
->andWhere($qb->expr()->eq('comments.customer', ':customer'))
|
||||
->addOrderBy('comments.pinned', 'DESC')
|
||||
->addOrderBy('comments.createdAt', 'DESC')
|
||||
->setParameter('customer', $customer)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function saveComment(CustomerComment $comment)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($comment);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteComment(CustomerComment $comment)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->remove($comment);
|
||||
$entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\ProjectComment;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Model\ProjectStatistic;
|
||||
@@ -351,6 +352,11 @@ class ProjectRepository extends EntityRepository
|
||||
}
|
||||
}
|
||||
|
||||
// this will make sure, that we do not accidentally create results with multiple rows
|
||||
// => which would result in a wrong LIMIT / pagination results
|
||||
// the second group by is needed due to SQL standard (even though logically not really required for this query)
|
||||
$qb->addGroupBy('p.id')->addGroupBy($orderBy);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
@@ -360,6 +366,7 @@ class ProjectRepository extends EntityRepository
|
||||
$qb
|
||||
->resetDQLPart('select')
|
||||
->resetDQLPart('orderBy')
|
||||
->resetDQLPart('groupBy')
|
||||
->select($qb->expr()->countDistinct('p.id'))
|
||||
;
|
||||
|
||||
@@ -438,4 +445,33 @@ class ProjectRepository extends EntityRepository
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
public function getComments(Project $project): array
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb
|
||||
->select('comments')
|
||||
->from(ProjectComment::class, 'comments')
|
||||
->andWhere($qb->expr()->eq('comments.project', ':project'))
|
||||
->addOrderBy('comments.pinned', 'DESC')
|
||||
->addOrderBy('comments.createdAt', 'DESC')
|
||||
->setParameter('project', $project)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function saveComment(ProjectComment $comment)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($comment);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteComment(ProjectComment $comment)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->remove($comment);
|
||||
$entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ class ActivityQuery extends ProjectQuery
|
||||
* @var bool
|
||||
*/
|
||||
private $globalsOnly = false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $excludeGlobals = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -54,6 +58,18 @@ class ActivityQuery extends ProjectQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isExcludeGlobals(): bool
|
||||
{
|
||||
return (bool) $this->excludeGlobals;
|
||||
}
|
||||
|
||||
public function setExcludeGlobals(bool $excludeGlobals): self
|
||||
{
|
||||
$this->excludeGlobals = (bool) $excludeGlobals;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project|int|null
|
||||
*/
|
||||
|
||||
@@ -82,6 +82,7 @@ class DateExtensions extends AbstractExtension
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dateShort($date)
|
||||
{
|
||||
@@ -99,6 +100,7 @@ class DateExtensions extends AbstractExtension
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dateTime($date)
|
||||
{
|
||||
@@ -110,14 +112,16 @@ class DateExtensions extends AbstractExtension
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
return date_format($date, $this->dateTimeFormat);
|
||||
return $date->format($this->dateTimeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
* @param bool $userTimezone
|
||||
* @return bool|false|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dateTimeFull($date)
|
||||
public function dateTimeFull($date, bool $userTimezone = true)
|
||||
{
|
||||
if (null === $this->dateTimeTypeFormat) {
|
||||
$this->dateTimeTypeFormat = $this->localeSettings->getDateTimeTypeFormat();
|
||||
@@ -127,11 +131,17 @@ class DateExtensions extends AbstractExtension
|
||||
$date = new DateTime($date);
|
||||
}
|
||||
|
||||
$timezone = date_default_timezone_get();
|
||||
|
||||
if (!$userTimezone) {
|
||||
$timezone = $date->getTimezone()->getName();
|
||||
}
|
||||
|
||||
$formatter = new \IntlDateFormatter(
|
||||
$this->localeSettings->getLocale(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
date_default_timezone_get(),
|
||||
$timezone,
|
||||
\IntlDateFormatter::GREGORIAN,
|
||||
$this->dateTimeTypeFormat
|
||||
);
|
||||
@@ -143,6 +153,7 @@ class DateExtensions extends AbstractExtension
|
||||
* @param DateTime|string $date
|
||||
* @param string $format
|
||||
* @return false|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dateFormat($date, string $format)
|
||||
{
|
||||
@@ -156,6 +167,7 @@ class DateExtensions extends AbstractExtension
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function time($date)
|
||||
{
|
||||
|
||||
@@ -40,12 +40,14 @@ final class IconExtension extends AbstractExtension
|
||||
'edit' => 'far fa-edit',
|
||||
'end' => 'fas fa-stopwatch',
|
||||
'export' => 'fas fa-file-export',
|
||||
'fax' => 'fas fa-fax',
|
||||
'filter' => 'fas fa-filter',
|
||||
'help' => 'far fa-question-circle',
|
||||
'home' => 'fas fa-home',
|
||||
'invoice' => 'fas fa-file-invoice-dollar',
|
||||
'invoice-template' => 'fas fa-file-signature',
|
||||
'list' => 'fas fa-list',
|
||||
'locked' => 'fas fa-lock',
|
||||
'logout' => 'fas fa-sign-out-alt',
|
||||
'mail' => 'fas fa-envelope-open',
|
||||
'mail-sent' => 'fas fa-paper-plane',
|
||||
@@ -55,6 +57,7 @@ final class IconExtension extends AbstractExtension
|
||||
'ods' => 'fas fa-table',
|
||||
'off' => 'fas fa-toggle-off',
|
||||
'on' => 'fas fa-toggle-on',
|
||||
'pin' => 'fas fa-thumbtack',
|
||||
'pdf' => 'fas fa-file-pdf',
|
||||
'pause' => 'fas fa-pause',
|
||||
'pause-small' => 'far fa-pause-circle',
|
||||
|
||||
@@ -15,9 +15,9 @@ use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* A twig extension to handle markdown parser.
|
||||
* A twig extension to handle markdown content.
|
||||
*/
|
||||
class MarkdownExtension extends AbstractExtension
|
||||
final class MarkdownExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var Markdown
|
||||
@@ -26,10 +26,9 @@ class MarkdownExtension extends AbstractExtension
|
||||
/**
|
||||
* @var TimesheetConfiguration
|
||||
*/
|
||||
protected $configuration;
|
||||
private $configuration;
|
||||
|
||||
/**
|
||||
* MarkdownExtension constructor.
|
||||
* @param Markdown $parser
|
||||
*/
|
||||
public function __construct(Markdown $parser, TimesheetConfiguration $configuration)
|
||||
@@ -46,10 +45,36 @@ class MarkdownExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
|
||||
new TwigFilter('desc2html', [$this, 'timesheetContent'], ['is_safe' => ['html']]),
|
||||
new TwigFilter('comment2html', [$this, 'timesheetContent'], ['is_safe' => ['html']]),
|
||||
new TwigFilter('comment2html', [$this, 'commentContent'], ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the entities comment (customer, project, activity ...) into HTML.
|
||||
*
|
||||
* @param string $content
|
||||
* @param bool $fullLength
|
||||
* @return string
|
||||
*/
|
||||
public function commentContent(?string $content, bool $fullLength = false): string
|
||||
{
|
||||
if (empty($content)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$fullLength && strlen($content) > 101) {
|
||||
$content = trim(substr($content, 0, 100)) . ' …';
|
||||
}
|
||||
|
||||
if ($this->configuration->isMarkdownEnabled()) {
|
||||
$content = $this->markdown->toHtml($content, false);
|
||||
} elseif ($fullLength) {
|
||||
$content = '<p>' . nl2br($content) . '</p>';
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the timesheet description content into HTML.
|
||||
*
|
||||
|
||||
@@ -12,19 +12,18 @@ namespace App\Utils;
|
||||
/**
|
||||
* A simple class to parse markdown syntax and return HTML.
|
||||
*/
|
||||
class Markdown
|
||||
final class Markdown
|
||||
{
|
||||
/**
|
||||
* @var ParsedownExtension
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Markdown constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = new ParsedownExtension();
|
||||
$this->parser->setUrlsLinked(true);
|
||||
$this->parser->setBreaksEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,8 +93,12 @@ class ActivityVoter extends AbstractVoter
|
||||
}
|
||||
}
|
||||
|
||||
if (null === ($customer = $project->getCustomer())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Team $team */
|
||||
foreach ($project->getCustomer()->getTeams() as $team) {
|
||||
foreach ($customer->getTeams() as $team) {
|
||||
if ($hasTeamleadPermission && $user->isTeamleadOf($team)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,25 +15,22 @@ use App\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
/**
|
||||
* A voter to check permissions on Customers.
|
||||
* A voter to check authorization on Customers.
|
||||
*/
|
||||
class CustomerVoter extends AbstractVoter
|
||||
{
|
||||
public const VIEW = 'view';
|
||||
public const EDIT = 'edit';
|
||||
public const BUDGET = 'budget';
|
||||
public const DELETE = 'delete';
|
||||
public const PERMISSIONS = 'permissions';
|
||||
|
||||
/**
|
||||
* support rules based on the given $subject (here: Customer)
|
||||
* supported attributes/rules based on the given customer
|
||||
*/
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
self::VIEW,
|
||||
self::EDIT,
|
||||
self::BUDGET,
|
||||
self::DELETE,
|
||||
self::PERMISSIONS,
|
||||
'view',
|
||||
'create',
|
||||
'edit',
|
||||
'budget',
|
||||
'delete',
|
||||
'permissions',
|
||||
'comments',
|
||||
'details',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -72,6 +69,11 @@ class CustomerVoter extends AbstractVoter
|
||||
return true;
|
||||
}
|
||||
|
||||
// those cannot be assigned to teams
|
||||
if (in_array($attribute, ['create', 'delete'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hasTeamleadPermission = $this->hasRolePermission($user, $attribute . '_teamlead_customer');
|
||||
$hasTeamPermission = $this->hasRolePermission($user, $attribute . '_team_customer');
|
||||
|
||||
|
||||
@@ -19,21 +19,17 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
*/
|
||||
class ProjectVoter extends AbstractVoter
|
||||
{
|
||||
public const VIEW = 'view';
|
||||
public const EDIT = 'edit';
|
||||
public const BUDGET = 'budget';
|
||||
public const DELETE = 'delete';
|
||||
public const PERMISSIONS = 'permissions';
|
||||
|
||||
/**
|
||||
* support rules based on the given $subject (here: Project)
|
||||
* support rules based on the given project
|
||||
*/
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
self::VIEW,
|
||||
self::EDIT,
|
||||
self::BUDGET,
|
||||
self::DELETE,
|
||||
self::PERMISSIONS,
|
||||
'view',
|
||||
'edit',
|
||||
'budget',
|
||||
'delete',
|
||||
'permissions',
|
||||
'comments',
|
||||
'details',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -72,6 +68,11 @@ class ProjectVoter extends AbstractVoter
|
||||
return true;
|
||||
}
|
||||
|
||||
// those cannot be assigned to teams
|
||||
if (in_array($attribute, ['create', 'delete'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hasTeamleadPermission = $this->hasRolePermission($user, $attribute . '_teamlead_project');
|
||||
$hasTeamPermission = $this->hasRolePermission($user, $attribute . '_team_project');
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class UserTeamProjects extends SimpleWidget implements AuthorizedWidget
|
||||
$options = parent::getOptions($options);
|
||||
|
||||
if (empty($options['id'])) {
|
||||
$options['id'] = uniqid('UserTeamProjects_');
|
||||
$options['id'] = 'WidgetUserTeamProjects';
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
@@ -17,7 +17,7 @@ class UserTeams extends SimpleWidget implements AuthorizedWidget
|
||||
public function __construct(CurrentUser $user)
|
||||
{
|
||||
$this->setId('UserTeams');
|
||||
$this->setTitle('label.teams');
|
||||
$this->setTitle('label.my_teams');
|
||||
$this->setOptions([
|
||||
'user' => $user->getUser(),
|
||||
'id' => '',
|
||||
@@ -29,7 +29,7 @@ class UserTeams extends SimpleWidget implements AuthorizedWidget
|
||||
$options = parent::getOptions($options);
|
||||
|
||||
if (empty($options['id'])) {
|
||||
$options['id'] = uniqid('UserTeams_');
|
||||
$options['id'] = 'WidgetUserTeams';
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
Reference in New Issue
Block a user