public function load()
{
$loader = function () {
$currentDate = Factory::getDate()->toSql();
$query = $this->db->getQuery(true)->select($this->db->quoteName(['m.id', 'm.menutype', 'm.title', 'm.alias', 'm.note', 'm.link', 'm.type', 'm.level', 'm.language', 'm.browserNav', 'm.access', 'm.params', 'm.home', 'm.img', 'm.template_style_id', 'm.component_id', 'm.parent_id']))->select($this->db->quoteName(['m.path', 'e.element'], ['route', 'component']))->from($this->db->quoteName('#__menu', 'm'))->join('LEFT', $this->db->quoteName('#__extensions', 'e'), $this->db->quoteName('m.component_id') . ' = ' . $this->db->quoteName('e.extension_id'))->where([$this->db->quoteName('m.published') . ' = 1', $this->db->quoteName('m.parent_id') . ' > 0', $this->db->quoteName('m.client_id') . ' = 0'])->extendWhere('AND', [$this->db->quoteName('m.publish_up') . ' IS NULL', $this->db->quoteName('m.publish_up') . ' <= :currentDate1'], 'OR')->bind(':currentDate1', $currentDate)->extendWhere('AND', [$this->db->quoteName('m.publish_down') . ' IS NULL', $this->db->quoteName('m.publish_down') . ' >= :currentDate2'], 'OR')->bind(':currentDate2', $currentDate)->order($this->db->quoteName('m.lft'));
$items = [];
$iterator = $this->db->setQuery($query)->getIterator();
foreach ($iterator as $item) {
$items[$item->id] = new MenuItem((array) $item);
}
return $items;
};
try {
$cache = Factory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController('callback', ['defaultgroup' => 'com_menus']);
$this->items = $cache->get($loader, array(), md5(\get_class($this)), false);
} catch (CacheExceptionInterface $e) {
try {
$this->items = $loader();
} catch (ExecutionFailureException $databaseException) {
$this->app->enqueueMessage(Text::sprintf('JERROR_LOADING_MENUS', $databaseException->getMessage()), 'warning');
return false;
}
} catch (ExecutionFailureException $e) {
$this->app->enqueueMessage(Text::sprintf('JERROR_LOADING_MENUS', $e->getMessage()), 'warning');
return false;
}
foreach ($this->items as &$item) {
$parent_tree = array();
if (isset($this->items[$item->parent_id])) {
$item->setParent($this->items[$item->parent_id]);
$parent_tree = $this->items[$item->parent_id]->tree;
}
$parent_tree[] = $item->id;
$item->tree = $parent_tree;
$url = str_replace('index.php?', '', $item->link);
$url = str_replace('&', '&', $url);
parse_str($url, $item->query);
}
return true;
}