function addProperty($type, $key, $value) { //properties manager is used to store properties $propertiesManager = Services::getService("Property"); //get the database id of the type $typeIdString = $propertiesManager->getTypeId($type); //an agent has one properties object for each Type, this gets the one for the type we're adding. $property = $this->getPropertiesByType($type); //if there aren't any properties of Type yet, create a new object if ($property === null) { //if agent has no properties of type $property = new HarmoniProperties($type); //create a new property of type $type } //add the property $property->addProperty($key, $value); //store the property to the database return $propertiesManager->storeProperties($this->_idString, $property); }
/** * Save our results. Tearing down and unsetting the Wizard is handled by * in {@link runWizard()} and does not need to be implemented here. * * @param string $cacheName * @return boolean TRUE if save was successful and tear-down/cleanup of the * Wizard should ensue. * @access public * @since 7/27/05 */ function saveWizard($cacheName) { $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $repositoryManager = Services::getService("Repository"); $wizard = $this->getWizard($cacheName); $properties = $wizard->getAllValues(); $centerPane = $this->getActionRows(); ob_start(); $path = $properties['filename']['tmp_name']; $filename = $properties['filename']['name']; if ($properties['filename']['name'] == "") { print "Please choose a file to upload!"; $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return FALSE; } $newName = $this->moveArchive($path, $filename); //===== THIS ARRAY DEFINES THINGS THAT SHOULD NOT BE IMPORTED =====// $this->_ignore = array("REMOTE_FILE", "FILE_URL", "FILE", "FILE_DATA", "FILE_NAME", "MIME_TYPE", "THUMBNAIL_DATA", "THUMBNAIL_MIME_TYPE", "FILE_SIZE", "DIMENSIONS", "THUMBNAIL_DIMENSIONS", "edu.middlebury.harmoni.repository.asset_content", "edu.middlebury.harmoni.repository.asset_content.Content"); $repository = $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id'))); $startTime = DateAndTime::now(); $this->_hasErrors = false; //===== Exif and Tab-Delim Importers are special =====// if ($properties['file_type'] == "Tab-Delimited") { $importer = new TabRepositoryImporter($newName, $repository->getId(), false); } else { if ($properties['file_type'] == "Exif") { $importer = new ExifRepositoryImporter($newName, $repository->getId(), false); } else { if ($properties['file_type'] == "FilesOnly") { $importer = new FilesOnlyRepositoryImporter($newName, $repository->getId(), false); } } } if (isset($importer)) { if ($properties['parent']) { $importer->setParent($repository->getAsset($idManager->getId($properties['parent']))); } $importer->import($properties['is_archived']); // something happened so tell the end user if ($importer->hasErrors()) { $importer->printErrorMessages(); $this->_hasErrors = true; } } //===== Done with special "RepositoryImporters" =====// if ($properties['file_type'] == "XML") { if ($properties['is_archived'] == TRUE) { // define an empty importer for decompression $importer = new XMLImporter($this->_ignore); $directory = $importer->decompress($newName); unset($importer); $this->_repository = $repository; $this->_importType = $properties['import_type']; if ($properties['parent']) { $parent = $repository->getAsset($idManager->getId($properties['parent'])); } else { $parent = null; } $this->importDirectoriesDown($directory, $parent); } else { // not compressed, only one xml file $importer = XMLRepositoryImporter::withObject($this->_ignore, $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id'))), $newName, $properties['import_type']); if ($properties['parent']) { $importer->setParent($repository->getAsset($idManager->getId($properties['parent']))); } $importer->parseAndImportBelow("asset", 100); // something happened so tell the end user if ($importer->hasErrors()) { $importer->printErrorMessages(); $this->_hasErrors = true; } unset($importer); } } // Unlink the directory if (isset($directory) && $directory) { $this->deleteRecursive($directory); } if (file_exists($newName)) { unlink($newName); } if ($this->_hasErrors) { $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return FALSE; } // Update any newly modified assets' tags $searchProperties = new HarmoniProperties(new Type("repository", "harmoni", "order")); $searchProperties->addProperty("order", $order = "ModificationDate"); $searchProperties->addProperty("direction", $direction = "DESC"); $assets = $repository->getAssetsBySearch($criteria = '*', new Type("Repository", "edu.middlebury.harmoni", "DisplayName"), $searchProperties); $systemAgentId = $idManager->getId('system:concerto'); $tagGenerator = StructuredMetaDataTagGenerator::instance(); while ($assets->hasNext()) { $asset = $assets->next(); if ($startTime->isGreaterThan($asset->getModificationDate())) { break; } $tagGenerator->regenerateTagsForAsset($asset, $systemAgentId, 'concerto', $repository->getId()); } // clean and clear $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return TRUE; }
/** * A public function to take a key/value array of properties as might be * gathered from a web form and turns it into a useable object * * @param array $propertiesArray * @param object Type $type * * @return object Property * * @acess public */ function convertArrayToObject($propertiesArray, $type) { $property = new HarmoniProperties($type); foreach ($propertiesArray as $key => $propertyValue) { $property->addProperty($key, $propertyValue); } return $property; }
/** * Answer an iterator of the latest assets * * @param object Repository $repository * @return object Iterator * @access public * @since 8/8/06 */ function getAssets($repository) { $searchModuleManager = Services::getService("RepositorySearchModules"); $searchProperties = new HarmoniProperties(HarmoniType::fromString("repository::harmoni::order")); if (RequestContext::value('order') == 'modification') { $searchProperties->addProperty("order", $arg0 = 'ModificationDate'); } else { $searchProperties->addProperty("order", $arg1 = "CreationDate"); } $searchProperties->addProperty("direction", $arg2 = 'DESC'); $assets = $repository->getAssetsBySearch($criteria = '*', new Type("Repository", "edu.middlebury.harmoni", "Keyword", "Search with a string for keywords."), $searchProperties); return $assets; }
function _getProperties() { $dbManager = Services::getService("DatabaseManager"); //get the record $query = new SelectQuery(); $query->addTable('cm_section'); $query->addColumn("*"); $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'"); $res = $dbManager->query($query); //make sure we can find that course if (!$res->hasMoreRows()) { print "<b>Warning!</b> Can't get Properties of Course with id " . $this->_id . " since that id wasn't found in the database."; return null; } $row = $res->getCurrentRow(); //grab (hopefully) the only row //make a type $courseType = $this->getSectionType(); $propertiesType = new Type("PropertiesType", $courseType->getAuthority(), "properties"); //create a custom Properties object $idManager = Services::getService("Id"); $property = new HarmoniProperties($propertiesType); $displayName = $this->_node->getDisplayName(); $property->addProperty('display_name', $displayName); $property->addProperty('title', $row['title']); $description = $this->_node->getDescription(); $property->addProperty('description', $description); $property->addProperty('id', $idManager->getId($row['id'])); $property->addProperty('number', $row['number']); $property->addProperty('type', $courseType); $statusType = $this->getStatus(); $property->addProperty('status_type', $statusType); $property->addProperty('location', $row['location']); $res->free(); return $property; }
/** * Get a Properties object with the information about this object. * * @return object Properties * * @access private */ function _getProperties() { //get the record $dbManager = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable('gr_gradable'); $query->addColumn("*"); $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'"); $res = $dbManager->query($query); //make sure we can find that record if (!$res->hasMoreRows()) { print "<b>Warning!</b> Can't get Properties of GradableObject with id " . $this->_id . " since that id wasn't found in the database."; return null; } $row = $res->getCurrentRow(); //grab (hopefully) the only row //make a type $type = $this->getGradeType(); $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties"); //create a custom Properties object $idManager = Services::getService("Id"); $property = new HarmoniProperties($propertiesType); $property->addProperty('id', $idManager->getId($row['id'])); $scoringType = $this->getScoringDefinition(); $property->addProperty('scoring_type', $scoringType); $gradeType = $this->getGradeType(); $property->addProperty('grade_type', $gradeType); $gradeScale = $this->getGradeScale(); $property->addProperty('grade_scale', $gradeScale); $property->addProperty('description', $row['description']); $property->addProperty('display_name', $row['name']); $property->addProperty('modified_date', $row['modified_date']); $property->addProperty('modified_by_agent_id', $idManager->getId($row['fk_modified_by_agent'])); $property->addProperty('reference_id', $idManager->getId($row['fk_reference_id'])); $property->addProperty('course_section_id', $idManager->getId($row['fk_cm_section'])); $property->addProperty('weight', $row['weight']); $res->free(); return $property; }
/** * Answer the root assets in the current repository * * @return object Iterator * @access public * @since 4/2/07 */ function getRootAssets() { $repository = $this->getRepository(); if (!$repository) { throw new Exception("Repository not found"); } $criteria = NULL; $searchProperties = new HarmoniProperties(HarmoniType::fromString("repository::harmoni::order")); $searchProperties->addProperty("order", $orderBy = 'DisplayName'); $searchProperties->addProperty("direction", $direction = 'ASC'); unset($orderBy, $direction); $assets = $repository->getAssetsBySearch($criteria, new HarmoniType("Repository", "edu.middlebury.harmoni", "RootAssets", ""), $searchProperties); return $assets; }
/** * Build the content for this action * * @return boolean * @access public * @since 4/26/05 */ function buildContent() { $actionRows = $this->getActionRows(); $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $repositoryManager = Services::getService("Repository"); $exhibitionRepositoryId = $idManager->getId("edu.middlebury.concerto.exhibition_repository"); $repository = $repositoryManager->getRepository($exhibitionRepositoryId); // If the Repository supports searching of root assets, just get those $hasRootSearch = FALSE; $rootSearchType = new HarmoniType("Repository", "edu.middlebury.harmoni", "RootAssets", ""); $searchTypes = $repository->getSearchTypes(); while ($searchTypes->hasNext()) { if ($rootSearchType->isEqual($searchTypes->next())) { $hasRootSearch = TRUE; break; } } ob_start(); print "<p>"; print _("Some <em>Exhibitions</em> and <em>Slide-Shows</em> may be restricted to certain users or groups of users. Log in above to ensure your greatest access to all parts of the system."); print "</p>"; $authZ = Services::getService("AuthZ"); //===== Create Link =====// if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $exhibitionRepositoryId)) { print "\n<p>"; print "\n\t<a href='" . $harmoni->request->quickURL("exhibitions", "create_exhibition") . "'>" . _("Create a new <em>Exhibition</em>") . "</a>"; //===== Import Link =====// // $harmoni->request->startNamespace("import"); // print "\t|\t<a href='". // $harmoni->request->quickURL("exhibitions", "import_exhibition"). // "'>". // _("Import <em>Exhibition(s)</em>"). // "</a>"; // $harmoni->request->endNamespace(); print "\n</p>"; } $introText = new Block(ob_get_contents(), STANDARD_BLOCK); ob_end_clean(); $actionRows->add($introText, "100%", null, CENTER, CENTER); //*********************************** // Get the assets to display //*********************************** if ($hasRootSearch) { $criteria = NULL; $searchProperties = new HarmoniProperties(HarmoniType::fromString("repository::harmoni::order")); $searchProperties->addProperty("order", $arg = "DisplayName"); unset($arg); $searchProperties->addProperty("direction", $arg = "ASC"); unset($arg); $assets = $repository->getAssetsBySearch($criteria, $rootSearchType, $searchProperties); } else { $assets = $repository->getAssets(); } //*********************************** // print the results //*********************************** $resultPrinter = new IteratorResultPrinter($assets, 1, 20, "printAssetShort", $harmoni); $resultLayout = $resultPrinter->getLayout("canView"); $actionRows->add($resultLayout, "100%", null, LEFT, CENTER); }
/** * Create a new CourseGroup * * @param object Id $id The Identifier to use for this Course Group. This may * be related to some sort of course code if desired. * @param string $displayName * @return object SegueCourseGroup * @access public * @since 8/20/07 */ public function createCourseGroup(Id $id, $displayName) { $agentMgr = Services::getService("Agent"); $idMgr = Services::getService("Id"); $rootGroup = $agentMgr->getGroup($idMgr->getId("edu.middlebury.segue.coursegroups")); $propType = new Type("segue", "edu.middlebury", "coursegroup"); $properties = new HarmoniProperties($propType); $idString = $id->getIdString(); $properties->addProperty("CourseGroupId", $idString); $courseGroup = $agentMgr->createGroup($displayName, new Type('segue', 'edu.middlebury', 'coursegroup'), "", $properties); $rootGroup->add($courseGroup); return $this->getCourseForGroup($courseGroup); }
function _getProperties() { $dbHandler = Services::getService("DBHandler"); //get the record $query = new SelectQuery(); $query->addTable('sc_item'); $query->addColumn("*"); $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'"); $res = $dbHandler->query($query); //make sure we can find that course if (!$res->hasMoreRows()) { print "<b>Warning!</b> Can't get Properties of ScheduleItem with id " . $this->_id . " since that id wasn't found in the database."; return null; } $row = $res->getCurrentRow(); //grab (hopefully) the only row //make a type $type = $this->getStatus(); $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties"); //create a custom Properties object $idManager = Services::getService("Id"); $property = new HarmoniProperties($propertiesType); $property->addProperty('display_name', $row['name']); $property->addProperty('description', $row['description']); $property->addProperty('id', $idManager->getId($row['id'])); $property->addProperty('start', $row['start_date']); $property->addProperty('end', $row['end_date']); $property->addProperty('master_identifier', $row['master_id']); $property->addProperty('status_type', $type); $res->free(); return $property; }
/** * Answer a Properties object from an entry XML element. * * @param DOMElement $element * @return Properties * @access public * @since 10/6/09 */ public function _getPropertiesFromCASEntry(DOMElement $element) { $properties = new HarmoniProperties(new Type('GroupProperties', 'edu.middlebury', 'CAS Properties')); foreach ($element->getElementsByTagNameNS('http://www.yale.edu/tp/cas', 'attribute') as $attra) { if ($attra->getAttribute('name') != 'MemberOf') { $properties->addProperty($attra->getAttribute('name'), $attra->getAttribute('value')); } } return $properties; }
/** * Get a Properties object with the information about this object. * * @return object Properties * * @access private */ function _getProperties() { //get the record $dbManager = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable('gr_record'); $query->addColumn("*"); $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'"); $res = $dbManager->query($query); //make sure we can find that record if (!$res->hasMoreRows()) { print "<b>Warning!</b> Can't get Properties of GradeRecord with id " . $this->_id . " since that id wasn't found in the database."; return null; } $row = $res->getCurrentRow(); //grab (hopefully) the only row //make a type $type = $this->getGradeRecordType(); $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties"); //create a custom Properties object $idManager = Services::getService("Id"); $property = new HarmoniProperties($propertiesType); $property->addProperty('id', $this->_id); $property->addProperty('value', $row['value']); $property->addProperty('gradable_object_id', $idManager->getId($row['fk_gr_gradable'])); $property->addProperty('agent_id', $idManager->getId($row['fk_agent_id'])); $property->addProperty('modified_by_agent_id', $idManager->getId($row['fk_modified_by_agent'])); $property->addProperty('modified_date', $row['modified_date']); $recordType = $this->getGradeRecordType(); $property->addProperty('type', $recordType); $res->free(); return $property; }
/** * Answer the assets that we are searching for * * @return object Iterator * @access public * @since 5/15/06 */ function getAssets() { $repository = $this->getRepository(); $searchModuleManager = Services::getService("RepositorySearchModules"); $searchProperties = new HarmoniProperties(HarmoniType::fromString("repository::harmoni::order")); $searchProperties->addProperty("order", $_SESSION["asset_order"]); $searchProperties->addProperty("direction", $_SESSION['asset_order_direction']); if ($this->_state["limit_by_type"] == 'true' && isset($this->_state['selectedTypes']) && count($this->_state['selectedTypes'])) { $searchProperties->addProperty("allowed_types", $this->_state['selectedTypes']); } if (isset($this->_state['searchtype']) && $searchModuleManager->getSearchCriteria($repository, $this->_state['searchtype'])) { $criteria = $searchModuleManager->getSearchCriteria($repository, $this->_state['searchtype']); $assets = $repository->getAssetsBySearch($criteria, $this->_state['searchtype'], $searchProperties); } else { if ($this->_state["limit_by_type"] == 'true' && isset($this->_state['selectedTypes']) && count($this->_state['selectedTypes'])) { $assets = new MultiIteratorIterator($null = null); foreach (array_keys($this->_state['selectedTypes']) as $key) { $assets->addIterator($repository->getAssetsByType($this->_state['selectedTypes'][$key])); } } else { if ($this->hasRootSearch()) { $criteria = NULL; $assets = $repository->getAssetsBySearch($criteria, new HarmoniType("Repository", "edu.middlebury.harmoni", "RootAssets", ""), $searchProperties); } else { $assets = $repository->getAssets(); } } } return $assets; }
/** * Get the Properties of this Type associated with this Group. * * @param object Type $propertiesType * * @return object Properties * * @throws object AgentException An exception with one of the * following messages defined in org.osid.agent.AgentException may * be thrown: {@link * org.osid.agent.AgentException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.agent.AgentException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.agent.AgentException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}, * {@link org.osid.agent.AgentException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE} * * @access public */ function getPropertiesByType(Type $propertiesType) { if (!$propertiesType->isEqual(new Type('GroupProperties', 'edu.middlebury', 'LDAP Properties'))) { throw new UnknownTypeException("Unsupported Properties type."); } if (!isset($_SESSION['LDAP_GROUP_PROPERTIES'][$this->_idString])) { $properties = new HarmoniProperties(new Type('GroupProperties', 'edu.middlebury', 'LDAP Properties')); $properties->addProperty('identifier', $this->_idString); $propertiesFields = $this->_configuration->getProperty('group_properties_fields'); if (is_array($propertiesFields)) { $fieldsToFetch = array(); foreach ($propertiesFields as $propertyKey => $fieldName) { $fieldsToFetch[] = $fieldName; } $info = $this->_authNMethod->_connector->getInfo($this->_idString, $fieldsToFetch); if (!$info) { // store a null so that we won't keep trying to fetch data. $_SESSION['LDAP_GROUP_PROPERTIES'][$this->_idString] = null; throw new OperationFailedException("Could not fetch LDAP group info."); } foreach ($propertiesFields as $propertyKey => $fieldName) { if (isset($info[$fieldName])) { if (count($info[$fieldName]) <= 1) { $properties->addProperty($propertyKey, $info[$fieldName][0]); } else { $properties->addProperty($propertyKey, $info[$fieldName]); } } } } $_SESSION['LDAP_GROUP_PROPERTIES'][$this->_idString] = $properties; } if (is_null($_SESSION['LDAP_GROUP_PROPERTIES'][$this->_idString])) { throw new OperationFailedException("Could not fetch LDAP group info."); } return $_SESSION['LDAP_GROUP_PROPERTIES'][$this->_idString]; }
/** * Return Properties associated with the Tokens. The properties will have * the AuthNMethod Type as their Type. One Property that should always be * included is 'identifier' which corresponds to the identifier for the tokens * * @param object AuthNTokens $authNTokens * @return object Properties * @access public * @since 3/1/05 */ function getPropertiesForTokens($authNTokens) { ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens")); $properties = new HarmoniProperties($this->getType()); // Properties take values by reference, so we have to work around // that by creating/unsetting variables. $value = $authNTokens->getIdentifier(); $properties->addProperty('identifier', $value); unset($value); $this->_populateProperties($authNTokens, $properties); return $properties; }