diff --git a/src/Controller/CompanyController.php b/src/Controller/CompanyController.php new file mode 100644 index 0000000..508440f --- /dev/null +++ b/src/Controller/CompanyController.php @@ -0,0 +1,182 @@ +navLinks = NavList::LIST; + } + + #[Route('/company', name: 'app_company')] + public function editCompanyInfo( + #[CurrentUser()] User $user, + Request $request, + SluggerInterface $slugger + ): Response { + $this->navLinks['company_nav'] = NavList::PRESENT_LINK; + $this->msgs = Libs::getMessages($user, $this->entityManager); + $company = $user->getCompany(); + + $form = $this->createForm(InternalCompanyFormType::class, $company); + + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) { + /** @var Company $company */ + $company = $form->getData(); + + if ($form->get('companyLogo')->getData()) { + $file = $form['companyLogo']->getData(); + $destination = $this->getParameter('kernel.project_dir').'/public/uploads/company/'; + $originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); + $newFilename = $slugger->slug($originalFilename).'-'.uniqid().'.'.$file->guessExtension(); + $file->move( + $destination, + $newFilename + ); + + $company->setCompanyLogo($newFilename); + } + + $this->entityManager->flush(); + return $this->redirectToRoute('app_admin_dashboard'); + } + + return $this->render( + 'internal/admin/company/company-info.html.twig', + array_merge( + $this->navLinks, + [ + 'form' => $form, + 'company' => $company, + 'breadcrumbs' => [ + new Breadcrumb($this->generateUrl('app_admin_dashboard'), "Admin Dashboard"), + ], + 'msgs' => $this->msgs, + ] + ) + ); + } + + #[Route('/docs/list', name: 'app_list_documents')] + public function listDocs(#[CurrentUser()] User $user): Response + { + $this->navLinks['company_nav'] = NavList::PRESENT_LINK; + + $this->msgs = Libs::getMessages($user, $this->entityManager); + $companyDocs = $this->entityManager->getRepository(CompanyDocument::class)->findBy(['company' => $user->getCompany()], ['title' => 'ASC']); + + return $this->render( + 'internal/admin/company/docs/list-documents.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [], + 'notifications' => $this->msgs, + 'docs' => $companyDocs, + ] + ) + ); + } + + #[Route('/docs/add', name: 'app_add_doc')] + public function addCompanyDocument(Request $request, #[CurrentUser()] User $user): Response + { + $this->navLinks['company_nav'] = NavList::PRESENT_LINK; + $this->msgs = Libs::getMessages($user, $this->entityManager); + + $form = $this->createForm(CompanyDocumentFormType::class); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + /** @var CompanyDocument $doc */ + $doc = $form->getData(); + + $doc->setCompany($user->getCompany()); + $doc->setUpdated(new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE']))); + + $this->entityManager->persist($doc); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_list_documents'); + } + + return $this->render( + 'internal/admin/company/docs/add-document.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [], + 'notifications' => $this->msgs, + 'form' => $form, + ] + ) + ); + } + + #[Route('/docs/edit/{docId}', name: 'app_edit_doc')] + public function editCompanyDocument(string $docId, Request $request, #[CurrentUser()] User $user): Response + { + $companyDoc = $this->entityManager->getRepository(CompanyDocument::class)->find($docId); + + $this->navLinks['company_nav'] = NavList::PRESENT_LINK; + $this->msgs = Libs::getMessages($user, $this->entityManager); + + $form = $this->createForm(CompanyDocumentFormType::class, $companyDoc); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + /** @var CompanyDocument $doc */ + $doc = $form->getData(); + + $doc->setUpdated(new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE']))); + + $this->entityManager->persist($doc); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_list_documents'); + } + + return $this->render( + 'internal/admin/company/docs/edit-document.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [], + 'notifications' => $this->msgs, + 'form' => $form, + 'doc' => $companyDoc, + 'docText' => str_replace("\r\n", "", $companyDoc->getText()) + ] + ) + ); + } +} \ No newline at end of file diff --git a/src/Form/CompanyFormType.php b/src/Form/CompanyFormType.php index d16fa9d..58f36c5 100644 --- a/src/Form/CompanyFormType.php +++ b/src/Form/CompanyFormType.php @@ -5,6 +5,7 @@ namespace App\Form; use App\DataTransferObject\CompanyDetailsDto; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; @@ -41,8 +42,9 @@ class CompanyFormType extends AbstractType ]) ->add('email', EmailType::class, [ 'required' => true - ]) + ]) ->add('url', UrlType::class) + ->add('companyLogo', FileType::class) ; }