-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCampusConnect.class.php
More file actions
executable file
·238 lines (212 loc) · 10.3 KB
/
CampusConnect.class.php
File metadata and controls
executable file
·238 lines (212 loc) · 10.3 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/*
* Copyright (c) 2012 Rasmus Fuhse <fuhse@data-quest.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
if (!interface_exists('AdminCourseWidgetPlugin')) {
interface AdminCourseWidgetPlugin {}
}
class CampusConnect extends StudIPPlugin implements SystemPlugin, StandardPlugin, AdminCourseWidgetPlugin
{
public function __construct()
{
parent::__construct();
StudipAutoloader::addAutoloadPath(__DIR__ . '/lib');
if ($GLOBALS['perm']->have_perm("root")) {
/*******************************************************************
* Einstellungsseiten *
*******************************************************************/
$navigation = new Navigation($this->getDisplayName(), PluginEngine::getURL($this, array(), "config/index"));
Navigation::addItem('/admin/campusconnect', $navigation);
$navigation = new AutoNavigation("Übersicht", PluginEngine::getURL($this, array(), "config/index"));
Navigation::addItem('/admin/campusconnect/index', $navigation);
$navigation = new AutoNavigation("Teilnehmer/LMS", PluginEngine::getURL($this, array(), "config/participants"));
Navigation::addItem('/admin/campusconnect/participants', $navigation);
$navigation = new AutoNavigation("ECS", PluginEngine::getURL($this, array(), "config/ecs"));
Navigation::addItem('/admin/campusconnect/ecs', $navigation);
$navigation = new Navigation("Log", PluginEngine::getURL($this, array(), "log/view"));
Navigation::addItem('/admin/campusconnect/log', $navigation);
}
/*******************************************************************
* Notifications für sendenswerte Daten *
*******************************************************************/
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidCreatOrUpdate");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidGetMember");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidChangeMember");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidDeleteMember");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidCreateOrUpdate");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidDelete");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidChangeSchedule");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidChangeStudyArea");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "CourseDidChangeInstitutes");
NotificationCenter::addObserver($this, "synchronizeStudipItems", "DatafieldDidUpdate");
/*******************************************************************
* Navigation für Kurse mit Kurs-URLs *
*******************************************************************/
// if (Navigation::hasItem("/course") && Context::getId()) {
// $course = new CCCourse(Context::getId());
// $course_urls = $course->getCourseUrls();
// if (count($course_urls) > 0) {
// $tab = new AutoNavigation(_("Lernplattformen"), PluginEngine::getUrl($this, array(), 'courselink/extern'));
// Navigation::addItem("/course/campusconnect_extern", $tab);
// }
// }
}
/**
* Adds a semininar or institute to the stack of objects, that need to be
* synced via CampusConnect.
* @param string $event : name of event
* @param mixed $object : seminar- or institute-object
* @param mixed $user_data : possible user_data, mostly useless here
*/
public function synchronizeStudipItems($event, $object, $user_data)
{
if (strpos($event, "Course") === 0) {
$type = "course";
$id = $object->getId();
}
if (strpos($event, "Institute") === 0) {
$type = "institute";
$id = $object->getId();
}
if (strpos($event, "DataFieldEntry") === 0) {
$range_id = $object->getRangeID();
$object_type = $object->structure->getID();
if ($object_type === "sem") {
$type = "course";
$id = $range_id;
} elseif($object_type === "inst") {
$type = "institute";
$id = $range_id;
}
}
if ($type) {
CampusConnectTriggerStack::add($type, $id);
}
}
public function getDisplayName()
{
return _("CampusConnect");
}
public function getTabNavigation($course_id)
{
$navigation = new Navigation(_("Informationen"), PluginEngine::getURL($this, array(), "courselink/overview"));
$navigation->addSubNavigation('overview', new Navigation(_("Informationen"), PluginEngine::getURL($this, array('cid' => $course_id), "courselink/overview")));
$navigation->addSubNavigation('details', new Navigation(_("Details"), URLHelper::getURL("dispatch.php/course/details", ['cid' => $course_id])));
return array('campusconnect_main' => $navigation);
}
public function getIconNavigation($course_id, $last_visit, $user_id)
{
return null;
}
public function getInfoTemplate($course_id)
{
return null;
}
public function getNotificationObjects($course_id, $since, $user_id)
{
return null;
}
/**
* Returns a list of widgets for the admin courses page.
*
* @return AdminCourseOptionsWidget[]
*/
public function getWidgets(): iterable {
$widgets = [];
$widget = new AdminCourseOptionsWidget(
_('CampusConnect')
);
$participants = CCParticipant::findBySQL('`type` = ? AND `active` = 1 ORDER BY `id` ASC ', array('participants'));
$options = [
'' => ''
];
foreach ($participants as $participant) {
if (!empty($participant['data']['export'])) {
$options['export_' . $participant->id] = _('Exportieren nach ').$participant['data']['name'];
break;
}
}
foreach ($participants as $participant) {
if (!empty($participant['data']['import'])) {
$options['import_' . $participant->id] = _('Importiert von ').$participant['data']['name'];
}
}
$widget->addSelect(
_("CampusConnect-Filter"),
'campusconnect',
$options,
$GLOBALS['user']->cfg->getValue("CAMPUSCONNECT_FILTER_SETTING")
);
$widgets['campusconnect'] = $widget;
return $widgets;
}
/**
* Return the filter values this widget provides. Return an associative
* array with filter names as indices and filter values as values.
*
* @return array
*/
public function getFilters(): array {
return [
'campusconnect' => $GLOBALS['user']->cfg->getValue("CAMPUSCONNECT_FILTER_SETTING")
];
}
/**
* Apply the set filters to the AdminCourseFilter query.
*
* @param AdminCourseFilter $filter
*/
public function applyFilters(AdminCourseFilter $filter): void
{
if ($GLOBALS['user']->cfg->getValue("CAMPUSCONNECT_FILTER_SETTING")) {
list($way, $participant_id) = explode('_', $GLOBALS['user']->cfg->getValue("CAMPUSCONNECT_FILTER_SETTING"));
if ($way === 'export') {
$participant = CampusConnectConfig::find($participant_id);
if ($participant && !empty($participant['data']['export_settings']) && $participant['data']['export_settings']['course_entity_type'] === 'kurslink') {
$export_settings = $participant['data']['export_settings'];
if ($export_settings['filter_sem_tree_activate']) {
$sem_tree_ids = array_keys($export_settings['filter_sem_tree']);
$filter->query->join('seminar_sem_tree', "seminar_sem_tree.seminar_id = seminare.Seminar_id", 'INNER JOIN');
$filter->query->where('seminar_sem_tree', "seminar_sem_tree.sem_tree_id IN (:sem_tree_ids) ", [
'sem_tree_ids' => $sem_tree_ids
]);
}
if ($export_settings['filter_datafields_activate']) {
$datafield_id = $export_settings['filter_datafield'];
$filter->query->join('datafields_entries', "datafields_entries.range_id = seminare.Seminar_id", 'INNER JOIN');
$filter->query->where('datafields_entries', "datafields_entries.datafield_id = :cc_datafield_id AND datafields_entries.content != '' AND datafields_entries.content != '0' AND datafields_entries.content IS NOT NULL", [
'cc_datafield_id' => $datafield_id
]);
}
}
} else {
list($way, $participant_id) = explode('_', $GLOBALS['user']->cfg->getValue("CAMPUSCONNECT_FILTER_SETTING"));
if ($way === 'import') {
$filter->query->join('campus_connect_entities', "campus_connect_entities.item_id = seminare.Seminar_id AND campus_connect_entities.type = 'course'", 'INNER JOIN');
$filter->query->where('campus_connect_import_participants', "campus_connect_entities.participant_id = :participant_id", [
'participant_id' => $participant_id
]);
}
}
}
}
/**
* Set filters from the admin course page. You will be given an associative
* array according to getFilters().
*
* @param array $filters
*/
public function setFilters(array $filters): void
{
foreach ($filters as $name => $value) {
if ($name === 'campusconnect') {
$GLOBALS['user']->cfg->store("CAMPUSCONNECT_FILTER_SETTING", $value);
}
}
}
}