Exemplo n.º 1
0
 /**
  * Gets only the recipients with at least a 'read' right
  * and checks if the user has disabled/enabled the settings for saving the messages.
  *
  * If no recipient is given, returns an empty array.
  *
  * @return array Array with user IDs.
  */
 public function getRecipients()
 {
     if (false === empty($this->_recipients)) {
         return $this->_recipients;
     }
     $recipients = array();
     if ($this->_model instanceof Phprojekt_Tree_Node_Database || $this->_model instanceof Phprojekt_Model_Interface) {
         $userIds = $this->_model->getUsersRights();
         if (is_array($userIds) && !empty($userIds)) {
             foreach ($userIds as $right) {
                 if ($right['userId'] == Phprojekt_Auth::getUserId() || true === $right['none']) {
                     continue;
                 }
                 $recipients[] = $right['userId'];
             }
         }
     } else {
         $user = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
         $userIds = $user->fetchAll();
         foreach ($userIds as $user) {
             if ($user->id == Phprojekt_Auth::getUserId()) {
                 continue;
             }
             $recipients[] = $user->id;
         }
     }
     return $this->filterRecipientsToSettings($recipients);
 }
Exemplo n.º 2
0
 /**
  * Add read, write and delete access to the assigned user in an item.
  *
  * @param string                    $key     The name of the user field.
  * @param array                     $params  The post values.
  * @param Phprojekt_Model_Interface $model   The current module to save.
  * @param boolean                   $newItem If is new item or not.
  *
  * @return array Array with user IDs per access.
  */
 public static function addRightsToAssignedUser($key, $params, $model, $newItem)
 {
     // Add rights to the Assigned user, if any
     $assignedUser = isset($params[$key]) ? $params[$key] : 0;
     // The assgined user is set
     if ($assignedUser != 0) {
         // Is an Existing item
         // The logged user don't have access to the 'Access' tab
         if (!$newItem && !isset($params['dataAccess'])) {
             // The rights will be added to the Request Params, but also it needs to be added the
             // already existing rights for users on this item. Case else, the saving routine deletes all
             // other rights that the ones added for the assigned user
             // Add already existing rights of the item,
             // except for the new assignedUser
             // except for the old assignedUser
             $currentRights = $model->getUsersRights();
             $rightsType = array('access', 'read', 'write', 'create', 'copy', 'delete', 'download', 'admin');
             foreach ($currentRights as $userRights) {
                 $userId = $userRights['userId'];
                 if ($userId != $assignedUser && $userId != $model->{$key}) {
                     $params = self::addUser($params, $userId);
                     foreach ($rightsType as $rightName) {
                         if (array_key_exists($rightName, $userRights)) {
                             if ($userRights[$rightName] == 1) {
                                 $rightCompleteName = 'check' . ucfirst($rightName) . 'Access';
                                 if (!array_key_exists($rightCompleteName, $params)) {
                                     $params[$rightCompleteName] = array();
                                 }
                                 $params[$rightCompleteName][$userId] = 1;
                             }
                         }
                     }
                 }
             }
         }
         // Add the assigned user basic write rights to $params
         // If is the owner, set full access
         if ($model->ownerId == $assignedUser) {
             $params = self::allowAll($params, $model->ownerId);
         } else {
             $params = self::allowReadWriteDownloadDelete($params, $assignedUser);
         }
     }
     return $params;
 }