<?php

$es_index = getEsIndex();
//
$request = @json_decode(es_execute("/$es_index/_search?q=(slm.type:module)&size=1000&sort=name.keyword:asc"), true);
//
$modules = [];
//
if (!isset($request['error'])) {
    if ($request['hits']['total']['value'] > 0) {
        $modules = array_map(function ($hit) {
            return array_merge(['id' => $hit['_id']], $hit['_source']);
        }, $request['hits']['hits']);
    }
}
//
$request = @json_decode(es_execute("/$es_index/_search?q=(slm.type:simple_menu)&size=1000&sort=name.keyword:asc"), true);
//
$simple_menu = [];
//
if (!isset($request['error'])) {
    if ($request['hits']['total']['value'] > 0) {
        $simple_menu = array_map(function ($hit) {
            return array_merge(['id' => $hit['_id']], $hit['_source']);
        }, $request['hits']['hits']);
    }
}
//
$request = @json_decode(es_execute("/$es_index/_search?q=(slm.type:dropdown_menu)&size=1000&sort=name.keyword:asc"), true);
//
$dropdown_menu = [];
//
if (!isset($request['error'])) {
    if ($request['hits']['total']['value'] > 0) {
        $dropdown_menu = array_map(function ($hit) {
            return array_merge(['id' => $hit['_id']], $hit['_source']);
        }, $request['hits']['hits']);
    }
}
//
$items = array_merge($simple_menu, $dropdown_menu);
//
$_groups = fetchGroupMenus();