|
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
|
|
|
/** |
|
21
|
|
|
* Configure course and account navigation placements |
|
22
|
|
|
* |
|
23
|
|
|
* @return Generator |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getGenerator() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::getGenerator(); |
|
28
|
|
|
|
|
29
|
|
|
$this->generator->setOptionProperty( |
|
30
|
|
|
Option::COURSE_NAVIGATION(), |
|
31
|
|
|
'visibility', |
|
32
|
|
|
'admins' |
|
33
|
|
|
); |
|
34
|
|
|
$this->generator->setOptionProperty( |
|
35
|
|
|
Option::ACCOUNT_NAVIGATION(), |
|
36
|
|
|
'visibility', |
|
37
|
|
|
'admins' |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
return $this->generator; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get a listing of all accounts organized for presentation in a select picker |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
**/ |
|
48
|
|
|
public function getAccountList() |
|
49
|
|
|
{ |
|
50
|
|
|
$cache = new HierarchicalSimpleCache($this->getMySQL(), __CLASS__); |
|
51
|
|
|
|
|
52
|
|
|
$accounts = $cache->getCache('accounts'); |
|
53
|
|
|
if ($accounts === false) { |
|
54
|
|
|
$accountsResponse = $this->api_get( |
|
55
|
|
|
'accounts/1/sub_accounts', |
|
56
|
|
|
[ |
|
57
|
|
|
'recursive' => 'true' |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
$accounts = []; |
|
61
|
|
|
foreach ($accountsResponse as $account) { |
|
|
|
|
|
|
62
|
|
|
$accounts[$account['id']] = $account; |
|
63
|
|
|
} |
|
64
|
|
|
$cache->setCache('accounts', $accounts); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $accounts; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get a listing of all terms organized for presentation in a select picker |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
**/ |
|
75
|
|
|
public function getTermList() |
|
76
|
|
|
{ |
|
77
|
|
|
$cache = new HierarchicalSimpleCache($this->getMySQL(), __CLASS__); |
|
78
|
|
|
|
|
79
|
|
|
$terms = $cache->getCache('terms'); |
|
80
|
|
|
if ($terms === false) { |
|
81
|
|
|
$_terms = $this->api_get( |
|
82
|
|
|
'accounts/1/terms', |
|
83
|
|
|
[ |
|
84
|
|
|
'workflow_state' => 'active' |
|
85
|
|
|
] |
|
86
|
|
|
); |
|
87
|
|
|
$termsResponse = $_terms['enrollment_terms']; |
|
88
|
|
|
$terms = []; |
|
89
|
|
|
foreach ($termsResponse as $term) { |
|
90
|
|
|
$terms[$term['id']] = $term; |
|
91
|
|
|
} |
|
92
|
|
|
$cache->setCache('terms', $terms); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $terms; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param array $arr |
|
100
|
|
|
* @param string|integer $key |
|
101
|
|
|
* @return string `$arr[$key]` if present, `''` otherwise |
|
102
|
|
|
*/ |
|
103
|
|
|
public function blank($arr, $key) |
|
104
|
|
|
{ |
|
105
|
|
|
if (empty($arr[$key])) { |
|
106
|
|
|
return ''; |
|
107
|
|
|
} else { |
|
108
|
|
|
return $arr[$key]; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param integer $account Canvas account ID |
|
114
|
|
|
* @return boolean `TRUE` if the account is a child of the Academics |
|
115
|
|
|
* account, `FALSE` otherwise |
|
116
|
|
|
*/ |
|
117
|
|
|
public function isAcademic($account) |
|
118
|
|
|
{ |
|
119
|
|
|
if ($account == 132) { // FIXME really, hard-coded values? Really? |
|
120
|
|
|
return true; |
|
121
|
|
|
} elseif ($account == 1 || !is_integer($account)) { |
|
122
|
|
|
return false; |
|
123
|
|
|
} else { |
|
124
|
|
|
if (empty($this->accounts)) { |
|
125
|
|
|
$this->accounts = $this->getAccountList(); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
return isAcademic($this->accounts[$account]['parent_account_id']); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
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.