Completed
Push — master ( 68e12f...ab20ed )
by Seth
02:02
created

Toolbox::getSchoolSnapshot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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