-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStoodlePlugin.php
205 lines (174 loc) · 6.8 KB
/
StoodlePlugin.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
require_once __DIR__ . '/bootstrap.php';
/**
* Stoodle.class.php
*
* Shameless doodle clone
*
* @author Jan-Hendrik Willms <[email protected]>
* @version 2.3
**/
class StoodlePlugin extends Stoodle\Plugin implements StandardPlugin, PrivacyPlugin, RESTAPIPlugin
{
const GETTEXT_DOMAIN = 'stoodle';
use Stoodle\PluginLocalizationTrait;
public function __construct()
{
parent::__construct();
$this->initializeLocalization();
NotificationCenter::addObserver($this, 'removeUserData', 'UserDataDidRemove');
}
public function getTitle()
{
return $this->_('Stoodle');
}
public function getTabNavigation($course_id)
{
$navigation = new Navigation($this->_('Stoodle'), PluginEngine::getURL($this, [], 'stoodle/index'));
$navigation->setImage(Icon::create('assessment', Icon::ROLE_INFO_ALT));
$navigation->setActiveImage(Icon::create('assessment', Icon::ROLE_INFO));
if ($GLOBALS['perm']->have_studip_perm('tutor', $course_id)) {
$navigation->addSubNavigation('index', new Navigation(
$this->_('Übersicht'),
PluginEngine::getLink($this, [], 'stoodle/index')
));
$navigation->addSubNavigation('administration', new Navigation(
$this->_('Verwaltung'),
PluginEngine::GetLink($this, [], 'admin')
));
}
return ['stoodle' => $navigation];
}
public function getIconNavigation($course_id, $last_visit, $user_id)
{
$icon = Icon::create(
'vote-stopped',
Icon::ROLE_CLICKABLE,
['title' => $this->_('Stoodle: keine laufenden Umfragen')]
);
$navigation = new Navigation(
$this->getTitle(),
PluginEngine::getURL($this, [], 'stoodle/index')
);
$navigation->setImage($icon);
$query = "SELECT COUNT(DISTINCT stoodle.stoodle_id) AS running,
SUM(stoodle_answers.user_id IS NULL) AS open,
SUM(GREATEST(stoodle.chdate, IFNULL(stoodle.start_date, 0)) > :last_visit) AS new
FROM stoodle
LEFT JOIN stoodle_answers USING (stoodle_id)
WHERE range_id = :course_id
AND stoodle_answers.user_id = :user_id
AND (start_date IS NULL OR start_date <= UNIX_TIMESTAMP())
AND (end_date IS NULL OR end_date >= UNIX_TIMESTAMP())";
$statement = DBManager::get()->prepare($query);
$statement->bindValue(':last_visit', $last_visit);
$statement->bindValue(':course_id', $course_id);
$statement->bindValue(':user_id', $user_id);
$statement->execute();
$data = $statement->fetch(PDO::FETCH_ASSOC);
if ($data['running'] === 0) {
return $navigation;
}
$message = sprintf(
$this->_('%u laufende Umfrage(n)'),
$data['running']
);
if ($data['open'] > 0) {
$message .= ', ' . sprintf(
$this->_('an %u noch nicht teilgenommen'),
$data['open']
);
}
if ($data['new'] > 0) {
$icon = Icon::create('vote+new', Icon::ROLE_STATUS_RED, ['title' => $message]);
} else {
$icon = Icon::create('vote', Icon::ROLE_NAVIGATION, ['title' => $message]);
}
$navigation->setImage($icon);
return $navigation;
}
public function getNotificationObjects($course_id, $since, $user_id)
{
return [];
}
public function getInfoTemplate($course_id)
{
return null;
}
/**
* This method dispatches all actions.
*
* @param string part of the dispatch path that was not consumed
*/
public function perform($unconsumed_path)
{
PageLayout::setTitle(Context::get()->getFullname() . ' - ' . $this->getTitle());
$manifest = $this->getMetadata();
Helpbar::get()->addPlainText($this->_('Informationen'), $manifest['description']);
$this->addStylesheet('assets/jquery-timepicker/jquery-ui-timepicker-addon.css');
$this->addStylesheet('assets/stoodle.less');
$this->addScript('assets/date-js/date-de-DE.js');
$this->addScript('assets/stoodle.js');
$this->addScript('assets/stoodle-config.js');
$range_id = Request::option('cid', Context::get()->id);
$app_path = $this->getPluginPath() . '/app';
URLHelper::removeLinkParam('cid');
$app_url = rtrim(PluginEngine::getURL($this, [], ''), '/');
URLHelper::addLinkParam('cid', $range_id);
$dispatcher = new Trails_Dispatcher($app_path, $app_url, 'stoodle');
$dispatcher->current_plugin = $this;
$dispatcher->range_id = $range_id;
$dispatcher->dispatch($unconsumed_path);
}
public function removeUserData($event, $user_id, $type)
{
Stoodle\Stoodle::deleteByUser_id($user_id);
Stoodle\Selection::deleteByUser_id($user_id);
Stoodle\Comment::deleteByUser_id($user_id);
Stoodle\Answer::removeByUserId($user_id);
}
/**
* Export available data of a given user into a storage object
* (an instance of the StoredUserData class) for that user.
*
* @param StoredUserData $store object to store data into
*/
public function exportUserData(StoredUserData $storage)
{
$options = [];
$storage->addTabularData('Stoodle: Erstellte Umfragen', 'stoodle', Stoodle\Stoodle::findAndMapBySQL(
function ($stoodle) use (&$options) {
foreach ($stoodle->options as $option) {
$options[] = $option->toRawArray();
}
return $stoodle->toRawArray();
},
'user_id = ?',
[$storage->user_id]
));
$storage->addTabularData('Stoodle: Antwortmöglichkeiten der Umfragen', 'stoodle_options', $options);
$storage->addTabularData('Stoodle: Abgegebene Kommentare', 'stoodle_comments', Stoodle\Comment::findAndMapBySQL(
function ($comment) {
return $comment->toRawArray();
},
'user_id = ?',
[$storage->user_id]
));
$storage->addTabularData(
'Stoodle: Abgegebene Antworten 1',
'stoodle_answers',
DBManager::get()->fetchAll("SELECT * FROM stoodle_answers WHERE user_id = ?", [$storage->user_id])
);
$storage->addTabularData(
'Stoodle: Abgegebene Antworten 2',
'stoodle_selection',
DBManager::get()->fetchAll("SELECT * FROM stoodle_selection WHERE user_id = ?", [$storage->user_id])
);
}
public function getRouteMaps()
{
return [
new Stoodle\RouteMaps\Stoodle()
];
}
}