add: CompanyController

Add company directory method
This commit is contained in:
2025-01-21 14:11:40 -05:00
parent 2af4b8e04e
commit caeb15f05b
2 changed files with 121 additions and 0 deletions

View File

@ -14,8 +14,10 @@ use DateTime;
use DateTimeZone;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
use Symfony\Component\Security\Http\Attribute\IsGranted;
@ -32,6 +34,7 @@ class CompanyController extends AbstractController
}
#[Route('/company', name: 'app_company')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function editCompanyInfo(
#[CurrentUser()] User $user,
Request $request,
@ -81,7 +84,54 @@ class CompanyController extends AbstractController
);
}
#[Route('/company/directory', name: 'app_company_directory')]
public function companyDirectory(#[CurrentUser()] User $user): Response
{
$this->navLinks['company_nav'] = NavList::PRESENT_LINK;
$users = $this->entityManager->getRepository(User::class)->findBy(['company' => $user->getCompany()], ['name' => 'ASC']);
return $this->render(
'internal/admin/company/directory.html.twig',
array_merge(
$this->navLinks,
[
'breadcrumbs' => [
new Breadcrumb(
($this->isGranted('ROLE_ADMIN') ? $this->generateUrl('app_admin_dashboard') : $this->generateUrl('app_dashboard')),
($this->isGranted('ROLE_ADMIN') ? "Admin Dashboard" : "Dashboard")
),
],
'users' => $users,
'notifications' => Libs::getMessages($user, $this->entityManager),
]
)
);
}
#[Route('/user/download-vcard/{id}', name: 'app_download_user_vcard')]
public function downloadUserVcard(#[CurrentUser()] User $user, string $id): Response
{
$coworker = $this->entityManager->getRepository(User::class)->find($id);
if (!$coworker) {
throw new NotFoundHttpException('Coworker not found');
}
if ($coworker->getCompany() !== $user->getCompany()) {
throw new NotFoundHttpException('Coworker not found');
}
return new Response($coworker->generateVCard(), 200, [
'Content-Type' => 'text/vcf',
'Content-Disposition' => 'attachment; filename="' . str_replace(' ', '', $coworker->getName()) . '.vcf"',
'Content-Length' => strlen($coworker->generateVCard()),
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Expires' => '0',
'Pragma' => 'public',
'Content-Transfer-Encoding' => 'binary'
]);
}
#[Route('/docs/list', name: 'app_list_documents')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function listDocs(#[CurrentUser()] User $user): Response
{
$this->navLinks['company_nav'] = NavList::PRESENT_LINK;
@ -102,6 +152,7 @@ class CompanyController extends AbstractController
}
#[Route('/docs/add', name: 'app_add_doc')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function addCompanyDocument(Request $request, #[CurrentUser()] User $user): Response
{
$this->navLinks['company_nav'] = NavList::PRESENT_LINK;
@ -137,6 +188,7 @@ class CompanyController extends AbstractController
}
#[Route('/docs/edit/{docId}', name: 'app_edit_doc')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function editCompanyDocument(string $docId, Request $request, #[CurrentUser()] User $user): Response
{
$companyDoc = $this->entityManager->getRepository(CompanyDocument::class)->find($docId);