-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathlti.php
More file actions
146 lines (116 loc) · 5.38 KB
/
lti.php
File metadata and controls
146 lines (116 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Materia
* License outlined in licenses folder
*/
class Controller_Lti extends \Controller
{
use \Trait_Analytics;
public function before()
{
$this->theme = \Theme::instance();
}
/**
* returns the LTI configuration xml
*/
public function action_index()
{
$cfg = \Config::get('lti.consumers.default');
// TODO: this is hard coded for Canvas, figure out if the request carries any info we can use to figure this out
$this->theme->set_template('partials/config_xml');
$this->theme->get_template()
->set('title', $cfg['title'])
->set('description', $cfg['description'])
->set('launch_url', \Uri::create('lti/assignment'))
->set('login_url', \Uri::create('lti/login'))
->set('picker_url', \Uri::create('lti/picker'))
->set('platform', $cfg['platform'])
->set('privacy_level', $cfg['privacy'])
->set('course_nav_enabled', $cfg['course_nav_enabled'] ?? true)
->set('course_nav_default', $cfg['course_nav_default'] ?? true)
->set('course_nav_text', $cfg['course_nav_text'] ?? true)
->set('course_nav_visibility', $cfg['course_nav_visibility'] ?? true)
->set('tool_id', $cfg['tool_id'] ?? true);
return \Response::forge($this->theme->render())->set_header('Content-Type', 'application/xml');
}
/**
* LTI for logging into Materia through Canvas
*
*/
public function action_login()
{
if ( ! Oauth::validate_post()) \Response::redirect('/lti/error?message=invalid_oauth_request');
$launch = LtiLaunch::from_request();
if ( ! LtiUserManager::authenticate($launch)) \Response::redirect('/lti/error?message=invalid_oauth_request');
$this->theme->set_template('layouts/main')
->set('title', 'Materia')
->set('page_type', 'lti-login');
$this->theme->set_partial('content', 'partials/post_login');
$this->insert_analytics();
\Js::push_inline('const BASE_URL = "'.\Uri::base().'";');
\Js::push_inline('const STATIC_CROSSDOMAIN = "'.\Config::get('materia.urls.static').'";');
\Css::push_group('core');
return \Response::forge($this->theme->render());
}
/**
* Instructor LTI view for choosing a widget
*
*/
public function action_picker(bool $authenticate = true)
{
if ( ! Oauth::validate_post()) \Response::redirect('/lti/error?message=invalid_oauth_request');
$launch = LtiLaunch::from_request();
if ($authenticate && ! LtiUserManager::authenticate($launch)) return \Response::redirect('/lti/error/unknown_user');
$system = \Input::post('tool_consumer_info_product_family_code', 'this system');
$lti_message_type = \Input::post('lti_message_type', 'none');
$lti_key = \Input::post('oauth_consumer_key', '');
$is_selector_mode = \Input::post('selection_directive') === 'select_link' || $lti_message_type === 'ContentItemSelectionRequest';
$return_url = \Input::post('launch_presentation_return_url') ?? \Input::post('content_item_return_url');
\Materia\Log::profile(['action_picker', \Input::post('selection_directive'), $system, $is_selector_mode ? 'yes' : 'no', $return_url], 'lti');
$this->theme->set_template('layouts/main');
\Js::push_group(['angular', 'materia', 'author']);
\Js::push_inline('var BASE_URL = "'.\Uri::base().'";');
\Js::push_inline('var WIDGET_URL = "'.\Config::get('materia.urls.engines').'";');
\Js::push_inline('var STATIC_CROSSDOMAIN = "'.\Config::get('materia.urls.static').'";');
\Js::push_inline('var LTI_MESSAGE_TYPE = "'.$lti_message_type.'"');
\Js::push_inline('var system = "'.htmlentities($system).'"');
\Js::push_inline('const LTI_KEY = "'.$lti_key.'"');
if ($is_selector_mode && ! empty($return_url))
{
\Js::push_inline('var RETURN_URL = "'.$return_url.'"');
}
\Css::push_group(['core', 'lti']);
$this->theme->get_template()
->set('title', 'Select a Widget for Use in '.ucfirst($system))
->set('page_type', 'lti-select');
$this->theme->set_partial('content', 'partials/select_item');
$this->theme->set_partial('header', 'partials/header_empty');
$this->insert_analytics();
return \Response::forge($this->theme->render());
}
// Successfully linked LTI page
public function action_success(string $inst_id)
{
$inst = \Materia\Widget_Instance_Manager::get($inst_id);
// If the current user does not have ownership over the embedded widget, find all of the users who do
$current_user_owns = \Materia\Perm_Manager::user_has_any_perm_to(\Model_User::find_current_id(), $inst_id, \Materia\Perm::INSTANCE, [\Materia\Perm::VISIBLE, \Materia\Perm::FULL]);
$instance_owner_list = $current_user_owns ? [] : $inst->get_owners();
$this->theme->set_template('layouts/main')
->set('title', 'Widget Connected Successfully')
->set('page_type', 'preview');
$this->theme->set_partial('content', 'partials/open_preview')
->set('inst_name', $inst->name)
->set('widget_name', $inst->widget->name)
->set('preview_url', \Uri::create('/preview/'.$inst_id))
->set('icon', \Config::get('materia.urls.engines')."{$inst->widget->dir}img/icon-92.png")
->set('preview_embed_url', \Uri::create('/preview-embed/'.$inst_id))
->set('current_user_owns', $current_user_owns)
->set('instance_owner_list', $instance_owner_list);
$this->insert_analytics();
\Js::push_inline('var BASE_URL = "'.\Uri::base().'";');
\Js::push_inline('var inst_id = "'.$inst_id.'";');
\Js::push_inline('var STATIC_CROSSDOMAIN = "'.\Config::get('materia.urls.static').'";');
\Css::push_group(['core', 'lti']);
return \Response::forge($this->theme->render());
}
}