/** * Returns the values of wizard-components. Should return an array if children are involved, * otherwise a whatever type of object is expected. * @access public * @return mixed */ function getAllValues() { if (is_null($this->_value)) { return null; } $obj = DateAndTime::fromString($this->_value); // print "<pre>"; var_dump($this->_value); print "</pre>"; // printpre($obj); return $obj; }
/** * Imports the current node's information * * @access public * @since 10/6/05 */ function importNode() { $idManager = Services::getService("Id"); if (!method_exists($this->_parent, "createAsset")) { $this->_stepParent = $this->_parent; $this->_parent = $this->_stepParent->getRepository(); } $this->getNodeInfo(); $hasId = $this->_node->hasAttribute("id"); if ($hasId && (in_array($this->_node->getAttribute("id"), $this->_existingArray) || $this->_type == "update")) { $this->_myId = $idManager->getId($this->_node->getAttribute("id")); $this->_object = $this->_parent->getAsset($this->_myId); $this->update(); } else { $this->_object = $this->_parent->createAsset($this->_info['name'], $this->_info['description'], $this->_info['type']); $this->_myId = $this->_object->getId(); if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Harmoni"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events."); $item = new AgentNodeEntryItem("Create Node", "Asset: " . htmlspecialchars($this->_myId->getIdString()) . " created."); $item->addNodeId($this->_myId); $item->addNodeId($this->_parent->getId()); } if (isset($this->_stepParent)) { $this->_stepParent->addAsset($this->_myId); if (isset($item)) { $item->addNodeId($this->_stepParent->getId()); } } if (isset($this->_info['effectivedate'])) { $this->_object->updateEffectiveDate(DateAndTime::fromString($this->_info['effectivedate'])); } if (isset($this->_info['expirationdate'])) { $this->_object->updateExpirationDate(DateAndTime::fromString($this->_info['expirationdate'])); } if (isset($item)) { $log->appendLogWithTypes($item, $formatType, $priorityType); } } if ($this->_node->hasAttribute("maintainOrder") && $this->_node->getAttribute("maintainOrder") == TRUE) { $this->doSets(); } }
/** * Converts a database datetime/timestamp/time value (that has been fetched * from the db) to a DateAndTime object. * * @access public * @param mixed A database datetime/timestamp/time value (that has been fetched * from the db). * @return ref object The DateAndTime object. */ function fromDBDate($value) { /* * NOT SURE HOW TO DO THIS FOR ORACLE */ $obj = DateAndTime::fromString($value); return $obj; }
/** * Answer true if the content has modified since the cache was last * updated, false otherwise. * * Based on info from: * Simon Willison - http://simonwillison.net/2003/Apr/23/conditionalGet/ * http://fishbowl.pastiche.org/archives/001132.html * * * @param object DateAndTime $timestamp * @param string $eTag * @return boolean * @access private * @since 5/13/08 */ private function changed(DateAndTime $timestamp, $eTag) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $clientTimestamp = DateAndTime::fromString(stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE'])); } if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $clientETag = trim($_SERVER['HTTP_IF_NONE_MATCH']); $eTag = trim($eTag); } // Check the HTTP 1.1 ETag/If None Match parts first. if (isset($clientETag) && $clientETag == $eTag) { return false; } // Check the HTTP 1.0 Modification date if (isset($clientTimestamp) && $timestamp->isLessThanOrEqual($clientTimestamp)) { return false; } return true; }
/** * Answer a new instance represented by a string: * * - '-1199-01-05T20:33:14.321-05:00' * - ' 2002-05-16T17:20:45.00000001+01:01' * - ' 2002-05-16T17:20:45.00000001' * - ' 2002-05-16T17:20' * - ' 2002-05-16T17:20:45' * - ' 2002-05-16T17:20:45+01:57' * - ' 2002-05-16T17:20:45-02:34' * - ' 2002-05-16T17:20:45+00:00' * - ' 1997-04-26T01:02:03+01:02:3' * * @param string $aString The input string. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object StorableTime * @access public * @since 5/12/05 * @static */ static function fromString($aString, $class = 'StorableTime') { return parent::fromString($aString, $class); }
/** * Update a record table for a set of harvesters and repositories * * @param string $table * @param array $allowedRepositoryIdStrings * @param array $authGroupIdStrings The ids of the groups to check view authorization for, * May be one of the following or another group Id string: * edu.middlebury.agents.everyone * edu.middlebury.agents.all_agents * If empty, all assets in the specified repositories will be added regardless of * their visibility. * * @return void * @access public * @since 3/9/07 */ function updateTable($table, $allowedRepositoryIdStrings, $authGroupIdStrings) { ArgumentValidator::validate($table, StringValidatorRule::getRule()); ArgumentValidator::validate($allowedRepositoryIdStrings, ArrayValidatorRuleWithRule::getRule(StringValidatorRule::getRule())); ArgumentValidator::validate($authGroupIdStrings, ArrayValidatorRuleWithRule::getRule(StringValidatorRule::getRule())); $harmoni = Harmoni::instance(); $config = $harmoni->getAttachedData('OAI_CONFIG'); $repositoryManager = Services::getService('Repository'); $authorizationManager = Services::getService('AuthZ'); $idManager = Services::getService("IdManager"); $dbc = Services::getService("DatabaseManager"); $authGroupIds = array(); foreach ($authGroupIdStrings as $id) { $authGroupIds[] = $idManager->getId($id); } $baseCheckQuery = new SelectQuery(); $baseCheckQuery->addTable('oai_' . $table); $baseCheckQuery->addColumn('datestamp'); $baseCheckQuery->addColumn('deleted'); $baseUpdateQuery = new UpdateQuery(); $baseUpdateQuery->setTable('oai_' . $table); $baseUpdateColumns = array('datestamp', 'deleted', 'oai_set', 'dc_title', 'dc_description'); $dcUpdateColumns = array('datestamp', 'deleted', 'oai_set', 'dc_title', 'dc_description', 'dc_creator', 'dc_subject', 'dc_contributor', 'dc_publisher', 'dc_date', 'dc_type', 'dc_format', 'dc_identifier', 'dc_source', 'dc_language', 'dc_relation', 'dc_coverage', 'dc_rights'); $baseInsertQuery = new InsertQuery(); $baseInsertQuery->setTable('oai_' . $table); $baseInsertColumns = array('datestamp', 'oai_identifier', 'deleted', 'oai_set', 'dc_title', 'dc_description'); $dcInsertColumns = array('datestamp', 'oai_identifier', 'deleted', 'oai_set', 'dc_title', 'dc_description', 'dc_creator', 'dc_subject', 'dc_contributor', 'dc_publisher', 'dc_date', 'dc_type', 'dc_format', 'dc_identifier', 'dc_source', 'dc_language', 'dc_relation', 'dc_coverage', 'dc_rights'); $baseDeleteQuery = new UpdateQuery(); $baseDeleteQuery->setTable('oai_' . $table); $baseDeleteQuery->addValue('deleted', 'true'); $baseDeleteQuery->addRawValue('datestamp', 'NOW()'); $baseUndeleteQuery = new UpdateQuery(); $baseUndeleteQuery->setTable('oai_' . $table); $baseUndeleteQuery->addValue('deleted', 'false'); $baseUndeleteQuery->addRawValue('datestamp', 'NOW()'); $forceUpdate = false; $repositories = $repositoryManager->getRepositories(); $r = 0; if (count($allowedRepositoryIdStrings)) { $numR = count($allowedRepositoryIdStrings); } else { $numR = $repositories->count(); } $numUpdates = 0; $numDeleted = 0; $message = _('Updating OAI records for repository (%1 of %2) : '); $message = str_replace('%2', $numR, $message); $instituteId = $idManager->getId('edu.middlebury.agents.users'); $viewId = $idManager->getId('edu.middlebury.authorization.view'); require_once HARMONI . "/utilities/Timer.class.php"; $timer = new Timer(); $timer->start(); $existingRepositoryIds = array(); while ($repositories->hasNext()) { $updatesInRepository = 0; $repository = $repositories->next(); $repositoryId = $repository->getId(); // Only work with allowed repositories if (count($allowedRepositoryIdStrings) && !in_array($repositoryId->getIdString(), $allowedRepositoryIdStrings)) { continue; } $r++; $existingRepositoryIds[] = $repositoryId->getIdString(); $assets = $repository->getAssets(); $status = new CLIStatusStars(str_replace('%1', $r, $message) . $repository->getDisplayName()); $status->initializeStatistics($assets->count()); $existingAssetIds = array(); while ($assets->hasNext()) { $asset = $assets->next(); $assetId = $asset->getId(); $existingAssetIds[] = $assetId->getIdString(); try { $modificationDate = $asset->getModificationDate(); } catch (UnimplementedException $e) { $modificationDate = DateAndTime::now(); } $query = $baseCheckQuery->copy(); $query->addWhereEqual("oai_set", $repositoryId->getIdString()); $query->addWhereEqual("oai_identifier", $assetId->getIdString()); $result = $dbc->query($query, $config->getProperty('OAI_DBID')); if (!$result->getNumberOfRows()) { // printpre("Doesn't exist:\t".$asset->getDisplayName().""); $query = $baseInsertQuery->copy(); $query->addValue('oai_set', $repositoryId->getIdString()); $query->addValue('oai_identifier', $assetId->getIdString()); } else { // printpre("Exists:\t".$asset->getDisplayName().""); if ($modificationDate->isGreaterThan(DateAndTime::fromString($result->field('datestamp'))) || $forceUpdate) { // printpre("\tUpdating:\t".$asset->getDisplayName()); $query = $baseUpdateQuery->copy(); $query->addWhereEqual("oai_set", $repositoryId->getIdString()); $query->addWhereEqual("oai_identifier", $assetId->getIdString()); } else { $query = null; } } if ($query) { $query->addRawValue('datestamp', 'NOW()'); } $isCurrentlyDeleted = $result->getNumberOfRows() && $result->field('deleted') == 'true' ? true : false; $result->free(); if (!count($authGroupIds)) { $isVisible = true; } else { $isVisible = false; try { foreach ($authGroupIds as $id) { if ($authorizationManager->isAuthorized($id, $viewId, $assetId)) { $isVisible = true; break; } } } catch (UnknownIdException $e) { $isVisible = true; } } if ($query) { //Add the data fields // Deleted if ($isVisible) { $query->addValue('deleted', 'false'); } else { $query->addValue('deleted', 'true'); } $query->addValue('dc_title', $asset->getDisplayName()); $query->addValue('dc_description', $asset->getDescription()); $this->addDublinCoreValues($asset, $query); $dbc->query($query, $config->getProperty('OAI_DBID')); $updatesInRepository++; $numUpdates++; } else { if ($isCurrentlyDeleted && $isVisible) { $query = $baseUndeleteQuery->copy(); } else { if (!$isCurrentlyDeleted && !$isVisible) { $query = $baseDeleteQuery->copy(); } else { $query = null; } } if ($query) { $query->addWhereEqual("oai_set", $repositoryId->getIdString()); $query->addWhereEqual("oai_identifier", $assetId->getIdString()); $dbc->query($query, $config->getProperty('OAI_DBID')); $updatesInRepository++; $numUpdates++; } } $status->updateStatistics(); } // Update any missing assets as deleted $query = $baseDeleteQuery->copy(); $query->addWhereEqual("oai_set", $repositoryId->getIdString()); if (count($existingAssetIds)) { $query->addWhereEqual("deleted", "false"); $query->addWhereNotIn("oai_identifier", $existingAssetIds); } $result = $dbc->query($query, $config->getProperty('OAI_DBID')); if ($result->getNumberOfRows()) { $updatesInRepository = $updatesInRepository + $result->getNumberOfRows(); $numUpdates = $numUpdates + $result->getNumberOfRows(); } print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n"; print "Elapsed Time:\t"; $timer->end(); printf("%1.2f", $timer->printTime()); print " seconds"; print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : ""; print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n"; print "Updates: " . $updatesInRepository; print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : "\n"; } // Update any missing repositories as deleted $query = $baseDeleteQuery->copy(); $query->addWhereEqual("deleted", "false"); if (count($existingRepositoryIds)) { $query->addWhereNotIn("oai_set", $existingRepositoryIds); } $result = $dbc->query($query, $config->getProperty('OAI_DBID')); if ($result->getNumberOfRows()) { $updatesInRepository = $updatesInRepository + $result->getNumberOfRows(); $numUpdates = $numUpdates + $result->getNumberOfRows(); } print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n"; print "Total Updates:\t" . $numUpdates; print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : "\n"; }
/** * creates appropriate object from given ids * * @param Id $structureId * @param Id $partStructureId * @param String $part * @return object mixed * @access public * @since 7/21/05 */ function getPartObject($structureId, $partStructureId, $part) { $structure = $this->_destinationRepository->getRecordStructure($structureId); $partStructure = $structure->getPartStructure($partStructureId); $type = $partStructure->getType(); $typeString = $type->getKeyword(); switch ($typeString) { case "shortstring": case "string": $obj = String::withValue($part); return $obj; break; case "integer": $obj = Integer::withValue($part); return $obj; break; case "boolean": $obj = Boolean::withValue($part); return $obj; break; case "float": $obj = Float::withValue($part); return $obj; break; case "datetime": $obj = DateAndTime::fromString($part); return $obj; break; case "type": $obj = HarmoniType::fromString($part); return $obj; break; default: $this->addError("Unsupported PartStructure DataType: " . HarmoniType::typeToString($type) . "."); $false = false; return $false; } }
/** * Answer an array of the versions for this plugin instance with the most * recent version first. * * @return array of SeguePluginVersion objects * @access public * @since 1/7/08 */ public function getVersions() { if (!isset($this->versions)) { $this->versions = array(); $query = new SelectQuery(); $query->addTable('segue_plugin_version'); $query->addColumn('version_id'); $query->addColumn('tstamp'); $query->addColumn('comment'); $query->addColumn('agent_id'); $query->addWhereEqual('node_id', $this->getId()); $query->addOrderBy('tstamp', SORT_DESC); $dbc = Services::getService('DBHandler'); $result = $dbc->query($query, IMPORTER_CONNECTION); $idMgr = Services::getService("Id"); $number = $result->getNumberOfRows(); while ($result->hasNext()) { $row = $result->next(); $this->versions[] = new SeguePluginVersion($this, $row['version_id'], DateAndTime::fromString($row['tstamp']), $idMgr->getId($row['agent_id']), $number, $row['comment']); $number--; } } return $this->versions; }
/** * Answer an approximate ending date for the semester * * @return DateAndTime * @access public * @since 8/21/07 */ public function getEndDate() { $info = $this->getInfo(); if (!isset($info['semester_order'])) { throw new Exception("No end date available for this course section."); } switch ($info['semester_order']) { case 1: return DateAndTime::fromString($info['year'] . "-02-08T00:00:00"); case 2: return DateAndTime::fromString($info['year'] . "-05-20T00:00:00"); case 3: return DateAndTime::fromString($info['year'] . "-09-01T00:00:00"); case 4: return DateAndTime::fromString($info['year'] . "-12-25T00:00:00"); } }
/** * Convert this object to a StorableTime * * @return object * @access public * @since 6/9/06 */ function asADateTime() { return DateAndTime::fromString($this->asString()); }
/** * Answer a list of most recently seen slot-names ordered recent-first. * * @return array * @access public * @since 9/22/08 */ public function getRecentSlots() { $slots = array(); $dbc = Services::getService('DatabaseManager'); $query = new SelectQuery(); $query->addTable('segue_accesslog'); $query->addColumn('fk_slotname'); $query->addColumn('tstamp'); $query->addWhereEqual('agent_id', $this->_getCurrentAgentId()); $query->addOrderBy('tstamp', DESCENDING); $query->limitNumberOfRows(50); $result = $dbc->query($query, IMPORTER_CONNECTION); while ($result->hasNext()) { $row = $result->next(); $slots[$row['fk_slotname']] = DateAndTime::fromString($row['tstamp'])->asString(); } // Add session-stored slots if (isset($_SESSION['segue_access_log'])) { foreach ($_SESSION['segue_access_log'] as $slotname => $tstamp) { $slots[$slotname] = $tstamp; } arsort($slots); } return array_keys($slots); }
/** * Answer a new instance represented by a string: * * - '-1199-01-05T20:33:14.321-05:00' * - ' 2002-05-16T17:20:45.00000001+01:01' * - ' 2002-05-16T17:20:45.00000001' * - ' 2002-05-16T17:20' * - ' 2002-05-16T17:20:45' * - ' 2002-05-16T17:20:45+01:57' * - ' 2002-05-16T17:20:45-02:34' * - ' 2002-05-16T17:20:45+00:00' * - ' 1997-04-26T01:02:03+01:02:3' * * @param string $aString The input string. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object TimeStamp * @access public * @since 5/12/05 * @static */ static function fromString($aString, $class = 'TimeStamp') { $obj = parent::fromString($aString, $class); return $obj; }
/** * Converts a database datetime/timestamp/time value (that has been fetched * from the db) to a DateAndTime object. * * Depending whether the value was fecthed from a datetime, date or * timestamp column, $value could have the following two formats: * 'YYYY-MM-DD HH:MM:SS' for datetime * 'YYYY-MM-DD' for date * For a timestamp, $value could be any of the following depending on * the column size. * TIMESTAMP(14) YYYYMMDDHHMMSS * TIMESTAMP(12) YYMMDDHHMMSS - NOT SUPPORTED * TIMESTAMP(10) YYMMDDHHMM - NOT SUPPORTED * TIMESTAMP(8) YYYYMMDD * TIMESTAMP(6) YYMMDD - NOT SUPPORTED * TIMESTAMP(4) YYMM - NOT SUPPORTED * TIMESTAMP(2) YY - NOT SUPPORTED * * From MySQL version 4.1, TIMESTAMP is returned as * a string with the format 'YYYY-MM-DD HH:MM:SS' and different timestamp * lengths are no longer supported. * * WARNING: Due to the ambiguity of 2-digit years, timestamp formats that * use 2-digit years are not supported. * * @access public * @param mixed A database datetime/timestamp/time value (that has been fetched * from the db). * @return ref object The DateAndTime object. */ function fromDBDate($value) { if (in_array($value, array(NULL, '', '0000-00-00 00:00:00'))) { $obj = null; } else { $obj = DateAndTime::fromString($value); } return $obj; }
/** * Set the creation and modification dates of an asset based on the dates listed * in its corresponding element. Extensions of this class may wish to override * this method to do nothing, there-by leaving the dates to be the time of the import. * * @param object Asset $asset * @param object DOMElement $element * @return void * @access protected * @since 1/25/08 */ protected function setAssetDates(Asset $asset, DOMElement $element) { if ($element->hasAttribute('create_date')) { $date = DateAndTime::fromString($element->getAttribute('create_date')); $asset->forceSetCreationDate($date); } if ($element->hasAttribute('modify_date') && $element->getAttribute('modify_date')) { $date = DateAndTime::fromString($element->getAttribute('modify_date')); if (is_null($date)) { throw new InvalidArgumentException("Cannot use '" . $element->getAttribute('modify_date') . "' to create a date."); } $asset->forceSetModificationDate($date); } }
/** * Answer an TagInfoIterator that lists information on tags attached to an item. * * @param object TaggedItem $item * @return object TagInfoIterator * @access public * @since 4/18/08 */ public function getTagInfoForItem(TaggedItem $item) { $query = new SelectQuery(); $query->addTable('tag'); $query->addColumn('value'); $query->addColumn('user_id'); $query->addColumn('tstamp'); $query->addWhereEqual("fk_item", $item->getDatabaseId()); $dbc = Services::getService("DatabaseManager"); $result = $dbc->query($query, $this->getDatabaseIndex()); $iterator = new HarmoniIterator(array()); $idManager = Services::getService("Id"); while ($result->hasNext()) { $row = $result->next(); $iterator->add(new TagInfo(new Tag($row['value']), $item, $idManager->getId($row['user_id']), DateAndTime::fromString($row['tstamp']))); } return $iterator; }
function test_year() { $dateAndTimeA = DateAndTime::withYearDay(2005, 0); $dateAndTimeB = DateAndTime::withYearDay(2005, 1); $dateAndTimeC = DateAndTime::fromString('2005'); $tz = DateAndTime::localTimeZone(); $this->assertTrue($dateAndTimeA->isEqual($dateAndTimeB)); $this->assertTrue($dateAndTimeA->isEqual($dateAndTimeC)); $this->assertEqual($dateAndTimeA->asString(), '2005-01-01T00:00:00' . $tz->asString()); $this->assertEqual($dateAndTimeB->asString(), '2005-01-01T00:00:00' . $tz->asString()); $this->assertEqual($dateAndTimeC->asString(), '2005-01-01T00:00:00' . $tz->asString()); }
/** * Answer an array of ThemeHistory items, in reverse chronological order. * * @return array * @access public * @since 5/8/08 */ public function getHistory() { if (!isset($this->info)) { $this->loadInfo(); } if (is_null($this->info)) { return array(); } $xpath = new DOMXPath($this->info); $entryElements = $xpath->query('/ThemeInfo/History/Entry'); $history = array(); $dates = array(); foreach ($entryElements as $entryElement) { $comment = $xpath->query('Comment', $entryElement)->item(0)->nodeValue; $name = $xpath->query('Name', $entryElement)->item(0)->nodeValue; $email = $xpath->query('EMail', $entryElement)->item(0)->nodeValue; $date = DateAndTime::fromString($entryElement->getAttribute('date')); $history[] = new Harmoni_Gui2_HistoryEntry($date, $comment, $name, $email); $dates[] = $date->asString(); } $unique = array_keys($history); array_multisort($dates, SORT_DESC, $unique, $history); return $history; }
/** * Returns the values of wizard-components. Should return an array if children are involved, * otherwise a whatever type of object is expected. * @access public * @return mixed */ function getAllValues() { $obj = DateAndTime::fromString($this->_value); return $obj; }
/** * load the info for this file * * @return null * @access protected * @since 5/15/08 */ protected function loadInfo() { $query = new SelectQuery(); $query->addTable('segue_site_theme_image'); $query->addColumn('size'); $query->addColumn('mime_type'); $query->addColumn('modify_timestamp'); $query->addWhereEqual('fk_theme', $this->themeId); $query->addWhereEqual('path', $this->path); $dbMgr = Services::getService("DatabaseManager"); $result = $dbMgr->query($query, $this->databaseIndex); if (!$result->hasNext()) { throw new UnknownIdException("Theme image '" . $this->path . "' for theme '" . $this->themeId . "' does not exist."); } $row = $result->next(); $this->size = $row['size']; $this->mimeType = $row['mime_type']; $this->modificationDate = DateAndTime::fromString($row['modify_timestamp']); }
/** * Converts a database datetime/timestamp/time value (that has been fetched * from the db) to a DateAndTime object. * * Depending on the server configuration PostgreSQL retrieves date/time * types as 4 different formats. (format could be set with SET DateStyle * ). The default formatting is 'ISO'. Note that timestamp column types * return the full string. Date column types only return the date (no time). * * Style Description Example * 'ISO' ISO-8601 standard 1997-12-17 07:37:16-08 * 'SQL' Traditional style 12/17/1997 07:37:16.00 PST * 'PostgreSQL' Original style Wed Dec 17 07:37:16 1997 PST * 'German' Regional style 17.12.1997 07:37:16.00 PST * * @access public * @param mixed A database datetime/timestamp/time value (that has been fetched * from the db). * @return ref object The DateAndTime object. */ function fromDBDate($value) { if (in_array($value, array(NULL, '', '0000-00-00 00:00:00'))) { return NULL; } // Postgre if (preg_match("/([a-zA-Z]{3}) ([a-zA-Z]{3}) ([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([0-9]{4})/", $value, $r)) { $months = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12); return DateAndTime::withYearMonthDayHourMinuteSecond($r[7], $months[$r[2]], $r[3], $r[4], $r[5], $r[6]); } // German if (preg_match("/([0-9]{2})\\.([0-9]{2})\\.([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{2}) .../", $value, $r)) { return DateAndTime::withYearMonthDayHourMinuteSecond($r[3], $r[2], $r[1], $r[4], $r[5], $r[6]); } // ISO/SQL $obj = DateAndTime::fromString($value); return $obj; }
/** * Load the information XML file * * @return null * @access protected * @since 5/7/08 */ protected function loadInfo() { $query = new SelectQuery(); $query->addTable('segue_site_theme'); $query->addColumn('display_name'); $query->addColumn('description'); $query->addColumn('modify_timestamp'); $query->addWhereEqual('id', $this->id); $dbMgr = Services::getService("DatabaseManager"); $result = $dbMgr->query($query, $this->databaseIndex); if (!$result->hasNext()) { throw new UnknownIdException("Theme with id '" . $this->id . "' does not exist."); } $row = $result->next(); $result->free(); $this->displayName = $row['display_name']; $this->description = $row['description']; $this->modificationDate = DateAndTime::fromString($row['modify_timestamp']); }
/** * Update the dublin core record with info from the form. * * @param object Asset $asset * @param object Record $record * @return void * @access public * @since 1/30/07 */ function updateDublinCoreRecord($asset, $record) { $idManager = Services::getService("Id"); $value = String::fromString(HtmlString::getSafeHtml($asset->getDisplayName())); $id = $idManager->getId("dc.title"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml($asset->getDescription())); $id = $idManager->getId("dc.description"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('creator'))); $id = $idManager->getId("dc.creator"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('source'))); $id = $idManager->getId("dc.source"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('publisher'))); $id = $idManager->getId("dc.publisher"); $this->updateSingleValuedPart($record, $id, $value); $value = DateAndTime::fromString(RequestContext::value('date')); $id = $idManager->getId("dc.date"); $this->updateSingleValuedPart($record, $id, $value); }
/** * 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 4/28/05 */ function saveWizard($cacheName) { $harmoni = Harmoni::instance(); $harmoni->request->startNamespace('modify_exhibition'); $harmoni->request->passthrough('exhibition_id'); $wizard = $this->getWizard($cacheName); // Make sure we have a valid Repository $idManager = Services::getService("Id"); $authZ = Services::getService("AuthZ"); $repositoryManager = Services::getService("Repository"); $exhibitionRepositoryId = $idManager->getId("edu.middlebury.concerto.exhibition_repository"); $repository = $repositoryManager->getRepository($exhibitionRepositoryId); $asset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_id'))); $properties = $wizard->getAllValues(); $assetType = new Type("Asset Types", "edu.middlebury.concerto", "Exhibition", "Exhibition Assets are containers for Slideshows."); $asset->updateDisplayName($properties['namedescstep']['display_name']); $asset->updateDescription($properties['namedescstep']['description']); $assetId = $asset->getId(); $this->_assetId = $assetId; // Update the effective/expiration dates if ($properties['datestep']['effective_date']) { $asset->updateEffectiveDate(DateAndTime::fromString($properties['datestep']['effective_date'])); } if ($properties['datestep']['expiration_date']) { $asset->updateExpirationDate(DateAndTime::fromString($properties['datestep']['expiration_date'])); } // Log the success or failure if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Concerto"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events."); $item = new AgentNodeEntryItem("Modify Node", "Exhibition Modified"); $item->addNodeId($asset->getId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } $harmoni->request->endNamespace(); return TRUE; }
/** * Test instance creation from a string. * */ function test_from_string() { $dateAndTime = DateAndTime::withYearMonthDay(2005, 8, 20); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('08/20/2005'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('August 20, 2005'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20aug05'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 25, 10); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 25, 0); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 0, 0); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 8, 20, 15, 25, 10, Duration::withHours(-7)); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10-07:00'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510-07'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 8, 20, 15, 25, 10, Duration::zero()); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10Z'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510Z'))); }