예제 #1
0
 /**
  * Save the rights for the current item.
  *
  * The users are a POST array with user IDs.
  *
  * @param array $rights Array of user IDs with the bitmask access.
  *
  * @return void
  */
 public function saveRights($rights)
 {
     // Do the default action
     parent::saveRights($rights);
     // Update access and delete the cache also for the children
     $itemRights = new Phprojekt_Item_Rights();
     $activeRecord = new Project_Models_Project();
     $tree = new Phprojekt_Tree_Node_Database($activeRecord, $this->id);
     $tree = $tree->setup();
     $users = array();
     foreach ($rights as $userId => $access) {
         $users[] = (int) $userId;
     }
     // Just a check
     if (empty($users)) {
         $users[] = 1;
     }
     // Keep on the childen only the access for the allowed users in the parent
     foreach ($tree as $node) {
         $projectId = (int) $node->id;
         // Delete users that are not allowed in the parent
         $where = sprintf('module_id = 1 AND item_id = %d AND user_id NOT IN (%s)', $projectId, implode(",", $users));
         $itemRights->delete($where);
     }
 }