public function testPositiveDuration() { $duration = new QtiDuration('P3Y4DT6H8M'); // 2 years, 4 days, 6 hours, 8 minutes. $this->assertEquals(3, $duration->getYears()); $this->assertEquals(4, $duration->getDays()); $this->assertEquals(6, $duration->getHours()); $this->assertEquals(8, $duration->getMinutes()); $this->assertEquals(0, $duration->getMonths()); $this->assertEquals(0, $duration->getSeconds()); }
/** * Whether the duration described by this Duration object is longer than or * equal to the one described by $duration. * * @param \qtism\common\datatypes\Duration $duration A Duration object to compare with this one. * @return boolean */ public function longerThanOrEquals(QtiDuration $duration) { return $this->getSeconds(true) >= $duration->getSeconds(true); }
/** * Sets the extra time to a list of delivery executions * * @param array $deliveryExecutions * @param float $extraTime * @return array * @throws \oat\oatbox\service\ServiceNotFoundException */ public static function setExtraTime($deliveryExecutions, $extraTime = null) { $serviceManager = ServiceManager::getServiceManager(); $deliveryMonitoringService = $serviceManager->get(DeliveryMonitoringService::CONFIG_ID); $result = array(); foreach ($deliveryExecutions as $deliveryExecution) { if (is_string($deliveryExecution)) { $deliveryExecution = self::getDeliveryExecutionById($deliveryExecution); } // reopen the execution if already closed if ($deliveryExecution->getState()->getUri() == DeliveryExecution::STATE_FINISHIED) { $deliveryExecution->setState(DeliveryExecution::STATE_ACTIVE); $testSessionService = ServiceManager::getServiceManager()->get(TestSessionService::SERVICE_ID); /* @var TestSession $testSession */ $testSession = $testSessionService->getTestSession($deliveryExecution); if ($testSession) { $testSession->getRoute()->setPosition(0); $testSession->setState(AssessmentTestSessionState::INTERACTING); // The duration store contains durations (time spent) on test, testPart(s) and assessmentSection(s). $durationStore = $testSession->getDurationStore(); $offsetDuration = new QtiDuration("PT{$extraTime}S"); $testDefinition = $testSession->getAssessmentTest(); $currentDuration = $durationStore[$testDefinition->getIdentifier()]; $offsetSeconds = $offsetDuration->getSeconds(true); $currentSeconds = $currentDuration->getSeconds(true); $newSeconds = $currentSeconds - $offsetSeconds; if ($newSeconds < 0) { $newSeconds = 0; } // Replace test duration with new duration. $durationStore[$testDefinition->getIdentifier()] = new QtiDuration("PT{$newSeconds}S"); $testSessionService->persist($testSession); } } $timer = self::getDeliveryTimer($deliveryExecution); $timer->setExtraTime($extraTime)->save(); $data = $deliveryMonitoringService->getData($deliveryExecution, true); $deliveryMonitoringService->save($data); $result[] = $deliveryExecution->getIdentifier(); } return $result; }