src/Controller/GMCollectionsController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Validator\Constraints\DateTime;
  10. use App\Utils\Constants;
  11. use App\Utils\Breadcrumbs;
  12. use App\Utils\Utils;
  13. use App\Entity\Setting;
  14. use App\Entity\WorkCollection;
  15. use App\Entity\Organisation;
  16. use App\Entity\SelfAssessment;
  17. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  18. /**
  19. *
  20. * @IsGranted("ROLE_COMPANY_ADMIN")
  21. */
  22. class GMCollectionsController extends AbstractController
  23. {
  24. /**
  25. * @Route("/gm/collections/{orgId}/{showArchived}", name="gm-collections", defaults={"orgId" = 0, "showArchived" = Constants::ACTIVE})
  26. * @IsGranted("ROLE_COMPANY_ADMIN")
  27. */
  28. public function index($orgId = 0, $showArchived = Constants::ACTIVE, Request $request)
  29. {
  30. // $hasAccess = $this->isGranted('ROLE_COMPANY_ADMIN');
  31. // $this->denyAccessUnlessGranted('ROLE_COMPANY_ADMIN');
  32. $user = $this->getUser();
  33. if($user->getOrganisations()->count() <= 0) {
  34. $this->addFlash('error','Organisation not found.');
  35. return $this->redirectToRoute('error');
  36. }
  37. $orgId = $user->getOrganisations()->first()->getId();
  38. $org = $user->getOrganisations()->first();
  39. //------------------
  40. // collections
  41. //------------------
  42. $repo = $this->getDoctrine()->getRepository(WorkCollection::class);
  43. if($showArchived == Constants::INACTIVE) {
  44. $collections = $repo->findBy(
  45. ['status' => Constants::INACTIVE, 'organisation' => $orgId],
  46. ['date_updated' => 'DESC']
  47. );
  48. } else {
  49. $collections = $repo->findBy(
  50. ['status' => Constants::ACTIVE, 'organisation' => $orgId],
  51. ['date_updated' => 'DESC']
  52. );
  53. }
  54. $constants = new Constants();
  55. $firstBreadcrumb = Breadcrumbs::getFirstBreadcrumb($this->getDoctrine(), $user, $request);
  56. $backLinkLabel = "Collections";
  57. $backLink = "/gm/collections";
  58. $breadcrumbs[$firstBreadcrumb] = "/";
  59. $breadcrumbs[$backLinkLabel] = $backLink;
  60. $calink = Utils::buildCALink($this, Constants::CA_LINK_COLLECTIONS);
  61. return $this->render('gm/collections.html.twig', array(
  62. 'page_heading' => $backLinkLabel,
  63. 'constants' => $constants,
  64. 'breadcrumbs' => $breadcrumbs,
  65. 'user' => $user,
  66. 'collections' => $collections,
  67. 'backlink' => $backLink,
  68. 'backlink_label' => $backLinkLabel,
  69. 'calink' => $calink,
  70. ));
  71. }
  72. }