Loading module/Oscar/src/Oscar/Controller/AdministrationController.php +3 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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()]); Loading module/Oscar/src/Oscar/Entity/OrganizationType.php +11 −3 Original line number Diff line number Diff line Loading @@ -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; } } module/Oscar/src/Oscar/Entity/OrganizationTypeRepository.php +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 module/Oscar/src/Oscar/Service/OrganizationService.php +14 −16 Original line number Diff line number Diff line Loading @@ -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() Loading Loading @@ -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'); Loading module/Oscar/view/oscar/administration/organization-type.phtml +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -23,4 +28,5 @@ } }).$mount('#app') }); /****/ </script> No newline at end of file Loading
module/Oscar/src/Oscar/Controller/AdministrationController.php +3 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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()]); Loading
module/Oscar/src/Oscar/Entity/OrganizationType.php +11 −3 Original line number Diff line number Diff line Loading @@ -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; } }
module/Oscar/src/Oscar/Entity/OrganizationTypeRepository.php +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
module/Oscar/src/Oscar/Service/OrganizationService.php +14 −16 Original line number Diff line number Diff line Loading @@ -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() Loading Loading @@ -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'); Loading
module/Oscar/view/oscar/administration/organization-type.phtml +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -23,4 +28,5 @@ } }).$mount('#app') }); /****/ </script> No newline at end of file