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 6 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
21 changes: 20 additions & 1 deletion helpers/class.TestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 Down Expand Up @@ -818,10 +819,28 @@ private function triggerResultTestVariablesTransmissionEvent(
$this->getSessionId(),
$variables,
$this->getSessionId(),
$testUri
$testUri,
$this->isManualScored()
));
}

private function isManualScored(): bool
{
/** @var AssessmentItemRef $itemRef */
foreach ($this->getRoute()->getAssessmentItemRefs() as $itemRef) {
foreach ($itemRef->getComponents() as $component) {
if (
$component instanceof OutcomeDeclaration
&& $component->isExternallyScored()
) {
return true;
}
}
}

return false;
}

/**
* @param TestSessionMemento $sessionMemento
*/
Expand Down
11 changes: 10 additions & 1 deletion models/classes/event/ResultTestVariablesTransmissionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ class ResultTestVariablesTransmissionEvent implements Event
private $transmissionId;
/** @var string */
private $testUri;
/** @var bool */
private bool $isManualScored;

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

public function getName(): string
Expand All @@ -71,4 +75,9 @@ public function getTestUri(): string
{
return $this->testUri;
}

public function isManualScored(): bool
{
return $this->isManualScored;
}
}
62 changes: 62 additions & 0 deletions models/classes/event/TestVariablesRecorded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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 TestVariablesRecorded implements Event
andreluizmachado marked this conversation as resolved.
Show resolved Hide resolved
{
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@

namespace oat\taoQtiTest\models\classes\eventHandler\ResultTransmissionEventHandler;

use oat\oatbox\event\EventManager;
use oat\oatbox\service\ServiceManager;
use oat\tao\model\service\InjectionAwareService;
use oat\taoDelivery\model\execution\DeliveryServerService;
use oat\taoQtiTest\models\classes\event\ResultTestVariablesTransmissionEvent;
use oat\taoQtiTest\models\event\ResultItemVariablesTransmissionEvent;
use oat\taoQtiTest\models\event\TestVariablesRecorded;
use taoQtiCommon_helpers_ResultTransmitter;
use oat\oatbox\service\exception\InvalidServiceManagerException;
use oat\taoResultServer\models\classes\implementation\ResultServerService;
use taoResultServer_models_classes_ReadableResultStorage as ReadableResultStorage;

class ResultTransmissionEventHandler extends InjectionAwareService implements
Api\ResultTransmissionEventHandlerInterface
Expand All @@ -45,6 +51,8 @@ public function transmitResultItemVariable(ResultItemVariablesTransmissionEvent
}

/**
* @param ResultTestVariablesTransmissionEvent $event
* @throws InvalidServiceManagerException
* @throws \taoQtiCommon_helpers_ResultTransmissionException
*/
public function transmitResultTestVariable(ResultTestVariablesTransmissionEvent $event): void
Expand All @@ -54,6 +62,12 @@ public function transmitResultTestVariable(ResultTestVariablesTransmissionEvent
$event->getTransmissionId(),
$event->getTestUri()
);

if (empty($this->containsScoreTotal($event))) {
return;
}

$this->triggerTestVariablesRecorded($event);
}

private function buildTransmitter($deliveryExecutionId): taoQtiCommon_helpers_ResultTransmitter
Expand All @@ -64,4 +78,59 @@ private function buildTransmitter($deliveryExecutionId): taoQtiCommon_helpers_Re

return new taoQtiCommon_helpers_ResultTransmitter($resultStore);
}

public function getEventManager()
{
return $this->getServiceLocator()->get(EventManager::SERVICE_ID);
}

public function getServiceLocator()
{
return ServiceManager::getServiceManager();
}

/**
* @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;
}

/**
* @param ResultTestVariablesTransmissionEvent $event
* @return array
*/
private function containsScoreTotal(ResultTestVariablesTransmissionEvent $event): array
Karol-Stelmaczonek marked this conversation as resolved.
Show resolved Hide resolved
{
return array_filter(
$event->getVariables(),
function ($item) {
return $item->getIdentifier() === 'SCORE_TOTAL';
}
);
}

/**
* @param ResultTestVariablesTransmissionEvent $event
* @return void
* @throws InvalidServiceManagerException
*/
private function triggerTestVariablesRecorded(ResultTestVariablesTransmissionEvent $event): void
Karol-Stelmaczonek marked this conversation as resolved.
Show resolved Hide resolved
{
$outcomeVariables = $this->getResultsStorage()->getDeliveryVariables($event->getDeliveryExecutionId());
$this->getEventManager()->trigger(new TestVariablesRecorded(
$event->getDeliveryExecutionId(),
$outcomeVariables,
$event->isManualScored()
));
}
}
Loading