Commit 8722e8dc authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Filtrage des applications par groupe

parent 76c5d51e
Loading
Loading
Loading
Loading
+10 −1
Changes for module/Application/src/Application/Controller/ApplicationController.php: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -23,16 +23,25 @@ class ApplicationController extends AbstractActionController {

    public function indexAction()
    {
        $groupeId = $this->params()->fromQuery('groupe');
        /**
         * @var Application[] $activites
         * @var ApplicationGroupe[] $groupes
         */
        $applications = $this->getApplicationService()->getApplications('libelle');

        $applications = [];
        if ($groupeId !== null AND $groupeId !== "") {
            $groupe = $this->getApplicationGroupeService()->getApplicationGroupe($groupeId);
            $applications = $this->getApplicationService()->getApplicationsGyGroupe($groupe);
        } else {
            $applications = $this->getApplicationService()->getApplications();
        }
        $groupes = $this->getApplicationGroupeService()->getApplicationsGroupes('libelle');

        return new ViewModel([
            'applications' => $applications,
            'groupes' => $groupes,
            'groupeSelected' => $groupeId,
        ]);
}

+36 −1
Changes for module/Application/src/Application/Service/Application/ApplicationService.php: 36 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Application\Service\Application;

use Application\Entity\Db\Application;
use Application\Entity\Db\ApplicationGroupe;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
@@ -59,6 +61,17 @@ class ApplicationService {

    /** REQUETES ******************************************************************************************************/

    /**
     * @return QueryBuilder
     */
    public function createQueryBuilder()
    {
        $qb = $this->getEntityManager()->getRepository(Application::class)->createQueryBuilder('application')
            ->addSelect('groupe')->leftJoin('application.groupe', 'groupe')
        ;
        return $qb;
    }

    /**
     * @param string $champ
     * @param string $ordre
@@ -66,7 +79,7 @@ class ApplicationService {
     */
    public function getApplications($champ = 'libelle', $ordre='ASC')
    {
        $qb = $this->getEntityManager()->getRepository(Application::class)->createQueryBuilder('application')
        $qb = $this->createQueryBuilder()
            ->orderBy('application.' . $champ, $ordre)
        ;

@@ -90,6 +103,28 @@ class ApplicationService {
        return $array;
    }

    /**
     * @param ApplicationGroupe $groupe
     * @return Application[]
     */
    public function getApplicationsGyGroupe($groupe)
    {
        $qb = $this->createQueryBuilder()
            ->orderBy('application.libelle')
        ;
        if ($groupe) {
            $qb = $qb->andWhere('groupe.id = :groupeId')
                ->setParameter('groupeId', $groupe->getId())
            ;
        } else {
            $qb = $qb->andWhere('groupe IS NULL')
            ;
        }

        $result = $qb->getQuery()->getResult();
        return $result;
    }

    /**
     * @param int $id
     * @return Application
+8 −1
Changes for module/Application/view/application/application/index.phtml: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use Application\Provider\Privilege\ApplicationPrivileges;
 * @see \Application\Controller\ApplicationController::indexAction()
 * @var Application[] $applications
 * @var ApplicationGroupe[] $groupes
 * @var int $groupeSelected
 */


@@ -20,6 +21,10 @@ $droits['canEffacer'] = $this->isAllowed(ApplicationPrivileges::getResourceId(A
$this->headTitle("Index des applications");
?>

<h1 class="page-header">
    Applications et groupes d'application
</h1>

<div role="tabpanel">
    <ul class="nav nav-tabs" role="tablist">
        <li role="application">
@@ -49,7 +54,7 @@ $this->headTitle("Index des applications");
            </div>

            <div id="application" class="tab-pane " role="tabpanel">
                <?php echo $this->partial('partial/index-application', ['applications' => $applications, 'droits' => $droits], [], true); ?>
                <?php echo $this->partial('partial/index-application', ['applications' => $applications, 'groupes' => $groupes, 'groupeSelected' => $groupeSelected, 'droits' => $droits], [], true); ?>
            </div>
        </div>
    </div>
@@ -67,6 +72,8 @@ $this->headTitle("Index des applications");
    $(function() {
        let hash = $(location).attr('hash');
        let name = hash.substr(1);
        name = name.split("?")[0];
        console.log(name);
        if (name === undefined || name === "") name = "application";

        $('a[aria-controls=' + name + ']').tab('show');
+31 −4
Changes for module/Application/view/application/application/partial/index-application.phtml: 31 added lines, 4 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Entity\Db\Application;
use Application\Entity\Db\ApplicationGroupe;

/**
 * @var Application[] $applications
 * @var ApplicationGroupe[] $groupes
 * @var int $groupeSelected
 * @var boolean[] $droits
 */

use Application\Entity\Db\Application;

$canAfficher = $droits['canAfficher'];
$canAjouter = $droits['canAjouter'];
$canEditer = $droits['canEditer'];
@@ -14,12 +17,28 @@ $canEffacer = $droits['canEffacer'];

?>
<div class="row">
    <div class="col-md-8">
    <div class="col-md-4">
        <h2>
            Applications
        </h2>
    </div>
    <div class="pull-right">
    <div class="col-md-4">
            Filtrer les applications par groupe : <br/>
            <select id="groupe-select" name="groupe-select" class="selectpicker" data-live-search="true">
                <option value="" <?php if (null == $groupeSelected) echo " selected "; ?>>
                    Aucune sélection
                </option>
                <?php foreach ($groupes as $groupe): ?>
                    <option value="<?php echo $groupe->getId(); ?>" <?php if ($groupe->getId() == $groupeSelected) echo " selected "; ?>>
                        <?php echo $groupe->getLibelle(); ?>
                    </option>
                <?php endforeach; ?>
                <option value="-1" <?php if (-1 == $groupeSelected) echo " selected "; ?>>
                    Sans groupe
                </option>
            </select>
    </div>
    <div class="col-md-4">
        <?php if ($canAjouter) : ?>
            <br/>
            <a  <?php /** @see \Application\Controller\ApplicationController::creerAction() */?>
@@ -100,3 +119,11 @@ $canEffacer = $droits['canEffacer'];
    </tbody>
</table>

<script>
    $('select#groupe-select').change(function() {
        let selected = $('select#groupe-select option:selected').val();
        let new_url = "?groupe="+ selected + "#application" ;
        window.location.href = new_url;
    });
</script>