Loading module/Application/config/merged/agent.config.php +33 Changes for module/Application/config/merged/agent.config.php: 33 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Application; use Application\Controller\Agent\AgentController; use Application\Controller\Agent\AgentControllerFactory; use Application\Controller\AgentFichier\AgentFichierController; use Application\Controller\AgentFichier\AgentFichierControllerFactory; use Application\Form\Agent\AgentForm; use Application\Form\Agent\AgentFormFactory; use Application\Form\Agent\AgentHydrator; Loading Loading @@ -61,6 +63,16 @@ return [ AgentPrivileges::EDITER, ], ], [ 'controller' => AgentFichierController::class, 'action' => [ 'index', 'upload' ], 'privileges' => [ AgentPrivileges::AFFICHER, ], ], ], ], ], Loading @@ -78,6 +90,26 @@ return [ ], 'may_terminate' => true, 'child_routes' => [ 'fichiers' => [ 'type' => Segment::class, 'options' => [ 'route' => '/fichiers/:agent', 'defaults' => [ 'controller' => AgentFichierController::class, 'action' => 'index', ], ], ], 'upload-fichier' => [ 'type' => Segment::class, 'options' => [ 'route' => '/upload-fichier/:agent/:nature', 'defaults' => [ 'controller' => AgentFichierController::class, 'action' => 'upload', ], ], ], 'afficher' => [ 'type' => Segment::class, 'options' => [ Loading Loading @@ -153,6 +185,7 @@ return [ 'controllers' => [ 'factories' => [ AgentController::class => AgentControllerFactory::class, AgentFichierController::class => AgentFichierControllerFactory::class, ], ], 'form_elements' => [ Loading module/Application/config/module.config.php +1 −1 Changes for module/Application/config/module.config.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ return [ 'inline_scripts' => [ '100_' => 'js/jquery.ui.datepicker-fr.js', // '110_' => 'https://gest.unicaen.fr/public/bootstrap-select-1.9.4/dist/js/bootstrap-select.min.js', // '111_' => 'https://gest.unicaen.fr/public/bootstrap-confirmation-2.4.0/bootstrap-confirmation.min.js', '111_' => 'https://gest.unicaen.fr/public/bootstrap-confirmation-2.4.0/bootstrap-confirmation.min.js', '112_' => 'vendor/font-awesome-5.0.9/fontawesome-all.min.js', '120_' => 'vendor/bootstrap-select-1.13.2/dist/js/bootstrap-select.min.js', '124_' => 'vendor/vakata-jstree-3.3.4/dist/jstree.min.js', Loading module/Application/src/Application/Controller/AgentFichier/AgentFichierController.php +85 Changes for module/Application/src/Application/Controller/AgentFichier/AgentFichierController.php: 85 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Controller\AgentFichier; use Application\Service\Agent\AgentServiceAwareTrait; use Fichier\Entity\Db\Fichier; use Fichier\Entity\Db\Nature; use Fichier\Form\Upload\UploadFormAwareTrait; use Fichier\Service\Fichier\FichierServiceAwareTrait; use Fichier\Service\Nature\NatureServiceAwareTrait; use Zend\Form\Element\Select; use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class AgentFichierController extends AbstractActionController { use AgentServiceAwareTrait; use FichierServiceAwareTrait; use NatureServiceAwareTrait; use UploadFormAwareTrait; public function indexAction() { $agent = $this->getAgentService()->getRequestedAgent($this,'agent'); /** @var Fichier $cv */ $cv = $agent->fetchFile(Nature::CV); /** @var Fichier $motiv */ $motiv = $agent->fetchFile(Nature::MOTIV); /** @var Fichier[] $formations */ $formations = $agent->fetchFiles(Nature::FORMATION); return new ViewModel([ 'agent' => $agent, 'cv' => $cv, 'motiv' => $motiv, 'formations' => $formations, ]); } public function uploadAction() { $agent = $this->getAgentService()->getRequestedAgent($this,'agent'); $nature = $this->getNatureService()->getNatureByCode($this->params()->fromRoute('nature')); $fichier = new Fichier(); $form = $this->getUploadForm(); $form->setAttribute('action', $this->url()->fromRoute('agent/upload-fichier',['agent' => $agent->getId(), 'nature' => $nature->getCode()] , [], true)); $form->bind($fichier); if ($nature) { /** @var Select $select */ $select = $form->get('nature'); $select->setValueOptions([ $nature->getId() => $nature->getLibelle()]); } /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $file = current($request->getFiles()); if ($file['name'] != '') { $nature = $this->getNatureService()->getNature($data['nature']); $fichier = $this->getFichierService()->createFichierFromUpload($file, $nature); $agent->addFichier($fichier); $this->getAgentService()->update($agent); $this->redirect()->toRoute('agent/fichiers', ['agent' => $agent->getId()], [], true); } } $vm = new ViewModel(); $vm->setTemplate('application/default/default-form'); $vm->setVariables([ 'title' => 'Téléverserment d\'un fichier', 'form' => $form, ]); return $vm; } } No newline at end of file module/Application/src/Application/Controller/AgentFichier/AgentFichierControllerFactory.php +37 Changes for module/Application/src/Application/Controller/AgentFichier/AgentFichierControllerFactory.php: 37 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Controller\AgentFichier; use Application\Service\Agent\AgentService; use Fichier\Form\Upload\UploadForm; use Fichier\Service\Fichier\FichierService; use Fichier\Service\Nature\NatureService; use Zend\Mvc\Controller\ControllerManager; class AgentFichierControllerFactory { public function __invoke(ControllerManager $manager) { /** * @var AgentService $agentService * @var FichierService $fichierService * @var NatureService $natureService */ $agentService = $manager->getServiceLocator()->get(AgentService::class); $fichierService = $manager->getServiceLocator()->get(FichierService::class); $natureService = $manager->getServiceLocator()->get(NatureService::class); /** * @var UploadForm $uploadForm */ $uploadForm = $manager->getServiceLocator()->get('FormElementManager')->get(UploadForm::class); /** @var AgentFichierController $controller */ $controller = new AgentFichierController(); $controller->setAgentService($agentService); $controller->setFichierService($fichierService); $controller->setNatureService($natureService); $controller->setUploadForm($uploadForm); return $controller; } } No newline at end of file module/Application/src/Application/Entity/Db/Agent.php +63 Changes for module/Application/src/Application/Entity/Db/Agent.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,9 @@ namespace Application\Entity\Db; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Fichier\Entity\Db\Fichier; use UnicaenApp\Exception\RuntimeException; class Agent { Loading Loading @@ -36,6 +39,13 @@ class Agent { /** @var string */ private $missionsComplementaires; /** @var ArrayCollection */ private $fichiers; public function __construct() { $this->fichiers = new ArrayCollection(); } /** * @return int */ Loading Loading @@ -247,7 +257,60 @@ class Agent { return $this; } /** * @return Fichier[] */ public function getFichiers() { return $this->fichiers->toArray(); } /** * @param Fichier $fichier * @return Agent */ public function addFichier($fichier) { $this->fichiers->add($fichier); return $this; } /** * @param Fichier $fichier * @return Agent */ public function removeFichier($fichier) { $this->fichiers->removeElement($fichier); return $this; } /** * @param string $natureCode * @return Fichier */ public function fetchFile($natureCode) { $result = $this->fetchFiles($natureCode); $nb = count($result); if ($nb === 0) return null; if ($nb > 1) throw new RuntimeException("Plusieurs fichiers de nature [] trouvés."); return current($result); } /** * @param string $natureCode * @return Fichier[] */ public function fetchFiles($natureCode) { $result = []; /** @var Fichier $fichier */ foreach ($this->fichiers as $fichier) { if ($fichier->getNature()->getCode() === $natureCode) $result[] = $fichier; } return $result; } } No newline at end of file Loading
module/Application/config/merged/agent.config.php +33 Changes for module/Application/config/merged/agent.config.php: 33 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Application; use Application\Controller\Agent\AgentController; use Application\Controller\Agent\AgentControllerFactory; use Application\Controller\AgentFichier\AgentFichierController; use Application\Controller\AgentFichier\AgentFichierControllerFactory; use Application\Form\Agent\AgentForm; use Application\Form\Agent\AgentFormFactory; use Application\Form\Agent\AgentHydrator; Loading Loading @@ -61,6 +63,16 @@ return [ AgentPrivileges::EDITER, ], ], [ 'controller' => AgentFichierController::class, 'action' => [ 'index', 'upload' ], 'privileges' => [ AgentPrivileges::AFFICHER, ], ], ], ], ], Loading @@ -78,6 +90,26 @@ return [ ], 'may_terminate' => true, 'child_routes' => [ 'fichiers' => [ 'type' => Segment::class, 'options' => [ 'route' => '/fichiers/:agent', 'defaults' => [ 'controller' => AgentFichierController::class, 'action' => 'index', ], ], ], 'upload-fichier' => [ 'type' => Segment::class, 'options' => [ 'route' => '/upload-fichier/:agent/:nature', 'defaults' => [ 'controller' => AgentFichierController::class, 'action' => 'upload', ], ], ], 'afficher' => [ 'type' => Segment::class, 'options' => [ Loading Loading @@ -153,6 +185,7 @@ return [ 'controllers' => [ 'factories' => [ AgentController::class => AgentControllerFactory::class, AgentFichierController::class => AgentFichierControllerFactory::class, ], ], 'form_elements' => [ Loading
module/Application/config/module.config.php +1 −1 Changes for module/Application/config/module.config.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ return [ 'inline_scripts' => [ '100_' => 'js/jquery.ui.datepicker-fr.js', // '110_' => 'https://gest.unicaen.fr/public/bootstrap-select-1.9.4/dist/js/bootstrap-select.min.js', // '111_' => 'https://gest.unicaen.fr/public/bootstrap-confirmation-2.4.0/bootstrap-confirmation.min.js', '111_' => 'https://gest.unicaen.fr/public/bootstrap-confirmation-2.4.0/bootstrap-confirmation.min.js', '112_' => 'vendor/font-awesome-5.0.9/fontawesome-all.min.js', '120_' => 'vendor/bootstrap-select-1.13.2/dist/js/bootstrap-select.min.js', '124_' => 'vendor/vakata-jstree-3.3.4/dist/jstree.min.js', Loading
module/Application/src/Application/Controller/AgentFichier/AgentFichierController.php +85 Changes for module/Application/src/Application/Controller/AgentFichier/AgentFichierController.php: 85 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Controller\AgentFichier; use Application\Service\Agent\AgentServiceAwareTrait; use Fichier\Entity\Db\Fichier; use Fichier\Entity\Db\Nature; use Fichier\Form\Upload\UploadFormAwareTrait; use Fichier\Service\Fichier\FichierServiceAwareTrait; use Fichier\Service\Nature\NatureServiceAwareTrait; use Zend\Form\Element\Select; use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class AgentFichierController extends AbstractActionController { use AgentServiceAwareTrait; use FichierServiceAwareTrait; use NatureServiceAwareTrait; use UploadFormAwareTrait; public function indexAction() { $agent = $this->getAgentService()->getRequestedAgent($this,'agent'); /** @var Fichier $cv */ $cv = $agent->fetchFile(Nature::CV); /** @var Fichier $motiv */ $motiv = $agent->fetchFile(Nature::MOTIV); /** @var Fichier[] $formations */ $formations = $agent->fetchFiles(Nature::FORMATION); return new ViewModel([ 'agent' => $agent, 'cv' => $cv, 'motiv' => $motiv, 'formations' => $formations, ]); } public function uploadAction() { $agent = $this->getAgentService()->getRequestedAgent($this,'agent'); $nature = $this->getNatureService()->getNatureByCode($this->params()->fromRoute('nature')); $fichier = new Fichier(); $form = $this->getUploadForm(); $form->setAttribute('action', $this->url()->fromRoute('agent/upload-fichier',['agent' => $agent->getId(), 'nature' => $nature->getCode()] , [], true)); $form->bind($fichier); if ($nature) { /** @var Select $select */ $select = $form->get('nature'); $select->setValueOptions([ $nature->getId() => $nature->getLibelle()]); } /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $file = current($request->getFiles()); if ($file['name'] != '') { $nature = $this->getNatureService()->getNature($data['nature']); $fichier = $this->getFichierService()->createFichierFromUpload($file, $nature); $agent->addFichier($fichier); $this->getAgentService()->update($agent); $this->redirect()->toRoute('agent/fichiers', ['agent' => $agent->getId()], [], true); } } $vm = new ViewModel(); $vm->setTemplate('application/default/default-form'); $vm->setVariables([ 'title' => 'Téléverserment d\'un fichier', 'form' => $form, ]); return $vm; } } No newline at end of file
module/Application/src/Application/Controller/AgentFichier/AgentFichierControllerFactory.php +37 Changes for module/Application/src/Application/Controller/AgentFichier/AgentFichierControllerFactory.php: 37 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Controller\AgentFichier; use Application\Service\Agent\AgentService; use Fichier\Form\Upload\UploadForm; use Fichier\Service\Fichier\FichierService; use Fichier\Service\Nature\NatureService; use Zend\Mvc\Controller\ControllerManager; class AgentFichierControllerFactory { public function __invoke(ControllerManager $manager) { /** * @var AgentService $agentService * @var FichierService $fichierService * @var NatureService $natureService */ $agentService = $manager->getServiceLocator()->get(AgentService::class); $fichierService = $manager->getServiceLocator()->get(FichierService::class); $natureService = $manager->getServiceLocator()->get(NatureService::class); /** * @var UploadForm $uploadForm */ $uploadForm = $manager->getServiceLocator()->get('FormElementManager')->get(UploadForm::class); /** @var AgentFichierController $controller */ $controller = new AgentFichierController(); $controller->setAgentService($agentService); $controller->setFichierService($fichierService); $controller->setNatureService($natureService); $controller->setUploadForm($uploadForm); return $controller; } } No newline at end of file
module/Application/src/Application/Entity/Db/Agent.php +63 Changes for module/Application/src/Application/Entity/Db/Agent.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,9 @@ namespace Application\Entity\Db; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Fichier\Entity\Db\Fichier; use UnicaenApp\Exception\RuntimeException; class Agent { Loading Loading @@ -36,6 +39,13 @@ class Agent { /** @var string */ private $missionsComplementaires; /** @var ArrayCollection */ private $fichiers; public function __construct() { $this->fichiers = new ArrayCollection(); } /** * @return int */ Loading Loading @@ -247,7 +257,60 @@ class Agent { return $this; } /** * @return Fichier[] */ public function getFichiers() { return $this->fichiers->toArray(); } /** * @param Fichier $fichier * @return Agent */ public function addFichier($fichier) { $this->fichiers->add($fichier); return $this; } /** * @param Fichier $fichier * @return Agent */ public function removeFichier($fichier) { $this->fichiers->removeElement($fichier); return $this; } /** * @param string $natureCode * @return Fichier */ public function fetchFile($natureCode) { $result = $this->fetchFiles($natureCode); $nb = count($result); if ($nb === 0) return null; if ($nb > 1) throw new RuntimeException("Plusieurs fichiers de nature [] trouvés."); return current($result); } /** * @param string $natureCode * @return Fichier[] */ public function fetchFiles($natureCode) { $result = []; /** @var Fichier $fichier */ foreach ($this->fichiers as $fichier) { if ($fichier->getNature()->getCode() === $natureCode) $result[] = $fichier; } return $result; } } No newline at end of file