forked from elan-ev/studip-opencast-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
155 lines (122 loc) · 4.99 KB
/
ajax.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
<?php
use Opencast\Models\OCConfig;
use Opencast\Models\OCSeminarEpisodes;
use Opencast\Models\OCSeminarSeries;
use Opencast\LTI\OpencastLTI;
use Opencast\LTI\LtiLink;
class AjaxController extends OpencastController
{
public function index_action()
{
$this->render_text($this->_('Ups..'));
}
public function logupload_action()
{
StudipLog::log('OC_UPLOAD_MEDIA', Request::get('workflow_id'), Request::get('course_id'), Request::get('episode_id'));
$this->render_text('ok');
}
public function getseries_action()
{
$user_id = $GLOBALS['user']->id;
$cache = StudipCacheFactory::getCache();
$cache_key = 'sop/series/'. $user_id .'/'. Context::getId();
$results = unserialize($cache->read($cache_key));
if ($results === false) {
$series = OCSeriesModel::getSeriesForUser($user_id, Context::getId());
$results = [];
foreach ($series as $series_id => $seminar_id) {
$course = Course::find($seminar_id);
if (!$course || !$oc_items = OCSeriesModel::getSeriesFromOpencast($series_id, $seminar_id)) {
continue;
}
$item = [
'seminar_id' => $seminar_id,
'series_id' => $series_id
];
$item['name'] = $course->getFullname('number-name-semester');
$item['endtime'] = $course->getEnd_Time();
$item = array_merge($item, $oc_items);
$results[] = $item;
}
uasort($results, function ($a, $b) {
return $a['endtime'] == $b['endtime'] ? 0
: ($a['endtime'] < $b['endtime'] ? -1 : 1);
});
$cache->write($cache_key, serialize($results), 3600);
}
$this->render_json(array_values($results));
}
public function getepisodes_action($course_id, $series_id, $simple = false)
{
$api_client = ApiEventsClient::getInstance(OCConfig::getConfigIdForSeries($series_id));
$search_client = SearchClient::getInstance(OCConfig::getConfigIdForSeries($series_id));
$check = !empty(OCSeminarSeries::findBySql('seminar_id = ? AND series_id = ?', [$course_id, $series_id]));
$result = $simple_result = [];
if (!$check || !OCPerm::editAllowed($course_id)
|| !$GLOBALS['perm']->have_studip_perm('autor', $course_id))
{
// do not list episodes if user has no permissions in the connected course
$this->render_json(array_values([]));
return;
}
$episodes = $api_client->getBySeries($series_id);
if (!is_array($episodes)) {
$episodes = [$episodes];
}
foreach ($episodes as $episode) {
$studip_episode = OCSeminarEpisodes::findOneBySQL(
'series_id = ? AND episode_id = ? AND seminar_id = ?',
[$series_id, $episode['id'], $course_id]
);
if ($studip_episode && (
(Context::getId() == $course_id && $studip_episode->visible != 'invisible'))
|| $studip_episode->visible == 'free'
) {
$result[] = $episode;
}
$simple_result[] = [
'id' => $episode['id'],
'name' => $episode['title'],
'date' => $episode['start'],
'url' => $search_client->getBaseURL() . "/paella/ui/watch.html?id=" . $episode['id'],
'visible' => $studip_episode->visible
];
}
if ($simple) {
$result = $simple_result;
}
$this->render_json(array_values($result));
}
public function getltidata_action($course_id, $series_id)
{
$config = OCConfig::getConfigForCourse($course_id);
$current_user_id = $GLOBALS['auth']->auth['uid'];
$lti_link = new LtiLink(
OpencastLTI::getSearchUrl($course_id),
$config['lti_consumerkey'],
$config['lti_consumersecret']
);
if (OCPerm::editAllowed($course_id, $current_user_id)) {
$role = 'Instructor';
} else if ($GLOBALS['perm']->have_studip_perm('autor', $course_id, $current_user_id)) {
$role = 'Learner';
}
$lti_link->setUser($current_user_id, $role, True);
$lti_link->setCourse($course_id);
$lti_link->setResource(
$series_id,
'series',
'view complete series for course'
);
$launch_data = $lti_link->getBasicLaunchData();
$signature = $lti_link->getLaunchSignature($launch_data);
$launch_data['oauth_signature'] = $signature;
$lti_data = json_encode($launch_data);
$lti_url = $lti_link->getLaunchURL();
$result = [
'lti_url' => $lti_url,
'lti_data' => $lti_data
];
$this->render_json($result);
}
}