/** * @see ProjectPermissionUserInterface::create() * @param integer $user_id * @param integer $project_id * @param integer $permission * @param integer $owner_id * @param integer $intention * @return integer * @throws ProjectPermissionUserCreateException * @throws ProjectPermissionUserCreateVirtualFolderException */ public function create($user_id, $project_id, $permission, $owner_id, $intention) { global $transaction; if (is_numeric($user_id) and is_numeric($project_id)) { $transaction_id = $transaction->begin(); if (($permission_id = parent::create($user_id, null, null, $project_id, $permission, $owner_id, $intention)) != null) { self::__construct($permission_id); $project_folder_id = ProjectFolder::get_folder_by_project_id($project_id); $permission_string = strrev(decbin($permission)); if ($permission_string[2] == 1 or $permission_string[3] == 1 or $permission_string[7] == 1) { $folder_id = UserFolder::get_folder_by_user_id($user_id); $virtual_folder = new VirtualFolder(null); $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id); foreach ($virtual_folder_array as $key => $value) { $virtual_folder = new ProjectVirtualFolder($value); if ($virtual_folder->is_project_vfolder() == true) { $virtual_folder_id = $value; } } if (is_numeric($virtual_folder_id)) { $virtual_folder = new VirtualFolder($virtual_folder_id); if ($virtual_folder->link_folder($project_folder_id) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectPermissionUserCreateVirtualFolderException(); } } } if ($transaction_id != null) { $transaction->commit($transaction_id); } return $permission_id; } else { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectPermissionUserCreateException(); } } else { throw new ProjectPermissionUserCreateException(); } }
/** * @see ProjectPermissionInterface::set_permission() * @param integer $permission * @return bool */ public function set_permission($permission) { if (is_numeric($permission) and $this->project_permission and $this->permission_id) { if (($user_id = $this->project_permission->get_user_id()) != null) { $current_permission_string = strrev(decbin($this->project_permission->get_permission())); $new_permission_string = strrev(decbin($permission)); $project_folder_id = ProjectFolder::get_folder_by_project_id($this->project_permission->get_project_id()); if ($current_permission_string[2] == 0 and $current_permission_string[3] == 0 and $current_permission_string[7] == 0) { $folder_id = UserFolder::get_folder_by_user_id($user_id); $virtual_folder = new VirtualFolder(null); $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id); foreach ($virtual_folder_array as $key => $value) { $virtual_folder = new ProjectVirtualFolder($value); if ($virtual_folder->is_project_vfolder() == true) { $virtual_folder_id = $value; } } if (is_numeric($virtual_folder_id)) { $virtual_folder = new VirtualFolder($virtual_folder_id); if ($virtual_folder->link_folder($project_folder_id) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } return null; } } } } return $this->project_permission->set_permission($permission); } else { return false; } }
/** * @see SampleSecurityInterface::create_organisation_unit() * @param integer $organisation_unit_id * @return integer */ public function create_organisation_unit($organisation_unit_id) { global $transaction; if ($this->sample_id) { $transaction_id = $transaction->begin(); $sample_has_organisation_unit = new SampleHasOrganisationUnit_Access(null); if (($sample_has_organisation_unit_pk = $sample_has_organisation_unit->create($this->sample_id, $organisation_unit_id)) != null) { $sample_folder_id = SampleFolder::get_folder_by_sample_id($this->sample_id); $folder_id = OrganisationUnitFolder::get_folder_by_organisation_unit_id($organisation_unit_id); $virtual_folder = new VirtualFolder(null); $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id); if (is_array($virtual_folder_array)) { foreach ($virtual_folder_array as $key => $value) { $virtual_folder = new SampleVirtualFolder($value); if ($virtual_folder->is_sample_vfolder() == true) { $virtual_folder_id = $value; } } } if ($virtual_folder_id) { $virtual_folder = new VirtualFolder($virtual_folder_id); if ($virtual_folder->link_folder($sample_folder_id) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } return null; } } $organisation_unit = new OrganisationUnit($organisation_unit_id); $group_array = $organisation_unit->list_groups(); if (is_array($group_array) and count($group_array) >= 1) { foreach ($group_array as $key => $value) { $folder_id = GroupFolder::get_folder_by_group_id($value); $virtual_folder = new VirtualFolder(null); $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id); if (is_array($virtual_folder_array)) { foreach ($virtual_folder_array as $key => $value) { $virtual_folder = new SampleVirtualFolder($value); if ($virtual_folder->is_sample_vfolder() == true) { $virtual_folder_id = $value; } } } if (is_numeric($virtual_folder_id)) { $virtual_folder = new VirtualFolder($virtual_folder_id); if ($virtual_folder->link_folder($sample_folder_id) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } return null; } } } } if ($transaction_id != null) { $transaction->commit($transaction_id); } return $sample_has_organisation_unit_pk; } else { if ($transaction_id != null) { $transaction->rollback($transaction_id); } return null; } } else { return null; } }