add: CompanyController

Add company directory method
This commit is contained in:
Ryan Prather 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 DateTimeZone;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser; use Symfony\Component\Security\Http\Attribute\CurrentUser;
use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Security\Http\Attribute\IsGranted;
@ -32,6 +34,7 @@ class CompanyController extends AbstractController
} }
#[Route('/company', name: 'app_company')] #[Route('/company', name: 'app_company')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function editCompanyInfo( public function editCompanyInfo(
#[CurrentUser()] User $user, #[CurrentUser()] User $user,
Request $request, 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')] #[Route('/docs/list', name: 'app_list_documents')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function listDocs(#[CurrentUser()] User $user): Response public function listDocs(#[CurrentUser()] User $user): Response
{ {
$this->navLinks['company_nav'] = NavList::PRESENT_LINK; $this->navLinks['company_nav'] = NavList::PRESENT_LINK;
@ -102,6 +152,7 @@ class CompanyController extends AbstractController
} }
#[Route('/docs/add', name: 'app_add_doc')] #[Route('/docs/add', name: 'app_add_doc')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN")'))]
public function addCompanyDocument(Request $request, #[CurrentUser()] User $user): Response public function addCompanyDocument(Request $request, #[CurrentUser()] User $user): Response
{ {
$this->navLinks['company_nav'] = NavList::PRESENT_LINK; $this->navLinks['company_nav'] = NavList::PRESENT_LINK;
@ -137,6 +188,7 @@ class CompanyController extends AbstractController
} }
#[Route('/docs/edit/{docId}', name: 'app_edit_doc')] #[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 public function editCompanyDocument(string $docId, Request $request, #[CurrentUser()] User $user): Response
{ {
$companyDoc = $this->entityManager->getRepository(CompanyDocument::class)->find($docId); $companyDoc = $this->entityManager->getRepository(CompanyDocument::class)->find($docId);

View File

@ -0,0 +1,69 @@
{% extends 'base.html.twig' %}
{% block body %}
{{ block('nav', 'internal/libs/nav.html.twig') }}
<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
{{ block('topnav', 'internal/libs/top-nav.html.twig') }}
<div class="container-fluid py-2">
<div class="row">
<div class="col-12">
<div class="card my-4">
<div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">
<div class="d-flex justify-content-between bg-gradient-dark shadow-dark border-radius-lg pt-4 pb-3 ps-3 p-2">
<div>
<h6 class="text-white text-capitalize ps-3">Company Directory</h6>
</div>
</div>
</div>
<div class="card-body px-0 pb-2">
<div class="table-responsive p-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Name</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Phone</th>
<th class="text-secondary opacity-7"></th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>
<div class='d-flex px-2 py-1'>
<div>
{% if user.imageName %}<img src='{{ user_image_path }}/{{ user.imageName }}' class='avatar avatar-sm me-3 border-radius-large' alt='{{ user.name }}'>{% endif %}
</div>
<div class='d-flex flex-column justify-content-center{% if not user.active %} text-muted {% endif %}'>
<h6 class='mb-0 text-small'>{{ user.name }}</h6>
<p class='text-xs text-secondary mb-0'>
<a href='mailto:{{ user.email }}'>{{ user.email }}</a>
</p>
</div>
</div>
</td>
<td>
{% if user.workPhone %}<a href='tel:{{ user.workPhone }}'>{{ user.getFormattedPhone() }}</a>{% endif %}
</td>
<td class='align-middle text-center text-xs'>
</td>
<td class='align-middle text-center text-xs'>
</td>
<td class='align-middle'>
<a href='{{ path('app_download_user_vcard', {id: user.id}) }}' class='text-secondary text-xs' tooltip="Download vCard">
<i class='material-symbols-rounded opacity-5'>badge</i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</main>
{% endblock %}