nelc / laravel-nelc-xapi-integration
与 NELC (国家电子学习中心) 的 xAPI 集成
Requires
- php: ^7.4 || ^8.0
- guzzlehttp/guzzle: ^7.2 || ^7.8
- jenssegers/agent: ^2.6
This package is auto-updated.
Last update: 2024-09-27 07:38:11 UTC
README
Laravel 包,用于与沙特 NELC xAPI 集成。
安装
步骤 1:导航到您的项目目录
在开始之前,导航到您的 Laravel 项目所在的目录。使用以下命令切换到您的项目目录
cd path/to/your/laravel-project
步骤 2:安装
您可以使用 Composer 安装此库。运行以下命令
composer require nelc/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"
这将部署公共文件夹中的 asset
文件,文件名为 lrs-nelc-xapi
,并在 config
文件夹中包含 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
如有需要,您可以打开 config
文件夹中的 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
观察语句
表示活动者已观察对象。此动词通常仅适用于对象代表动态、可见内容(如电影、电视剧或公开表演)时。这是 experience、play 和 consume 动词的更具体形式。
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