Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 190 |
|
0.00% |
0 / 26 |
CRAP | |
0.00% |
0 / 1 |
| TestSession | |
0.00% |
0 / 190 |
|
0.00% |
0 / 26 |
3906 | |
0.00% |
0 / 1 |
| getUserUri | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| setUserUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTimer | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getTimerTarget | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 | |||
| setTimerTarget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getItemTags | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| getItemAttemptTag | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| initItemTimer | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| startItemTimer | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| endItemTimer | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
90 | |||
| getTimerDuration | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getDurationKey | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| updateDurationCache | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| updateCurrentDurationCache | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| computeItemTime | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| computeSectionTime | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| computeTestPartTime | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| computeTestTime | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| updateDuration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTimeConstraint | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| buildTimeConstraints | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
110 | |||
| getTimeConstraints | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRegularTimeConstraints | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isTimeout | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| submitItemResults | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| endTestSession | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016-2024 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiTest\models\runner\session; |
| 23 | |
| 24 | use oat\oatbox\service\ServiceManager; |
| 25 | use oat\taoQtiTest\models\runner\config\QtiRunnerConfig; |
| 26 | use oat\taoQtiTest\models\runner\time\QtiTimeConstraint; |
| 27 | use oat\taoQtiTest\models\runner\time\QtiTimer; |
| 28 | use oat\taoQtiTest\models\runner\time\QtiTimerFactory; |
| 29 | use oat\taoQtiTest\models\cat\CatService; |
| 30 | use oat\taoTests\models\runner\time\TimePoint; |
| 31 | use qtism\common\datatypes\QtiDuration; |
| 32 | use qtism\data\AssessmentSection; |
| 33 | use qtism\data\TestPart; |
| 34 | use qtism\runtime\tests\AssessmentItemSession; |
| 35 | use qtism\runtime\tests\AssessmentTestPlace; |
| 36 | use qtism\runtime\tests\AssessmentTestSessionException; |
| 37 | use qtism\runtime\tests\RouteItem; |
| 38 | use qtism\runtime\tests\TimeConstraint; |
| 39 | use qtism\runtime\tests\TimeConstraintCollection; |
| 40 | use taoQtiTest_helpers_TestSession; |
| 41 | use oat\oatbox\log\LoggerAwareTrait; |
| 42 | |
| 43 | /** |
| 44 | * TestSession override |
| 45 | * |
| 46 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 47 | */ |
| 48 | class TestSession extends taoQtiTest_helpers_TestSession implements UserUriAware |
| 49 | { |
| 50 | use LoggerAwareTrait; |
| 51 | |
| 52 | /** |
| 53 | * The Timer bound to the test session |
| 54 | * @var QtiTimer |
| 55 | */ |
| 56 | protected $timer; |
| 57 | |
| 58 | /** |
| 59 | * The target from which compute the durations |
| 60 | * @var int |
| 61 | */ |
| 62 | protected $timerTarget; |
| 63 | |
| 64 | /** |
| 65 | * A temporary cache for computed durations |
| 66 | * @var array |
| 67 | */ |
| 68 | protected $durationCache = []; |
| 69 | |
| 70 | /** |
| 71 | * The URI (Uniform Resource Identifier) of the user the Test Session belongs to. |
| 72 | * |
| 73 | * @var string |
| 74 | */ |
| 75 | private $userUri; |
| 76 | |
| 77 | /** |
| 78 | * Get the URI (Uniform Resource Identifier) of the user the Test Session belongs to. |
| 79 | * |
| 80 | * @return string |
| 81 | */ |
| 82 | public function getUserUri() |
| 83 | { |
| 84 | if (is_null($this->userUri)) { |
| 85 | return \common_session_SessionManager::getSession()->getUserUri(); |
| 86 | } |
| 87 | return $this->userUri; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Set the URI (Uniform Resource Identifier) of the user the Test Session belongs to. |
| 92 | * |
| 93 | * @param string $userUri |
| 94 | */ |
| 95 | public function setUserUri($userUri) |
| 96 | { |
| 97 | $this->userUri = $userUri; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Gets the Timer bound to the test session |
| 102 | * @return QtiTimer |
| 103 | */ |
| 104 | public function getTimer() |
| 105 | { |
| 106 | if (!$this->timer) { |
| 107 | $qtiTimerFactory = $this->getServiceLocator()->get(QtiTimerFactory::SERVICE_ID); |
| 108 | $this->timer = $qtiTimerFactory->getTimer($this->getSessionId(), $this->getUserUri()); |
| 109 | } |
| 110 | return $this->timer; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Gets the target from which compute the durations |
| 115 | * @return int |
| 116 | */ |
| 117 | public function getTimerTarget() |
| 118 | { |
| 119 | if (is_null($this->timerTarget)) { |
| 120 | $testConfig = $this->getServiceLocator()->get(QtiRunnerConfig::SERVICE_ID); |
| 121 | $config = $testConfig->getConfigValue('timer'); |
| 122 | switch (strtolower($config['target'])) { |
| 123 | case 'client': |
| 124 | $target = TimePoint::TARGET_CLIENT; |
| 125 | break; |
| 126 | |
| 127 | case 'server': |
| 128 | default: |
| 129 | $target = TimePoint::TARGET_SERVER; |
| 130 | } |
| 131 | |
| 132 | $this->setTimerTarget($target); |
| 133 | } |
| 134 | return $this->timerTarget; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Set the target from which compute the durations |
| 139 | * @param int $timerTarget |
| 140 | */ |
| 141 | public function setTimerTarget($timerTarget) |
| 142 | { |
| 143 | $this->timerTarget = intval($timerTarget); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Gets the tags describing a particular item with an assessment test |
| 148 | * @param RouteItem $routeItem |
| 149 | * @return array |
| 150 | */ |
| 151 | public function getItemTags(RouteItem $routeItem) |
| 152 | { |
| 153 | $test = $routeItem->getAssessmentTest(); |
| 154 | $testPart = $routeItem->getTestPart(); |
| 155 | $sections = $routeItem->getAssessmentSections(); |
| 156 | $sections->rewind(); |
| 157 | $sectionId = key(current($sections)); |
| 158 | $itemRef = $routeItem->getAssessmentItemRef(); |
| 159 | $itemId = $itemRef->getIdentifier(); |
| 160 | $occurrence = $routeItem->getOccurence(); |
| 161 | |
| 162 | $tags = [ |
| 163 | $itemId, |
| 164 | $itemId . '#' . $occurrence, |
| 165 | $sectionId, |
| 166 | $testPart->getIdentifier(), |
| 167 | $test->getIdentifier(), |
| 168 | ]; |
| 169 | |
| 170 | if ($this->isRunning() === true) { |
| 171 | $tags[] = $this->getItemAttemptTag($routeItem); |
| 172 | } |
| 173 | |
| 174 | return $tags; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Gets the item tags for its last occurrence |
| 179 | * @param RouteItem $routeItem |
| 180 | * @return string |
| 181 | */ |
| 182 | public function getItemAttemptTag(RouteItem $routeItem) |
| 183 | { |
| 184 | $itemRef = $routeItem->getAssessmentItemRef(); |
| 185 | $itemId = $itemRef->getIdentifier(); |
| 186 | $occurrence = $routeItem->getOccurence(); |
| 187 | $itemSession = $this->getAssessmentItemSessionStore()->getAssessmentItemSession($itemRef, $occurrence); |
| 188 | return $itemId . '#' . $occurrence . '-' . $itemSession['numAttempts']->getValue(); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Initializes the timer for the current item in the TestSession |
| 193 | * |
| 194 | * @param $timestamp |
| 195 | * @throws \oat\taoTests\models\runner\time\InvalidDataException |
| 196 | */ |
| 197 | public function initItemTimer($timestamp = null) |
| 198 | { |
| 199 | if (is_null($timestamp)) { |
| 200 | $timestamp = microtime(true); |
| 201 | } |
| 202 | |
| 203 | // try to close existing time range if any, in order to be sure the test will start or restart a new range. |
| 204 | // if the range is already closed, a message will be added to the log |
| 205 | $tags = $this->getItemTags($this->getCurrentRouteItem()); |
| 206 | $this->getTimer()->end($tags, $timestamp)->save(); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Starts the timer for the current item in the TestSession |
| 211 | * |
| 212 | * @param $timestamp |
| 213 | */ |
| 214 | public function startItemTimer($timestamp = null) |
| 215 | { |
| 216 | if (is_null($timestamp)) { |
| 217 | $timestamp = microtime(true); |
| 218 | } |
| 219 | $tags = $this->getItemTags($this->getCurrentRouteItem()); |
| 220 | $this->getTimer()->start($tags, $timestamp)->save(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Ends the timer for the current item in the TestSession. |
| 225 | * Sets the client duration for the current item in the TestSession. |
| 226 | * |
| 227 | * @param float $duration The client duration, or null to force server duration to be used as client duration |
| 228 | * @param $timestamp |
| 229 | * @throws \oat\taoTests\models\runner\time\InvalidStorageException |
| 230 | * @throws \oat\taoTests\models\runner\time\TimeException |
| 231 | */ |
| 232 | public function endItemTimer($duration = null, $timestamp = null) |
| 233 | { |
| 234 | if (is_null($timestamp)) { |
| 235 | $timestamp = microtime(true); |
| 236 | } |
| 237 | $timer = $this->getTimer(); |
| 238 | $currentItem = $this->getCurrentRouteItem(); |
| 239 | |
| 240 | if ($currentItem) { |
| 241 | $tags = $this->getItemTags($currentItem); |
| 242 | } else { |
| 243 | $tags = []; |
| 244 | } |
| 245 | |
| 246 | $timer->end($tags, $timestamp); |
| 247 | |
| 248 | if (is_numeric($duration) || is_null($duration)) { |
| 249 | if (!is_null($duration)) { |
| 250 | $duration = floatval($duration); |
| 251 | } |
| 252 | try { |
| 253 | $this->logInfo(sprintf('[%s] - test session timer adjustment', $this->getSessionId())); |
| 254 | $timer->adjust($tags, $duration); |
| 255 | } catch (\oat\taoTests\models\runner\time\TimeException $e) { |
| 256 | $this->logAlert($e->getMessage() . '; Test session identifier: ' . $this->getSessionId()); |
| 257 | } |
| 258 | } |
| 259 | $constraints = $this->getTimeConstraints(); |
| 260 | |
| 261 | $maxTime = 0; |
| 262 | /** @var QtiTimeConstraint $constraint */ |
| 263 | foreach ($constraints as $constraint) { |
| 264 | if (($maximumTime = $constraint->getAdjustedMaxTime()) !== null) { |
| 265 | $maxTime = $maximumTime->getSeconds(true); |
| 266 | } |
| 267 | } |
| 268 | $this->getTimer()->getConsumedExtraTime($tags, $maxTime); |
| 269 | $this->updateCurrentDurationCache(); |
| 270 | $timer->save(); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Gets the timer duration for a particular identifier |
| 275 | * @param string|array $identifier |
| 276 | * @param int $target |
| 277 | * @return QtiDuration |
| 278 | * @throws \oat\taoTests\models\runner\time\TimeException |
| 279 | */ |
| 280 | public function getTimerDuration($identifier, $target = 0) |
| 281 | { |
| 282 | if (!$target) { |
| 283 | $target = $this->getTimerTarget(); |
| 284 | } |
| 285 | |
| 286 | $durationKey = $this->getDurationKey($identifier, $target); |
| 287 | |
| 288 | if (!isset($this->durationCache[$durationKey])) { |
| 289 | $this->updateDurationCache($identifier, $target); |
| 290 | } |
| 291 | |
| 292 | return $this->durationCache[$durationKey]; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Gets the timer duration key for a particular identifier |
| 297 | * @param string|array $identifier |
| 298 | * @param int $target |
| 299 | * @return string |
| 300 | */ |
| 301 | protected function getDurationKey($identifier, int $target): string |
| 302 | { |
| 303 | $durationKey = $target . '-'; |
| 304 | if (is_array($identifier)) { |
| 305 | sort($identifier); |
| 306 | $durationKey .= implode('-', $identifier); |
| 307 | } else { |
| 308 | $durationKey .= $identifier; |
| 309 | } |
| 310 | |
| 311 | return $durationKey; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Updates the duration cache for a particular identifier |
| 316 | * @param string|array $identifier |
| 317 | * @param int $target |
| 318 | * @return float |
| 319 | * @throws \oat\taoTests\models\runner\time\TimeException |
| 320 | */ |
| 321 | protected function updateDurationCache($identifier, int $target): float |
| 322 | { |
| 323 | $duration = round($this->getTimer()->compute($identifier, $target), 6); |
| 324 | $durationKey = $this->getDurationKey($identifier, $target); |
| 325 | |
| 326 | $this->durationCache[$durationKey] = new QtiDuration('PT' . $duration . 'S'); |
| 327 | |
| 328 | return $duration; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Updates the duration cache for all identifiers from the current context |
| 333 | * @throws \oat\taoTests\models\runner\time\TimeException |
| 334 | */ |
| 335 | protected function updateCurrentDurationCache() |
| 336 | { |
| 337 | $target = $this->getTimerTarget(); |
| 338 | $routeItem = $this->getCurrentRouteItem(); |
| 339 | |
| 340 | $sources = [ |
| 341 | $this->getAssessmentTest(), |
| 342 | $this->getCurrentTestPart(), |
| 343 | $this->getCurrentAssessmentSection(), |
| 344 | ]; |
| 345 | |
| 346 | if ($routeItem instanceof RouteItem) { |
| 347 | $sources[] = $routeItem->getAssessmentItemRef(); |
| 348 | } |
| 349 | |
| 350 | foreach (array_filter($sources) as $source) { |
| 351 | $this->updateDurationCache($source->getIdentifier(), $target); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Gets the total duration for the current item in the TestSession |
| 357 | * @param int $target |
| 358 | * @return QtiDuration |
| 359 | * @throws \oat\taoTests\models\runner\time\InconsistentCriteriaException |
| 360 | */ |
| 361 | public function computeItemTime($target = 0) |
| 362 | { |
| 363 | $currentItem = $this->getCurrentAssessmentItemRef(); |
| 364 | return $this->getTimerDuration($currentItem->getIdentifier(), $target); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Gets the total duration for the current section in the TestSession |
| 369 | * @param int $target |
| 370 | * @return QtiDuration |
| 371 | * @throws \oat\taoTests\models\runner\time\InconsistentCriteriaException |
| 372 | */ |
| 373 | public function computeSectionTime($target = 0) |
| 374 | { |
| 375 | $routeItem = $this->getCurrentRouteItem(); |
| 376 | $sections = $routeItem->getAssessmentSections(); |
| 377 | $sections->rewind(); |
| 378 | return $this->getTimerDuration(key(current($sections)), $target); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Gets the total duration for the current test part in the TestSession |
| 383 | * @param int $target |
| 384 | * @return QtiDuration |
| 385 | * @throws \oat\taoTests\models\runner\time\InconsistentCriteriaException |
| 386 | */ |
| 387 | public function computeTestPartTime($target = 0) |
| 388 | { |
| 389 | $routeItem = $this->getCurrentRouteItem(); |
| 390 | $testPart = $routeItem->getTestPart(); |
| 391 | return $this->getTimerDuration($testPart->getIdentifier(), $target); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Gets the total duration for the whole assessment test |
| 396 | * @param int $target |
| 397 | * @return QtiDuration |
| 398 | * @throws \oat\taoTests\models\runner\time\InconsistentCriteriaException |
| 399 | */ |
| 400 | public function computeTestTime($target = 0) |
| 401 | { |
| 402 | $routeItem = $this->getCurrentRouteItem(); |
| 403 | $test = $routeItem->getAssessmentTest(); |
| 404 | return $this->getTimerDuration($test->getIdentifier(), $target); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Update the durations involved in the AssessmentTestSession to mirror the durations at the current time. |
| 409 | * This method can be useful for stateless systems that make use of QtiSm. |
| 410 | */ |
| 411 | public function updateDuration() |
| 412 | { |
| 413 | // not needed anymore |
| 414 | \common_Logger::t('Call to disabled updateDuration()'); |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Gets a TimeConstraint from a particular source |
| 419 | * @param $source |
| 420 | * @param $navigationMode |
| 421 | * @param $considerMinTime |
| 422 | * @param $applyExtraTime |
| 423 | * @return TimeConstraint |
| 424 | * @throws \oat\taoTests\models\runner\time\InconsistentCriteriaException |
| 425 | */ |
| 426 | protected function getTimeConstraint($source, $navigationMode, $considerMinTime, $applyExtraTime = true) |
| 427 | { |
| 428 | $constraint = new QtiTimeConstraint( |
| 429 | $source, |
| 430 | $this->getTimerDuration($source->getIdentifier()), |
| 431 | $navigationMode, |
| 432 | $considerMinTime, |
| 433 | $applyExtraTime, |
| 434 | $this->getTimerTarget() |
| 435 | ); |
| 436 | $constraint->setTimer($this->getTimer()); |
| 437 | return $constraint; |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Builds the time constraints running for the current testPart or/and current assessmentSection |
| 442 | * or/and assessmentItem. Takes care of the extra time if needed. |
| 443 | * |
| 444 | * @param integer $places A composition of values (use | operator) from the AssessmentTestPlace enumeration. |
| 445 | * If the null value is given, all places will be taken into account. |
| 446 | * @param boolean $applyExtraTime Allow to take care of extra time |
| 447 | * @return TimeConstraintCollection A collection of TimeConstraint objects. |
| 448 | * @qtism-test-duration-update |
| 449 | */ |
| 450 | protected function buildTimeConstraints($places = null, $applyExtraTime = true) |
| 451 | { |
| 452 | if ($places === null) { |
| 453 | // Get the constraints from all places in the Assessment Test. |
| 454 | $places = ( |
| 455 | AssessmentTestPlace::ASSESSMENT_TEST |
| 456 | | AssessmentTestPlace::TEST_PART |
| 457 | | AssessmentTestPlace::ASSESSMENT_SECTION |
| 458 | | AssessmentTestPlace::ASSESSMENT_ITEM |
| 459 | ); |
| 460 | } |
| 461 | |
| 462 | $constraints = new TimeConstraintCollection(); |
| 463 | $navigationMode = $this->getCurrentNavigationMode(); |
| 464 | $routeItem = $this->getCurrentRouteItem(); |
| 465 | $considerMinTime = $this->mustConsiderMinTime(); |
| 466 | |
| 467 | if (($places & AssessmentTestPlace::ASSESSMENT_TEST) && ($routeItem instanceof RouteItem)) { |
| 468 | $constraints[] = $this->getTimeConstraint( |
| 469 | $routeItem->getAssessmentTest(), |
| 470 | $navigationMode, |
| 471 | $considerMinTime, |
| 472 | $applyExtraTime |
| 473 | ); |
| 474 | } |
| 475 | |
| 476 | $currentTestPart = $this->getCurrentTestPart(); |
| 477 | if (($places & AssessmentTestPlace::TEST_PART) && ($currentTestPart instanceof TestPart)) { |
| 478 | $constraints[] = $this->getTimeConstraint( |
| 479 | $currentTestPart, |
| 480 | $navigationMode, |
| 481 | $considerMinTime, |
| 482 | $applyExtraTime |
| 483 | ); |
| 484 | } |
| 485 | |
| 486 | $currentAssessmentSection = $this->getCurrentAssessmentSection(); |
| 487 | if ( |
| 488 | ($places & AssessmentTestPlace::ASSESSMENT_SECTION) |
| 489 | && ($currentAssessmentSection instanceof AssessmentSection) |
| 490 | ) { |
| 491 | $constraints[] = $this->getTimeConstraint( |
| 492 | $currentAssessmentSection, |
| 493 | $navigationMode, |
| 494 | $considerMinTime, |
| 495 | $applyExtraTime |
| 496 | ); |
| 497 | } |
| 498 | |
| 499 | if (($places & AssessmentTestPlace::ASSESSMENT_ITEM) && ($routeItem instanceof RouteItem)) { |
| 500 | $constraints[] = $this->getTimeConstraint( |
| 501 | $routeItem->getAssessmentItemRef(), |
| 502 | $navigationMode, |
| 503 | $considerMinTime, |
| 504 | $applyExtraTime |
| 505 | ); |
| 506 | } |
| 507 | |
| 508 | return $constraints; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Get the time constraints running for the current testPart or/and current assessmentSection |
| 513 | * or/and assessmentItem. The extra time is taken into account. |
| 514 | * |
| 515 | * @param integer $places A composition of values (use | operator) from the AssessmentTestPlace enumeration. |
| 516 | * If the null value is given, all places will be taken into account. |
| 517 | * @return TimeConstraintCollection A collection of TimeConstraint objects. |
| 518 | * @qtism-test-duration-update |
| 519 | */ |
| 520 | public function getTimeConstraints($places = null) |
| 521 | { |
| 522 | return $this->buildTimeConstraints($places, true); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Get the regular time constraints running for the current testPart or/and current assessmentSection |
| 527 | * or/and assessmentItem, without taking care of the extra time. |
| 528 | * |
| 529 | * @param integer $places A composition of values (use | operator) from the AssessmentTestPlace enumeration. |
| 530 | * If the null value is given, all places will be taken into account. |
| 531 | * @return TimeConstraintCollection A collection of TimeConstraint objects. |
| 532 | * @qtism-test-duration-update |
| 533 | */ |
| 534 | public function getRegularTimeConstraints($places = null) |
| 535 | { |
| 536 | return $this->buildTimeConstraints($places, false); |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Whether or not the current Assessment Item to be presented to the candidate is timed-out. By timed-out |
| 541 | * we mean: |
| 542 | * |
| 543 | * * current Assessment Test level time limits are not respected OR, |
| 544 | * * current Test Part level time limits are not respected OR, |
| 545 | * * current Assessment Section level time limits are not respected OR, |
| 546 | * * current Assessment Item level time limits are not respected. |
| 547 | * |
| 548 | * @return boolean |
| 549 | */ |
| 550 | public function isTimeout() |
| 551 | { |
| 552 | try { |
| 553 | $this->checkTimeLimits(false, true, false); |
| 554 | } catch (AssessmentTestSessionException $e) { |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * AssessmentTestSession implementations must override this method in order |
| 563 | * to submit item results from a given $assessmentItemSession to the appropriate |
| 564 | * data source. |
| 565 | * |
| 566 | * This method is triggered each time response processing takes place. |
| 567 | * |
| 568 | * @param AssessmentItemSession $itemSession The lastly updated AssessmentItemSession. |
| 569 | * @param integer $occurrence The occurrence number of the item bound to $assessmentItemSession. |
| 570 | * @throws AssessmentTestSessionException With error code RESULT_SUBMISSION_ERROR if an error occurs |
| 571 | * while transmitting results. |
| 572 | */ |
| 573 | public function submitItemResults(AssessmentItemSession $itemSession, $occurrence = 0) |
| 574 | { |
| 575 | $itemRef = $itemSession->getAssessmentItem(); |
| 576 | |
| 577 | // Ensure that specific results from adaptive placeholders are not recorded. |
| 578 | $catService = ServiceManager::getServiceManager()->get(CatService::SERVICE_ID); |
| 579 | if (!$catService->isAdaptivePlaceholder($itemRef)) { |
| 580 | $identifier = $itemRef->getIdentifier(); |
| 581 | $duration = $this->getTimerDuration($identifier); |
| 582 | |
| 583 | $itemDurationVar = $itemSession->getVariable('duration'); |
| 584 | $sessionDuration = $itemDurationVar->getValue(); |
| 585 | \common_Logger::t("Force duration of item '${identifier}' to ${duration} instead of ${sessionDuration}"); |
| 586 | $itemSession->getVariable('duration')->setValue($duration); |
| 587 | |
| 588 | parent::submitItemResults($itemSession, $occurrence); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * QTISM endTestSession method overriding. |
| 594 | * |
| 595 | * It consists of including an additional processing when the test ends, |
| 596 | * in order to send the LtiOutcome |
| 597 | * |
| 598 | * @see http://www.imsglobal.org/lis/ Outcome Management Service |
| 599 | * @throws \taoQtiTest_helpers_TestSessionException If the session is already ended or if an error occurs while |
| 600 | * transmitting/processing the result. |
| 601 | */ |
| 602 | public function endTestSession() |
| 603 | { |
| 604 | // try to close existing time range if any, in order to be sure the test will be closed with a consistent timer. |
| 605 | // if the range is already closed, a message will be added to the log |
| 606 | if ($this->isRunning() === true) { |
| 607 | $route = $this->getRoute(); |
| 608 | if ($route->valid()) { |
| 609 | $routeItem = $this->getCurrentRouteItem(); |
| 610 | } |
| 611 | if (isset($routeItem)) { |
| 612 | $this->endItemTimer(); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | parent::endTestSession(); |
| 617 | } |
| 618 | } |