-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCliqrPlugin.php
169 lines (143 loc) · 4.03 KB
/
CliqrPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
use Cliqr\DB\Assignment;
use Studip\Plugins\CustomPerformLegacyRouteStrategy;
use Studip\Plugins\LegacyRouteStrategy;
class CliqrPlugin extends StudIPPlugin implements StandardPlugin, SystemPlugin
{
public $config;
public function __construct()
{
parent::__construct();
require_once __DIR__.'/vendor/autoload.php';
}
public function initialize()
{
$this->config = new \Cliqr\Container();
$this->initializeCourse();
}
public function getContext()
{
global $user;
return (\Request::int('cancel_login')
&& (!is_object($user) || 'nobody' === $user->id))
? null
: Request::option('cid');
}
public function getPluginVersion()
{
static $manifest = null;
if ($manifest === null) {
$manifest = $this->getMetadata();
}
return $manifest['version'];
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getIconNavigation($courseId, $lastVisit, $userId = null)
{
// ...
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getInfoTemplate($courseId)
{
// ...
}
public function getTabNavigation($cid)
{
$url = \PluginEngine::getURL($this, compact('cid'), '', true);
$cliqr = new Navigation('Cliqr', $url);
return compact('cliqr');
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getNotificationObjects($courseId, $since, $userId)
{
// ...
}
const DEFAULT_CONTROLLER = 'app';
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function perform($unconsumedPath)
{
if (!$this->config) {
$this->initialize();
}
$trailsRoot = $this->getPluginPath().'/app';
$dispatcher = new \Cliqr\Dispatcher(
$trailsRoot,
rtrim(PluginEngine::getLink($this, [], null), '/'),
self::DEFAULT_CONTROLLER
);
$dispatcher->plugin = $this;
$dispatcher->container = $this->config;
$dispatcher->dispatch($unconsumedPath);
}
/**
* @SuppressWarnings(UnusedFormalParameter)
*/
protected function getLegacyRouteStrategy(string $unconsumedPath): LegacyRouteStrategy
{
return app(CustomPerformLegacyRouteStrategy::class);
}
private function initializeCourse()
{
if (!$cid = $this->config['cid']) {
return;
}
if (!$course = Course::find($cid)) {
throw new \Cliqr\RecordNotFound();
}
$datafields = DatafieldEntryModel::findByModel(
$course,
$this->config['datafield_first_run_complete_id']
);
if (1 !== count($datafields)) {
throw new RuntimeException('Missing Cliqr First Run Datafield');
}
$firstRunComplete = $datafields[0];
$initialized = (bool) $firstRunComplete->content;
if (!$initialized) {
// create default task group
if (!count(Assignment::findTaskGroups($cid))) {
Assignment::createTaskGroup('course', $cid);
}
$firstRunComplete->content = 1;
$firstRunComplete->store();
}
}
public static function onEnable($pluginId)
{
// enable nobody role by default
\RolePersistence::assignPluginRoles($pluginId, array(7));
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function getMetadata()
{
$metadata = parent::getMetadata();
if (version_compare($GLOBALS['SOFTWARE_VERSION'], '4', '<')) {
foreach ($metadata as $key => $value) {
if (is_string($value)) {
$metadata[$key] = utf8_decode($value);
}
}
}
return $metadata;
}
}