getEntitiesForProfileByUser() статический публичный Метод

retrieve the entities allowed to a user for a profile
static public getEntitiesForProfileByUser ( $users_id, $profiles_id, $child = false ) : Array
$users_id Integer ID of the user
$profiles_id Integer ID of the profile
$child Boolean when true, include child entity when recursive right (false by default)
Результат Array of entity ID
Пример #1
0
 /**
  * @see Rule::executeActions()
  **/
 function executeActions($output, $params)
 {
     if (count($this->actions)) {
         foreach ($this->actions as $action) {
             switch ($action->fields["action_type"]) {
                 case "assign":
                     switch ($action->fields["field"]) {
                         default:
                             $output[$action->fields["field"]] = $action->fields["value"];
                             break;
                         case "_affect_entity_by_user_entity":
                             //3 cases :
                             //1 - rule contains a criteria like : Profil is XXXX
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible)
                             //2-   rule contains criteria "User has only one profile"
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible) (same as 1)
                             //3   -> rule contains only one profile
                             $profile = 0;
                             //Case 2:
                             if (isset($this->criterias_results['ONE_PROFILE'])) {
                                 $profile = $this->criterias_results['ONE_PROFILE'];
                                 //Case 3
                             } else {
                                 if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                     $profile = $this->criterias_results['UNIQUE_PROFILE'];
                                     //Case 1
                                 } else {
                                     if (isset($this->criterias_results['PROFILES'])) {
                                         $profile = $this->criterias_results['PROFILES'];
                                     }
                                 }
                             }
                             if ($profile) {
                                 $entities = array();
                                 if (isset($params['_users_id_requester'])) {
                                     // Not set when testing
                                     $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile);
                                 }
                                 //Case 2 : check if there's only one profile for this user
                                 if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) {
                                     if (count($entities) == 1) {
                                         //User has right on only one entity
                                         $output['entities_id'] = array_pop($entities);
                                     } else {
                                         if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                             $output['entities_id'] = array_pop($entities);
                                         } else {
                                             //Rights on more than one entity : get the user's prefered entity
                                             if (isset($params['_users_id_requester'])) {
                                                 // Not set when testing
                                                 $user = new User();
                                                 $user->getFromDB($params['_users_id_requester']);
                                                 $tmpid = $user->getField('entities_id');
                                                 // Retrieve all the entities (pref could be set on a child)
                                                 $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile, true);
                                                 // If an entity is defined in user's preferences,
                                                 // and this entity allowed for this profile, use this one
                                                 // else do not set the rule as matched
                                                 if (in_array($tmpid, $entities)) {
                                                     $output['entities_id'] = $user->fields['entities_id'];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                     }
                     break;
                 case "regex_result":
                     foreach ($this->regex_results as $regex_result) {
                         $entity_found = -1;
                         $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
                         if ($res != null) {
                             switch ($action->fields["field"]) {
                                 case "_affect_entity_by_domain":
                                     $entity_found = Entity::getEntityIDByDomain(addslashes($res));
                                     break;
                                 case "_affect_entity_by_tag":
                                     $entity_found = Entity::getEntityIDByTag(addslashes($res));
                                     break;
                             }
                             //If an entity was found
                             if ($entity_found > -1) {
                                 $output['entities_id'] = $entity_found;
                                 break;
                             }
                         }
                     }
                     // switch (field)
                     break;
             }
         }
     }
     return $output;
 }