Skip to content

Commit

Permalink
create repository per oc instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamara Gunkel committed Oct 21, 2021
1 parent 47b78df commit 9bfde07
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions lang/en/repository_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

$string['configplugin'] = 'Opencast settings';
$string['opencastinstance'] = 'Opencast instance';
$string['opencastauthor'] = 'Opencast default author';
$string['opencastchannelid'] = 'Opencast channelid';
$string['opencastchannelid_help'] = 'Setup the channelid of the publication channel to search for retrieving url of thumbnail and video.';
Expand Down
61 changes: 37 additions & 24 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public static function instance_config_form($mform) {
return false;
}

$options = array();
foreach (\tool_opencast\local\settings_api::get_ocinstances() as $ocinstance) {
$options[$ocinstance->id] = $ocinstance->name;
}
$mform->addElement('select', 'opencast_instance', get_string('opencastinstance', 'repository_opencast'), $options);
$mform->setType('opencast_instance', PARAM_INT);

$mform->addElement('text', 'opencast_author', get_string('opencastauthor', 'repository_opencast'));
$mform->setType('opencast_author', PARAM_TEXT);

Expand Down Expand Up @@ -84,6 +91,7 @@ public static function instance_config_form($mform) {
* @return bool
*/
public function set_option($options = array()) {
$options['opencast_instance'] = clean_param($options['opencast_instance'], PARAM_INT);
$options['opencast_author'] = clean_param($options['opencast_author'], PARAM_TEXT);
$options['opencast_channelid'] = clean_param($options['opencast_channelid'], PARAM_TEXT);
$options['opencast_playerurl'] = clean_param($options['opencast_playerurl'], PARAM_BOOL);
Expand All @@ -102,6 +110,7 @@ public function set_option($options = array()) {
public static function get_instance_option_names() {

$instanceoptions = array();
$instanceoptions [] = 'opencast_instance';
$instanceoptions [] = 'opencast_author';
$instanceoptions [] = 'opencast_channelid';
$instanceoptions [] = 'opencast_playerurl';
Expand All @@ -127,6 +136,14 @@ private function get_author() {
return self::get_option('opencast_author');
}

/**
* Get Opencast instance id to which this repository belongs.
* @return string
*/
private function get_ocinstance() {
return self::get_option('opencast_instance');
}

/**
* Select the url for the video based on configuration of preferred flavors.
*
Expand Down Expand Up @@ -275,36 +292,32 @@ private function add_video_published_data($ocinstanceid, $video) {
private function get_course_videos($courseid) {
$publishedvideos = [];

// Get all videos from all instances and series.
foreach (\tool_opencast\local\settings_api::get_ocinstances() as $ocinstance) {
if (!$ocinstance->isvisible) {
// Get all videos from all series.
$ocinstanceid = $this->get_ocinstance();
$videos = array();

foreach (\tool_opencast\seriesmapping::get_records(array('courseid' => $courseid,
'ocinstanceid' => $ocinstanceid)) as $mapping) {
if (!$mapping || !($seriesid = $mapping->get('series'))) {
continue;
}
$videos = array();

foreach (\tool_opencast\seriesmapping::get_records(array('courseid' => $courseid,
'ocinstanceid' => $ocinstance->id)) as $mapping) {
if (!$mapping || !($seriesid = $mapping->get('series'))) {
continue;
}

$seriesfilter = "series:" . $seriesid;
$seriesfilter = "series:" . $seriesid;

$query = '/api/events?sign=1&withmetadata=1&withpublications=1&filter=' . urlencode($seriesfilter);
try {
$api = new api($ocinstance->id);
$seriesvideos = $api->oc_get($query);
$seriesvideos = json_decode($seriesvideos);
$videos = array_merge($videos, $seriesvideos);
} catch (\moodle_exception $e) {
continue;
}
$query = '/api/events?sign=1&withmetadata=1&withpublications=1&filter=' . urlencode($seriesfilter);
try {
$api = new api($ocinstanceid);
$seriesvideos = $api->oc_get($query);
$seriesvideos = json_decode($seriesvideos);
$videos = array_merge($videos, $seriesvideos);
} catch (\moodle_exception $e) {
continue;
}
}

foreach ($videos as $video) {
if ($this->add_video_published_data($ocinstance->id, $video)) {
$publishedvideos[] = $video;
}
foreach ($videos as $video) {
if ($this->add_video_published_data($ocinstanceid, $video)) {
$publishedvideos[] = $video;
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/opencast_repository_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function test_add_video_published_data() {
$generator = $this->getDataGenerator()->get_plugin_generator('repository_opencast');
$instance = $generator->create_instance([
'pluginname' => 'Opencast',
'opencast_instance' => 1,
'opencast_author' => 'Test user',
'opencast_channelid' => 'api',
'opencast_thumbnailflavor' => 'presenter/search+preview',
Expand All @@ -62,6 +63,7 @@ public function test_add_video_published_data() {
// Test not valid thumbnail flavor.
$instance = $generator->create_instance([
'pluginname' => 'Opencast',
'opencast_instance' => 1,
'opencast_author' => 'Test user',
'opencast_channelid' => 'api',
'opencast_thumbnailflavor' => 'notvalid',
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021091200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2021091201; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2015050500; // Requires this Moodle version.
$plugin->component = 'repository_opencast'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = array('tool_opencast' => 2021091200);

0 comments on commit 9bfde07

Please sign in to comment.