qtism/qtism

OAT QTI-SDK

v19.5.0 2024-07-03 12:16 UTC

This package is auto-updated.

Last update: 2024-08-29 12:23:40 UTC


README

QTI-SDK

Latest Version Coverage Status License GPL2 Packagist Downloads

PHP QTI 软件开发套件

IMS QTI (问题 & 测试互操作性) 软件开发套件,支持 PHP 7.0 及更高版本,支持由 IMS QTI 规范家族 描述的广泛功能。

QTI 的此实现正在持续增强。主分支的 API 可能会随时更改。

功能

  • 目标 QTI 2.0、2.1 和部分 2.2
  • 完整的 QTI 信息模型
  • 完整的 QTI 规则引擎支持
  • 通过 PSR-0/PSR-4 进行自定义操作钩子
  • 威尔伯特·克拉恩的Goldilocks 渲染 / 史蒂夫·莱的 XHTML5 转换
  • 在渲染时直接映射到 QTI 信息模型的 CSS 解析器
  • 项目和测试会话(具有闪电般的二进制持久性)
  • 用于 QTI 文档操作/遍历的简洁 API
  • 前置条件 & 分支
  • 选择和排序
  • 响应、结果和模板处理
  • aria-* 属性
  • 单元测试驱动

安装(开发者)

  1. 克隆仓库。
  2. 确保您了解如何使用 Composer,并且它已安装在本系统上。
  3. php composer.phar install
  4. 您已准备好!

单元测试(开发者)

通过以下 shell 命令运行单元测试

cp phpunit.xml.dist phpunit.xml
./vendor/bin/phpunit test

贡献

我们一直在寻找人们为项目提供以下内容

  • 错误报告
  • 单元测试
  • 新功能

请介绍自己!

QTI 项目会话管理

介绍示例

以下示例演示了如何为给定的 QTI XML 项目文档实例化一个项目会话。在此示例中使用的项目是来自 QTI 2.1 实施指南"水的组成" 项目。

<?php
use qtism\common\enums\BaseType;
use qtism\common\enums\Cardinality;
use qtism\common\datatypes\QtiIdentifier;
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\common\State;
use qtism\runtime\common\ResponseVariable;
use qtism\runtime\common\MultipleContainer;
use qtism\runtime\tests\AssessmentItemSession;

// Instantiate a new QTI XML document, and load a QTI XML document.
$itemDoc = new XmlDocument('2.1');
$itemDoc->load('choice_multiple.xml');

/* 
 * A QTI XML document can be used to load various pieces of QTI content such as assessmentItem,
 * assessmentTest, responseProcessing, ... components. Our target is an assessmentItem, which is the
 * root component of our document.
 */
$item = $itemDoc->getDocumentComponent();

/* 
 * The item session represents the collected and computed data related to the interactions a
 * candidate performs on a single assessmentItem. As per the QTI specification, "an item session
 * is the accumulation of all attempts at a particular instance of an assessmentItem made by
 * a candidate.
 */
$itemSession = new AssessmentItemSession($item);

// The candidate is entering the item session, and is beginning his first attempt.
$itemSession->beginItemSession();
$itemSession->beginAttempt();

/* 
 * We instantiate the responses provided by the candidate for this assessmentItem, for the current
 * item session. For this assessmentItem, the data collected from the candidate is represented by 
 * a State, composed of a single ResponseVariable named 'RESPONSE'.
 */
$responses = new State(
    array(
        // The 'RESPONSE' ResponseVariable has a QTI multiple cardinality, and a QTI identifier baseType.
        new ResponseVariable(
            'RESPONSE',
            Cardinality::MULTIPLE,
            BaseType::IDENTIFIER,
            /* 
             * The ResponseVariable value is a Container with multiple cardinality and an identifier
             * baseType to meet the cardinality and baseType requirements of the ResponseVariable.
             */
            new MultipleContainer(
                BaseType::IDENTIFIER,
                /*
                 * The values composing the Container are identifiers 'H' and 'O', which represent
                 * the correct response to this item.
                 */
                array(
                    new QtiIdentifier('H'),
                    new QtiIdentifier('O')
                )
            )
        )
    )
);

/*
 * The candidate is finishing the current attempt, by providing a correct response.
 * ResponseProcessing takes place to produce a new value for the 'SCORE' OutcomeVariable.
 */
$itemSession->endAttempt($responses);

// The item session variables and their values can be accessed by their identifier.
echo 'numAttempts: ' . $itemSession['numAttempts'] . "\n";
echo 'completionStatus: ' . $itemSession['completionStatus'] . "\n";
echo 'RESPONSE: ' . $itemSession['RESPONSE'] . "\n";
echo 'SCORE: ' . $itemSession['SCORE'] . "\n";

