Skip to content

Commit 25fe2e3

Browse files
committed
Merge branch 'main' into issue-1318
2 parents 09b944c + 06a36d0 commit 25fe2e3

37 files changed

+602
-440
lines changed

app/controllers/redirect.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function before_filter(&$action, &$args)
2727

2828
public function perform_action($action, $token)
2929
{
30+
$this->set_layout(null);
31+
$this->assets_url = rtrim($this->plugin->getPluginUrl(), '/') . '/assets';
32+
3033
$video = null;
3134
$video_share = null;
3235
if ($action == 'share') {
@@ -38,8 +41,10 @@ public function perform_action($action, $token)
3841

3942
if (empty($video)) {
4043
$this->error = _('Das Video wurde nicht gefunden, ist defekt oder momentan (noch) nicht verfügbar.');
44+
return;
4145
} else if ($video->trashed) {
4246
$this->error = _('Das Video wurde zur Löschung markiert und kann daher nicht abgerufen werden.');
47+
return;
4348
}
4449

4550
/*
@@ -53,6 +58,7 @@ public function perform_action($action, $token)
5358
$lti = LtiHelper::getLaunchData($video->config_id, $customtool, $video_share);
5459
if (empty($lti) || empty($customtool)) {
5560
$this->error = _('Das Video wurde nicht gefunden, ist defekt oder momentan (noch) nicht verfügbar.');
61+
return;
5662
}
5763

5864
// get correct endpoint for redirect type
@@ -64,12 +70,6 @@ public function perform_action($action, $token)
6470

6571
$this->launch_data = $ltilink['launch_data'];
6672
$this->launch_url = $ltilink['launch_url'];
67-
68-
if (!empty($this->error)) {
69-
$this->assets_url = rtrim($this->plugin->getPluginUrl(), '/') . '/assets';
70-
}
71-
72-
$this->set_layout(null);
7373
}
7474

7575
public function download_action($token, $type, $index)

courseware/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cronjobs/opencast_courseware_block_copy_mapping.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Opencast\Models\CoursewareBlockMappings;
77
use Opencast\Models\VideoCoursewareBlocks;
8+
use Opencast\Models\Videos;
89
use Courseware\Block;
910

1011
class OpencastCoursewareBlockCopyMapping extends CronJob
@@ -36,23 +37,24 @@ public function execute($last_result, $parameters = array())
3637
$token = $mapping->token;
3738
$new_block_query->execute([':token' => $token]);
3839
$new_block_record = $new_block_query->fetchOne(PDO::FETCH_ASSOC);
39-
if (!empty($new_block_record)) {
40+
$video = Videos::find($mapping->video_id);
41+
if (!empty($new_block_record) && !empty($video)) {
4042
echo 'Peform mapping for block: ' . $new_block_record['id'] . "\n";
4143

4244
// Add record into the VideoCoursewareBlocks
4345
$msg = 'Record is added into oc_video_cw_blocks';
44-
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $mapping->token, $new_block_record['id']);
46+
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $video->token, $new_block_record['id']);
4547
if (!$added) {
4648
$msg = 'No record is added into oc_video_cw_blocks!';
4749
}
48-
echo $msg;
50+
echo $msg . "\n";
4951

5052
// Get the actual block object.
5153
$new_block = Block::find($new_block_record['id']);
5254
if (!empty($new_block)) {
5355
// Remove extra param from block's payload.
5456
$palyload = json_decode($new_block->payload, true);
55-
unset($palyload['copied_from']);
57+
unset($palyload['copied_token']);
5658
$new_block->payload = json_encode($palyload);
5759
$new_block->store();
5860
echo "Block's Playload cleared \n";

cronjobs/opencast_sync_acls.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function execute($last_result, $parameters = array())
7979
// check if video exists in Stud.IP
8080
$video = Videos::findByEpisode($event->identifier);
8181

82+
$video->created = date('Y-m-d H:i:s', strtotime($event->created));
83+
$video->store();
84+
8285
if ($video->config_id != $config->id) {
8386
echo 'config id mismatch for Video with id: '. $video->id .", $config->id <> {$video->config_id}\n";
8487
continue;

lib/BlockTypes/OpencastBlockV3.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Opis\JsonSchema\Schema;
55
use Opencast\Models\VideoCoursewareBlocks;
66
use Opencast\Models\CoursewareBlockMappings;
7+
use Opencast\Models\Videos;
78
/**
89
* This class represents the content of a Courseware test block.
910
*
@@ -63,7 +64,10 @@ public function copyPayload(string $rangeId = ''): array
6364
$token = md5($this->block['id'] . time());
6465
$payload['copied_token'] = $token;
6566

66-
CoursewareBlockMappings::setRecord($token, $payload['token'], $rangeId);
67+
if (!empty($payload['token']) && Course::exists($rangeId)) {
68+
$video = Videos::findByToken($payload['token']);
69+
CoursewareBlockMappings::setRecord($token, $video->id, $rangeId);
70+
}
6771

6872
return $payload;
6973
}

lib/Models/Tags.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public static function getCourseVideosTags($course_id)
115115
' INNER JOIN oc_playlist_seminar AS ops ON (ops.playlist_id = opv.playlist_id AND ops.seminar_id = :cid)';
116116
$params = [':cid' => $course_id];
117117

118-
if (!$perm->have_studip_perm('dozent', $course_id)) {
118+
$required_course_perm = \Config::get()->OPENCAST_TUTOR_EPISODE_PERM ? 'tutor' : 'dozent';
119+
if (!$perm->have_studip_perm($required_course_perm, $course_id)) {
119120
$query .= ' LEFT JOIN oc_playlist_seminar_video AS opsv ON (opsv.playlist_seminar_id = ops.id AND opsv.video_id = opv.video_id)'.
120121
' WHERE (opsv.visibility IS NULL AND opsv.visible_timestamp IS NULL AND ops.visibility = "visible"'.
121122
' OR opsv.visibility = "visible" AND opsv.visible_timestamp IS NULL'.

lib/Models/Videos.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static function getPlaylistVideos($playlist_id, $filters)
109109
$sql .= ' INNER JOIN oc_playlist_seminar AS ops ON (ops.seminar_id = :cid AND ops.playlist_id = opv.playlist_id)'.
110110
' LEFT JOIN oc_playlist_seminar_video AS opsv ON (opsv.playlist_seminar_id = ops.id AND opsv.video_id = opv.video_id)';
111111

112-
$where = ' WHERE '. self::getVisibilitySql();
112+
$where = ' WHERE '. self::getVisibilitySql($cid);
113113

114114
$params[':cid'] = $cid;
115115
}
@@ -150,7 +150,7 @@ public static function getCourseVideos($course_id, $filters)
150150
if (!$perm->have_studip_perm($required_course_perm, $course_id)) {
151151
$sql .= ' LEFT JOIN oc_playlist_seminar_video AS opsv ON (opsv.playlist_seminar_id = ops.id AND opsv.video_id = opv.video_id)';
152152

153-
$where = ' WHERE '. self::getVisibilitySql();
153+
$where = ' WHERE '. self::getVisibilitySql($course_id);
154154
}
155155

156156
$query = [
@@ -162,10 +162,15 @@ public static function getCourseVideos($course_id, $filters)
162162
return self::getFilteredVideos($query, $filters);
163163
}
164164

165-
private static function getVisibilitySql()
165+
private static function getVisibilitySql($course_id)
166166
{
167167
// if each video has to explicitly set to visible, filter out everything else
168-
if (\Config::get()->OPENCAST_HIDE_EPISODES) {
168+
$course_hide_episodes = \Config::get()->OPENCAST_HIDE_EPISODES;
169+
$course_default_episodes_visibility = \CourseConfig::get($course_id)->OPENCAST_COURSE_DEFAULT_EPISODES_VISIBILITY ?? 'default';
170+
if ($course_default_episodes_visibility !== 'default') {
171+
$course_hide_episodes = $course_default_episodes_visibility === 'hidden' ? true : false;
172+
}
173+
if ($course_hide_episodes) {
169174
return '(
170175
(opsv.visibility = "visible" AND opsv.visible_timestamp IS NULL)
171176
OR (opsv.visible_timestamp < NOW())
@@ -494,7 +499,7 @@ public static function getNumberOfNewCourseVideos($course_id, $last_visit, $user
494499
if (!$perm->have_perm('dozent', $user_id)) {
495500
$sql .= ' LEFT JOIN oc_playlist_seminar_video AS opsv ON (opsv.playlist_seminar_id = ops.id AND opsv.video_id = opv.video_id)';
496501

497-
$where .= ' AND '. self::getVisibilitySql();
502+
$where .= ' AND '. self::getVisibilitySql($course_id);
498503
}
499504

500505
$sql .= $where;
@@ -980,7 +985,7 @@ public static function parseEvent($eventType, $episode, $video)
980985
$presentation_download = [];
981986
$audio_download = [];
982987
$annotation_tool = false;
983-
$duration = 0;
988+
$duration = $video->duration;
984989
$track_link = '';
985990
$livestream_link = '';
986991

lib/Providers/Perm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function hasRole($check_role, $user_id = null)
126126
* @param string $check_role
127127
* @param string $user_id
128128
*
129-
* @return boolean
129+
* @return array|boolean list of institutes or false if the checks are not met!
130130
*/
131131
public static function getRoleInstitutes($check_role, $user_id)
132132
{

lib/RouteMap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function authenticatedRoutes(RouteCollectorProxy $group)
6363

6464
$group->get("/videos/{token}/shares", Routes\Video\VideoSharesList::class);
6565
$group->put("/videos/{token}/shares", Routes\Video\VideoSharesUpdate::class);
66-
$group->post("/videos/{course_id}/copy", Routes\Video\VideoCopyToCourse::class);
6766

6867
$group->put("/videos/{token}/worldwide_share", Routes\Video\VideoWorldwideShareUpdate::class);
6968

@@ -108,6 +107,8 @@ public function authenticatedRoutes(RouteCollectorProxy $group)
108107
$group->delete("/courses/{course_id}/playlist/{token}", Routes\Course\CourseRemovePlaylist::class);
109108

110109
$group->put("/courses/{course_id}/upload/{upload}", Routes\Course\CourseSetUpload::class); // TODO: document in api docs
110+
// TODO: document in api docs?
111+
$group->put("/courses/{course_id}/episodes_visibility", Routes\Course\CourseSetDefaultVideosVisibility::class);
111112

112113
$group->get("/courses/videos", Routes\Course\CourseListForUserVideos::class);
113114
$group->get("/courses/videos/playlist/{token}", Routes\Course\CourseListForPlaylistVideos::class);

lib/Routes/Course/CourseConfig.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public function __invoke(Request $request, Response $response, $args)
3636

3737
if (empty($series)) {
3838
// only tutor or above should be able to trigger this series creation!
39-
if ($perm->have_studip_perm('tutor', $course_id)) {
39+
$required_course_perm = \Config::get()->OPENCAST_TUTOR_EPISODE_PERM ? 'tutor' : 'dozent';
40+
if ($perm->have_studip_perm($required_course_perm, $course_id)) {
4041
// No series for this course yet! Create one!
4142
$config_id = \Config::get()->OPENCAST_DEFAULT_SERVER;
4243
$series_client = new SeriesClient($config_id);
@@ -53,16 +54,31 @@ public function __invoke(Request $request, Response $response, $args)
5354
}
5455
}
5556

57+
// Default Course Episodes Visibility.
58+
// The course specific config option OPENCAST_COURSE_DEFAULT_EPISODES_VISIBILITY has 3 possible values:
59+
// - default: use the default value from the config (OPENCAST_HIDE_EPISODES) at the time!
60+
// - visible: show the episodes to students by default
61+
// - hidden: hide the episodes from students by default
62+
// Getting with the default value from the config (OPENCAST_HIDE_EPISODES).
63+
$course_hide_episodes = \Config::get()->OPENCAST_HIDE_EPISODES;
64+
$course_default_episodes_visibility = \CourseConfig::get($course_id)->OPENCAST_COURSE_DEFAULT_EPISODES_VISIBILITY
65+
?? 'default';
66+
if ($course_default_episodes_visibility !== 'default') {
67+
$course_hide_episodes = $course_default_episodes_visibility === 'hidden' ? true : false;
68+
}
69+
5670
$results = [
5771
'series' => [
5872
'series_id' => $series->series_id,
5973
],
60-
'workflow' => SeminarWorkflowConfiguration::getWorkflowForCourse($course_id),
61-
'edit_allowed' => Perm::editAllowed($course_id),
62-
'upload_allowed' => Perm::uploadAllowed($course_id),
63-
'upload_enabled' => \CourseConfig::get($course_id)->OPENCAST_ALLOW_STUDENT_UPLOAD ? 1 : 0,
64-
'has_default_playlist' => Helpers::checkCourseDefaultPlaylist($course_id),
65-
'scheduling_allowed' => Perm::schedulingAllowed($course_id)
74+
'workflow' => SeminarWorkflowConfiguration::getWorkflowForCourse($course_id),
75+
'edit_allowed' => Perm::editAllowed($course_id),
76+
'upload_allowed' => Perm::uploadAllowed($course_id),
77+
'upload_enabled' => \CourseConfig::get($course_id)->OPENCAST_ALLOW_STUDENT_UPLOAD ? 1 : 0,
78+
'has_default_playlist' => Helpers::checkCourseDefaultPlaylist($course_id),
79+
'scheduling_allowed' => Perm::schedulingAllowed($course_id),
80+
'course_hide_episodes' => $course_hide_episodes, // Use this in a course instead of OPENCAST_HIDE_EPISODES!
81+
'course_default_episodes_visibility' => $course_default_episodes_visibility,
6682
];
6783

6884
return $this->createResponse($results, $response);

0 commit comments

Comments
 (0)