msaaq/nelc-xapi-php-sdk

与沙特NELC(国家电子学习中心)的xAPI集成

v1.3 2024-04-29 19:19 UTC

This package is auto-updated.

Last update: 2024-08-29 20:06:24 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

此包的基本概念是提供一个简单的方法来向沙特NELC(国家电子学习中心)LRS(学习记录存储)发送xAPI语句。

安装

您可以通过composer安装此包

composer require msaaq/nelc-xapi-php-sdk

用法

1. 创建API客户端。

使用SDK的第一步是创建一个ApiClient实例。该ApiClient是SDK的主要入口点。它负责创建其他对象并向API发送请求。

ApiClient需要以下凭证

  • 密钥
  • 密钥
  • 平台名称

您需要联系NELC以获取您的集成凭证。

use Msaaq\Nelc\ApiClient;

$client = new ApiClient(
    key: 'username', // required
    secret: 'password', // required
    isSandbox: true, // optional, default is false
);

$platform = new \Msaaq\Nelc\Common\Platform($identifier = 'platform-identifier', $name = 'platform-name', $language = \Msaaq\Nelc\Enums\Language::ARABIC); // required

创建我们的客户端后,我们可以使用它向NELC LRS发送语句。

2. 发送语句

要向NELC LRS发送语句,我们需要创建一个StatementClient类的实例。

StatementClient需要一个我们在上一步创建的ApiClient实例,以及$platform

use Msaaq\Nelc\StatementClient;

$statementClient = StatementClient::setClient($client)->setPlatform($platform);

现在我们几乎准备好向NELC LRS发送第一条语句了,我们只需要创建一个我们要发送的Statement实例,但首先让我们了解Statement类的结构。

语句结构

您可以将Statement视为在您的应用程序中发生的事件,并且对于每种情况都有8种类型的语句。

每个语句都需要以下内容

  • Actor,表示执行动作的用户(学生)。
    • 它有以下属性
      • national_id,表示用户的国民身份证号。
      • email,表示用户的电子邮件。
  • Instructor,表示课程或模块的讲师(教师)。
    • 它有以下属性
      • name,表示讲师的姓名。
      • email,表示讲师的电子邮件。
  • Module,表示学生注册的课程或模块。
    • 它有以下属性
      • url,表示模块的URL。
      • name,表示模块的名称。
      • description,表示模块的描述。
      • language,表示模块的语言,它必须是Language的一个实例。
      • activityType,表示模块的类型。
        • 它可以有以下几种
          • ActivityType::COURSE
          • ActivityType::LESSON
          • ActivityType::VIDEO
          • ActivityType::MODULE
          • ActivityType::UNIT_TEST
          • ActivityType::CERTIFICATE
      • duration,表示模块的持续时间(秒),仅在activityTypeActivityType::VIDEO时使用。
      • score,表示模块的分数,仅在activityTypeActivityType::UNIT_TEST时使用。
    • language是一个枚举,具有以下值
      • Language::ARABIC
      • Language::ENGLISH
    • timestamp日期/时间,遵循ISO 8601格式,如2022-09-14T10:33:43+03:00
      • 如果您不提供时间戳,将使用当前日期/时间。

对于timestamp,您可以使用Carbon,您可以使用toIso8601String()方法获取正确的格式。

让我们准备ActorInstructor对象,因为我们将在所有语句中使用它们。

use Msaaq\Nelc\Common\Actor;
use Msaaq\Nelc\Common\Instructor;

$actor = new Actor();
$actor->national_id = '123456789';
$actor->email = 'student@msaaq.com';

$instructor = new Instructor();
$instructor->email = 'instructor@msaaq.com';
$instructor->name = 'Instructor Name';

现在我们准备好创建我们的第一个语句

已注册语句

RegisteredStatement用于表示学生正式注册或加入活动。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\RegisteredStatement;

$statement = new RegisteredStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course';
$statement->module->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::COURSE;

var_dump($statementClient->send($statement));

初始化语句

InitializedStatement用于表示演员(学生)已成功开始课程。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\InitializedStatement;

$statement = new InitializedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course';
$statement->module->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::COURSE;

var_dump($statementClient->send($statement));

观看语句

WatchedStatement用于表示演员(学生)已观看对象(视频)。

此语句比之前的语句需要更多的属性,因为它有以下属性

  • parent是一个实例Module,在我们的情况下是课程。
  • completed是一个布尔值,表示视频是否完成。
  • 浏览器信息
    • family是浏览器家族(Mozilla、Google等)。
    • name是浏览器名称(Firefox、Chrome等)。
    • version是浏览器版本。
use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Common\BrowserInformation;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\WatchedStatement;

