Skip to content
Snippets Groups Projects
Commit 752ea8d4 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

WIP

parent 8f3f4bfe
No related branches found
No related tags found
No related merge requests found
Pipeline #29730 failed
Showing
with 400 additions and 58 deletions
......@@ -8,6 +8,10 @@ use Application\Form\Application\ApplicationForm;
use Application\Form\Application\ApplicationFormFactory;
use Application\Form\Application\ApplicationHydrator;
use Application\Form\Application\ApplicationHydratorFactory;
use Application\Form\AssocierApplications\AssocierApplicationFormFactory;
use Application\Form\AssocierApplications\AssocierApplicationsForm;
use Application\Form\AssocierApplications\AssocierApplicationsHydrator;
use Application\Form\AssocierApplications\AssocierApplicationsHydratorFactory;
use Application\Provider\Privileges\ApplicationPrivileges;
use Application\Service\Application\ApplicationService;
use Application\Service\Application\ApplicationServiceFactory;
......@@ -181,11 +185,13 @@ return [
'form_elements' => [
'factories' => [
ApplicationForm::class => ApplicationFormFactory::class,
AssocierApplicationsForm::class => AssocierApplicationFormFactory::class,
],
],
'hydrators' => [
'factories' => [
ApplicationHydrator::class => ApplicationHydratorFactory::class,
AssocierApplicationsHydrator::class => AssocierApplicationsHydratorFactory::class,
],
],
......
......@@ -53,6 +53,7 @@ return [
'controller' => CategorieController::class,
'action' => [
'modifier',
'associer-applications',
],
'privileges' => [
CategoriePrivileges::CATEGORIE_MODIFIER,
......@@ -125,6 +126,16 @@ return [
],
],
],
'associer-applications' => [
'type' => Segment::class,
'options' => [
'route' => '/associer-applications/:categorie',
'defaults' => [
/** @see CategorieController::associerApplicationsAction() */
'action' => 'associer-applications',
],
],
],
'historiser' => [
'type' => Segment::class,
'options' => [
......
......@@ -4,6 +4,7 @@ namespace Application\Controller;
use Application\Entity\Db\Categorie;
use Application\Form\AssocierApplications\AssocierApplicationsFormAwareTrait;
use Application\Form\Categorie\CategorieFormAwareTrait;
use Application\Service\Categorie\CategorieServiceAwareTrait;
use Laminas\Http\Response;
......@@ -13,7 +14,7 @@ use Laminas\View\Model\ViewModel;
class CategorieController extends AbstractActionController {
use CategorieServiceAwareTrait;
use CategorieFormAwareTrait;
// use AssocierApplicationsFormAwareTrait;
use AssocierApplicationsFormAwareTrait;
public function indexAction(): ViewModel
{
......@@ -130,31 +131,31 @@ class CategorieController extends AbstractActionController {
return $vm;
}
// public function associerAction()
// {
// $categorie = $this->getCategorieService()->getRequestedCategorie($this);
// $form = $this->getAssocierApplicationsForm();
// $form->setAttribute('action', $this->url()->fromRoute('categorie/associer', ['categorie' => $categorie->getId()], [], true));
// $form->bind($categorie);
//
// /** @var Request $request */
// $request = $this->getRequest();
// if ($request->isPost()) {
// $data = $request->getPost();
// if (!isset($data['applications'])) $data['applications'] = [];
// $form->setData($data);
// if ($form->isValid()) {
// $this->getCategorieService()->update($categorie);
// //return $this->redirect()->toRoute('categorie', [], [], true);
// }
// }
//
// $vm = new ViewModel();
// $vm->setTemplate('application/default/default-form');
// $vm->setVariables([
// 'title' => "Associer des applications à une catégorie",
// 'form' => $form,
// ]);
// return $vm;
// }
public function associerApplicationsAction(): ViewModel
{
$categorie = $this->getCategorieService()->getRequestedCategorie($this);
$form = $this->getAssocierApplicationsForm();
$form->setAttribute('action', $this->url()->fromRoute('categorie/associer-applications', ['categorie' => $categorie->getId()], [], true));
$form->bind($categorie);
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
if (!isset($data['categories'])) $data['categories'] = [];
$form->setData($data);
if ($form->isValid()) {
$this->getCategorieService()->update($categorie);
exit();
}
}
$vm = new ViewModel();
$vm->setTemplate('default/default-form');
$vm->setVariables([
'title' => "Associer des applications à une catégorie",
'form' => $form,
]);
return $vm;
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace Application\Controller;
use Application\Form\AssocierApplications\AssocierApplicationsForm;
use Application\Form\Categorie\CategorieForm;
use Application\Service\Categorie\CategorieService;
use Psr\Container\ContainerExceptionInterface;
......@@ -20,17 +21,17 @@ class CategorieControllerFactory {
/**
* @var CategorieService $categorieService
* @var CategorieForm $categorieForm
// * @var AssocierApplicationsForm $associerApplicationsForm
* @var AssocierApplicationsForm $associerApplicationsForm
*/
$categorieService = $container->get(CategorieService::class);
$categorieForm = $container->get('FormElementManager')->get(CategorieForm::class);
// $associerApplicationsForm = $container->get('FormElementManager')->get(AssocierApplicationsForm::class);
$associerApplicationsForm = $container->get('FormElementManager')->get(AssocierApplicationsForm::class);
$controller = new CategorieController();
$controller->setCategorieService($categorieService);
$controller->setCategorieForm($categorieForm);
// $controller->setAssocierApplicationsForm($associerApplicationsForm);
$controller->setAssocierApplicationsForm($associerApplicationsForm);
return $controller;
}
}
\ No newline at end of file
......@@ -3,14 +3,42 @@
namespace Application\Controller;
use Application\Entity\Db\Categorie;
use Application\Service\Application\ApplicationServiceAwareTrait;
use Application\Service\Categorie\CategorieServiceAwareTrait;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
class IndexController extends AbstractActionController
{
use UserServiceAwareTrait;
use ApplicationServiceAwareTrait;
use CategorieServiceAwareTrait;
public function indexAction(): ViewModel
{
return new ViewModel();
$connectedUser = $this->getUserService()->getConnectedUser();
$categories = []; $sans = [];
if ($connectedUser) {
$categories = $this->getCategorieService()->getCategories('ordre');
$sans = $this->getApplicationService()->getApplicationsSansCategories();
if (!empty($sans)) {
$categorie = new Categorie();
$categorie->setId(0);
$categorie->setLibelle("Sans Catégorie");
$categorie->setOrdre(1000000);
foreach ($sans as $san) $categorie->addApplication($san);
$categories[] = $categorie;
}
}
return new ViewModel([
'connectedUser' => $connectedUser,
'categories' => $categories,
]);
}
public function administrationAction(): ViewModel
......
......@@ -2,12 +2,34 @@
namespace Application\Controller;
use Application\Service\Application\ApplicationService;
use Application\Service\Categorie\CategorieService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenUtilisateur\Service\User\UserService;
class IndexControllerFactory
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): IndexController
{
return new IndexController();
/**
* @var UserService $connectedService
* @var ApplicationService $applicationService
* @var CategorieService $categorieService
**/
$userService = $container->get(UserService::class);
$applicationService = $container->get(ApplicationService::class);
$categorieService = $container->get(CategorieService::class);
$controller = new IndexController();
$controller->setUserService($userService);
$controller->setApplicationService($applicationService);
$controller->setCategorieService($categorieService);
return $controller;
}
}
\ No newline at end of file
......@@ -26,6 +26,11 @@ class Categorie implements HistoriqueAwareInterface {
return $this->id;
}
public function setId(?int $id): void
{
$this->id = $id;
}
public function getLibelle(): ?string
{
return $this->libelle;
......@@ -57,9 +62,12 @@ class Categorie implements HistoriqueAwareInterface {
}
/** @return Application[] */
public function getApplications(): array
public function getApplications(bool $withHisto = false): array
{
return $this->applications->toArray();
$applications = $this->applications->toArray();
if (!$withHisto) $applications = array_filter($applications, function (Application $application) { return $application->estNonHistorise();});
usort($applications, function (Application $a, Application $b) { return $a->getLibelle() <=> $b->getLibelle(); });
return $applications;
}
public function clearApplications(): void
......
<?php
namespace Application\Form\AssocierApplications;
use Application\Service\Application\ApplicationService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class AssocierApplicationFormFactory {
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): AssocierApplicationsForm
{
/**
* @var ApplicationService $applicationService
* @var AssocierApplicationsHydrator $hydrator
*/
$applicationService = $container->get(ApplicationService::class);
$hydrator = $container->get('HydratorManager')->get(AssocierApplicationsHydrator::class);
$form = new AssocierApplicationsForm();
$form->setApplicationService($applicationService);
$form->setHydrator($hydrator);
return $form;
}
}
\ No newline at end of file
<?php
namespace Application\Form\AssocierApplications;
use Application\Service\Application\ApplicationServiceAwareTrait;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Select;
use Laminas\Form\Form;
use Laminas\InputFilter\Factory;
class AssocierApplicationsForm extends Form {
use ApplicationServiceAwareTrait;
public function init(): void
{
//parent
$this->add([
'type' => Select::class,
'name' => 'applications',
'options' => [
'label' => "Applications à associer :",
//'empty_option' => "Aucune application",
'value_options' => $this->getApplicationService()->getApplicationsAsOptions(),
],
'attributes' => [
'id' => 'applications',
'multiple' => true,
'data-live-search' => "true",
],
]);
//submit
$this->add([
'type' => Button::class,
'name' => 'bouton',
'options' => [
'label' => '<i class="fas fa-save"></i> Enregistrer',
'label_options' => [
'disable_html_escape' => true,
],
],
'attributes' => [
'type' => 'submit',
'class' => 'btn btn-primary',
],
]);
$this->setInputFilter((new Factory())->createInputFilter([
'applications' => [
'name' => 'applications',
'required' => false,
],
]));
}
}
\ No newline at end of file
<?php
namespace Application\Form\AssocierApplications;
trait AssocierApplicationsFormAwareTrait {
private AssocierApplicationsForm $associerApplicationsForm;
public function getAssocierApplicationsForm(): AssocierApplicationsForm
{
return $this->associerApplicationsForm;
}
public function setAssocierApplicationsForm(AssocierApplicationsForm $associerApplicationsForm): void
{
$this->associerApplicationsForm = $associerApplicationsForm;
}
}
\ No newline at end of file
<?php
namespace Application\Form\AssocierApplications;
use Application\Entity\Db\Categorie;
use Application\Service\Application\ApplicationServiceAwareTrait;
use Laminas\Hydrator\HydratorInterface;
class AssocierApplicationsHydrator implements HydratorInterface {
use ApplicationServiceAwareTrait;
public function extract(object $object): array
{
/** @var Categorie $object */
$applicationsId = [];
foreach ($object->getApplications() as $application) $applicationsId[] = $application->getId();
$data = [
'applications' => $applicationsId,
];
return $data;
}
public function hydrate(array $data, object $object): object
{
$applications = [];
foreach ($data['applications'] as $applicationId) $applications[] = $this->getApplicationService()->getApplication($applicationId);
/** @var Categorie $object */
$object->clearApplications();
foreach ($applications as $application) $object->addApplication($application);
return $object;
}
}
\ No newline at end of file
<?php
namespace Application\Form\AssocierApplications;
use Application\Service\Application\ApplicationService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class AssocierApplicationsHydratorFactory {
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): AssocierApplicationsHydrator
{
/**
* @var ApplicationService $applicationService
*/
$applicationService = $container->get(ApplicationService::class);
$hydrator = new AssocierApplicationsHydrator();
$hydrator->setApplicationService($applicationService);
return $hydrator;
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ class AssocierCategoriesForm extends Form {
'attributes' => [
'id' => 'categories',
'multiple' => true,
'data-live-search' => "true",
],
]);
//submit
......
......@@ -102,4 +102,16 @@ class ApplicationService
return $result;
}
/** @return Application[] */
public function getApplicationsSansCategories(string $champ = 'ordre', string $ordre = 'ASC', bool $withHisto = false): array
{
$qb = $this->createQueryBuilder()
->andWhere('categorie.id IS NULL')
->orderBy('application.' . $champ, $ordre)
;
if (!$withHisto) $qb = $qb->andWhere('application.histoDestruction IS NULL');
$result = $qb->getQuery()->getResult();
return $result;
}
}
\ No newline at end of file
......@@ -19,7 +19,6 @@ $canApplicationSupprimer = $this->isAllowed(ApplicationPrivileges::getResourceId
$this->headTitle('Application');
?>
<br>
<div class="row">
<div class="col-md-8">
<h1 class="page-header">
......
......@@ -19,7 +19,6 @@ $canCategorieSupprimer = $this->isAllowed(CategoriePrivileges::getResourceId(Cat
$this->headTitle('Catégorie');
?>
<br>
<div class="row">
<div class="col-md-8">
<h1 class="page-header">
......@@ -104,7 +103,7 @@ $this->headTitle('Catégorie');
</a>
<br>
<?php /** @see \Application\Controller\CategorieController::associerApplicationsAction() */ ?>
<a href="<?php //echo $this->url('categorie/associer-applications', ['categorie' => $categorie->getId()], [], true); ?>"
<a href="<?php echo $this->url('categorie/associer-applications', ['categorie' => $categorie->getId()], [], true); ?>"
class="ajax-modal" data-event="modification"
>
<span class="icon icon-lier"></span> Associer applications
......
<div class="jumbotron">
<h1><?php echo sprintf($this->translate("Bienvenue dans le squelette d'application Unicaen")) ?></h1>
<p>
Félicitations! Vous avez insallé avec succès le squelette d'application Unicaen.
</p>
<?php if (!$this->identity()): ?>
<p class="text-danger">
<strong>
<?php echo $this->translate("Vous n'êtes pas connecté-e."); ?>
</strong>
</p>
<p>
<?php
/**
* @see \Application\Controller\IndexController::indexAction()
* @var UserInterface $connectedUser
* @var Categorie[] $categories
*/
use Application\Entity\Db\Categorie;
use UnicaenUtilisateur\Entity\Db\UserInterface;
?>
<?php if ($connectedUser === null) : ?>
<div>
<strong>Vous n'êtes pas connecté·e.</strong><br>
Veuillez vous connecter pour pouvoir visualiser la liste des applications.
</div>
<a class="btn btn-success btn-lg" href="<?php echo $this->url('zfcuser/login') ?>">
<?php echo $this->translate('Connectez-vous...') ?>
</a>
</p>
<?php endif ?>
<?php else: ?>
<div class="row">
<div class="col-md-2" >
<div style="position: fixed; width:12%; ">
<?php foreach ($categories as $categorie) : ?>
<div class="pill"
onclick='window.location = String(window.location).replace(/\#.*$/, "") + "#categorie_<?php echo $categorie->getId(); ?>";'>
<?php echo $categorie->getLibelle(); ?>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-md-10">
<?php foreach ($categories as $categorie) : ?>
<?php $applications = $categorie->getApplications(); ?>
<?php if (!empty($categorie)) : ?>
<a name="categorie_<?php echo $categorie->getId(); ?>">
<h2 class="categorie">
<?php echo $categorie->getLibelle(); ?>
<span class="badge"><?php echo count($applications); ?></span>
</h2>
<ul>
<?php foreach ($applications as $application) : ?>
<li>
<?php if ($application->getLien()) : ?>
<a href="<?php echo $application->getLien(); ?>" target="_blank">
<?php echo $application->getLibelle(); ?></a>
<?php else: ?>
<?php echo $application->getLibelle(); ?>
<?php endif; ?>
<?php if ($application->getDescription()) : ?>
: <?php echo strip_tags($application->getDescription(), '<strong><i>'); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<style>
h2.categorie {
border-bottom: 1px gray solid;
padding-bottom: 1px;
font-size: larger;
font-weight: bold;
}
.pill {
border-radius:0.25rem;
margin-bottom: 0.1rem;
padding: 0.1rem;
/*background: #79b2a6;*/
background: rgb(217, 237, 247);
color: rgb(49, 112, 143);
}
.pill:hover {
background: lightgrey;
cursor: pointer;
}
</style>
\ No newline at end of file
......@@ -89,7 +89,7 @@ echo $this->doctype();
<path d="M1200 0L0 0 892.25 114.72 1200 0z" class="shape-fill"></path>
</svg>
</div>
<div id="contenu-principal" class="container bg-white px-4 pt-4 pb-6">
<div id="contenu-principal" class="container bg-white px-4 pt-4 pb-6" style="position:relative; top:20px;">
<?php echo $this->content; ?>
</div>
</main>
......@@ -106,6 +106,10 @@ echo $this->doctype();
</div>
</footer>
<a href="#" class="gotop" style="" title="Remonter en haut de cette page">
<i class="fas fa-angle-up" style=""></i>
</a>
<?php echo $this->inlineScript(); ?>
<script>
$(function () {
......@@ -123,6 +127,20 @@ echo $this->doctype();
background-attachment: fixed;
background-position: right var(--position-x) top var(--position-y);
}
a.gotop {
position:fixed;
right:50px;
bottom:150px;
z-index:1060;
background: whitesmoke;
border-radius: 1rem;
padding: 0 0.5rem ;
}
a.gotop:hover {
border: 2px solid black
}
</style>
<style>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment