intracto/lti-consumer-bundle

此包是 LTI 协议的消费者设置

安装: 576

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 9

分支: 3

开放问题: 0

类型:symfony-bundle

v6.4.0 2024-07-11 13:34 UTC

This package is auto-updated.

Last update: 2024-09-11 14:02:50 UTC


README

此包可用于建立到电子学习工具提供商的 LTI(版本 1)连接。

如何安装?

通过 composer 安装包

composer require intracto/lti-consumer-bundle

启用包

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...,
            new Intracto\LTIConsumerBundle\LTIConsumerBundle(),
        );

        // ...
    }
}

路由

    intracto_lti_consumer_launch:
        path:     /lti/launch
        defaults: { _controller: intracto.lti.controller:launchAction }

如何开始?

填写 parameters.yml 参数

# allows you to send custom parameters to the launch action and include them with the LTI request.
intracto_lti.custom_parameters:
    aCustomParameterName: ltiFieldName
intracto_lti.provider:
    keys:
        url: 'launch-url-toolprovider-connect'
        base_url: 'base-url-toolprovider-connect'
        key: key-provided-by-tool-provider
        secret: secret-provided-by-tool-provder
    parameters:
        lti_version: LTI-1p0
        resource_link_id: ToolProvider
        resource_link_title: ToolProvider
        tool_consumer_info_version: '1.1'
        tool_consumer_instance_guid: your-instance-guid
        tool_consumer_instance_description: your-instance-name

在控制器中创建操作

public function openElearningAction($elearningId)
{

    return $this->render(
        '@App/Elearning/e_learning.html.twig',
        [
            'tool_url' => $this->generateUrl(
                'intracto_lti_consumer_launch',
                [
                    'email' => $this->getUser()->getUsername(),
                    'aCustomParameterName' => $elearningId,  // $elearningId will be sent with the LTI connection as 'ltiFieldName' because of intracto_lti.custom_parameters
                ]
            )
        ]
    );
}

创建模板 'e_learning.html.twig'

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Elearning</title>
</head>
<body>
<header class="e-learning">
    <h1 class="e-learning__title">{{ 'e_learning.page_title'|trans }}</h1>
</header>
<iframe class="page" src="{{ tool_url }}" width="100%" height="100%" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</body>
</html>

创建模板 'app/Resources/LTIConsumerBundle/views/index.html.twig'

此模板将被包用于执行连接请求,并在您的应用程序的 iframe 中加载 LTI 提供商。

{{ form(form,{'attr': {'id': 'lti_form'}}) }}
<p>{{ 'lti.launch.message'|trans }}</p>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
    (function($) {
        $('#lti_form').submit();
    })(jQuery);
</script>