$statement = new WatchedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$browserInformation = new BrowserInformation();
$browserInformation->family = 'Mozilla';
$browserInformation->name = 'Firefox';
$browserInformation->version = '92.0';

$statement->browserInformation = $browserInformation;

$statement->actor = $actor;
$statement->instructor = $instructor;

// Our parent module is the course
$parent = new Module();
$parent->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$parent->title = 'How to create professional course';
$parent->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$parent->language = $statement->language;
$parent->activityType = ActivityType::COURSE;

$statement->parent = $parent;

// Our module is the video
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course/contents/11919';
$statement->module->title = 'Introduction to creating training courses';
$statement->module->description = 'In this video, we will talk about the importance of creating training courses and the benefits of doing so.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::VIDEO;
// Duration in seconds, required when the activity type is VIDEO
$statement->module->duration = 630; // 10:30 minutes

$statement->completed = true;

var_dump($statementClient->send($statement));

尝试语句

AttemptedStatement用于表示演员(学生)已尝试对象(测验)。

此语句比之前的语句需要更多的属性,因为它有以下属性

  • 父级
  • 完成
  • 浏览器信息
  • succeeded是一个布尔值,表示测验是否成功。
  • attemptId是尝试的唯一标识符。
use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Common\Score;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\AttemptedStatement;

$statement = new AttemptedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->browserInformation = $browserInformation;

$statement->actor = $actor;
$statement->instructor = $instructor;

// Our parent module is the course
$statement->parent = $parent;

// Our module is the video
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course/contents/11919';
$statement->module->title = 'Quiz title';
$statement->module->description = 'Quiz description';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::UNIT_TEST;
// score required when the activity type is UNIT_TEST
$statement->module->score = new Score(); // 10:30 minutes
$statement->module->score->min = 0;
$statement->module->score->max = 100;
$statement->module->score->score = 70; // 70% student score

$statement->completed = true;
$statement->succeeded = true;

var_dump($statementClient->send($statement));

完成语句(模块、章节或单元)

CompletedStatement用于表示演员(学生)已完成对象(模块)。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\CompletedStatement;

$statement = new CompletedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->browserInformation = $browserInformation;

$statement->actor = $actor;
$statement->instructor = $instructor;

// Our parent module is the course
$statement->parent = $parent;

// Our module is the video
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course/contents/11919';
$statement->module->title = 'Unit title';
$statement->module->description = 'Unit description';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::MODULE;

var_dump($statementClient->send($statement));

进度语句

ProgressedStatement用于表示演员(学生)已推进对象(模块/课程)。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\ProgressedStatement;

$statement = new ProgressedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

// Our module is the course
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course';
$statement->module->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::COURSE;

$score = new \Msaaq\Nelc\Common\Score();
$score->score = 15; // the student has progressed 15% of the course

$statement->module->score = $score;

$statement->completed = false;

var_dump($statementClient->send($statement));

完成语句(课程)

CompletedStatement用于表示演员(学生)已完成对象(课程)。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\CompletedStatement;

$statement = new CompletedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

// Our module is the course
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course';
$statement->module->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::COURSE;

var_dump($statementClient->send($statement));

评分语句

RatedStatement用于表示演员(学生)已评分对象(课程)。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Common\Score;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\RatedStatement;

$statement = new RatedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

// The course that student rated
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course';
$statement->module->description = 'This series will cover the most important principles of course making, marketing and content preparation.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::COURSE;

$statement->rate = new Score();
$statement->rate->min = 1;
$statement->rate->max = 5;
$statement->rate->score = 3; // 3 stars out of 5

$statement->rateContent = 'This course is very good.';

var_dump($statementClient->send($statement));

获得语句

EarnedStatement用于表示演员(学生)已获得对象(证书)。

use Msaaq\Nelc\Common\Module;
use Msaaq\Nelc\Common\Score;
use Msaaq\Nelc\Enums\ActivityType;
use Msaaq\Nelc\Enums\Language;
use Msaaq\Nelc\Statements\EarnedStatement;

$statement = new EarnedStatement();
$statement->language = Language::ENGLISH;
$statement->timestamp = '2022-09-14T10:33:43+03:00';

$statement->actor = $actor;
$statement->instructor = $instructor;

// The course that student earned the certificate
$statement->parent = $parent;

// The certificate that student earned
$statement->module = new Module();
$statement->module->url = 'https://academy.msaaq.com/courses/how-to-create-professional-course';
$statement->module->title = 'How to create professional course certificate';
$statement->module->description = 'This certificate is awarded to students who completed the course.';
$statement->module->language = $statement->language;
$statement->module->activityType = ActivityType::CERTIFICATE;

$statement->certificateUrl = 'path to download the certificate';

var_dump($statementClient->send($statement));

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件