/** * Print the dateRange form * * @param object DateAndTime $startDate * @param object DateAndTime $endDate * @return void * @access public * @since 3/8/06 */ function printDateRangeForm($startDate, $endDate) { $min = $this->minDate(); $max = DateAndTime::tomorrow(); $harmoni = Harmoni::instance(); print "\n<form action='"; $harmoni->request->forget('startYear'); $harmoni->request->forget('startMonth'); $harmoni->request->forget('startDay'); $harmoni->request->forget('startHour'); $harmoni->request->forget('endYear'); $harmoni->request->forget('endMonth'); $harmoni->request->forget('endDay'); $harmoni->request->forget('endHour'); print $harmoni->request->quickURL('logs', 'browse'); $harmoni->request->passthrough('log', 'priority', 'startYear', 'startMonth', 'startDay', 'startHour', 'endYear', 'endMonth', 'endDay', 'endHour', 'agent_id', 'node_id', 'category'); print "' method='post'>"; print "\n\t<select name='" . RequestContext::name("startMonth") . "'>"; $month = 1; while ($month <= 12) { print "\n\t\t<option value='" . $month . "'"; print $month == $startDate->month() ? " selected='selected'" : ""; print ">" . Month::nameOfMonth($month) . "</option>"; $month++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startDay") . "'>"; $day = 1; while ($day <= 31) { print "\n\t\t<option value='" . $day . "'"; print $day == $startDate->dayOfMonth() ? " selected='selected'" : ""; print ">" . $day . "</option>"; $day++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startYear") . "'>"; $year = $max->year(); $minYear = $min->year(); while ($year >= $minYear) { print "\n\t\t<option value='" . $year . "'"; print $year == $startDate->year() ? " selected='selected'" : ""; print ">{$year}</option>"; $year--; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("startHour") . "'>"; $hour = 0; while ($hour <= 23) { print "\n\t\t<option value='" . $hour . "'"; print $hour == $startDate->hour() ? " selected='selected'" : ""; print ">" . sprintf("%02d", $hour) . ":00</option>"; $hour++; } print "\n\t</select>"; print "\n\t<strong> to: </strong>"; print "\n\t<select name='" . RequestContext::name("endMonth") . "'>"; $month = 1; while ($month <= 12) { print "\n\t\t<option value='" . $month . "'"; print $month == $endDate->month() ? " selected='selected'" : ""; print ">" . Month::nameOfMonth($month) . "</option>"; $month++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endDay") . "'>"; $day = 1; while ($day <= 31) { print "\n\t\t<option value='" . $day . "'"; print $day == $endDate->dayOfMonth() ? " selected='selected'" : ""; print ">" . $day . "</option>"; $day++; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endYear") . "'>"; $year = $max->year(); $minYear = $min->year(); while ($year >= $minYear) { print "\n\t\t<option value='" . $year . "'"; print $year == $endDate->year() ? " selected='selected'" : ""; print ">{$year}</option>"; $year--; } print "\n\t</select>"; print "\n\t<select name='" . RequestContext::name("endHour") . "'>"; $hour = 0; while ($hour <= 23) { print "\n\t\t<option value='" . $hour . "'"; print $hour == $endDate->hour() ? " selected='selected'" : ""; print ">" . sprintf("%02d", $hour) . ":00</option>"; $hour++; } print "\n\t</select>"; print "\n\t<input type='submit' value='" . _("Set Range") . "'/>"; print "\n\t<a href='"; print $harmoni->request->quickURL('logs', 'browse', array('startYear' => $min->year(), 'startMonth' => $min->month(), 'startDay' => $min->dayOfMonth(), 'startHour' => $min->hour(), 'endYear' => $max->year(), 'endMonth' => $max->month(), 'endDay' => $max->dayOfMonth(), 'endHour' => $max->hour())); print "'>"; print "\n\t\t<input type='button' value='" . _("Clear") . "' />"; print "</a>"; print "\n</form>"; }
/** * Test converting methods * */ function test_converting() { $time = Time::withHourMinuteSecond(15, 25, 10); // asDate () $temp = $time->asDate(); $this->assertTrue($temp->isEqualTo(Date::today())); $this->assertEqual(strtolower(get_class($temp)), 'date'); // asDateAndTime () $temp = $time->asDateAndTime(); $comparison = DateAndTime::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'dateandtime'); // asDuration () $temp = $time->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510))); $this->assertEqual(strtolower(get_class($temp)), 'duration'); // asMonth () $temp = $time->asMonth(); $this->assertTrue($temp->isEqualTo(Month::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'month'); // asSeconds () $this->assertEqual($time->asSeconds(), 55510); // asTime () $temp = $time->asTime(); $this->assertTrue($temp->isEqualTo($time)); $this->assertEqual(strtolower(get_class($temp)), 'time'); // asTimeStamp () $temp = $time->asTimeStamp(); $comparison = TimeStamp::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'timestamp'); // asWeek () $temp = $time->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'week'); // asYear () $temp = $time->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'year'); // to () $today = DateAndTime::today(); $tomorrow = DateAndTime::tomorrow(); $result = $time->to($tomorrow); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50)))); $result = $time->to(Time::withHourMinuteSecond(23, 25, 10)); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0)))); }
/** * Answer a new instance representing tomorow * * @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 tomorrow($class = 'TimeStamp') { $obj = parent::tomorrow($class); return $obj; }
/** * Build the rss feed * * @return void * @access public * @since 8/8/06 */ function buildFeed() { $defaultTextDomain = textdomain("polyphony"); $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("polyphony-logs"); $harmoni->request->passthrough('log', 'priority', 'startYear', 'startMonth', 'startDay', 'startHour', 'endYear', 'endMonth', 'endDay', 'endHour', 'agent_id', 'node_id', 'category'); $agentManager = Services::getService("Agent"); $idManager = Services::getService("Id"); $hierarchyManager = Services::getService("Hierarchy"); $loggingManager = Services::getService("Logging"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); if (RequestContext::value("log")) { $currentLogName = RequestContext::value("log"); } else { $logNames = $loggingManager->getLogNamesForReading(); $currentLogName = $logNames->next(); } // --- The Current log --- if (isset($currentLogName) && $currentLogName) { $log = $loggingManager->getLogForReading($currentLogName); // Priority Type if (RequestContext::value("priority")) { $currentPriorityType = HarmoniType::fromString(RequestContext::value("priority")); } else { $priorityTypes = $loggingManager->getPriorityTypes(); $currentPriorityType = $priorityTypes->next(); } // --- The Current log with Priority type --- if (isset($currentPriorityType) && $currentPriorityType) { // Do a search if needed if (RequestContext::value('agent_id') || RequestContext::value('node_id') || RequestContext::value('category')) { $criteria = array(); $criteria['start'] = $this->minDate(); $criteria['end'] = DateAndTime::tomorrow(); if (RequestContext::value('agent_id')) { $criteria['agent_id'] = $idManager->getId(RequestContext::value('agent_id')); } if (RequestContext::value('node_id')) { $criteria['node_id'] = $idManager->getId(RequestContext::value('node_id')); } if (RequestContext::value('category')) { $criteria['category'] = urldecode(RequestContext::value('category')); } $searchType = new Type("logging_search", "edu.middlebury", "Date-Range/Agent/Node"); $entries = $log->getEntriesBySearch($criteria, $searchType, $formatType, $currentPriorityType); if ($entries->hasNext()) { $firstEntry = $entries->next(); } $entries = $log->getEntriesBySearch($criteria, $searchType, $formatType, $currentPriorityType); } else { $entries = $log->getEntries($formatType, $currentPriorityType); if ($entries->hasNext()) { $firstEntry = $entries->next(); } $entries = $log->getEntries($formatType, $currentPriorityType); } } } $this->setTitle($currentLogName . " " . $currentPriorityType->getKeyword() . " " . _("Logs")); $this->setLink($harmoni->request->quickURL('logs', 'browse')); $this->addCategory("Logs"); ob_start(); print $currentLogName . " " . _("logs of priority,"); print " " . $currentPriorityType->getKeyword(); if (RequestContext::value('agent_id')) { print "\n<p style='text-indent: 0.5in'>"; print _("Limited to agent: "); $id = $idManager->getId(RequestContext::value('agent_id')); $agent = $agentManager->getAgent($id); print $agent->getDisplayName(); print "</p>"; } if (RequestContext::value('node_id')) { print "\n<p style='text-indent: 0.5in'>"; print _("Limited to node: "); $id = $idManager->getId(RequestContext::value('node_id')); try { $node = $hierarchyManager->getNode($id); if ($node->getDisplayName()) { print $node->getDisplayName(); } else { print _("Id: ") . $nodeId->getIdString(); } } catch (UnknownIdException $e) { print $id->getIdString(); } catch (UnimplementedException $e) { print $id->getIdString(); } print "</p>"; } if (RequestContext::value('category')) { print "\n<p style='text-indent: 0.5in'>"; print _("Limited to category: "); print urldecode(RequestContext::value('category')); print "</p>"; } $this->setDescription(ob_get_clean()); $i = 0; while ($entries->hasNext() && $i < 30) { $this->addEntry($entries->next()); $i++; } textdomain($defaultTextDomain); }
/** * Answer a new instance representing tomorow * * @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 tomorrow($class = 'StorableTime') { return parent::tomorrow($class); }