コード例 #1
0
ファイル: Base.php プロジェクト: jonatanolofsson/solidba.se
 /**
  * Load the privileges for the object
  * @return void
  */
 private function __loadPrivileges($beneficiary)
 {
     if (!is_object($beneficiary)) {
         global $Controller;
         $beneficiary = $Controller->get($beneficiary, OVERRIDE);
     }
     if (!$this->ID || in_array($beneficiary->ID, self::$BENEFICIARIES)) {
         return;
     }
     global $DB;
     $new = array_merge(array($beneficiary->ID), $beneficiary->groupIds);
     self::$PRIVILEGES = arrayKeyMergeRecursive(self::$PRIVILEGES, $DB->privileges->asMDList(array('beneficiary' => $new, 'beneficiary!' => self::$BENEFICIARIES), 'id,beneficiary,privileges'));
     self::$BENEFICIARIES = array_merge(self::$BENEFICIARIES, $new);
 }
コード例 #2
0
 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;
 }
コード例 #3
0
function arrayKeyMergeRecursive()
{
    $arrays = func_get_args();
    $result = array();
    foreach ($arrays as $array) {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                if (isset($result[$key])) {
                    $result[$key] = arrayKeyMergeRecursive($result[$key], $value);
                } else {
                    $result[$key] = $value;
                }
            } else {
                $result[$key] = $value;
            }
        }
    }
    return $result;
}
コード例 #4
0
ファイル: Menu.php プロジェクト: jonatanolofsson/solidba.se
 /**
  *
  * @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;
     }
 }