/** * Answer true if a comment should be added to the history to indicate a change in * author/time. * * @param object Id $origAgentId * @param object Id $newAgentId * @return boolean * @access protected * @since 1/25/08 */ protected function addChangedAgentComment(Id $origAgentId, Id $newAgentId) { if ($origAgentId->isEqual($newAgentId)) { return false; } else { return true; } }
/** * Create a Part. Records are composed of Parts. Parts can also contain * other Parts. Each Record is associated with a specific RecordStructure * and each Part is associated with a specific PartStructure. * * @param object Id $partStructureId * @param object mixed $value (original type: java.io.Serializable) * * @return object Part * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function createPart(Id $partStructureId, $value) { $found = FALSE; foreach ($this->_parts as $key => $val) { if ($partStructureId->isEqual($val->getId())) { break; } $found = TRUE; /* while ($parts->hasNext()) { $part =$parts->next(); if ($partStructureId->isEqual($part->getId())) { break; $found = TRUE; } */ } if (!$found) { throwError(new Error(RepositoryException::UNKNOWN_ID(), "FileRecord", true)); } $partIdString = $partStructureId->getIdString(); // if (is_object($this->_parts[$partIdString])) // throwError(new Error(PERMISSION_DENIED.": Can't add another field to a // non-multi-valued part.", "FileRecord", true)); // } else { // // switch ($partIdString) { // case "FILE_DATA": // $className = "FileDataPart"; // break; // case "FILE_NAME": // $className = "FileNamePart"; // break; // case "FILE_SIZE": // $className = "FileSizePart"; // break; // case "MIME_TYPE": // $className = "MimeTypePart"; // break; // default: // throwError(new Error(OPERATION_FAILED, "FileRecord", true)); // } // // $this->_parts[$partIdString] = new $className( // $part, // $this->_id, // $this->configuration); // } $this->_parts[$partIdString]->updateValue($value); // Make sure that we don't trigger deleting of the whole record by deleting // and recreating parts if (isset($this->_toDelete) && in_array($partIdString, $this->_toDelete)) { $key = array_search($partIdString, $this->_toDelete); unset($this->_toDelete[$key]); } $this->_asset->updateModificationDate(); return $this->_parts[$partIdString]; }
/** * Get the Parts of the Records for this Asset that are based on this * RecordStructure PartStructure's unique Id. * * @param object Id $partStructureId * * @return object PartIterator * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function getPartsByPartStructure(Id $partStructureId) { $returnParts = array(); $records = $this->getRecords(); while ($records->hasNext()) { $record = $records->next(); $parts = $record->getParts(); while ($parts->hasNext()) { $part = $parts->next(); $partStructure = $part->getPartStructure(); if ($partStructureId->isEqual($partStructure->getId())) { $returnParts[] = $part; } } } $obj = new HarmoniIterator($returnParts); return $obj; }
/** * Add an External group to a Hierarchy-based group. * * @param object Id $hierarchyParentId * @param object Id $externalChildId * @return void * @access public * @since 11/6/07 */ public function addExternalChildGroup(Id $hierarchyParentId, Id $externalChildId) { // Check to see that it hasn't been added. $children = $this->getExternalChildGroupIds($hierarchyParentId); foreach ($children as $child) { if ($externalChildId->isEqual($child)) { throw new HarmoniException("Child group '" . $externalChildId->getIdString() . "' has already been added to group '" . $hierarchyParentId->getIdString() . "'."); } } // Insert the row. $query = new InsertQuery(); $query->setTable('agent_external_children'); $query->addValue('fk_parent', $hierarchyParentId->getIdString()); $query->addValue('fk_child', $externalChildId->getIdString()); $dbc = Services::getService("DBHandler"); $dbc->query($query, $this->_configuration->getProperty('database_index')); }
/** * Get the Repository with the specified unique Id. * * @param object Id $repositoryId * * @return object Repository * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function getRepository(Id $repositoryId) { if (!isset($this->repository)) { throw new ConfigurationErrorException("No configuration."); } if (!$repositoryId->isEqual($this->repositoryId)) { throw new UnknownIdException("Unkown repositoryId, '{$repositoryId}'."); } return $this->repository; }
/** * Determines if this Qualifier is a descendant of the given qualifierId. * * @param object Id $ancestorId * * @return boolean * * @throws object AuthorizationException An exception with * one of the following messages defined in * org.osid.authorization.AuthorizationException may be thrown: * {@link * org.osid.authorization.AuthorizationException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.authorization.AuthorizationException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.authorization.AuthorizationException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.authorization.AuthorizationException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.authorization.AuthorizationException#UNKNOWN_ID * UNKNOWN_ID} * * @access public */ function isDescendantOf(Id $ancestorId) { // Alright, I realize this could be written much more efficiently (for // example by using Hierarchy->traverse()) but it is too much pain to do so. // The code below uses the methods in this class and is clearer, albeit slower. // Are we going to use this method a lot anyway? // base case if ($ancestorId->isEqual($this->getId())) { return true; } // recurse up $parents = $this->getParents(); while ($parents->hasNext()) { $parent = $parents->next(); if ($parent->isDescendantOf($ancestorId)) { return true; } } return false; }
/** * Get the Record for this Asset that matches this Record's unique Id. * * @param object Id $recordId * * @return object Record * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function getRecord(Id $recordId) { if ($recordId->isEqual($this->dcRecord->getId())) { return $this->dcRecord; } if ($recordId->isEqual($this->customRecord->getId())) { return $this->customRecord; } else { throw new UnknownIdException(); } }
/** * Changes the parent of this Node by adding a new parent and removing the * old parent. * * @param object Id $oldParentId * @param object Id $newParentId * * @throws object HierarchyException An exception with one of * the following messages defined in * org.osid.hierarchy.HierarchyException may be thrown: {@link * org.osid.hierarchy.HierarchyException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.hierarchy.HierarchyException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.hierarchy.HierarchyException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.hierarchy.HierarchyException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.hierarchy.HierarchyException#NODE_TYPE_NOT_FOUND * NODE_TYPE_NOT_FOUND}, {@link * org.osid.hierarchy.HierarchyException#ATTEMPTED_RECURSION * ATTEMPTED_RECURSION} * * @access public */ function changeParent(Id $oldParentId, Id $newParentId) { if ($oldParentId->isEqual($newParentId)) { return; } $authZ = $this->_cache->getAuthorizationManager(); $isAuthorizedCache = $authZ->getIsAuthorizedCache(); $isAuthorizedCache->dirtyNode($this->_id); // Store the current ancestor Ids for AuthZ updating $oldAncestorIds = $this->getAncestorIds(); $this->_cache->removeParent($oldParentId->getIdString(), $this->_id->getIdString()); $this->_cache->addParent($newParentId->getIdString(), $this->_id->getIdString()); // Instruct the Authorization system to remove any implicit AZs given // the removal of our ancestors. $removedAncestors = $this->idsRemoved($oldAncestorIds, $this->getAncestorIds()); $authZ->getAuthorizationCache()->deleteHierarchyImplictAZs($this, $removedAncestors); // Instruct the Authorization system to add any implicit AZs given // the addintion of our ancestors. $addedAncestors = $this->idsAdded($oldAncestorIds, $this->getAncestorIds()); $authZ->getAuthorizationCache()->createHierarchyImplictAZs($this, $addedAncestors); }
/** * Set authorizations to apply this role for an Agent at a Qualifier. * * Explicit Authorizations for the Agent at the Qualifier will be removed * and added in order to apply the role. * * Implicit Authorizations will not be changed. * * @param object Id $agentId * @param object Id $qualifierId * @param optional boolean $overrideAzCheck If true, not not check AZs. Used by admin functions to force-set a role. * @return void * @access public * @since 11/5/07 */ public function apply(Id $agentId, Id $qualifierId, $overrideAzCheck = false) { $authZ = Services::getService("AuthZ"); $idMgr = Services::getService("Id"); $everyoneId = $idMgr->getId('edu.middlebury.agents.everyone'); if (!$agentId->isEqual($everyoneId)) { return parent::apply($agentId, $qualifierId, $overrideAzCheck); } if (!$overrideAzCheck) { if (!$authZ->isUserAuthorized($idMgr->getId("edu.middlebury.authorization.modify_authorizations"), $qualifierId)) { throw new PermissionDeniedException("Cannot modify authorizations here."); } } /********************************************************* * For this role, give the view and view_comments authorizations to * the 'everyone' group and the 'comment' authorization to * the 'users' group to prevent anonymous posting. * * Search for the string 'only-logged-in-can-edit' to find other code that * makes this effect happen. *********************************************************/ // Run through the Authorizations for the 'everyone' group $authorizations = $authZ->getExplicitAZs($everyoneId, null, $qualifierId, true); // Delete Conflicting functions. We leave functions that the roles don't know about. $existing = array(); while ($authorizations->hasNext()) { $authorization = $authorizations->next(); if ($this->functionConflicts($authorization->getFunction()->getId())) { $authZ->deleteAuthorization($authorization); } else { if ($this->hasFunction($authorization->getFunction()->getId())) { $existing[] = $authorization->getFunction()->getId(); } } } // Add in new needed functions $this->addAuthorizationForFunction($everyoneId, $idMgr->getId("edu.middlebury.authorization.view"), $qualifierId, $existing); $this->addAuthorizationForFunction($everyoneId, $idMgr->getId("edu.middlebury.authorization.view_comments"), $qualifierId, $existing); // Run through the Authorizations for the 'users' group $usersId = $idMgr->getId('edu.middlebury.agents.users'); $authorizations = $authZ->getExplicitAZs($usersId, null, $qualifierId, true); // Delete Conflicting functions. We leave functions that the roles don't know about. $existing = array(); while ($authorizations->hasNext()) { $authorization = $authorizations->next(); if ($this->functionConflicts($authorization->getFunction()->getId())) { $authZ->deleteAuthorization($authorization); } else { if ($this->hasFunction($authorization->getFunction()->getId())) { $existing[] = $authorization->getFunction()->getId(); } } } // Add in new needed functions $this->addAuthorizationForFunction($usersId, $idMgr->getId("edu.middlebury.authorization.comment"), $qualifierId, $existing); /********************************************************* * End only-logged-in-can-edit *********************************************************/ }
/** * Recursively copies an asset and its children to a new parent. * * @access private */ function _copyAsset(Asset $asset, Id $newParentId) { // Create the new asset $newAsset = $this->createAsset($asset->getDisplayName(), $asset->getDescription(), $asset->getAssetType()); // Move the new asset to the proper parent if it // is not being copied to the dr root. if (!$newParentId->isEqual($this->getId())) { $newParent = $this->getAsset($newParentId); $newParent->addAsset($newAsset->getId()); } // Copy its data // @todo // Copy the children $children = $asset->getAssets(); while ($children->hasNext()) { $childAsset = $children->next(); $this->_copyAsset($childAsset, $newAsset->getId()); } // Return its Id return $newAsset->getId(); }
/** * Add an authorization * * @param object Id $agentId * @param object Id $functionId * @param object Id $qualifierId * @param array $appliedFunctions An array of function ids * @return void * @access protected * @since 11/5/07 */ protected function addAuthorizationForFunction(Id $agentId, Id $functionId, Id $qualifierId, array $appliedFunctions = array()) { foreach ($appliedFunctions as $func) { if ($functionId->isEqual($func)) { return; } } $authZ = Services::getService("AuthZ"); $authZ->createAuthorization($agentId, $functionId, $qualifierId); }