From dfbbefb6bb75300dc6ab0eb38d9163e047ebaa59 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Fri, 20 Sep 2019 16:44:43 +0100 Subject: [PATCH] FEAT #11271 TIME 0:25 route entitites list --- rest/index.php | 1 + .../controllers/IndexingModelController.php | 39 +++++++++++++++++++ .../indexing-form/indexing-form.component.ts | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/rest/index.php b/rest/index.php index a7857d68923..24887234a03 100755 --- a/rest/index.php +++ b/rest/index.php @@ -136,6 +136,7 @@ $app->delete('/customFields/{id}', \CustomField\controllers\CustomFieldControlle //IndexingModels $app->get('/indexingModels', \IndexingModel\controllers\IndexingModelController::class . ':get'); +$app->get('/indexingModels/entities', \IndexingModel\controllers\IndexingModelController::class . ':getEntities'); $app->get('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':getById'); $app->post('/indexingModels', \IndexingModel\controllers\IndexingModelController::class . ':create'); $app->put('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':update'); diff --git a/src/app/indexingModel/controllers/IndexingModelController.php b/src/app/indexingModel/controllers/IndexingModelController.php index d7760c97c0c..6f2a088a1b8 100644 --- a/src/app/indexingModel/controllers/IndexingModelController.php +++ b/src/app/indexingModel/controllers/IndexingModelController.php @@ -17,10 +17,12 @@ namespace IndexingModel\controllers; +use Entity\models\EntityModel; use Group\models\ServiceModel; use History\controllers\HistoryController; use IndexingModel\models\IndexingModelFieldModel; use IndexingModel\models\IndexingModelModel; +use Resource\controllers\IndexingController; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; @@ -207,4 +209,41 @@ class IndexingModelController return $response->withStatus(204); } + + public function getEntities(Request $request, Response $response, array $aArgs) + { + $entitiesTmp = EntityModel::get([ + 'select' => ['id', 'entity_label', 'entity_id'], + 'where' => ['enabled = ?', '(parent_entity_id is null OR parent_entity_id = \'\')'], + 'data' => ['Y'], + 'orderBy' => ['entity_label'] + ]); + if (!empty($entitiesTmp)) { + foreach ($entitiesTmp as $key => $value) { + $entitiesTmp[$key]['level'] = 0; + } + $entitiesId = array_column($entitiesTmp, 'entity_id'); + $entitiesChild = IndexingController::getEntitiesChildrenLevel(['entitiesId' => $entitiesId, 'level' => 1]); + $entitiesTmp = array_merge([$entitiesTmp], $entitiesChild); + } + + $entities = []; + foreach ($entitiesTmp as $keyLevel => $levels) { + foreach ($levels as $entity) { + if ($keyLevel == 0) { + $entities[] = $entity; + continue; + } else { + foreach ($entities as $key => $oEntity) { + if ($oEntity['entity_id'] == $entity['parent_entity_id']) { + array_splice($entities, $key+1, 0, [$entity]); + continue; + } + } + } + } + } + + return $response->withJson(['entities' => $entities]); + } } diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts index 1fd0d58fee4..9359fb5e185 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -293,7 +293,7 @@ export class IndexingFormComponent implements OnInit { } else if (elem.identifier === 'destination') { if (this.adminMode) { - this.http.get("../../rest/indexing/entities").pipe( + this.http.get("../../rest/indexingModels/entities").pipe( tap((data: any) => { let title = ''; elem.values = data.entities.map((entity: any) => { -- GitLab