<?php
namespace App\Controller\Kernel;
use App\Entity\Kernel\KernelFile;
use App\Entity\Kernel\Folder;
use App\Entity\Kernel\Mail;
use App\Entity\CRM\Client;
use App\Entity\Finance\Product;
use App\Entity\Finance\Invoice;
use App\Entity\Finance\CreditNote;
use App\Entity\HR\Employee;
use App\Entity\CMS\Website;
use App\Form\Kernel\KernelFileType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\Kernel\DMSService;
/**
* @Route("/{_locale}/kernelfile")
*/
class KernelFileController extends AbstractController
{
/**
* @Route("/", name="kernel_file_index", methods={"GET"})
*/
public function index(): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute);
$kernelFiles = $this->getDoctrine()
->getRepository(KernelFile::class)
->findBy(array('state' => 0));
return $this->render('kernel/kernel_file/index.html.twig', [
'kernel_files' => $kernelFiles,
]);
}
/**
* @Route("/showarchived", name="kernel_file_showarchived", methods={"GET"})
*/
public function showarchived(): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute);
$kernelFiles = $this->getDoctrine()
->getRepository(KernelFile::class)
->findBy(array('state' => 1));
return $this->render('kernel/kernel_file/archived.html.twig', [
'kernel_files' => $kernelFiles,
]);
}
/**
* @Route("/showdeleted", name="kernel_file_showdeleted", methods={"GET"})
*/
public function showdeleted(): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute);
$kernelFiles = $this->getDoctrine()
->getRepository(KernelFile::class)
->findBy(array('state' => 2));
return $this->render('kernel/kernel_file/deleted.html.twig', [
'kernel_files' => $kernelFiles,
]);
}
/**
* @Route("/{folder}/new/{type}/{entityid}", name="kernel_file_new", methods={"POST"})
*/
public function new($folder, int $type = 0, int $entityid = 0, Request $request, DMSService $dmsservice): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute);
$folder = $this->getDoctrine()->getRepository(Folder::class)->find($folder);
$content = $request->files->get('file');
if (!empty($content))
{
$file = $dmsservice->uploadfile($content,$folder);
}
if ($type == 1)
{
return $this->redirect($this->generateUrl('client_show' , array('id'=>$entityid)));
}
if ($type == 2)
{
return $this->redirect($this->generateUrl('product_show' , array('id'=>$entityid)));
}
if($type == 3)
{
return $this->redirect($this->generateUrl('invoice_show', array('id'=>$entityid)));
}
if($type == 4)
{
return $this->redirect($this->generateUrl('employee_showdocuments', array('id'=>$entityid)));
}
if($type == 5)
{
//no option
}
if($type == 6)
{
return $this->redirect($this->generateUrl('website_show', array('id'=>$entityid)));
}
if($type == 7)
{
return $this->redirect($this->generateUrl('employee_sharedfiles'));
}
if($type == 8)
{
return $this->redirect($this->generateUrl('app_credit_note_show', array('id'=>$entityid)));
}
return $this->redirect($this->generateUrl('folder_show' , array('id'=>$folder->getId(), 'type'=>$type, 'entityid' => $entityid)));
}
/**
* @Route("/{id}/show/{type}/{entityid}", name="kernel_file_show", methods={"GET"})
*/
public function show(KernelFile $kernelFile, int $type = 0, int $entityid = 0, DMSService $dmsservice): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
//$dmsservice->testExcel("test", $kernelFile->getFolder());
//$dmsservice->readExcel($kernelFile);
$entityManager = $this->getDoctrine()->getManager();
$entity = null;
if ($type == 1)
{
$entity = $entityManager->getRepository(Client::class)->findOneById($entityid);
}
if ($type == 2)
{
$entity = $entityManager->getRepository(Product::class)->findOneById($entityid);
}
if($type == 3){
$entity = $entityManager->getRepository(Invoice::class)->findOneById($entityid);
}
if($type == 4)
{
$entity = $entityManager->getRepository(Employee::class)->findOneById($entityid);
}
if($type == 5)
{
$entity = $entityManager->getRepository(Mail::class)->findOneById($entityid);
}
if($type == 6)
{
$entity = $entityManager->getRepository(Website::class)->findOneById($entityid);
}
if($type == 8)
{
$entity = $entityManager->getRepository(CreditNote::class)->findOneById($entityid);
}
return $this->render('kernel/kernel_file/show.html.twig', [
'kernel_file' => $kernelFile,
'type' => $type,
'entityid' => $entityid,
'entity' => $entity
]);
}
/**
* @Route("/{id}/audit", name="kernel_file_showaudit", methods={"GET"})
*/
public function showaudit(KernelFile $kernelFile): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
return $this->render('kernel/kernel_file/showaudit.html.twig', [
'kernel_file' => $kernelFile,
]);
}
/**
* @Route("/{id}/archive/{type}/{entityid}", name="kernel_file_archive", methods={"GET"})
*/
public function archive(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
$entityManager = $this->getDoctrine()->getManager();
$kernelFile->setState(1);
$entityManager->persist($kernelFile);
$entityManager->flush();
return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
}
/**
* @Route("/{id}/restore/{type}/{entityid}", name="kernel_file_restore", methods={"GET"})
*/
public function restore(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
$entityManager = $this->getDoctrine()->getManager();
$kernelFile->setState(0);
$entityManager->persist($kernelFile);
$entityManager->flush();
return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
}
/**
* @Route("/{id}/delete/{type}/{entityid}", name="kernel_file_logicaldelete", methods={"GET"})
*/
public function logicaldelete(KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
$entityManager = $this->getDoctrine()->getManager();
$kernelFile->setState(2);
$entityManager->persist($kernelFile);
$entityManager->flush();
if ($type == 1)
{
return $this->redirect($this->generateUrl('client_show' , array('id'=>$entityid)));
}
if ($type == 2)
{
return $this->redirect($this->generateUrl('product_show' , array('id'=>$entityid)));
}
if ($type == 3)
{
return $this->redirect($this->generateUrl('invoice_show', array('id'=>$entityid)));
}
if ($type == 5)
{
return $this->redirect($this->generateUrl('employee_showdocuments', array('id'=>$entityid)));
}
if($type == 6)
{
return $this->redirect($this->generateUrl('website_show', array('id'=>$entityid)));
}
if($type == 7)
{
return $this->redirect($this->generateUrl('employee_sharedfiles'));
}
if($type == 8)
{
return $this->redirect($this->generateUrl('app_credit_note_show', array('id'=>$entityid)));
}
return $this->redirect($this->generateUrl('folder_show' , array('id'=>$folder->getId(), 'type'=>$type, 'entityid' => $entityid)));
}
/**
* @Route("/{id}/edit/{type}/{entityid}", name="kernel_file_edit", methods={"GET","POST"})
*/
public function edit(Request $request, KernelFile $kernelFile, int $type = 0, int $entityid = 0): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
$form = $this->createForm(KernelFileType::class, $kernelFile,
['action' => $this->generateUrl('kernel_file_edit', array('id' => $kernelFile->getId(), 'type' => $type, 'entityid' => $entityid)),
'attr' => ['id' => $this->generateUrl('kernel_file_edit', array('id' => $kernelFile->getId(), 'type' => $type, 'entityid' => $entityid))]]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('kernel_file_show', array('id' => $kernelFile->getId(), 'type'=>$type, 'entityid' => $entityid));
}
$entityManager = $this->getDoctrine()->getManager();
$entity = null;
if ($type == 1)
{
$entity = $entityManager->getRepository(Client::class)->findOneById($entityid);
}
if ($type == 2)
{
$entity = $entityManager->getRepository(Product::class)->findOneById($entityid);
}
if($type == 3)
{
$entity = $entityManager->getRepository(Invoice::class)->findOneById($entityid);
}
if($type == 4)
{
$entity = $entityManager->getRepository(Employee::class)->findOneById($entityid);
}
if($type == 6)
{
$entity = $entityManager->getRepository(Website::class)->findOneById($entityid);
}
if($type == 8)
{
$entity = $entityManager->getRepository(CreditNote::class)->findOneById($entityid);
}
return $this->render('kernel/kernel_file/edit.html.twig', [
'kernel_file' => $kernelFile,
'form' => $form->createView(),
'type' => $type,
'entityid' => $entityid,
'entity' => $entity
]);
}
/**
* @Route("/{id}", name="kernel_file_delete", methods={"DELETE"})
*/
public function delete(Request $request, KernelFile $kernelFile): Response
{
$classname = explode("\\", get_class($this));
$arraysize = count($classname);
$attribute = str_replace("Controller", "", $classname[$arraysize-1]) . ":" . str_replace("Action", "", __FUNCTION__);
$this->denyAccessUnlessGranted($attribute, $kernelFile);
if ($this->isCsrfTokenValid('delete'.$kernelFile->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($kernelFile);
$entityManager->flush();
}
return $this->redirectToRoute('kernel_file_index');
}
}