示例#1
0
 public function __construct($roleId = 0)
 {
     if (!is_int($roleId)) {
         throw new Exception("No valid role id provided. Role id must be an integer", 500);
     }
     // Role information
     $roleInfo = Role::getRoleInfo($roleId);
     $this->id = $roleId;
     $this->label = $roleInfo['name'];
     // Rules that are maintained by this role
     $this->maintains = (array) $roleInfo['ruleNames'];
     // Editable concepts
     $this->editableConcepts = (array) $roleInfo['editableConcepts'];
     // Interfaces that are accessible by this role
     foreach (InterfaceObject::getAllInterfaceObjects() as $ifc) {
         if (in_array($this->label, $ifc->interfaceRoles) || empty($ifc->interfaceRoles)) {
             $this->interfaces[] = $ifc;
         }
     }
 }
 public static function getPublicInterfaces()
 {
     $interfaces = array();
     foreach (InterfaceObject::getAllInterfaceObjects() as $ifc) {
         if (empty($ifc->interfaceRoles)) {
             $interfaces[$ifc->id] = $ifc;
         }
     }
     return $interfaces;
 }
示例#3
0
 private function doPatchRemove($patch, $interface, $before)
 {
     $pathArr = explode('/', $patch['path']);
     $tgtInterface = $interface;
     $tgtAtom = $this->id;
     // init of tgtAtom is this atom itself, will be changed in while statement
     // remove first empty arr element, due to root slash e.g. '/Projects/{atomid}/...'
     if (current($pathArr) == false) {
         array_shift($pathArr);
     }
     // was empty(current($pathArr)), but prior to PHP 5.5, empty() only supports variables, not expressions.
     // find the right subinterface
     while (count($pathArr)) {
         $interfaceId = array_shift($pathArr);
         // if path starts with '@' skip
         if (substr($interfaceId, 0, 1) == '@') {
             return;
         }
         // break function
         if ($interfaceId == '_sortValues_') {
             return;
         }
         // break function
         $tgtInterface = InterfaceObject::getSubinterface($tgtInterface, $interfaceId);
         $srcAtom = $tgtAtom;
         // set srcAtom, before changing tgtAtom
         $tgtAtom = array_shift($pathArr);
         // set tgtAtom
     }
     // Check if interface is editable
     if (!$tgtInterface->editable) {
         Notifications::addError($tgtInterface->label . " is not editable in interface '" . $interface->label . "'");
         return;
     }
     /******* Perform edit *********
      * Properties are always a 'replace', so no dealing with them here
      */
     /* Interface is a relation to an object
      */
     if ($tgtInterface->tgtConceptIsObject) {
         $this->database->editDelete($tgtInterface->relation, $tgtInterface->relationIsFlipped, $srcAtom, $tgtInterface->srcConcept, $tgtAtom, $tgtInterface->tgtConcept);
         /* Interface is a relation to a scalar (i.e. not an object)
          * Two situations:
          * 1) Interface is UNI -> not handled here, this is detected as a replace to ''
          * 2) Interface is not UNI -> $tgtAtom is index of array, so we have to get the corresponding value
          */
     } elseif (!$tgtInterface->tgtConceptIsObject) {
         try {
             $tgtAtom = JsonPatch::get($before, $patch['path']);
         } catch (Exception $e) {
             Notifications::addError($e->getMessage());
         }
         $this->database->editDelete($tgtInterface->relation, $tgtInterface->relationIsFlipped, $srcAtom, $tgtInterface->srcConcept, $tgtAtom, $tgtInterface->tgtConcept);
     }
 }
示例#4
0
 public function activateRoles($roleIds = null)
 {
     $roles = $this->getSessionRoles();
     if (empty($roles)) {
         Notifications::addLog("No roles available to activate", 'SESSION');
     } elseif (is_null($roleIds)) {
         // TODO: insert default roles here
         Notifications::addLog("No roles provided to activate", 'SESSION');
     } elseif (empty($roleIds)) {
         Notifications::addLog("No roles provided to activate", 'SESSION');
     } else {
         if (!is_array($roleIds)) {
             throw new Exception('$roleIds must be an array', 500);
         }
         foreach ($this->sessionRoles as &$role) {
             if (in_array($role->id, $roleIds)) {
                 $role->active = true;
                 Notifications::addLog("Role {$role->id} is active", 'SESSION');
                 $this->ifcsOfActiveRoles = array_merge($this->ifcsOfActiveRoles, $role->interfaces());
                 $this->accessibleInterfaces = array_merge($this->accessibleInterfaces, $role->interfaces());
                 $this->rulesToMaintain = array_merge($this->rulesToMaintain, $role->maintains());
             }
         }
     }
     // Add public interfaces
     $this->ifcsOfActiveRoles = array_merge($this->ifcsOfActiveRoles, InterfaceObject::getPublicInterfaces());
     $this->accessibleInterfaces = array_merge($this->accessibleInterfaces, InterfaceObject::getPublicInterfaces());
     // If login enabled, add also the other interfaces of the sessionRoles (incl. not activated roles) to the accesible interfaces
     if (Config::get('loginEnabled')) {
         foreach ($roles as $role) {
             $this->accessibleInterfaces = array_merge($this->accessibleInterfaces, $role->interfaces());
         }
     }
     // Filter duplicate values
     $this->ifcsOfActiveRoles = array_unique($this->ifcsOfActiveRoles);
     $this->accessibleInterfaces = array_unique($this->accessibleInterfaces);
     $this->rulesToMaintain = array_unique($this->rulesToMaintain);
 }
 public static function getAllInterfacesForConcept($concept)
 {
     $interfaces = array();
     foreach (InterfaceObject::getAllInterfaceObjects() as $interfaceId => $interface) {
         if ($interface['srcConcept'] == $concept) {
             $interfaces[] = $interfaceId;
         }
     }
     return $interfaces;
 }