Ejemplo n.º 1
0
 /**
  * Subtract a duration to this one. If $duration is greather than or equal to
  * the current duration, a duration of 0 seconds is returned.
  *
  * For instance P2S - P1S = P1S
  */
 public function sub(QtiDuration $duration)
 {
     if ($duration->longerThanOrEquals($this) === true) {
         $this->setInterval(new DateInterval('PT0S'));
     } else {
         $refStrDate = '@0';
         $tz = new DateTimeZone(self::TIMEZONE);
         $d1 = new DateTime($refStrDate, $tz);
         $d2 = new DateTime($refStrDate, $tz);
         $d1->add(new DateInterval($this->__toString()));
         $d2->add(new DateInterval($duration->__toString()));
         $interval = $d1->diff($d2);
         $this->setInterval($interval);
     }
 }
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider longerThanOrEqualsProvider
  *
  * @param Duration $duration1
  * @param Duration $duration2
  * @param boolean $expected
  */
 public function testLongerThanOrEquals(QtiDuration $duration1, QtiDuration $duration2, $expected)
 {
     $this->assertSame($expected, $duration1->longerThanOrEquals($duration2));
 }
Ejemplo n.º 4
0
 /**
  * Marshall a QTI duration datatype into its PCI JSON Representation.
  *
  * @param \qtism\common\datatypes\Duration $duration
  * @return array
  */
 protected function marshallDuration(QtiDuration $duration)
 {
     return array('base' => array('duration' => $duration->__toString()));
 }
Ejemplo n.º 5
0
 /**
  * Write a Duration in the current binary stream.
  *
  * @param \qtism\common\datatypes\Duration $duration A Duration object.
  * @throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
  */
 public function writeDuration(QtiDuration $duration)
 {
     try {
         $this->writeString($duration->__toString());
     } catch (BinaryStreamAccessException $e) {
         $msg = "An error occured while writing a duration.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
     }
 }