<?php
namespace Website\Widgets\Menu; use Moto\Application\Menus\MenuItemsTable; use Moto\System\Widgets\AbstractWidget; use Moto; use Zend\Stdlib\ArrayUtils; class Widget extends AbstractWidget { protected $_init = false; protected $_name = 'menu'; protected static $_defaultProperties = array( 'id' => 1, 'preset' => 'default', 'stickyPreset' => '', 'align' => array( 'desktop' => 'left', 'tablet' => '', 'mobile-v' => '', 'mobile-h' => '', ), 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'auto', 'left' => 'auto', ), ); protected $_templateType = 'templates'; protected $_widgetId = true; protected $_menuItems = null; public function __construct($options = array()) { parent::__construct($options); try { $table = new MenuItemsTable(); $table->useResultAsModel(true); $this->_menuItems = $table->getList(array('menu_id' => $this->id, 'status' => 'publish')); $this->_init = true; } catch(\Exception $e) {} } protected function _exportDataAfter($data) { $data['extraOptions']['currentItems'] = $this->getCurrentItemsAsTree(); return $data; } public function getCurrentItemsAsTree() { $items = array(); if (!empty($this->_menuItems['records'])) { $items = Moto\Util::arrayToTree($this->_menuItems['records'], 0, 'id', 'parent_id', 'items'); } return $items; } protected function _generateClickAction() { return false; } public function preRender() { $html = ''; if (!$this->_init) { return $html; } $items = array(); if (!empty($this->_menuItems['records'])) { $items = Moto\Util::arrayToTree($this->_menuItems['records'], 0, 'id', 'parent_id', 'items'); } $this->_widget = ArrayUtils::merge($this->_widget, array( 'menuId' => $this->id, 'type' => 'horizontal', 'items' => $items )); return parent::preRender(); } } 