al-saloul / laravel-nelc-xapi-integration
与NELC(国家电子学习中心)的xAPI集成
Requires
- php: ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3
- al-saloul/agent: ^3.0
- guzzlehttp/guzzle: ^7.2 || ^7.8
README
为与沙特NELC xAPI集成的Laravel包。
安装
步骤1:导航到您的项目目录
在开始之前,导航到您的Laravel项目所在的目录。使用以下命令切换到您的项目目录
cd path/to/your/laravel-project
步骤2:安装
您可以使用Composer安装此库。运行以下命令
composer require al-saloul/laravel-nelc-xapi-integration
步骤3:注册 ServiceProvider
在您的Laravel项目中注册 NelcXapiServiceProvider
。打开 config/app.php
文件,并在 providers
数组中添加以下行
// config/app.php 'providers' => ServiceProvider::defaultProviders()->merge([ /* * Package Service Providers... */ // Other providers... Nelc\LaravelNelcXapiIntegration\NelcXapiServiceProvider::class, ])->toArray(),
步骤4:导出自动加载文件
注册 ServiceProvider 后,运行以下命令重新生成 Composer 的自动加载文件
composer dump-autoload
步骤5:发布配置文件
要发布此包提供的配置文件,请运行以下 Artisan 命令
php artisan vendor:publish --provider="Nelc\LaravelNelcXapiIntegration\NelcXapiServiceProvider"
这将部署公共文件夹中名为 lrs-nelc-xapi
的 asset
文件以及配置文件夹中的 lrs-nelc-xapi.php
文件。
步骤6:配置基本设置
要开始使用此包,请按照以下步骤配置基本设置并连接到NELC XAPI
将您的 LRS_ENDPOINT
、LRS_USERNAME
和 LRS_PASSWORD
添加到项目 .env
文件中
# .env file content
LRS_ENDPOINT=provided_lrs_endpoint
LRS_USERNAME=your_lrs_username
LRS_PASSWORD=your_lrs_password
如果需要,您可以打开配置文件夹中的 lrs-nelc-xapi.php
文件。根据您的需求调整基本设置。请确保通过 .env
文件设置任何 认证(密钥、密钥)
详细信息,以避免将这些敏感信息提交到git存储库并公开。
// config/lrs-nelc-xapi.php return [ 'endpoint' => env('LRS_ENDPOINT'), 'middleware' => ['web'], // Middleware to display the demo page, ['web', 'auth', ...] 'key' => env('LRS_USERNAME'), 'secret' => env('LRS_PASSWORD'), 'platform_in_arabic' => '', // Platform name in Arabic 'platform_in_english' => '', // Platform name in English 'base_route' => 'nelcxapi/test', // Demo Page Link ];
现在,您可以通过以下链接访问演示页面并开始测试语句提交:https://your-site.com/nelcxapi/test
或通过 route('lrs-nelc-xapi.base_route')
。
用法
安装包并注册 ServiceProvider 后,您可以在 Laravel 项目中使用它。以下是一个简单的示例
注册语句
表示参与者正式注册或加入活动。
use Nelc\LaravelNelcXapiIntegration\XapiIntegration; // ... $xapi = new XapiIntegration(); $response = $xapi->Registered( '123456789', // Student National ID 'betalamoud@gmail.com', // Student Email '123', // Course Id OR url Or slug 'New Course', // Course Title 'New Course description', // Course description 'MR Hassan', // instructor Name 'mrhassan@mail.com', // instructor Email ); // dd( $response['status'] ); return 200 // dd( $response['message'] ); return ok // dd( $response['body'] ); return UUID
初始化语句
表示活动提供者已确定参与者成功开始活动。
use Nelc\LaravelNelcXapiIntegration\XapiIntegration; // ... $xapi = new XapiIntegration(); $response = $xapi->Initialized( '123456789', // Student National ID 'betalamoud@gmail.com', // Student Email '123', // Course Id OR url Or slug 'New Course', // Course Title 'New Course description', // Course description 'MR Hassan', // instructor Name 'mrhassan@mail.com', // instructor Email ); // dd( $response['status'] ); return 200 // dd( $response['message'] ); return ok // dd( $response['body'] ); return UUID
观看语句
表示参与者已观看对象。此动词通常仅适用于对象代表动态、可见内容时,如电影、电视剧或公开表演。这是一个比动词体验、播放和消费更具体的动词。
use Nelc\LaravelNelcXapiIntegration\XapiIntegration; // ... $xapi = new XapiIntegration(); $response = $xapi->Watched( '123456789', // Student National ID 'betalamoud@gmail.com', // Student Email '/url/to/lesson', // Lesson Or object URL 'Lesson title', // Object title 'Lesson description', // Object description true, // The status indicating whether it has been fully watched (boolean). 'PT15M', // The duration of the watching session in `ISO 8601` format. '123', // Course Id OR url Or slug 'New Course', // Course Title 'New Course description', // Course description 'MR Hassan', // instructor Name 'mrhassan@mail.com', // instructor Email ); // dd( $response['status'] ); return 200 // dd( $response['message'] ); return ok // dd( $response['body'] ); return UUID
完成语句
表示参与者正常完成或结束活动。
完成(课程或班级)
use Nelc\LaravelNelcXapiIntegration\XapiIntegration; // ... $xapi = new XapiIntegration(); $response = $xapi->CompletedLesson( '123456789', // Student National ID 'betalamoud@gmail.com', // Student Email '/url/to/lesson', // Lesson URL 'Lesson title', 'Lesson description', '123', // Course Id OR url Or slug 'New Course', // Course Title 'New Course description', // Course description 'MR Hassan', // instructor Name 'mrhassan@mail.com', // instructor Email ); // dd( $response['status'] ); return 200 // dd( $response['message'] ); return ok // dd( $response['body'] ); return UUID