/*
 * numAttempts: 1
 * completionStatus: completed
 * RESPONSE: ['H'; 'O']
 * SCORE: 2
 */

// End the current item session.
$itemSession->endItemSession();

多次尝试示例

根据 QTI 规范,项目会话默认允许单个尝试。尝试开始一个会使项目会话超过最大尝试次数的尝试将导致 PHP 异常,如以下示例所示。

<?php
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\common\State;
use qtism\runtime\tests\AssessmentItemSession;
use qtism\runtime\tests\AssessmentItemSessionException;

$itemDoc = new XmlDocument('2.1');
$itemDoc->load('choice_multiple.xml');
$item = $itemDoc->getDocumentComponent();

$itemSession = new AssessmentItemSession($item);
$itemSession->beginItemSession();

// Begin 1st attempt.
$itemSession->beginAttempt();
// End attempt by providing an empty response...
$itemSession->endAttempt(new State());

// Begin 2nd attempt, but by default, maximum number of attempts is 1.
try {
    $itemSession->beginAttempt();
} catch (AssessmentItemSessionException $e) {
    echo $e->getMessage();
    // A new attempt for item 'choiceMultiple' is not allowed. The maximum number of attempts (1) is reached.
}

如果允许在给定的评估项上多次尝试,则可以将 itemSessionControlmaxAttempts 属性修改为允许多次或无限次尝试,候选人可以执行。

<?php
use qtism\data\ItemSessionControl;
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\common\State;
use qtism\runtime\tests\AssessmentItemSession;

$itemDoc = new XmlDocument('2.1');
$itemDoc->load('choice_multiple.xml');
$item = $itemDoc->getDocumentComponent();
$itemSession = new AssessmentItemSession($item);

// Set the maximum number of attempts to 0 (means unlimited).
$itemSessionControl = new ItemSessionControl();
$itemSessionControl->setMaxAttempts(0);
$itemSession->setItemSessionControl($itemSessionControl);

// Performing multiple attempts will not lead to a PHP exception anymore, because the maximum number of attemps is unlimited!
$itemSession->beginItemSession();

// 1st attempt will be an incorrect response from the candidate (['H'; 'Cl']).
$responses = new State(
    array(
        new ResponseVariable(
            'RESPONSE',
            Cardinality::MULTIPLE,
            BaseType::IDENTIFIER,
            new MultipleContainer(
                BaseType::IDENTIFIER,
                array(
                    new QtiIdentifier('H'),
                    new QtiIdentifier('Cl')
                )
            )
        )
    )
);

$itemSession->endAttempt($responses);

echo 'numAttempts: ' . $itemSession['numAttempts'] . "\n";
echo 'completionStatus: ' . $itemSession['completionStatus'] . "\n";
echo 'RESPONSE: ' . $itemSession['RESPONSE'] . "\n";
echo 'SCORE: ' . $itemSession['SCORE'] . "\n";

/*
 * numAttempts: 1
 * completionStatus: completed
 * RESPONSE: ['H'; 'N']
 * SCORE: 0
 */

// 2nd attempt will send a correct response this time (['H'; 'O'])!
$itemSession->beginAttempt();
$responses['RESPONSE'][1]->setValue('O');
$itemSession->endAttempt();

echo 'numAttempts: ' . $itemSession['numAttempts'] . "\n";
echo 'completionStatus: ' . $itemSession['completionStatus'] . "\n";
echo 'RESPONSE: ' . $itemSession['RESPONSE'] . "\n";
echo 'SCORE: ' . $itemSession['SCORE'] . "\n";

/*
 * numAttempts: 2
 * completionStatus: completed
 * RESPONSE: ['H'; 'O']
 * SCORE: 2
 */

$itemSession->endItemSession();

您可以在 QTI-SDK GitHub Wiki 上获取更多信息!

QTI 渲染

QTI 软件开发套件允许您将 XML 序列化的 QTI 文件转换为它们的 (X)HTML5 Goldilocks 相当物。以下 shell 命令使用具有缩进格式的 (X)HTML5 Golidlocks 渲染风格将 path/to/qti.xml QTI 文件渲染为 HTML5 文档。渲染输出(stdout)重定向到 /home/jerome/qti.html 文件。

./vendor/bin/qtisdk render -df --source path/to/qti.xml --flavour goldilocks > /home/jerome/qti.html

有关更多帮助和信息,只需调用帮助屏幕即可了解渲染二进制文件提供的功能!

./vendor/bin/qtisdk render --help

配置

对于其他主要的PHP框架,例如Doctrine QTI-SDK使用注解。在这种情况下,以下两个Zend Opcache配置指令必须按照以下方式配置。