1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
require_once 'common.inc.php'; |
4
|
|
|
|
5
|
|
|
use smtech\SeeAllSubmissions\Toolbox; |
6
|
|
|
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider; |
7
|
|
|
use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException; |
8
|
|
|
|
9
|
|
|
define('ACTION_CONFIG', 'config'); |
10
|
|
|
define('ACTION_INSTALL', 'install'); |
11
|
|
|
define('ACTION_CONSUMERS', 'consumers'); |
12
|
|
|
define('ACTION_UNSPECIFIED', false); |
13
|
|
|
|
14
|
|
|
/* store any requested actions for future handling */ |
15
|
|
|
$action = (empty($_REQUEST['action']) ? |
16
|
|
|
ACTION_UNSPECIFIED : |
17
|
|
|
strtolower($_REQUEST['action']) |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
/* action requests only come from outside the LTI! */ |
21
|
|
|
if ($action) { |
22
|
|
|
unset($_SESSION[ToolProvider::class]); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/* authenticate LTI launch request, if present */ |
26
|
|
|
if ($toolbox->lti_isLaunching()) { |
27
|
|
|
$toolbox->resetSession(); |
28
|
|
|
$toolbox->lti_authenticate(); |
29
|
|
|
exit; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/* if authenticated LTI launch, redirect to appropriate placement view */ |
33
|
|
|
if (!empty($_SESSION[ToolProvider::class]['canvas']['course_id'])) { |
34
|
|
|
$_SESSION[COURSE_ID] = $_SESSION[ToolProvider::class]['canvas']['course_id']; |
35
|
|
|
header('Location: submissions.php'); |
36
|
|
|
exit; |
37
|
|
|
|
38
|
|
|
/* if not authenticated, default to showing credentials */ |
39
|
|
|
} else { |
40
|
|
|
$action = (empty($action) ? |
41
|
|
|
ACTION_CONFIG : |
42
|
|
|
$action |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/* process any actions */ |
47
|
|
|
switch ($action) { |
48
|
|
|
/* reset cached install data from config file */ |
49
|
|
|
case ACTION_INSTALL: |
50
|
|
|
$_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
51
|
|
|
$toolbox =& $_SESSION['toolbox']; |
52
|
|
|
|
53
|
|
|
/* test to see if we can connect to the API */ |
54
|
|
|
try { |
55
|
|
|
$toolbox->getAPI(); |
56
|
|
|
} catch (ConfigurationException $e) { |
57
|
|
|
/* if there isn't an API token in config.xml, are there OAuth credentials? */ |
58
|
|
|
if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) { |
59
|
|
|
$toolbox->interactiveGetAccessToken( |
|
|
|
|
60
|
|
|
'This tool requires access to the Canvas APIs by an administrative user. ' . |
61
|
|
|
'This API access is used to query student analytics data that is presented on ' . |
62
|
|
|
'the Advisor Dashboard. Please enter the URL of your Canvas instance below ' . |
63
|
|
|
'(e.g. <code>https://canvas.instructure.com</code> -- the URL that you would ' . |
64
|
|
|
'enter to log in to Canvas). If you are not already logged in, you will be asked ' . |
65
|
|
|
'to log in. After logging in, you will be asked to authorize this tool.</p>' . |
66
|
|
|
'<p>If you are already logged, but <em>not</em> logged in as an administrative user, ' . |
67
|
|
|
'please log out now, so that you may log in as administrative user to authorize this tool.' |
68
|
|
|
); |
69
|
|
|
exit; |
70
|
|
|
} else { /* no (understandable) API credentials available -- doh! */ |
71
|
|
|
throw $e; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/* finish by opening consumers control panel */ |
76
|
|
|
header('Location: consumers.php'); |
77
|
|
|
exit; |
78
|
|
|
|
79
|
|
|
/* show LTI configuration XML file */ |
80
|
|
|
case ACTION_CONFIG: |
81
|
|
|
header('Content-type: application/xml'); |
82
|
|
|
echo $toolbox->saveConfigurationXML(); |
83
|
|
|
exit; |
84
|
|
|
} |
85
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.