Skip to content

Commit

Permalink
feat: CompactTest command
Browse files Browse the repository at this point in the history
  • Loading branch information
bugalot committed Feb 9, 2024
1 parent 056da8d commit c34c1e0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/qtisdk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
use qtism\cli\Cli;
use qtism\cli\CompactTest;
use qtism\cli\Render;
use qtism\cli\AssessmentTestSessionDump;
use cli as CliTools;
Expand Down Expand Up @@ -42,6 +43,10 @@ switch ($module) {
case 'dump':
AssessmentTestSessionDump::main();
break;

case 'compact':
CompactTest::main();
break;
default:
CliTools\err("%RUnknown module '{$requestedModuleName}'. Available modules are: " . implode(',', $availableModules) . '.%n');
exit(Cli::EXIT_FAILURE);
Expand Down
15 changes: 14 additions & 1 deletion src/qtism/cli/AssessmentTestSessionDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
use qtism\runtime\storage\binary\LocalQtiBinaryStorage;
use qtism\runtime\storage\common\StorageException;
use qtism\runtime\tests\AssessmentItemSession;
use qtism\runtime\tests\AssessmentItemSessionState;
use qtism\runtime\tests\AssessmentTestSessionState;
use qtism\runtime\tests\SessionManager;
use qtism\runtime\tests\TimeConstraint;

class AssessmentTestSessionDump extends Cli
{
Expand Down Expand Up @@ -48,16 +51,18 @@ protected function run(): void
$this->out("Test Title: " . $session->getAssessmentTest()->getTitle());
$this->out("Test Tool Name: " . $session->getAssessmentTest()->getToolName());
$this->out("Test Tool Version: " . $session->getAssessmentTest()->getToolVersion());
$this->out("Session State: " . AssessmentTestSessionState::getNameByConstant($session->getState()));
$this->out('');

$this->out("Assessment Item Sessions");
$this->out('------------------------');
$this->out('========================');

/** @var AssessmentItemSession $itemSession */
foreach ($session->getAssessmentItemSessionStore()->getAllAssessmentItemSessions() as $itemSession) {
$this->out("Assessment Item Identifier: " . $itemSession->getAssessmentItem()->getIdentifier());
$this->out("Assessment Item Title: " . $itemSession->getAssessmentItem()->getTitle());
$this->out("Assessment Item Label: " . $itemSession->getAssessmentItem()->getLabel());
$this->out("Assessment Item Session State: " . AssessmentItemSessionState::getNameByConstant($itemSession->getState()));

/** @var Variable $variable */
foreach ($itemSession as $variable) {
Expand All @@ -76,6 +81,14 @@ protected function run(): void
$this->out('');
}

$this->out("Duration by Location");
$this->out("====================");

$durationStore = $session->getDurationStore();
foreach ($durationStore as $variable) {
echo 'Identifier: ' . $variable->getIdentifier() . ' / Time: ' . $variable->getValue() . "\n";
}

} catch (XmlStorageException $e) {
$this->fail('XML Compact Test document could not be read.');
} catch (StorageException $e) {
Expand Down
65 changes: 65 additions & 0 deletions src/qtism/cli/CompactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace qtism\cli;

use cli\Arguments;
use qtism\data\storage\xml\XmlCompactDocument;
use qtism\data\storage\xml\XmlDocument;
use qtism\data\storage\xml\XmlStorageException;
use ReflectionException;

class CompactTest extends Cli
{

protected function run()
{
$arguments = $this->getArguments();

$doc = new XmlDocument();
try {
$doc->load($arguments['input']);
$compactDoc = XmlCompactDocument::createFromXmlAssessmentTestDocument($doc);
$compactDoc->save($arguments['output']);

} catch (XmlStorageException $e) {
$this->fail('Input XML Test document could not be read.');
} catch (ReflectionException $e) {
$this->fail('An unexpected error occurred.');
}
}

protected function setupArguments(): Arguments
{
$arguments = new Arguments(['strict' => false]);

// -- Options
// Session option.
$arguments->addOption(
['input'],
[
'description' => 'The input QTI test file.',
]
);

// XML option.
$arguments->addOption(
['output'],
[
'description' => 'The output QTI compact test file.',
]
);

return $arguments;
}

protected function checkArguments()
{
$arguments = $this->getArguments();

if ($arguments['input'] === null) {
$this->fail('Please provide the --input argument.');
} else if ($arguments['output'] === null) {
$this->fail('Please provide the --output argument.');
}
}
}

0 comments on commit c34c1e0

Please sign in to comment.