|
1
|
|
|
<?php |
|
2
|
|
|
/** Toolbox class */ |
|
3
|
|
|
|
|
4
|
|
|
namespace smtech\GradingAnalytics; |
|
5
|
|
|
|
|
6
|
|
|
use smtech\LTI\Configuration\Option; |
|
7
|
|
|
use smtech\GradingAnalytics\Snapshots\Domain; |
|
8
|
|
|
use smtech\GradingAnalytics\Snapshots\History; |
|
9
|
|
|
use smtech\GradingAnalytics\Snapshots\Snapshot; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A reflexive Canvas LTI toolbox |
|
13
|
|
|
* |
|
14
|
|
|
* @author Seth Battis <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox |
|
17
|
|
|
{ |
|
18
|
|
|
const TOOL_CANVAS_EXTERNAL_TOOL_ID = 'TOOL_CANVAS_EXTERNAL_TOOL_ID'; |
|
19
|
|
|
const TOOL_CANVAS_ACCOUNT_ID = 'TOOL_CANVAS_ACCOUNT_ID'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Course statistics history |
|
23
|
|
|
* @var History |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $history; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Course statistics snapshots |
|
29
|
|
|
* @var Statistic[] |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $snapshots; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Configure LTI configuration XML generator to include course and account |
|
35
|
|
|
* navigation placements. |
|
36
|
|
|
* |
|
37
|
|
|
* {@inheritDoc} |
|
38
|
|
|
* |
|
39
|
|
|
* @return \smtech\LTI\Configuration\Generator |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getGenerator() |
|
42
|
|
|
{ |
|
43
|
|
|
parent::getGenerator(); |
|
44
|
|
|
|
|
45
|
|
|
$this->generator->setOptionProperty( |
|
46
|
|
|
Option::COURSE_NAVIGATION(), |
|
47
|
|
|
'visibility', |
|
48
|
|
|
'admins' |
|
49
|
|
|
); |
|
50
|
|
|
$this->generator->setOptionProperty( |
|
51
|
|
|
Option::ACCOUNT_NAVIGATION(), |
|
52
|
|
|
'visibility', |
|
53
|
|
|
'admins' |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
return $this->generator; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Extend load configuration to reset `TOOL_CANVAS_EXTERNAL_TOOL_ID` |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $configFilePath |
|
63
|
|
|
* @param boolean $forceRecache |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function loadConfiguration($configFilePath, $forceRecache = false) |
|
67
|
|
|
{ |
|
68
|
|
|
parent::loadConfiguration($configFilePath, $forceRecache); |
|
69
|
|
|
|
|
70
|
|
|
if ($forceRecache) { |
|
71
|
|
|
$this->clearConfig(self::TOOL_CANVAS_EXTERNAL_TOOL_ID); |
|
72
|
|
|
$this->clearConfig(self::TOOL_CANVAS_ACCOUNT_ID); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the course statistics history for a particular course |
|
78
|
|
|
* |
|
79
|
|
|
* @link https://smtech.github.io/grading-analytics/definitions.html Online |
|
80
|
|
|
* documentation of course statistic fields |
|
81
|
|
|
* |
|
82
|
|
|
* @param string|integer $courseId Numerica Canvas course ID |
|
83
|
|
|
* @return array|false One row per course statistic collected daily, as |
|
84
|
|
|
* described in the documentation, or `FALSE` if no |
|
85
|
|
|
* statistics are available |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getHistory($courseId) |
|
88
|
|
|
{ |
|
89
|
|
|
if (!is_a($this->history, History::class)) { |
|
90
|
|
|
$this->history = new History($this, $courseId); |
|
91
|
|
|
} |
|
92
|
|
|
return $this->history->getHistory(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get a snapshot across a particular domain relevant to a course or |
|
97
|
|
|
* department |
|
98
|
|
|
* |
|
99
|
|
|
* @link https://smtech.github.io/grading-analytics/definitions.html Online |
|
100
|
|
|
* documentation of course statistic fields |
|
101
|
|
|
* |
|
102
|
|
|
* @param string|integer $courseOrDepartmentId A numeric Canvas course or |
|
103
|
|
|
* ccount ID (course is is assumed unless explicitly specified by |
|
104
|
|
|
* `$isCourseId`) |
|
105
|
|
|
* @param Domain $domain Domain across which to take snapshot |
|
106
|
|
|
* @param boolean $isCourseId (Optional, defaults to `TRUE`) whether or |
|
107
|
|
|
* not `$courseOrDepartmentId` is a course |
|
108
|
|
|
* (`TRUE`) or department (`FALSE`) Id |
|
109
|
|
|
* @param string|integer|boolean $teacherFilter (Optional, defaults to |
|
110
|
|
|
* `FALSE`) An optional filter |
|
111
|
|
|
* to limit the snapshot data |
|
112
|
|
|
* to courses taught by a |
|
113
|
|
|
* particular numerica Canvas |
|
114
|
|
|
* user ID |
|
115
|
|
|
* @return array|false One row per course statistic collected daily, as |
|
116
|
|
|
* described in the documentation, or `FALSE` if no |
|
117
|
|
|
* statistics are available |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getSnapshot($courseOrDepartmentId, Domain $domain, $isCourseId = true, $teacherFilter = false) |
|
120
|
|
|
{ |
|
121
|
|
|
$d = $domain->getValue(); |
|
122
|
|
|
if (empty($this->snapshots[$d])) { |
|
123
|
|
|
$this->snapshots[$d] = new Snapshot($this, $domain, $courseOrDepartmentId, $isCourseId); |
|
124
|
|
|
} |
|
125
|
|
|
return $this->snapshots[$d]->getSnapshot($teacherFilter); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|