1
- Yii2 LTI Tool Provider
1
+ Yii2 LTI Tool
2
2
======================
3
3
4
- LTI Tool Provider module for Yii2.
4
+ LTI Tool module for Yii2.
5
5
6
6
[ ![ Latest Stable Version] ( https://poser.pugx.org/izumi-kun/yii2-lti-tool-provider/v/stable )] ( https://packagist.org/packages/izumi-kun/yii2-lti-tool-provider )
7
7
[ ![ Total Downloads] ( https://poser.pugx.org/izumi-kun/yii2-lti-tool-provider/downloads )] ( https://packagist.org/packages/izumi-kun/yii2-lti-tool-provider )
@@ -23,27 +23,34 @@ Add namespaced migrations: `izumi\yii2lti\migrations`. Apply new migrations.
23
23
24
24
### Application config
25
25
26
- Add module to web config and configure. The module has three main events for handling messages from Tool Consumers :
26
+ Add the module to the web config and configure it . The module supports the following events for handling messages from Platforms :
27
27
28
- - ` launch ` for ` basic-lti-launch-request ` message type
29
- - ` contentItem ` for ` ContentItemSelectionRequest ` message type
30
- - ` register ` for ` ToolProxyRegistrationRequest ` message type
28
+ - ` launch `
29
+ - ` configure `
30
+ - ` dashboard `
31
+ - ` contentItem `
32
+ - ` contentItemUpdate `
33
+ - ` submissionReview `
31
34
32
- Make sure to configure access to ` lti/consumer ` controller actions.
33
- All messages from Tool Consumers handles by ` lti/connect ` controller and there is no access restrictions.
35
+ Make sure to configure access to the ` lti/platform ` controller actions.
36
+ All messages from Platforms are handled by the ` lti/tool ` controller, and there are no access restrictions.
34
37
35
38
``` php
36
39
$config = [
37
40
'modules' => [
38
41
'lti' => [
39
- 'class' => '\izumi\yii2lti\Module',
40
- 'on launch' => ['\app\controllers\SiteController', 'ltiLaunch'],
41
- 'on error' => ['\app\controllers\SiteController', 'ltiError'],
42
+ 'class' => \izumi\yii2lti\Module::class,
43
+ 'tool' => [
44
+ 'debugMode' => YII_DEBUG,
45
+ 'rsaKey' => 'A PEM formatted private key (for LTI 1.3 support)',
46
+ ],
47
+ 'on launch' => [SiteController::class, 'ltiLaunch'],
48
+ 'on error' => [SiteController::class, 'ltiError'],
42
49
'as access' => [
43
- 'class' => ' \yii\filters\AccessControl' ,
50
+ 'class' => \yii\filters\AccessControl::class ,
44
51
'rules' => [
45
- ['allow' => true, 'controllers' => ['lti/connect ']],
46
- ['allow' => true, 'controllers' => ['lti/consumer '], 'roles' => ['admin']],
52
+ ['allow' => true, 'controllers' => ['lti/tool ']],
53
+ ['allow' => true, 'controllers' => ['lti/platform '], 'roles' => ['admin']],
47
54
],
48
55
],
49
56
],
@@ -53,12 +60,12 @@ $config = [
53
60
54
61
### Event handlers
55
62
56
- Create event handlers to respect module config .
63
+ Create event handlers according to the module configuration .
57
64
58
65
``` php
59
66
namespace app\controllers;
60
67
61
- use izumi\yii2lti\ToolProviderEvent ;
68
+ use izumi\yii2lti\ToolEvent ;
62
69
use Yii;
63
70
use yii\web\BadRequestHttpException;
64
71
use yii\web\Controller;
@@ -67,9 +74,9 @@ class SiteController extends Controller
67
74
{
68
75
/**
69
76
* basic-lti-launch-request handler
70
- * @param ToolProviderEvent $event
77
+ * @param ToolEvent $event
71
78
*/
72
- public static function ltiLaunch(ToolProviderEvent $event)
79
+ public static function ltiLaunch(ToolEvent $event)
73
80
{
74
81
$tool = $event->sender;
75
82
@@ -78,25 +85,25 @@ class SiteController extends Controller
78
85
$isAdmin = $tool->user->isStaff() || $tool->user->isAdmin();
79
86
80
87
Yii::$app->session->set('isAdmin', $isAdmin);
81
- Yii::$app->session->set('isLtiSession', true);
82
88
Yii::$app->session->set('userPk', $userPk);
83
89
Yii::$app->controller->redirect(['/site/index']);
84
90
85
91
$tool->ok = true;
92
+ $event->handled = true;
86
93
}
87
94
88
95
/**
89
96
* LTI error handler
90
- * @param ToolProviderEvent $event
97
+ * @param ToolEvent $event
91
98
* @throws BadRequestHttpException
92
99
*/
93
- public static function ltiError(ToolProviderEvent $event)
100
+ public static function ltiError(ToolEvent $event)
94
101
{
95
102
$tool = $event->sender;
96
103
$msg = $tool->message;
97
104
if (!empty($tool->reason)) {
98
105
Yii::error($tool->reason);
99
- if ($tool->isDebugMode() ) {
106
+ if ($tool->debugMode ) {
100
107
$msg = $tool->reason;
101
108
}
102
109
}
@@ -108,17 +115,17 @@ class SiteController extends Controller
108
115
### Outcome
109
116
110
117
``` php
111
- use IMSGlobal \LTI\ToolProvider ;
118
+ use ceLTIc \LTI;
112
119
113
120
/* @var \izumi\yii2lti\Module $module */
114
121
$module = Yii::$app->getModule('lti');
115
122
116
- $user = ToolProvider\User::fromRecordId (Yii::$app->session->get('userPk'), $module->toolProvider->dataConnector );
123
+ $user = $module->findUserById (Yii::$app->session->get('userPk'));
117
124
118
125
$result = '0.8';
119
- $outcome = new ToolProvider \Outcome($result);
126
+ $outcome = new LTI \Outcome($result);
120
127
121
- if ($user->getResourceLink()-> doOutcomesService(ToolProvider\ResourceLink::EXT_WRITE , $outcome, $user)) {
128
+ if ($module-> doOutcomesService(LTI\Enum\ServiceAction::Write , $outcome, $user)) {
122
129
Yii::$app->session->addFlash('success', 'Result sent successfully');
123
130
}
124
131
```
@@ -129,5 +136,5 @@ if ($user->getResourceLink()->doOutcomesService(ToolProvider\ResourceLink::EXT_W
129
136
130
137
### Useful
131
138
132
- - [ LTI Tool Consumer emulator] ( https://lti.tools/saltire/tc )
133
- - [ IMSGlobal /LTI-Tool-Provider-Library- PHP/wiki] ( https://github.com/IMSGlobal /LTI-Tool-Provider-Library -PHP/wiki )
139
+ - [ LTI Platform emulator] ( https://saltire. lti.app/platform )
140
+ - [ celtic-project /LTI-PHP/wiki] ( https://github.com/celtic-project /LTI-PHP/wiki )
0 commit comments