Commit 8982c5a4 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Up : Migration de l'interface de gestion des types d'organisation

parent 1aaaeb69
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -801,7 +801,7 @@ class AdministrationController extends AbstractOscarController implements UsePro
            return $this->getResponseBadRequest();
        }

        if ($this->isAjax()) {
        if ($this->isAjax() || $this->getRequest()->getQuery('f') === 'json') {
            $method = $this->getHttpXMethod();
            try {
                switch ($method) {
@@ -811,12 +811,13 @@ class AdministrationController extends AbstractOscarController implements UsePro

                    case 'DELETE' :
                        $id = $this->params()->fromRoute('id');
                        $this->getLoggerService()->info("Suppression de $id");
                        $this->getOrganizationService()->removeOrganizationType($id);
                        return $this->getResponseOk("Type d'organisation supprimée");

                    case 'POST' :
                        $type = $this->getOrganizationService()->updateOrCreateOrganizationType(
                            $this->params()->fromPost()
                           $this->getJsonREST()
                        );
                        return $this->ajaxResponse([$type->toJson()]);

+11 −3
Original line number Diff line number Diff line
@@ -132,18 +132,26 @@ class OrganizationType implements ITrackable
        return $this->getLabel();
    }

    function toJson(){
    function toJson(?array $counted = null): array
    {
        $children = [];
        foreach ($this->getChildren() as $c ){
            $children[] = $c->toJson();
            $children[] = $c->toJson($counted);
        }
        return [

        $out = [
            'id' => $this->getId(),
            'label' => $this->getLabel(),
            'description' => $this->getDescription(),
            'root_id' => $this->getRoot() ? $this->getRoot()->getId() : null,
            'children' => $children
        ];

        if( $counted ){
            $out['count'] = $counted[$this->getId()];
        }

        return $out;
    }

}
+19 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Entity;

use Doctrine\ORM\EntityRepository;

class OrganizationTypeRepository extends EntityRepository
{
    public function getCountedTypes()
    {
        $query = $this->getEntityManager()->createQuery(
            "SELECT 
                    t.id AS id, 
                    COUNT(o.id) AS count
                FROM Oscar\Entity\OrganizationType t 
                LEFT JOIN Oscar\Entity\Organization o WITH t.id = o.typeObj
                GROUP BY t.id
                ORDER BY t.label ASC 
                "
        );
        $out = [];
        foreach ($query->getResult() as $row) {
            $out[$row['id']] = $row['count'];
        }

        return $out;
    }
}
 No newline at end of file
+14 −16
Original line number Diff line number Diff line
@@ -600,20 +600,20 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
    }


    public function getOrganizationTypes()
    public function getOrganizationTypes(?int $root = null, ?array $types = null): array
    {
        $types = [];
        $result = $this->getEntityManager()->getRepository(OrganizationType::class)->findBy(
            ['root' => null],
            ['label' => 'DESC']
        );
        $counted = $this->getEntityManager()->getRepository(OrganizationType::class)->getCountedTypes();
        $types = $this->getEntityManager()->getRepository(OrganizationType::class)->findBy([], ['label' => 'ASC']);

        /** @var OrganizationType $type */
        foreach ($result as $type) {
            $types[$type->getId()] = $type->toJson();
        $out = [];
        foreach ($types as $type) {
            if( !$type->getRoot() ){
                $out[] = $type->toJson($counted);
            }
        }

        return $types;
        return $out;
    }

    public function getTypes()
@@ -875,8 +875,6 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
                    $qb->addOrderBy('o.dateCreated', $direction);
                    break;
            }


        }
//        else {
//            $qb->addOrderBy('o.dateEnd', 'DESC')->addOrderBy('o.dateUpdated', 'DESC');
+7 −1
Original line number Diff line number Diff line
@@ -3,9 +3,14 @@
        <i class="icon-building-filled"></i>
        Gestion des types d'oganisation
    </h1>
    <div id="app"></div>
    <div id="admintypeorganization"
         data-url="<?= $this->url('administration/organizationtype') ?>"
         data-manage="true"
    ></div>
    <?php echo $this->Vite()->addJs('src/AdminTypeOrganization.js') ?>
</section>
<script>
    /****
    require(["vue", "vue-resource", 'OrganizationType'], function(Vue, VueResource, OrganizationType){
        Vue.use(VueResource);
        Vue.http.options.emulateJSON = true;
@@ -23,4 +28,5 @@
            }
       }).$mount('#app')
    });
    /****/
</script>
 No newline at end of file
Loading