| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /* * ********************************************************************
- * KerioEmail product developed. (Nov 19, 2018)
- * *
- *
- * CREATED BY THURDATA -> http://thurdata.com
- * CONTACT -> contact@thurdata.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use \ThurData\Servers\KerioEmail\Core\ModuleConstants;
- use \ThurData\Servers\KerioEmail\Core\FileReader\Reader;
- /**
- * Description of SidebarService
- *
- * @autor ThurData <info@thrudata.ch>
- */
- class SidebarService
- {
- use SidebarTrait;
-
- protected $id;
- /**
- *
- * @var Sidebar[]
- */
- protected $children = [];
-
- public function __construct()
- {
- $this->load();
- }
- private function load()
- {
- if (!file_exists(ModuleConstants::getDevConfigDir() . DS . 'sidebars.yml'))
- {
- return;
- }
- $data = Reader::read(ModuleConstants::getDevConfigDir() . DS . 'sidebars.yml');
- foreach ($data->get() as $parent => $sidebars)
- {
- $this->add(new Sidebar($parent));
- foreach($sidebars as $id => $sidebar)
- {
- $sidebarItem = new SidebarItem($id, $sidebar['uri'], $sidebar['order'], $sidebar['target_blank']);
- /**
- * check if sidebar is active
- */
- if($sidebarItem->getTitle() === di('request')->get('mg-page'))
- {
- $sidebarItem->setActive(true);
- }
- $this->getSidebar($parent)->add($sidebarItem);
- }
- }
- }
- /**
- *
- * @param type $id
- * @return Sidebar
- * @throws \Exception
- */
- public function getSidebar($id){
- if(!isset($this->children[$id])){
- throw new \Exception(sprintf("Sidebar %s does not exist", $id));
- }
- return $this->children[$id];
- }
-
- public function isEmpty(){
- return empty($this->children);
- }
- public function get(){
- $children =[];
- foreach($this->children as $child){
- if(!$child->getOrder()){
- $children[]= $child;
- continue;
- }
- $children[$child->getOrder()]= $child;
- }
- ksort($children);
- return $children;
- }
- }
|