2017 © Pedro Peláez
 

yii2-extension yii2-lti-tool-provider

LTI Tool Provider library for Yii2

image

izumi-kun/yii2-lti-tool-provider

LTI Tool Provider library for Yii2

  • Sunday, June 10, 2018
  • by Izumi-kun
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 1100 % Grown

The README.md

Yii2 LTI Tool

LTI Tool module for Yii2., (*1)

Latest Stable Version Total Downloads License, (*2)

Installation

composer require izumi-kun/yii2-lti-tool-provider

Usage

Migrations

Add namespaced migrations: izumi\yii2lti\migrations. Apply new migrations., (*3)

Application config

Add the module to the web config and configure it. The module supports the following events for handling messages from Platforms:, (*4)

  • launch
  • configure
  • dashboard
  • contentItem
  • contentItemUpdate
  • submissionReview

Make sure to configure access to the lti/platform controller actions. All messages from Platforms are handled by the lti/tool controller, and there are no access restrictions., (*5)

$config = [
    'modules' => [
        'lti' => [
            'class' => \izumi\yii2lti\Module::class,
            'tool' => [
                'debugMode' => YII_DEBUG,
                'rsaKey' => 'A PEM formatted private key (for LTI 1.3 support)',
            ],
            'on launch' => [SiteController::class, 'ltiLaunch'],
            'on error' => [SiteController::class, 'ltiError'],
            'as access' => [
                'class' => \yii\filters\AccessControl::class,
                'rules' => [
                    ['allow' => true, 'controllers' => ['lti/tool']],
                    ['allow' => true, 'controllers' => ['lti/platform'], 'roles' => ['admin']],
                ],
            ],
        ],
    ],
];

Event handlers

Create event handlers according to the module configuration., (*6)

namespace app\controllers;

use izumi\yii2lti\ToolEvent;
use Yii;
use yii\web\BadRequestHttpException;
use yii\web\Controller;

class SiteController extends Controller
{
    /**
     * basic-lti-launch-request handler
     * @param ToolEvent $event
     */
    public static function ltiLaunch(ToolEvent $event)
    {
        $tool = $event->sender;

        // $userPk can be used for user identity
        $userPk = $tool->user->getRecordId();
        $isAdmin = $tool->user->isStaff() || $tool->user->isAdmin();

        Yii::$app->session->set('isAdmin', $isAdmin);
        Yii::$app->session->set('userPk', $userPk);
        Yii::$app->controller->redirect(['/site/index']);

        $tool->ok = true;
        $event->handled = true;
    }

    /**
     * LTI error handler
     * @param ToolEvent $event
     * @throws BadRequestHttpException
     */
    public static function ltiError(ToolEvent $event)
    {
        $tool = $event->sender;
        $msg = $tool->message;
        if (!empty($tool->reason)) {
            Yii::error($tool->reason);
            if ($tool->debugMode) {
                $msg = $tool->reason;
            }
        }
        throw new BadRequestHttpException($msg);
    }
}

Outcome

use ceLTIc\LTI;

/* @var \izumi\yii2lti\Module $module */
$module = Yii::$app->getModule('lti');

$user = $module->findUserById(Yii::$app->session->get('userPk'));

$result = '0.8';
$outcome = new LTI\Outcome($result);

if ($module->doOutcomesService(LTI\Enum\ServiceAction::Write, $outcome, $user)) {
    Yii::$app->session->addFlash('success', 'Result sent successfully');
}

Sample app

https://github.com/Izumi-kun/yii2-lti-tool-provider-sample, (*7)

Useful

The Versions

10/06 2018

dev-master

9999999-dev

LTI Tool Provider library for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Viktor Khokhryakov

07/06 2018

0.3.0

0.3.0.0

LTI Tool Provider library for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Viktor Khokhryakov

04/06 2018

0.2.0

0.2.0.0

LTI Tool Provider library for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Viktor Khokhryakov

04/06 2018

0.1.0

0.1.0.0

LTI Tool Provider library for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Viktor Khokhryakov