Skip to content

Commit

Permalink
Add possibility to sort videos by title
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Oct 9, 2023
1 parent a8f407a commit 4acf39e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 10 deletions.
10 changes: 8 additions & 2 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ public static function get_instance($ocinstanceid, $forcenewinstance = false) {
* @param string $seriesid
* @return false|mixed
*/
public function get_episodes_in_series($seriesid) {
public function get_episodes_in_series($seriesid, int|null $sortseriesby = null) {

$sortstring = 'start_date:DESC,title:ASC';
if ($sortseriesby == 1) {
$sortstring = 'title:ASC,start_date:DESC';
}

$api = new api($this->ocinstanceid);
$resource = "/api/events?filter=is_part_of:$seriesid&withpublications=true&sort=start_date:DESC,title:ASC&sign=true";
$resource = "/api/events?filter=is_part_of:$seriesid&withpublications=true&sort=$sortstring&sign=true";
$response = $api->oc_get($resource);

if ($api->get_http_code() != 200) {
Expand Down
13 changes: 8 additions & 5 deletions classes/local/output_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ class output_helper {

/**
* Prints output for series view.
* @param int $ocinstanceid Opencast instance id
* @param string $seriesid opencast id of series.
* @param string $activityname name of Activity.
* @param stdClass $moduleinstance
* @throws \coding_exception
*/
public static function output_series($ocinstanceid, $seriesid, $activityname): void {
public static function output_series(stdClass $moduleinstance): void {
global $OUTPUT, $PAGE;

$ocinstanceid = $moduleinstance->ocinstanceid;
$seriesid = $moduleinstance->opencastid;
$activityname = $moduleinstance->name;
$sortseriesby = $moduleinstance->sortseriesby;

$api = apibridge::get_instance($ocinstanceid);
$response = $api->get_episodes_in_series($seriesid);
$response = $api->get_episodes_in_series($seriesid, $sortseriesby);

if ($response === false) {
throw new \exception('There was a problem reaching opencast!');
Expand Down
3 changes: 2 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/opencast/db" VERSION="20230523" COMMENT="XMLDB file for Moodle mod_opencast"
<XMLDB PATH="mod/opencast/db" VERSION="20231009" COMMENT="XMLDB file for Moodle mod_opencast"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -19,6 +19,7 @@
<FIELD NAME="type" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The type of instance. See opencasttype"/>
<FIELD NAME="ocinstanceid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="allowdownload" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="sortseriesby" TYPE="int" LENGTH="2" NOTNULL="false" SEQUENCE="false" COMMENT="1 = title, 0 / null = upload date."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,20 @@ function xmldb_opencast_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2023052300, 'opencast');
}

if ($oldversion < 2023100900) {

// Define field sortseriesby to be added to opencast.
$table = new xmldb_table('opencast');
$field = new xmldb_field('sortseriesby', XMLDB_TYPE_INTEGER, '2', null, null, null, null, 'allowdownload');

// Conditionally launch add field sortseriesby.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Opencast savepoint reached.
upgrade_mod_savepoint(true, 2023100900, 'opencast');
}

return true;
}
7 changes: 7 additions & 0 deletions lang/en/opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@
$string['uploadinprogress'] = 'Uploading video ({$a}) is in progress, please try again later.';
$string['uploadedvideoisbeingprocesses'] = 'This video ({$a}) is already uploaded and is being processed by Opencast, please wait!';
$string['uploadjobmissing'] = 'There was an error fetching upload data for this video, please try uploading a new one. Due to insufficient data this module is deleted.';

// Strings for mod form.
$string['sortseriesby'] = 'Order videos by';
$string['sortseriesby_help'] = 'Only affects series';
$string['uploaddate'] = 'Upload date';
$string['videotitle'] = 'Video title';
$string['advancedsettings'] = 'Advanced settings';
8 changes: 8 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public function definition() {
$mform->setType('allowdownload', PARAM_INT);
$mform->setDefault('allowdownload', get_config('mod_opencast', 'download_default_' . $ocinstanceid));
}

$mform->addElement('header', 'advancedsettings', get_string('advancedsettings', 'mod_opencast'));

$mform->addElement('select', 'sortseriesby', get_string('sortseriesby', 'mod_opencast'), [
0 => get_string('uploaddate', 'mod_opencast'),
1 => get_string('videotitle', 'mod_opencast')
]);
$mform->addHelpButton('sortseriesby', 'sortseriesby', 'mod_opencast');
}

$mform->addElement('hidden', 'type');
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$plugin->component = 'mod_opencast';
$plugin->release = 'development-version';
$plugin->version = 2023052300;
$plugin->version = 2023100900;
$plugin->requires = 2020061500; // Requires Moodle 3.9+.
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = array(
Expand Down
2 changes: 1 addition & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
if ($episode) {
output_helper::output_episode($moduleinstance->ocinstanceid, $episode, $moduleinstance->id, $moduleinstance->opencastid);
} else {
output_helper::output_series($moduleinstance->ocinstanceid, $moduleinstance->opencastid, $moduleinstance->name);
output_helper::output_series($moduleinstance);
}
} else if ($moduleinstance->type == opencasttype::UPLOAD) {
// Redirect to the upload video page in the mod_opencast by default.
Expand Down

0 comments on commit 4acf39e

Please sign in to comment.