Skip to content

Commit

Permalink
Ticket 566 (#567)
Browse files Browse the repository at this point in the history
* fix duration calculation

* fix episode embed
  • Loading branch information
tgloeggl authored Mar 19, 2022
1 parent df601c7 commit 3389473
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 54 deletions.
7 changes: 6 additions & 1 deletion classes/OCRestClient/ApiEventsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ private function prepareEpisode($episode)
'series_id' => $episode->is_part_of,
'title' => $episode->title,
'start' => $episode->start,
'duration' => $episode->duration,
'description' => $episode->description,
'author' => $episode->creator,
'has_previews' => false
Expand All @@ -227,6 +226,7 @@ private function prepareEpisode($episode)
$presentation_download = [];
$audio_download = [];
$annotation_tool = false;
$duration = 0;

foreach ((array) $episode->publications[0]->attachments as $attachment) {
if ($attachment->flavor === "presenter/search+preview" || $attachment->type === "presenter/search+preview") {
Expand Down Expand Up @@ -254,6 +254,8 @@ private function prepareEpisode($episode)
'url' => $track->url,
'info' => $this->getResolutionString($track->width, $track->height)
];

$duration = $track->duration;
}

if (in_array($track->mediatype, ['audio/aac', 'audio/mp3', 'audio/mpeg', 'audio/m4a', 'audio/ogg', 'audio/opus'])
Expand All @@ -267,6 +269,8 @@ private function prepareEpisode($episode)
'url' => $track->url,
'info' => round($track->audio->bitrate / 1000, 1) . 'kb/s, ' . explode('/', $track->mediatype)[1]
];

$duration = $track->duration;
}
}

Expand Down Expand Up @@ -313,6 +317,7 @@ private function prepareEpisode($episode)
$new_episode['audio_download'] = $audio_download;
$new_episode['annotation_tool'] = $annotation_tool;
$new_episode['has_previews'] = $episode->has_previews ?: false;
$new_episode['duration'] = $duration;
}

return $new_episode;
Expand Down
46 changes: 23 additions & 23 deletions controllers/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Opencast\Models\OCConfig;
use Opencast\Models\OCSeminarEpisodes;
use Opencast\Models\OCSeminarSeries;

use Opencast\LTI\OpencastLTI;
use Opencast\LTI\LtiLink;
Expand Down Expand Up @@ -61,14 +62,15 @@ public function getseries_action()
$this->render_json(array_values($results));
}

public function getepisodes_action($series_id, $simple = false)
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));
$course_id = OCConfig::getCourseIdForSeries($series_id);

$check = !empty(OCSeminarSeries::findBySql('seminar_id = ? AND series_id = ?', [$course_id, $series_id]));
$result = $simple_result = [];

if (!OCPerm::editAllowed($course_id)
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
Expand All @@ -83,27 +85,25 @@ public function getepisodes_action($series_id, $simple = false)
}

foreach ($episodes as $episode) {
if (key_exists('publications', $episode)) {
$studip_episode = OCSeminarEpisodes::findOneBySQL(
'series_id = ? AND episode_id = ? AND seminar_id = ?',
[$series_id, $episode->identifier, $course_id]
);

if ($studip_episode && (
(Context::getId() == $course_id && $studip_episode->visible != 'invisible'))
|| $studip_episode->visible == 'free'
) {
$result[] = $episode;
}

$simple_result[] = [
'id' => $episode->identifier,
'name' => $episode->title,
'date' => $episode->start,
'url' => $search_client->getBaseURL() . "/paella/ui/watch.html?id=" . $episode->identifier,
'visible' => $studip_episode->visible
];
$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) {
Expand Down
38 changes: 9 additions & 29 deletions javascripts/embed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/courseware-plugin-opencast-video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default {
axios
.get(STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencast/ajax/getepisodes/'
+ this.currentSeries + '/simple'
+ this.context.id + '/' + this.currentSeries + '/simple'
+ '?cid=' + this.context.id)
.then(response => {
this.episodes = response.data;
Expand Down

0 comments on commit 3389473

Please sign in to comment.