Skip to content

Commit

Permalink
add paging to series overview
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamara Gunkel committed Mar 17, 2022
1 parent dea080f commit 77e0c45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 12 additions & 0 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,10 @@ public function has_owner($acls) {
* @throws \dml_exception
*/
private function get_owner_role_for_user($userid, $courseid) {
if (empty(get_config('block_opencast', 'aclownerrole_' . $this->ocinstanceid))) {
return null;
}

$roles = json_decode(get_config('block_opencast', 'roles_' . $this->ocinstanceid));
$ownerrole = array_search(get_config('block_opencast', 'aclownerrole_' . $this->ocinstanceid),
array_column($roles, 'rolename'));
Expand All @@ -2179,6 +2183,9 @@ public function get_series_owned_by($userid) {
$resource = '/api/series?withacl=1&onlyWithWriteAccess=1';
// Course id should not be used in owner role, so we can use the site id.
$ownerrole = self::get_owner_role_for_user($userid, $SITE->id);
if (!$ownerrole) {
return array();
}

$response = $api->oc_get($resource, array($ownerrole));
if ($api->get_http_code() == 200) {
Expand Down Expand Up @@ -2206,6 +2213,11 @@ public function get_videos_owned_by($userid) {
$result = new \stdClass();
$result->videos = array();
$result->error = 0;

if (!$ownerrole) {
return $result;
}

$response = $api->oc_get($resource, array($ownerrole));

if ($api->get_http_code() == 200) {
Expand Down
23 changes: 13 additions & 10 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
global $PAGE, $OUTPUT, $CFG, $DB, $USER, $SITE;

$ocinstanceid = optional_param('ocinstanceid', \tool_opencast\local\settings_api::get_default_ocinstance()->id, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 20, PARAM_INT);

$baseurl = new moodle_url('/blocks/opencast/overview.php', array('ocinstanceid' => $ocinstanceid));
$PAGE->set_url($baseurl);
Expand Down Expand Up @@ -73,7 +75,7 @@

// Add series that are owned by the user.
$ownedseries = $apibridge->get_series_owned_by($USER->id);
$myseries = array_unique(array_merge($myseries, $ownedseries));
$myseries = array_values(array_unique(array_merge($myseries, $ownedseries)));

// Build course table.
$columns = array('owner', 'series', 'linked', 'activities', 'videos');
Expand All @@ -90,17 +92,17 @@
$showchangeownerlink = has_capability('block/opencast:viewusers', context_system::instance()) &&
!empty(get_config('block_opencast', 'aclownerrole_' . $ocinstanceid));

foreach ($myseries as $seriesid) {
for ($i = $page * $perpage; $i < min(($page + 1) * $perpage, count($myseries)); $i++) {
$row = array();

// Try to retrieve name from opencast.
$ocseries = $apibridge->get_series_by_identifier($seriesid, true);
$ocseries = $apibridge->get_series_by_identifier($myseries[$i], true);

// Check if current user is owner of the series.
if (in_array($seriesid, $ownedseries) || ($ocseries && !$apibridge->has_owner($ocseries->acl))) {
if (in_array($myseries[$i], $ownedseries) || ($ocseries && !$apibridge->has_owner($ocseries->acl))) {
if ($showchangeownerlink) {
$row[] = html_writer::link(new moodle_url('/blocks/opencast/changeowner.php',
array('ocinstanceid' => $ocinstanceid, 'identifier' => $seriesid, 'isseries' => true)),
array('ocinstanceid' => $ocinstanceid, 'identifier' => $myseries[$i], 'isseries' => true)),
$OUTPUT->pix_icon('i/user', get_string('changeowner', 'block_opencast')));
} else {
$row[] = $OUTPUT->pix_icon('i/user', get_string('changeowner', 'block_opencast'));
Expand All @@ -114,16 +116,16 @@
$row[] = $ocseries->title;
} else {
// If that fails use id.
$row[] = $seriesid;
$row[] = $myseries[$i];
}

$blocklinks = $DB->get_records('tool_opencast_series', array('ocinstanceid' => $ocinstanceid, 'series' => $seriesid));
$blocklinks = $DB->get_records('tool_opencast_series', array('ocinstanceid' => $ocinstanceid, 'series' => $myseries[$i]));
$blocklinks = array_column($blocklinks, 'courseid');

$activitylinks = array();
if ($activityinstalled) {
$activitylinks = $DB->get_records('opencast', array('ocinstanceid' => $ocinstanceid,
'opencastid' => $seriesid, 'type' => opencasttype::SERIES));
'opencastid' => $myseries[$i], 'type' => opencasttype::SERIES));
$activitylinks = array_column($activitylinks, 'course');
}

Expand All @@ -147,7 +149,7 @@

if (in_array($course, $activitylinks)) {
// Get activity.
$moduleid = \block_opencast\local\activitymodulemanager::get_module_for_series($ocinstanceid, $mc->id, $seriesid);
$moduleid = \block_opencast\local\activitymodulemanager::get_module_for_series($ocinstanceid, $mc->id, $myseries[$i]);

$rowactivities[] = html_writer::link(new moodle_url('/mod/opencast/view.php', array('id' => $moduleid)),
$mc->fullname);
Expand All @@ -157,13 +159,14 @@
$row[] = join("<br>", $rowblocks);
$row[] = join("<br>", $rowactivities);
$row[] = html_writer::link(new moodle_url('/blocks/opencast/overview_videos.php',
array('ocinstanceid' => $ocinstanceid, 'series' => $seriesid)),
array('ocinstanceid' => $ocinstanceid, 'series' => $myseries[$i])),
$OUTPUT->pix_icon('i/messagecontentvideo', get_string('showvideos', 'block_opencast')));

$table->add_data($row);
}

$table->finish_html();
echo $OUTPUT->paging_bar(count($myseries), $page, $perpage, $baseurl);

// Show videos that the user owns but are not included in any of the series he has access to.
$ownedvideos = $apibridge->get_videos_owned_by($USER->id);
Expand Down

0 comments on commit 77e0c45

Please sign in to comment.