diff --git a/application/config/treemenu/stv_menu.php b/application/config/treemenu/stv_menu.php index 15d64aa64..8e89ca788 100644 --- a/application/config/treemenu/stv_menu.php +++ b/application/config/treemenu/stv_menu.php @@ -2,12 +2,12 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); $config['stv_menu'] = array( - 'library' => 'treemenu/StvMenuLib', + 'library' => 'treemenu/TreeMenuLib', 'children' => array( 'stg' => array( 'library' => 'treemenu/StgLib', -/* 'children' => array( +/* 'pre' => array( 'library' => 'treemenu/PrestudentLib' ), @@ -19,9 +19,11 @@ $config['stv_menu'] = array( ) ) ), +*/ 'orgform' => array( 'library' => 'treemenu/OrgFormLib', 'children' => array( +/* 'pre' => array( 'library' => 'treemenu/PrestudentLib' ), @@ -33,10 +35,10 @@ $config['stv_menu'] = array( ) ) ) +*/ ) ) ) -*/ ), 'inout' => array( 'library' => 'treemenu/InOutLib' diff --git a/application/controllers/api/frontend/v1/TreeMenu.php b/application/controllers/api/frontend/v1/TreeMenu.php index f45ea7b52..94edf07b4 100644 --- a/application/controllers/api/frontend/v1/TreeMenu.php +++ b/application/controllers/api/frontend/v1/TreeMenu.php @@ -37,25 +37,17 @@ class TreeMenu extends FHCAPI_Controller public function fullMenu($treemenu=null) { - if(is_null($treemenu)) - { - $this->terminateWithError('missing parameter treemenu.'); - } - - $this->loadMenuConfig($treemenu); - - $bhdebug = (object) array( - 'treemenu' => $treemenu, - 'treemenuconfig' => $this->treemenuconfig - - ); - $this->addMeta('bhdebug', $bhdebug); - - $data = array(); - $this->terminateWithSuccess($data); + $includeSubMenu = true; + $this->getMenu($treemenu, $includeSubMenu); } public function partMenu($treemenu=null) + { + $includeSubMenu = false; + $this->getMenu($treemenu, $includeSubMenu); + } + + protected function getMenu($treemenu=null, $includeSubMenu=false) { if(is_null($treemenu)) { @@ -64,7 +56,8 @@ class TreeMenu extends FHCAPI_Controller $this->loadMenuConfig($treemenu); - $startconfig = $this->findStartLib($this->treemenuconfig, array_keys($this->uri->uri_to_assoc(7))); + $uri = $this->uri->uri_to_assoc(7); + $startconfig = $this->findStartLib($this->treemenuconfig, array_keys($uri)); $libpath = $startconfig['library']; $children = isset($startconfig['children']) ? $startconfig['children'] : array(); @@ -79,7 +72,7 @@ class TreeMenu extends FHCAPI_Controller $bhdebug = (object) array( 'treemenu' => $treemenu, 'treemenuconfig' => $this->treemenuconfig, - 'uri' => $this->uri->uri_to_assoc(7), + 'uri' => $uri, 'libpath' => $libpath, 'libname' => $libname, 'children' => $children, @@ -88,6 +81,7 @@ class TreeMenu extends FHCAPI_Controller $this->addMeta('bhdebug', $bhdebug); //$this->addMeta('bhci', $this); + $this->$libname->init($uri, $includeSubMenu); $data = $this->$libname->getSubMenu(); $this->terminateWithSuccess($data); } diff --git a/application/libraries/treemenu/InOutLib.php b/application/libraries/treemenu/InOutLib.php index 5c52da996..af78272f3 100644 --- a/application/libraries/treemenu/InOutLib.php +++ b/application/libraries/treemenu/InOutLib.php @@ -8,7 +8,7 @@ require_once APPPATH . 'libraries/treemenu/TreeMenuLib.php'; */ class InOutLib extends TreeMenuLib { - public function getNodes() + public function getNodes($params=array(), $includeSubMenu=false) { return [ [ @@ -34,9 +34,4 @@ class InOutLib extends TreeMenuLib ] ]; } - - public function getSubMenu() - { - return []; - } } diff --git a/application/libraries/treemenu/OrgFormLib.php b/application/libraries/treemenu/OrgFormLib.php new file mode 100644 index 000000000..f05b03327 --- /dev/null +++ b/application/libraries/treemenu/OrgFormLib.php @@ -0,0 +1,64 @@ +params['stg'])) + { + throw new Exception(self::class . ' Missing Parameter stg.'); + } + + $this->ci->load->model('codex/Orgform_model', 'OrgFormModel'); + + $sql = <<ci->OrgFormModel->escape($this->params['stg'])} + and + orgform_kurzbz IS NOT null + group by + orgform_kurzbz + ) v on o.orgform_kurzbz = v.orgform_kurzbz + order by + o.orgform_kurzbz +EOSQL; + + $res = $this->ci->OrgFormModel->execReadonlyQuery($sql); + $orgforms = hasData($res) ? getData($res) : array(); + + $this->ci->addMeta('bhorgform_' . $this->params['stg'] , $orgforms); + + return $orgforms; + } + + protected function getParamsForNextLevel($element=null) + { + if($element) + { + $paramsstg = array_merge($this->params, array('orgform' => $element->orgform_kurzbz)); + return $paramsstg; + } + return $this->params; + } + + protected function getName($element) + { + $name = $element->orgform_kurzbz . ' ' . $element->bezeichnung; + return $name; + } +} diff --git a/application/libraries/treemenu/PreStudentLib.php b/application/libraries/treemenu/PreStudentLib.php new file mode 100644 index 000000000..6e3a34280 --- /dev/null +++ b/application/libraries/treemenu/PreStudentLib.php @@ -0,0 +1,37 @@ + 'International', + 'link' => 'inout', + 'children' => [ + [ + 'name' => 'Incoming', + 'link' => 'inout/incoming', + 'leaf' => true + ], + [ + 'name' => 'Outgoing', + 'link' => 'inout/outgoing', + 'leaf' => true + ], + [ + 'name' => 'Gemeinsame Studien', + 'link' => 'inout/gemeinsamestudien', + 'leaf' => true + ] + ] + ] + ]; + } +} diff --git a/application/libraries/treemenu/StgLib.php b/application/libraries/treemenu/StgLib.php index d2f8d9a16..1f005edbc 100644 --- a/application/libraries/treemenu/StgLib.php +++ b/application/libraries/treemenu/StgLib.php @@ -8,31 +8,32 @@ require_once APPPATH . 'libraries/treemenu/TreeMenuLib.php'; */ class StgLib extends TreeMenuLib { - public function getNodes() + protected function getData() { $this->ci->load->model('organisation/Studiengang_model', 'StudiengangModel'); + $this->ci->StudiengangModel->addOrder('typ'); + $this->ci->StudiengangModel->addOrder('kurzbz'); $res = $this->ci->StudiengangModel->loadWhere(array('aktiv' => true)); $stgs = hasData($res) ? getData($res) : array(); $this->ci->addMeta('bhstg', $stgs); - $nodes = array_map( - function($stg) { - return array( - 'name' => strtoupper($stg->typ . $stg->kurzbz) . ' ' . $stg->bezeichnung, - 'link' => 'stg/' . $stg->studiengang_kz, - 'leaf' => false - ); - }, - $stgs - ); - return $nodes; + return $stgs; } - public function getSubMenu() + protected function getParamsForNextLevel($element=null) { - return [ - 'StgLib' => 'test123' - ]; + if($element) + { + $paramsstg = array_merge($this->params, array('stg' => $element->studiengang_kz)); + return $paramsstg; + } + return $this->params; + } + + protected function getName($element) + { + $name = strtoupper($element->typ . $element->kurzbz) . ' ' . $element->bezeichnung; + return $name; } } diff --git a/application/libraries/treemenu/StvMenuLib.php b/application/libraries/treemenu/StvMenuLib.php index e4db7ce28..a876023e2 100644 --- a/application/libraries/treemenu/StvMenuLib.php +++ b/application/libraries/treemenu/StvMenuLib.php @@ -7,17 +7,8 @@ require_once APPPATH . 'libraries/treemenu/TreeMenuLib.php'; */ class StvMenuLib extends TreeMenuLib { - public function getSubMenu() + public function getNodes($params=array(), $includeSubMenu=false) { - $nodes = array(); - - foreach($this->children_config as $childconfig) - { - $childlib = basename($childconfig['library']); - $childnodes = $this->ci->$childlib->getNodes(); - $nodes = array_merge($nodes, $childnodes); - } - - return $nodes; + return []; } } diff --git a/application/libraries/treemenu/TreeMenuLib.php b/application/libraries/treemenu/TreeMenuLib.php index 618f69e80..1ba0e7901 100644 --- a/application/libraries/treemenu/TreeMenuLib.php +++ b/application/libraries/treemenu/TreeMenuLib.php @@ -10,15 +10,20 @@ * * @author bambi */ -abstract class TreeMenuLib +class TreeMenuLib { protected $ci; protected $children_config; + protected $params; + protected $includeSubMenu; public function __construct($children_config) { $this->ci =& get_instance(); $this->children_config = $children_config; + $this->params = array(); + $this->includeSubMenu = false; + foreach($this->children_config as $child_config) { $grandchildren_config = isset($child_config['children']) ? $child_config['children'] : []; @@ -26,14 +31,78 @@ abstract class TreeMenuLib } } - public function getNode($name) + public function init($params=array(), $includeSubMenu=false) { - $node = array( - 'name' => $name - ); - - return $node; + $this->params = $params; + $this->includeSubMenu = $includeSubMenu; } - public abstract function getSubMenu(); + public function getNodes() + { + $data = $this->getData(); + + $nodes = array(); + foreach($data as $element) + { + $node = array( + 'name' => $this->getName($element), + 'link' => $this->getLink($element), + 'leaf' => $this->isLeaf() + ); + if($this->includeSubMenu) + { + $node['children'] = $this->getSubMenu($element); + } + $nodes[] = $node; + }; + + return $nodes; + } + + public function getSubMenu($element=null) + { + $nodes = array(); + + foreach($this->children_config as $childconfig) + { + $childlib = basename($childconfig['library']); + $this->ci->$childlib->init( + $this->getParamsForNextLevel($element), + $this->includeSubMenu + ); + $childnodes = $this->ci->$childlib->getNodes(); + $nodes = array_merge($nodes, $childnodes); + } + + return $nodes; + } + + protected function getData() + { + return array(); + } + + protected function getParamsForNextLevel($element=null) + { + return $this->params; + } + + protected function getName($element) + { + return __METHOD__ . 'NOT IMPLEMENTED'; + } + + protected function getLink($element) + { + $link = $this->ci->uri->assoc_to_uri($this->getParamsForNextLevel($element)); + return $link; + } + + protected function isLeaf() + { + if(count($this->children_config) === 0) { + return true; + } + return false; + } }