mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-23 06:59:28 +00:00
refactor
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once APPPATH . 'libraries/treemenu/TreeMenuLib.php';
|
||||
|
||||
/**
|
||||
* Description of OrgFormLib
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
class OrgFormLib extends TreeMenuLib
|
||||
{
|
||||
public function getData()
|
||||
{
|
||||
if(!isset($this->params['stg']))
|
||||
{
|
||||
throw new Exception(self::class . ' Missing Parameter stg.');
|
||||
}
|
||||
|
||||
$this->ci->load->model('codex/Orgform_model', 'OrgFormModel');
|
||||
|
||||
$sql = <<<EOSQL
|
||||
select
|
||||
o.*
|
||||
from
|
||||
bis.tbl_orgform o
|
||||
join (
|
||||
SELECT
|
||||
tl.orgform_kurzbz
|
||||
FROM
|
||||
public.tbl_lehrverband AS tl
|
||||
WHERE
|
||||
studiengang_kz = {$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once APPPATH . 'libraries/treemenu/TreeMenuLib.php';
|
||||
|
||||
/**
|
||||
* Description of PreStudentLib
|
||||
*
|
||||
* @author bambi
|
||||
*/
|
||||
class PreStudentLib extends TreeMenuLib
|
||||
{
|
||||
public function getNodes($params=array())
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => '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
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user