1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace smtech\AdvisorDashboard; |
4
|
|
|
|
5
|
|
|
use smtech\LTI\Configuration\Option; |
6
|
|
|
use Battis\HierarchicalSimpleCache; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Advisor Dashboard toolbox |
10
|
|
|
* |
11
|
|
|
* Adds some common, useful methods to the St. Mark's-styled |
12
|
|
|
* ReflexiveCanvasLTI Toolbox |
13
|
|
|
* |
14
|
|
|
* @author Seth Battis <[email protected]> |
15
|
|
|
* @version v1.2 |
16
|
|
|
*/ |
17
|
|
|
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Store a listing of Canvas accounts for quick access |
21
|
|
|
* @var \smtech\CanvasPest\CanvasObject[] |
22
|
|
|
*/ |
23
|
|
|
private $accounts; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Configure course and account navigation placements |
27
|
|
|
* |
28
|
|
|
* @return Generator |
29
|
|
|
*/ |
30
|
|
|
public function getGenerator() |
31
|
|
|
{ |
32
|
|
|
parent::getGenerator(); |
33
|
|
|
|
34
|
|
|
$this->generator->setOptionProperty( |
35
|
|
|
Option::COURSE_NAVIGATION(), |
36
|
|
|
'visibility', |
37
|
|
|
'admins' |
38
|
|
|
); |
39
|
|
|
$this->generator->setOptionProperty( |
40
|
|
|
Option::ACCOUNT_NAVIGATION(), |
41
|
|
|
'visibility', |
42
|
|
|
'admins' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
return $this->generator; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get a listing of all accounts organized for presentation in a select picker |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
**/ |
53
|
|
|
public function getAccountList() |
54
|
|
|
{ |
55
|
|
|
$cache = new HierarchicalSimpleCache($this->getMySQL(), __CLASS__); |
56
|
|
|
|
57
|
|
|
$accounts = $cache->getCache('accounts'); |
58
|
|
|
if ($accounts === false) { |
59
|
|
|
$accountsResponse = $this->api_get( |
60
|
|
|
'accounts/1/sub_accounts', |
61
|
|
|
[ |
62
|
|
|
'recursive' => 'true' |
63
|
|
|
] |
64
|
|
|
); |
65
|
|
|
$accounts = []; |
66
|
|
|
foreach ($accountsResponse as $account) { |
|
|
|
|
67
|
|
|
$accounts[$account['id']] = $account; |
68
|
|
|
} |
69
|
|
|
$cache->setCache('accounts', $accounts); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $accounts; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get a listing of all terms organized for presentation in a select picker |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
**/ |
80
|
|
|
public function getTermList() |
81
|
|
|
{ |
82
|
|
|
$cache = new HierarchicalSimpleCache($this->getMySQL(), __CLASS__); |
83
|
|
|
|
84
|
|
|
$terms = $cache->getCache('terms'); |
85
|
|
|
if ($terms === false) { |
86
|
|
|
$_terms = $this->api_get( |
87
|
|
|
'accounts/1/terms', |
88
|
|
|
[ |
89
|
|
|
'workflow_state' => 'active' |
90
|
|
|
] |
91
|
|
|
); |
92
|
|
|
$termsResponse = $_terms['enrollment_terms']; |
93
|
|
|
$terms = []; |
94
|
|
|
foreach ($termsResponse as $term) { |
95
|
|
|
$terms[$term['id']] = $term; |
96
|
|
|
} |
97
|
|
|
$cache->setCache('terms', $terms); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $terms; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param array $arr |
105
|
|
|
* @param string|integer $key |
106
|
|
|
* @return string `$arr[$key]` if present, `''` otherwise |
107
|
|
|
*/ |
108
|
|
|
public function blank($arr, $key) |
109
|
|
|
{ |
110
|
|
|
if (empty($arr[$key])) { |
111
|
|
|
return ''; |
112
|
|
|
} else { |
113
|
|
|
return $arr[$key]; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param integer $account Canvas account ID |
119
|
|
|
* @return boolean `TRUE` if the account is a child of the Academics |
120
|
|
|
* account, `FALSE` otherwise |
121
|
|
|
*/ |
122
|
|
|
public function isAcademic($account) |
123
|
|
|
{ |
124
|
|
|
if ($account == 132) { // FIXME really, hard-coded values? Really? |
125
|
|
|
return true; |
126
|
|
|
} elseif ($account == 1 || !is_integer($account)) { |
127
|
|
|
return false; |
128
|
|
|
} else { |
129
|
|
|
if (empty($this->accounts)) { |
130
|
|
|
$this->accounts = $this->getAccountList(); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
return $this->isAcademic($this->accounts[$account]['parent_account_id']); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.