Skip to content

Commit

Permalink
Merge branch 'master' into issue-368
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Aug 21, 2024
2 parents 23adef5 + ee80fb7 commit a1cae03
Show file tree
Hide file tree
Showing 51 changed files with 2,292 additions and 918 deletions.
4 changes: 3 additions & 1 deletion addtranscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@

/**
* Add new transcription to the event
*
* @package block_opencast
* @copyright 2022 Farbod Zamani Boroujeni, ELAN e.V.
* @author Farbod Zamani Boroujeni <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');

use block_opencast\local\addtranscription_form;
use block_opencast\local\apibridge;
use block_opencast\local\attachment_helper;
use core\output\notification;
use tool_opencast\local\settings_api;

require_once('../../config.php');

global $PAGE, $OUTPUT, $CFG, $SITE;

require_once($CFG->dirroot . '/repository/lib.php');
Expand Down
2 changes: 1 addition & 1 deletion addvideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* @copyright 2017 Andreas Wagner, SYNERGY LEARNING
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');

use block_opencast\local\addvideo_form;
use block_opencast\local\apibridge;
use block_opencast\local\file_deletionmanager;
use block_opencast\local\upload_helper;
use core\output\notification;
use tool_opencast\local\settings_api;
require_once('../../config.php');

global $PAGE, $OUTPUT, $CFG, $USER, $SITE, $DB;

Expand Down
144 changes: 132 additions & 12 deletions backup/moodle2/backup_opencast_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @package block_opencast
* @copyright 2017 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @author Farbod Zamani Boroujeni (2024)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -40,6 +41,7 @@
* @package block_opencast
* @copyright 2017 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @author Farbod Zamani Boroujeni (2024)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_opencast_block_task extends backup_block_task {
Expand All @@ -55,15 +57,38 @@ protected function define_my_settings() {
if (importvideosmanager::is_enabled_and_working_for_coreimport($ocinstance->id) == true) {

// Get default value, to include opencast video.
$defaultimportvalue = get_config('block_opencast', 'importvideoscoredefaultvalue_' . $ocinstance->id);
$defaultimportvalue = boolval(get_config('block_opencast', 'importvideoscoredefaultvalue_' . $ocinstance->id));

// Get import mode, to determine whether to offer selective feature or not.
// Duplicate videos mode is capable of selection.
// ACL Change mode is not, due to changing the acl of the whole series at once.
$importmode = get_config('block_opencast', 'importmode_' . $ocinstance->id);

// Check, whether there are course videos available.
$apibridge = apibridge::get_instance($ocinstance->id);
$courseid = $this->get_courseid();

$seriestobackup = $apibridge->get_course_series($courseid);

// A flag to check if the main include is added.
$ocinstanceisincluded = false;
$includesettingname = 'opencast_videos_' . $ocinstance->id . '_included';
// Course level setting inclusion.
$setting = new backup_block_opencast_setting(
$includesettingname,
base_setting::IS_BOOLEAN,
$defaultimportvalue
);
$setting->get_ui()->set_label(get_string('backupopencastvideos', 'block_opencast', $ocinstance->name));

foreach ($seriestobackup as $series) {
$result = $apibridge->get_series_videos($series->series);
$seriesobj = $apibridge->get_series_by_identifier($series->series, false);

if (empty($seriesobj)) {
continue;
}

$result = $apibridge->get_series_videos($seriesobj->identifier);

$videostobackup = [];
foreach ($result->videos as $video) {
Expand All @@ -73,12 +98,72 @@ protected function define_my_settings() {
}

if (count($videostobackup) > 0) {
$setting = new backup_block_opencast_setting('opencast_videos_include_' . $ocinstance->id,
base_setting::IS_BOOLEAN, boolval($defaultimportvalue));
$setting->get_ui()->set_label(get_string('backupopencastvideos', 'block_opencast', $ocinstance->name));
$this->add_setting($setting);
$this->plan->get_setting('blocks')->add_dependency($setting);
break;
// Here we make sure that the main inclusion happens only once.
if (!$ocinstanceisincluded) {
$this->add_setting($setting);
$this->plan->get_setting('blocks')->add_dependency($setting);
$ocinstanceisincluded = true;
}
// Section Level setting for series.
$seriessettingname =
'opencast_videos_' . $ocinstance->id . '_series_' . $seriesobj->identifier . '_included';
$seriessetting = new backup_block_opencast_setting(
$seriessettingname,
base_setting::IS_BOOLEAN,
$defaultimportvalue,
backup_block_opencast_setting::SECTION_LEVEL
);
$stringobj = new \stdClass();
$stringobj->title = $seriesobj->title;
// To avoid cluttered ui and ugly display, we present only the last 6 digit of the id.
$stringobj->identifier = '***' . substr($seriesobj->identifier, -6);
$seriessettinglabel = get_string('importvideos_wizard_series_cb_title', 'block_opencast', $stringobj);
// Adding the help button to emphasize that in ACL Change only series selection is possible.
if ($importmode === 'acl') {
$seriessetting->set_help(
'importvideos_wizard_unselectableeventreason',
'block_opencast'
);
$videolist = [];
foreach ($videostobackup as $videotobackup) {
// To avoid cluttered ui and ugly display, we present only the last 6 digit of the id.
$stringobj = new \stdClass();
$stringobj->title = $videotobackup->title;
$stringobj->identifier = '***' . substr($videotobackup->identifier, -6);
$videolist[] = "- " . get_string('importvideos_wizard_event_cb_title',
'block_opencast', $stringobj);
}
// The label does not support any html, so we need to use the text for line breaks.
$seriessetting->get_ui()->set_text(join('<br>', $videolist));
}
$seriessetting->get_ui()->set_label($seriessettinglabel);

$this->add_setting($seriessetting);
$this->get_setting($includesettingname)->add_dependency($seriessetting,
setting_dependency::DISABLED_NOT_CHECKED);

if ($importmode !== 'acl') {
foreach ($videostobackup as $bkvideo) {
// Activity level settings for episodes.
$episodesetting = new backup_block_opencast_setting(
'opencast_videos_' . $ocinstance->id . '_episode_' . $bkvideo->identifier . '_included',
base_setting::IS_BOOLEAN,
$defaultimportvalue,
backup_block_opencast_setting::ACTIVITY_LEVEL,
backup_block_opencast_setting::VISIBLE,
);
$stringobj = new \stdClass();
$stringobj->title = $bkvideo->title;
// To avoid cluttered ui and ugly display, we present only the last 6 digit of the id.
$stringobj->identifier = '***' . substr($bkvideo->identifier, -6);
$episodesetting->get_ui()->set_label(
get_string('importvideos_wizard_event_cb_title', 'block_opencast', $stringobj)
);
$this->add_setting($episodesetting);
$this->get_setting($seriessettingname)->add_dependency($episodesetting,
setting_dependency::DISABLED_NOT_CHECKED);
}
}
}
}
}
Expand All @@ -90,14 +175,49 @@ protected function define_my_settings() {
*/
protected function define_my_steps() {
$ocinstances = settings_api::get_ocinstances();
$courseid = $this->get_courseid();
foreach ($ocinstances as $ocinstance) {
if (!$this->setting_exists('opencast_videos_include_' . $ocinstance->id)) {
$importmode = get_config('block_opencast', 'importmode_' . $ocinstance->id);
$includesettingname = 'opencast_videos_' . $ocinstance->id . '_included';
// Checking the main level inclusion.
if (!$this->setting_exists($includesettingname)) {
continue;
}

if ($this->get_setting_value('opencast_videos_include_' . $ocinstance->id)) {
$this->add_step(new backup_opencast_block_structure_step('opencast_structure_' . $ocinstance->id,
'opencast_' . $ocinstance->id . '.xml'));
// If the main level is included.
if ($this->get_setting_value($includesettingname)) {
// Get API Bridge to get data.
$apibridge = apibridge::get_instance($ocinstance->id);
$backupstructuredata = [];

// Get course series to loop through and verify.
$seriestobackup = $apibridge->get_course_series($courseid);
foreach ($seriestobackup as $series) {
// Checking the series inclusion.
$seriessettingname =
'opencast_videos_' . $ocinstance->id . '_series_' . $series->series . '_included';
if (!$this->setting_exists($seriessettingname) || empty($this->get_setting_value($seriessettingname))) {
continue;
}

// Get the series video to lopp through and check the inclusion.
$result = $apibridge->get_series_videos($series->series);
foreach ($result->videos as $video) {
// Checking the episode inclusion.
$episodesettingname = 'opencast_videos_' . $ocinstance->id . '_episode_' . $video->identifier . '_included';
if ($importmode === 'acl' || $this->setting_exists($episodesettingname) &&
$this->get_setting_value($episodesettingname)) {
// We store the episode of series in backupstructuredata.
$backupstructuredata[$series->series][] = $video->identifier;
}
}
}

// Pass the collected backup data into the step.
$backupstep = new backup_opencast_block_structure_step('opencast_structure_' . $ocinstance->id,
'opencast_' . $ocinstance->id . '.xml');
$backupstep->set_data($backupstructuredata);
$this->add_step($backupstep);
}
}
}
Expand Down
53 changes: 51 additions & 2 deletions backup/moodle2/backup_opencast_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
* @package block_opencast
* @copyright 2018 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @author Farbod Zamani Boroujeni (2024)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -36,6 +38,8 @@
*
* @package block_opencast
* @copyright 2018 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @author Farbod Zamani Boroujeni (2024)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_opencast_block_structure_step extends backup_block_structure_step {
Expand All @@ -47,9 +51,48 @@ class backup_opencast_block_structure_step extends backup_block_structure_step {
* @throws base_step_exception
* @throws dml_exception
*/

/** @var array data The information about backup structure */
private $data = [];

/**
* Returns data.
* @return array data
*/
public function get_data() {
return $this->data;
}

/**
* Sets data.
* @see backup_opencast_block_task::define_my_steps() Usage.
* @param array $data the information about backup structure.
*/
public function set_data($data) {
$this->data = $data;
}

/**
* Defines the structure of the block backup.
*
* @return backup_nested_element
*/
protected function define_structure() {

// Extracting ocinstanceid from the structure.
$ocinstanceid = intval(ltrim($this->get_name(), "opencast_structure_"));

// Extracting selected series and events from the data structure.
$selectedseriestobackup = [];
$selectedvideostobackup = [];
if (!empty($this->data)) {
foreach ($this->data as $seriesid => $eventslist) {
if (!empty($eventslist)) {
$selectedseriestobackup[] = $seriesid;
$selectedvideostobackup = array_merge($eventslist, $selectedvideostobackup);
}
}
}
// Root.
$opencast = new backup_nested_element('opencast');

Expand Down Expand Up @@ -79,7 +122,10 @@ protected function define_structure() {
$list = [];
// Add course videos.
foreach ($coursevideos as $video) {
$list[] = (object)['eventid' => $video->identifier];
// Check if they are selected.
if (in_array($video->identifier, $selectedvideostobackup)) {
$list[] = (object)['eventid' => $video->identifier];
}
}

// Define sources.
Expand All @@ -96,7 +142,10 @@ protected function define_structure() {

$list = [];
foreach ($courseseries as $series) {
$list[] = (object)['seriesid' => $series->series];
// Check if it is selected.
if (in_array($series->series, $selectedseriestobackup)) {
$list[] = (object)['seriesid' => $series->series];
}
}
$serieselement->set_source_array($list);

Expand Down
25 changes: 21 additions & 4 deletions backup/moodle2/restore_opencast_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* @package block_opencast
* @copyright 2018 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -34,6 +35,11 @@

/**
* Define settings of the restore tasks for the opencast block.
*
* @package block_opencast
* @copyright 2018 Andreas Wagner, SYNERGY LEARNING
* @author Andreas Wagner
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_opencast_block_task extends restore_block_task {

Expand Down Expand Up @@ -84,8 +90,18 @@ protected function define_my_settings() {
$canrestore = $this->can_restore_events($ocinstance->id);
$locktype = ($canrestore) ? backup_setting::NOT_LOCKED : backup_setting::LOCKED_BY_CONFIG;

$setting = new restore_block_opencast_setting('opencast_videos_include_' . $ocinstance->id, base_setting::IS_BOOLEAN,
$canrestore, backup_setting::VISIBLE, $locktype);
// NOTE: At the moment we don't offer any selection here,
// because it is a job that needs to be done in backup step more efficiently.

$settingname = 'opencast_videos_' . $ocinstance->id . '_included';
$setting = new restore_block_opencast_setting(
$settingname,
base_setting::IS_BOOLEAN,
$canrestore,
restore_block_opencast_setting::COURSE_LEVEL,
backup_setting::VISIBLE,
$locktype
);
$setting->get_ui()->set_label(get_string('restoreopencastvideos', 'block_opencast', $ocinstance->name));

$this->add_setting($setting);
Expand All @@ -103,12 +119,13 @@ protected function define_my_steps() {
}

foreach ($ocinstances as $ocinstance) {
$settingname = 'opencast_videos_' . $ocinstance->id . '_included';
// Settings, does not exists, if opencast system does not support copying workflow.
if (!$this->setting_exists('opencast_videos_include_' . $ocinstance->id)) {
if (!$this->setting_exists($settingname)) {
continue;
}

if (!$this->get_setting_value('opencast_videos_include_' . $ocinstance->id) &&
if (!$this->get_setting_value($settingname) &&
($this->plan->get_mode() != backup::MODE_IMPORT)) {
continue;
}
Expand Down
Loading

0 comments on commit a1cae03

Please sign in to comment.