Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add new event ResultTestVariablesAfterTransmissionEvent #2425

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion helpers/class.TestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
*/

use oat\oatbox\event\EventManager;
use oat\oatbox\service\exception\InvalidServiceManagerException;
use oat\oatbox\service\ServiceManager;
use oat\taoQtiTest\helpers\TestSessionMemento;
use oat\taoQtiTest\models\classes\event\ResultTestVariablesTransmissionEvent;
use oat\taoQtiTest\models\event\QtiTestChangeEvent;
use oat\taoQtiTest\models\event\QtiTestStateChangeEvent;
use oat\taoQtiTest\models\event\ResultItemVariablesTransmissionEvent;
use oat\taoQtiTest\models\event\ResultTestVariablesAfterTransmissionEvent;
use oat\taoResultServer\models\classes\implementation\ResultServerService;
use oat\taoResultServer\models\classes\ResultStorageWrapper;
use oat\taoTests\models\event\TestExecutionPausedEvent;
use oat\taoTests\models\event\TestExecutionResumedEvent;
Expand All @@ -44,6 +47,7 @@
use qtism\data\processing\OutcomeProcessing;
use qtism\data\rules\OutcomeRuleCollection;
use qtism\data\rules\SetOutcomeValue;
use qtism\data\state\OutcomeDeclaration;
use qtism\runtime\common\OutcomeVariable;
use qtism\runtime\common\ProcessingException;
use qtism\runtime\processing\OutcomeProcessingEngine;
Expand All @@ -57,6 +61,7 @@
use qtism\runtime\tests\Route;
use Symfony\Component\Lock\LockInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use taoResultServer_models_classes_ReadableResultStorage as ReadableResultStorage;

/**
* A TAO Specific extension of QtiSm's AssessmentTestSession class.
Expand Down Expand Up @@ -814,14 +819,49 @@ private function triggerResultTestVariablesTransmissionEvent(
array $variables,
string $testUri = ''
): void {
$this->getEventManager()->trigger(new ResultTestVariablesTransmissionEvent(
$event = new ResultTestVariablesTransmissionEvent(
$this->getSessionId(),
$variables,
$this->getSessionId(),
$testUri
);

$this->getEventManager()->attach($event, [$this, 'attachToTransmissionEvent']);
Karol-Stelmaczonek marked this conversation as resolved.
Show resolved Hide resolved
$this->getEventManager()->trigger($event);
}

public function attachToTransmissionEvent(ResultTestVariablesTransmissionEvent $event): void
{
$scoreTotal = array_filter($event->getVariables(), function ($item) {
Karol-Stelmaczonek marked this conversation as resolved.
Show resolved Hide resolved
return $item->getIdentifier() === 'SCORE_TOTAL';
})[0];
if ($scoreTotal === null) {
return;
}
$outcomeVariables = $this->getResultsStorage()->getDeliveryVariables($event->getDeliveryExecutionId());
pnal marked this conversation as resolved.
Show resolved Hide resolved
$this->getEventManager()->trigger(new ResultTestVariablesAfterTransmissionEvent(
$event->getDeliveryExecutionId(),
$outcomeVariables,
$this->isManualScored()
));
}

private function isManualScored(): bool
{
/** @var AssessmentItemRef $itemRef */
foreach ($this->getRoute()->getAssessmentItemRefs() as $itemRef) {
foreach ($itemRef->getComponents() as $component) {
if ($component instanceof OutcomeDeclaration) {
Karol-Stelmaczonek marked this conversation as resolved.
Show resolved Hide resolved
if ($component->isExternallyScored()) {
return true;
}
}
}
}

return false;
}

/**
* @param TestSessionMemento $sessionMemento
*/
Expand Down Expand Up @@ -882,4 +922,20 @@ protected function getSessionMemento()
{
return new TestSessionMemento($this);
}

/**
* @throws common_exception_Error
* @throws InvalidServiceManagerException
*/
private function getResultsStorage(): ReadableResultStorage
{
$resultServerService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID);
$storage = $resultServerService->getResultStorage();

if (!$storage instanceof ReadableResultStorage) {
throw new common_exception_Error('Configured result storage is not writable.');
}

return $storage;
}
}
63 changes: 63 additions & 0 deletions models/classes/event/ResultTestVariablesAfterTransmissionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiTest\models\event;

use oat\oatbox\event\Event;

class ResultTestVariablesAfterTransmissionEvent implements Event
{
private string $deliveryExecutionId;

private array $variables;
private bool $isManualScored;

public function __construct(
string $deliveryExecutionId,
array $variables,
bool $isManualScored
) {
$this->deliveryExecutionId = $deliveryExecutionId;
$this->variables = $variables;
$this->isManualScored = $isManualScored;
}

public function getName(): string
{
return self::class;
}

public function getDeliveryExecutionId(): string
{
return $this->deliveryExecutionId;
}

public function getVariables(): array
{
return $this->variables;
}

public function getIsManualScored(): bool
{
return $this->isManualScored;
}
}
Loading