/** * Gets the Timer bound to the test session * @return QtiTimer * @throws \oat\taoTests\models\runner\time\InvalidDataException * @throws \oat\taoTests\models\runner\time\InvalidStorageException */ public function getTimer() { if (!$this->timer) { $this->timer = new QtiTimer(); $this->timer->setStorage(new QtiTimeStorage($this->getSessionId(), $this->getUserUri())); $this->timer->load(); } return $this->timer; }
/** * Get the time remaining to be spent by the candidate on the source of the time * constraint. Please note that this method will never return negative durations. * * @return Duration|boolean A Duration object or false if there is no maxTime constraint running for the source of the time constraint. */ public function getMaximumRemainingTime() { if (($timeLimits = $this->getSource()->getTimeLimits()) !== null && ($maxTime = $timeLimits->getMaxTime()) !== null) { $remaining = clone $maxTime; if ($this->getApplyExtraTime() && $this->timer) { // take care of the already consumed extra time under the current constraint // and append the full remaining extra time // the total must correspond to the already elapsed time plus the remaining time $currentExtraTime = $this->timer->getRemainingExtraTime() + $this->timer->getConsumedExtraTime($this->getSource()->getIdentifier()); $extraTime = min($this->timer->getExtraTime(), $currentExtraTime); $remaining->add(new QtiDuration('PT' . $extraTime . 'S')); } $remaining->sub($this->getDuration()); return $remaining->isNegative() === true ? new QtiDuration('PT0S') : $remaining; } else { return false; } }
/** * Gets the delivery time counter * * @param \taoDelivery_models_classes_execution_DeliveryExecution $deliveryExecution * @return QtiTimer * @throws \oat\oatbox\service\ServiceNotFoundException */ public static function getDeliveryTimer($deliveryExecution) { if (is_string($deliveryExecution)) { $deliveryExecution = self::getDeliveryExecutionById($deliveryExecution); } $testSessionService = ServiceManager::getServiceManager()->get(TestSessionService::SERVICE_ID); $testSession = $testSessionService->getTestSession($deliveryExecution); if ($testSession instanceof TestSession) { $timer = $testSession->getTimer(); } else { $timer = new QtiTimer(); $timer->setStorage(new QtiTimeStorage($deliveryExecution->getIdentifier(), $deliveryExecution->getUserIdentifier())); $timer->load(); } return $timer; }
/** * Test the QtiTimer::consumeExtraTime() */ public function testConsumeExtraTime() { $timer = new QtiTimer(); $this->assertEquals(0, $timer->getExtraTime()); $extraTime = 77; $timer->setExtraTime($extraTime); $this->assertEquals($extraTime, $timer->getExtraTime()); $consume = 6; $consumedTime = $consume; $timer->consumeExtraTime($consume); $this->assertEquals($extraTime, $timer->getExtraTime()); $this->assertEquals($consumedTime, $timer->getConsumedExtraTime()); $remainingTime = $extraTime - $consumedTime; $this->assertEquals($remainingTime, $timer->getRemainingExtraTime()); $consume = 5; $consumedTime += $consume; $timer->consumeExtraTime($consume); $this->assertEquals($extraTime, $timer->getExtraTime()); $this->assertEquals($consumedTime, $timer->getConsumedExtraTime()); $remainingTime = $extraTime - $consumedTime; $this->assertEquals($remainingTime, $timer->getRemainingExtraTime()); $tags = ['test', 'part1']; $consume = 2; $consumedTime += $consume; $timer->consumeExtraTime($consume, $tags); $this->assertEquals($extraTime, $timer->getExtraTime()); $this->assertEquals($consumedTime, $timer->getConsumedExtraTime()); $this->assertEquals($consume, $timer->getConsumedExtraTime($tags)); $this->assertEquals($consume, $timer->getConsumedExtraTime($tags[0])); $this->assertEquals($consume, $timer->getConsumedExtraTime($tags[1])); $this->assertEquals(0, $timer->getConsumedExtraTime('unknown')); $remainingTime = $extraTime - $consumedTime; $this->assertEquals($remainingTime, $timer->getRemainingExtraTime()); }