function schematicEditor() { global $DB, $CONFIG, $USER, $Controller; $bookItems = $DB->booking_items->asArray(false, 'id,parent,place', false, false, 'place ASC'); $Controller->get(arrayExtract($bookItems, 'id')); foreach ($bookItems as &$bi) { $bi['item'] = $Controller->{$bi['id']}; } $inflatedBookItems = inflate($bookItems); $content = self::renderItems($inflatedBookItems); if ($this->mayI(EDIT)) { $content .= Form::quick(null, null, new Input(__('Object name'), 'oname'), new Select(__('Parent'), 'oparent', $inflatedBookItems, false, false, __('None'))); } $this->setContent('main', $content); }
/** * View a list of the object and it's subobjects * @return string List */ function listView() { global $DB, $Controller; $Objects = $Controller->get(arrayPrepend($DB->booking_items->asList(array('parent' => $this->ID), 'id', false, false, 'place ASC'), $this->ID)); $booked_items = array(); foreach ($Objects as $obj) { $booked_items[] = array('link' => $obj->link(), 'id' => $obj->ID, 'parent' => $obj->parentBookID()); } return listify(inflate($booked_items), false, true, 'link', 'children'); }
function dir2Array($directory, $prevDir = '', $level = 0) { $array_items = array(); if ($dh = @opendir($directory)) { while (false !== ($file = readdir($dh))) { if ($level <= $this->maxMenuLevel && !in_array($file, $this->ignore) && is_dir($directory . '/' . $file) && $file[0] != '.') { $array_items = array_merge($array_items, $this->dir2Array($directory . '/' . $file, $file, $level + 1)); $array_items[] = array('parent' => $prevDir, 'id' => utf8($file)); } } closedir($dh); } return inflate($array_items); }
function getMenu($obj = false, $limit = true, $hide_sections = true) { global $DB, $Controller, $CONFIG, $USER; $Menus = array(); $iMenus = array(); $MenuRows = array(); if (!$obj) { $last_level = $DB->menu->asList(array('parent' => array('', 0, null)), 'id'); $MenuRows = $DB->{'spine,menu'}->asArray(array('spine.id' => $last_level), false, false, true, 'place'); } else { $last_level = array($obj->ID); } $new_rows = 0; do { $newMenuRows = $DB->{'spine,menu'}->asArray(array('menu.parent' => $last_level), false, false, true, 'place'); $last_level = array(); $MenuRows = arrayKeyMergeRecursive($MenuRows, $newMenuRows); if ($limit) { foreach ($newMenuRows as $id => $row) { if ($row['class'] != 'MenuSection' || $id == $_REQUEST['expand']) { $last_level[] = $id; } } } else { $last_level = array_keys($newMenuRows); } } while ($last_level); if ($MenuRows) { MenuItem::preload(array_keys($MenuRows)); foreach ($MenuRows as $id => $row) { $obj = $Controller->{$id}; if ($obj) { $Menus[] = array('id' => $id, 'parent' => $row['parent'], 'place' => $row['place'], 'object' => $obj); } } $iMenus = inflate($Menus, true); } return $iMenus; }
/** * * @param string $which Which (alias) the menu should begin rendering from * @param bool $quiet If set to false, the menu will not be printed, rather just put in $fMenu. * @return void */ function __construct($which, $maxlevel = false, $extendActive = false, $ignore_sections = false, $quiet = false, $includeDescription = false, $excludeSelf = false) { global $DB, $Controller, $CURRENT, $USER; if ($extendActive == -1) { $extendActive = 100000.0; } if (is_string($which) || is_numeric($which)) { $which = $Controller->{(string) $which}(OVERRIDE); } if ($which && (is_a($which, 'MenuSection') && $which->may($USER, READ, true) || $which->mayI(READ))) { $which = $which->ID; } else { return false; } if (!is_numeric($which) || !$which) { return false; } $ids = array(); $AllObjects = array(); $parents = array(); $pids = array($which); $active = $CURRENT->parentIDs; $active[] = $CURRENT->ID; $menuparentObject = $Controller->{$which}; if (!is_a($menuparentObject, 'MenuSection') && !$excludeSelf) { $AllObjects[$which] = $menuparentObject; } $i = 0; while (count($pids) > 0) { $dbids = $DB->menu->asList(array('parent' => $pids), 'id', false, false, 'place'); if (!$dbids) { break; } $newO = $Controller->get($dbids, OVERRIDE, false, false); $newObjects = array(); global $USER; foreach ($newO as $o) { if (is_a($o, 'MenuSection')) { if ($o->may($USER, READ, true)) { $newObjects[] = $o; } } elseif ($o->mayI(READ)) { $newObjects[] = $o; } } $pids = array(); foreach ($newObjects as $obj) { if (is_a($obj, 'MenuSection')) { if (!$ignore_sections) { if ($singleDepthIDS = $this->singleVirtualDepth($obj->ID)) { $AllObjects = arrayKeyMergeRecursive($AllObjects, $Controller->get($singleDepthIDS, READ, false, false)); $parents = arrayKeyMergeRecursive($parents, array_fill_keys($singleDepthIDS, $obj->parentID)); $pids = array_merge($pids, $singleDepthIDS); } } } else { $AllObjects[$obj->ID] = $obj; $pids[] = $obj->ID; $parents[$obj->ID] = $obj->parentID; } } if ($maxlevel !== false) { $maxlevel--; if ($maxlevel <= 0) { $pids = array_intersect($pids, $active); } if ($extendActive !== true && $maxlevel + $extendActive <= 0) { break; } } } $menu = array(); foreach ($AllObjects as $m) { if (is_a($m, 'MenuItem') && $m->isActive()) { $menu[] = array("id" => $m->ID, "parent" => @$parents[$m->ID], "item" => $m); } } $inflatedMenu = inflate($menu); $this->fMenu = $this->format($inflatedMenu, $includeDescription); if (!$quiet) { echo $this->fMenu; } }