<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\DateTime;
use App\Utils\Constants;
use App\Utils\Breadcrumbs;
use App\Utils\Utils;
use App\Entity\Setting;
use App\Entity\WorkCollection;
use App\Entity\Organisation;
use App\Entity\SelfAssessment;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
/**
*
* @IsGranted("ROLE_COMPANY_ADMIN")
*/
class GMCollectionsController extends AbstractController
{
/**
* @Route("/gm/collections/{orgId}/{showArchived}", name="gm-collections", defaults={"orgId" = 0, "showArchived" = Constants::ACTIVE})
* @IsGranted("ROLE_COMPANY_ADMIN")
*/
public function index($orgId = 0, $showArchived = Constants::ACTIVE, Request $request)
{
// $hasAccess = $this->isGranted('ROLE_COMPANY_ADMIN');
// $this->denyAccessUnlessGranted('ROLE_COMPANY_ADMIN');
$user = $this->getUser();
if($user->getOrganisations()->count() <= 0) {
$this->addFlash('error','Organisation not found.');
return $this->redirectToRoute('error');
}
$orgId = $user->getOrganisations()->first()->getId();
$org = $user->getOrganisations()->first();
//------------------
// collections
//------------------
$repo = $this->getDoctrine()->getRepository(WorkCollection::class);
if($showArchived == Constants::INACTIVE) {
$collections = $repo->findBy(
['status' => Constants::INACTIVE, 'organisation' => $orgId],
['date_updated' => 'DESC']
);
} else {
$collections = $repo->findBy(
['status' => Constants::ACTIVE, 'organisation' => $orgId],
['date_updated' => 'DESC']
);
}
$constants = new Constants();
$firstBreadcrumb = Breadcrumbs::getFirstBreadcrumb($this->getDoctrine(), $user, $request);
$backLinkLabel = "Collections";
$backLink = "/gm/collections";
$breadcrumbs[$firstBreadcrumb] = "/";
$breadcrumbs[$backLinkLabel] = $backLink;
$calink = Utils::buildCALink($this, Constants::CA_LINK_COLLECTIONS);
return $this->render('gm/collections.html.twig', array(
'page_heading' => $backLinkLabel,
'constants' => $constants,
'breadcrumbs' => $breadcrumbs,
'user' => $user,
'collections' => $collections,
'backlink' => $backLink,
'backlink_label' => $backLinkLabel,
'calink' => $calink,
));
}
}