Example #1
0
 /**
  * Writes timestamped data into log file
  *
  * @param string $data data to be written
  */
 static function write($data)
 {
     global $CFG;
     if (!mod_opencast_series::getValueForKey('logging_enabled')) {
         return;
     }
     $logdir = $CFG->dataroot . '/mod/opencast';
     if (!file_exists($logdir)) {
         mkdir($logdir, 0755, true);
     }
     $logfile = $logdir . '/opencast_api.log';
     if (!is_writable($logdir)) {
         print_error('nologfilewrite', 'opencast', null, $logfile);
     }
     $date = date("Y-m-d H:i:s (T)");
     $logged = error_log($date . "\n" . $data . "\n\n", 3, $logfile);
     if (!$logged) {
         print_error('nologfilewrite', 'opencast', null, $logfile);
     }
 }
Example #2
0
 /**
  * Displays a list of a user's pending and uploaded clips
  *
  * @param bool $show_uploaded
  * @param bool $show_pending
  * @param bool $allusers
  * @param bool $with_uploader display clip uploader
  * @param bool $with_owner    display clip owner
  */
 function display_user_pending_clips($show_uploaded = true, $show_pending = true, $allusers = false, $with_uploader = false, $with_owner = true)
 {
     global $DB, $opencast, $USER, $context;
     $isproducer = has_capability('mod/opencast:isproducer', $context);
     if ($allusers && $isproducer) {
         // display for all users
         $uploaded_title = 'uploadedclips';
         $pending_title = 'pendingclips';
         $records = $DB->get_records('opencast_uploadedclip', ['opencastid' => $opencast->id]);
     } else {
         // display for current user
         $uploaded_title = 'myuploadedclips';
         $pending_title = 'mypendingclips';
         $records = $DB->get_records('opencast_uploadedclip', ['userid' => $USER->id, 'opencastid' => $opencast->id]);
     }
     $sc_obj = new mod_opencast_series();
     $sc_obj->fetch($opencast->id);
     $pending = [];
     $uploaded = [];
     foreach ($records as $record) {
         if ($record->status == OPENCAST_CLIP_READY) {
             // encoding finished
             $uploaded[] = $record;
         } else {
             if ($record->status == OPENCAST_CLIP_UPLOADED) {
                 // encoding in progress
                 $pending[] = $record;
             }
         }
     }
     // display clips uploaded by this user:
     if ($show_uploaded && count($uploaded)) {
         echo html_writer::tag('h3', get_string($uploaded_title, 'opencast', count($uploaded)));
         echo html_writer::start_tag('table', ['class' => 'opencast-clips']);
         $this->display_singleclip_table_header(false, $with_owner, $with_uploader, false);
         foreach ($uploaded as $uploaded_record) {
             $sc_clip = new mod_opencast_event($sc_obj, $uploaded_record->ext_id, null, $uploaded_record->opencastid);
             $this->display_clip_outline($sc_clip, false, false, null, $with_owner, $with_uploader, false, false);
         }
         echo html_writer::end_tag('table');
     }
     // display this user's pending clips (uploaded but not yet available):
     if ($show_pending && count($pending)) {
         echo html_writer::tag('h3', get_string($pending_title, 'opencast', count($pending)));
         echo html_writer::start_tag('table', ['class' => 'opencast-clips']);
         $this->display_singleclip_table_header(false, $with_owner, $with_uploader, false);
         foreach ($pending as $pending_record) {
             try {
                 $sc_clip = new mod_opencast_event($sc_obj, $pending_record->ext_id, null, $pending_record->opencastid);
             } catch (Exception $e) {
                 if ($e->errorcode == 'api_404' && $e->module == 'opencast') {
                     $DB->delete_records('opencast_uploadedclip', ['id' => $pending_record->id]);
                 }
                 continue;
             }
             $this->display_clip_outline($sc_clip, false, false, null, $with_owner, $with_uploader, false, false);
         }
         echo html_writer::end_tag('table');
     }
     if ($allusers && !count($records)) {
         echo html_writer::tag('p', get_string('nouploadedclips', 'opencast'));
     }
 }
Example #3
0
/**
 * Version information
 *
 * @package    mod
 * @subpackage opencast
 * @copyright  2013-2015 Université de Lausanne
 * @author     Nicolas Dunand <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
    $settings->add(new admin_setting_heading('opencast/operationsettings', get_string('operationsettings', 'opencast'), ''));
    $settings->add(new admin_setting_configtext('opencast/moreinfo_url', get_string('moreinfo_url', 'opencast'), get_string('moreinfo_url_desc', 'opencast'), '', PARAM_URL, 50));
    $settings->add(new admin_setting_configcheckbox('opencast/display_select_columns', get_string('display_select_columns', 'opencast'), get_string('display_select_columns_desc', 'opencast', $CFG->dataroot), '0'));
    $settings->add(new admin_setting_configcheckbox('opencast/allow_userupload', get_string('allow_userupload', 'opencast'), get_string('allow_userupload_desc', 'opencast'), '0'));
    $settings->add(new admin_setting_configselect('opencast/userupload_maxfilesize', get_string('userupload_maxfilesize', 'opencast'), get_string('userupload_maxfilesize_desc', 'opencast'), 10 * 1024 * 1024, mod_opencast_series::getMaxfilesizes()));
    $settings->add(new admin_setting_configtext('opencast/uploadfile_extensions', get_string('uploadfile_extensions', 'opencast'), get_string('uploadfile_extensions_desc', 'opencast'), 'mov, mp4, m4v, avi, mpg, mpe, mpeg, mts, vob, flv, mkv, dv, mp3, aac, wav, wma, wmv, divx', PARAM_RAW, 50));
    $settings->add(new admin_setting_heading('opencast/adminsettings', get_string('adminsettings', 'opencast'), ''));
    $settings->add(new admin_setting_configtext('opencast/switch_api_host', get_string('switch_api_host', 'opencast'), get_string('switch_api_host_desc', 'opencast'), 'https://api.cast.switch.ch/api/v2', PARAM_URL, 50));
    $settings->add(new admin_setting_configtext('opencast/switch_api_username', get_string('switch_api_username', 'opencast'), get_string('switch_api_username_desc', 'opencast'), '', PARAM_RAW));
    $settings->add(new admin_setting_configpasswordunmask('opencast/switch_api_password', get_string('switch_api_password', 'opencast'), get_string('switch_api_password_desc', 'opencast'), '', PARAM_RAW_TRIMMED));
    $settings->add(new admin_setting_configtext('opencast/switch_admin_host', get_string('switch_admin_host', 'opencast'), get_string('switch_admin_host_desc', 'opencast'), 'https://cast.switch.ch/', PARAM_URL, 50));
    $settings->add(new admin_setting_configtext('opencast/import_workflow', get_string('import_workflow', 'opencast'), '', 'switchcast-import-api-1.0', PARAM_RAW_TRIMMED, 50));
    $settings->add(new admin_setting_configtext('opencast/pubchannel_videoplayer', get_string('pubchannel_videoplayer', 'opencast'), '', 'switchcast-player', PARAM_RAW_TRIMMED, 50));
    $settings->add(new admin_setting_configtext('opencast/pubchannel_download', get_string('pubchannel_download', 'opencast'), '', 'switchcast-api', PARAM_RAW_TRIMMED, 50));
    $settings->add(new admin_setting_configtext('opencast/pubchannel_annotate', get_string('pubchannel_annotate', 'opencast'), '', 'switchcast-annotate', PARAM_RAW_TRIMMED, 50));
    $settings->add(new admin_setting_configtext('opencast/thumbnail_flavors', get_string('thumbnail_flavors', 'opencast'), '', 'presenter/search+preview, presentation/search+preview', PARAM_RAW_TRIMMED, 50));
    $settings->add(new admin_setting_configtext('opencast/local_cache_time', get_string('local_cache_time', 'opencast'), get_string('local_cache_time_desc', 'opencast'), '1200', PARAM_INT));
    $settings->add(new admin_setting_configcheckbox('opencast/logging_enabled', get_string('logging_enabled', 'opencast'), get_string('logging_enabled_desc', 'opencast', $CFG->dataroot), '0'));
    $settings->add(new admin_setting_configtext('opencast/uid_field', get_string('uid_field', 'opencast'), get_string('uid_field_desc', 'opencast'), 'username', PARAM_RAW));
    $settings->add(new admin_setting_configtext('opencast/curl_proxy', get_string('curl_proxy', 'opencast'), get_string('curl_proxy_desc', 'opencast'), '', PARAM_URL, 50));
Example #4
0
/**
 * mod_opencast cron
 *
 * @return true
 */
function opencast_cron()
{
    mtrace('mod_opencast: processing uploaded clips');
    mod_opencast_series::processUploadedClips();
    return true;
}
Example #5
0
 /**
  * Updates event metadata at SWITCHCast server
  *
  * @return bool true if succesful
  */
 public function update()
 {
     // TODO WAIT FOR SWITCH : can not send empty strings (to remove e.g. description), see my e-mail to switch-api on 20150703
     // first, update clip metadata
     $event_metadata = ['metadata' => json_encode([['id' => 'title', 'value' => $this->getTitle()], ['id' => 'isPartOf', 'value' => $this->series->getExtId()], ['id' => 'description', 'value' => $this->getSubtitle()], ['id' => 'location', 'value' => $this->getLocation()], ['id' => 'creator', 'value' => explode(',', $this->getPresenter())]], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)];
     mod_opencast_apicall::sendRequest('/events/' . $this->getExtId() . '/metadata?type=dublincore/episode', 'PUT', $event_metadata);
     // second, update ACLs with (possibly) new owner :
     // 1.- get current ACLs
     $event_acls = mod_opencast_apicall::sendRequest('/events/' . $this->getExtId() . '/acl', 'GET', null, false, true, null, false, true);
     // 2.- delete any ACL that is not the system_user
     $new_acls = [];
     while ($acl = array_pop($event_acls)) {
         if (preg_match('/^ROLE\\_AAI\\_USER\\_([^\\_]+)$/', $acl->role, $matches) && $matches[1] != mod_opencast_series::getValueForKey('default_sysaccount')) {
             // drop ACL (i.e. do nothing)
         } else {
             // user is either OpenCast internal, or system_user -> keep ACL
             $new_acls[] = $acl;
         }
     }
     // 3.- add specified owner
     $new_acls[] = ['action' => 'write', 'allow' => true, 'role' => 'ROLE_AAI_USER_' . $this->getOwner()];
     if ($this->series->getIvt()) {
         $new_acls[] = ['action' => 'write', 'allow' => true, 'role' => 'ROLE_USER_IVT_AAI_' . $this->getOwner()];
     }
     $data = ['acl' => json_encode($new_acls, JSON_UNESCAPED_SLASHES)];
     mod_opencast_apicall::sendRequest('/events/' . $this->getExtId() . '/acl', 'PUT', $data);
     return true;
 }
Example #6
0
$url = new moodle_url('/mod/opencast/uploads.php', ['id' => $id]);
$return_channel = new moodle_url('/mod/opencast/view.php', ['id' => $id]);
$PAGE->set_url($url);
if (!($cm = get_coursemodule_from_id('opencast', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record('course', ['id' => $cm->course]))) {
    print_error('coursemisconf');
}
$return_course = new moodle_url('/course/view.php', ['id' => $course->id]);
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
if (!has_capability('mod/opencast:isproducer', $context)) {
    print_error('feature_forbidden', 'opencast', $return_channel);
}
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id);
// Display
$PAGE->set_title(format_string($opencast->name));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
$renderer = $PAGE->get_renderer('mod_opencast');
echo html_writer::tag('h2', get_string('uploaded_clips', 'opencast'));
$renderer->display_user_pending_clips(true, true, true, true, $sc_obj->getIvt());
echo html_writer::link($return_channel, get_string('back_to_channel', 'opencast'));
echo $OUTPUT->footer();
Example #7
0
 /**
  * @param string $url
  *
  * @return mixed
  */
 static function hashfilename($url = '')
 {
     $f = str_replace(mod_opencast_series::getValueForKey('switch_api_host'), '', $url);
     $f = str_replace(mod_opencast_series::getValueForKey('default_sysaccount'), '', $f);
     $f = preg_replace('/[^a-zA-Z0-9]/', '_', $f);
     $f = preg_replace('/^(_)+/', '', $f);
     //        return sha1($f);
     return $f;
 }
Example #8
0
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $scuser = new mod_opencast_user();
     if ($data['channelnew'] == OPENCAST_CHANNEL_NEW) {
         if ($scuser->getExternalAccount() == '') {
             $errors['channelnew'] = get_string('user_notaai', 'opencast');
         }
         if (!$data['newchannelname']) {
             $errors['newchannelname'] = get_string('required');
         }
     }
     if ($data['channelnew'] == OPENCAST_CHANNEL_EXISTING) {
         // make sure we can be external_authority for this channel
         $scobj = new mod_opencast_series();
         $ext_id = isset($data['ext_id']) ? $data['ext_id'] : $this->current->ext_id;
         $scobj->setExtId($ext_id);
         $sysaccount_extid = mod_opencast_series::getSysAccountOfUser();
         // we must explicitly set $USER as a producer in $scobj or we won't be allowed to add his system_user
         $scobj->setOrganizationDomain(mod_opencast_series::getOrganizationByEmail($sysaccount_extid));
         $scobj->setProducer($scuser->getExternalAccount());
         // first, add SysAccount as producer (using $USER account), so we can use SysAccount later to make API calls
         //            $scobj->addProducer($sysaccount_extid, false);
         $channelid = empty($this->_instance) ? $ext_id : $this->current->id;
         // if there already is one instance we must refer to it by its Moodle ID otherwise there could
         // be several records!
         $thechannel = $scobj->fetch($channelid, !empty($this->_instance), true);
     } else {
         if ($data['groupmode'] != NOGROUPS && !$data['is_ivt']) {
             $errors['groupmode'] = get_string('nogroups_withoutivt', 'opencast');
         }
     }
     return $errors;
 }
if (!($cm = get_coursemodule_from_id('opencast', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record("course", ["id" => $cm->course]))) {
    print_error('coursemisconf');
}
$return_course = new moodle_url('/course/view.php', ['id' => $course->id]);
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
$allclips = [];
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id, true);
$sc_user = new mod_opencast_user();
$arr_filter = [];
$filters = explode('&', urldecode($filterstr));
foreach ($filters as $filter) {
    $parts = explode('=', $filter);
    if (count($parts) == 2) {
        $arr_filter[$parts[0]] = $parts[1];
    }
}
$xml_clips = $sc_obj->getEvents($arr_filter);
$xml_clips_access_allowed = $sc_obj->checkAccess($xml_clips);
$clips = [];
foreach ($xml_clips_access_allowed as $xml_clip) {
    $clips[] = (array) $xml_clip;
Example #10
0
 /**
  * @return array
  * @throws coding_exception
  */
 public static function processUploadedClips()
 {
     global $CFG, $DB;
     $admin = get_admin();
     $opencasts = $DB->get_records('opencast');
     // first, some maintenance: delete stale records (e.g. if an error occured at SCast)
     $staletime = time() - OPENCAST_STALE_PERIOD;
     $stale_records = $DB->get_records_select('opencast_uploadedclip', 'status = ' . OPENCAST_CLIP_UPLOADED . ' AND timestamp < ' . $staletime);
     foreach ($stale_records as $stale_record) {
         $user_stale = $DB->get_record('user', ['id' => $stale_record->userid]);
         if ($user_stale) {
             // notify uploader
             $a_s = new stdClass();
             $a_s->filename = $stale_record->filename;
             $cm_s = get_coursemodule_from_instance('opencast', $stale_record->opencastid);
             $a_s->link = $CFG->wwwroot . '/mod/opencast/view.php?id=' . $cm_s->id;
             email_to_user($user_stale, $admin, get_string('clipstale_subject', 'opencast'), get_string('clipstale_body', 'opencast', $a_s));
             // notify admin too
             $a_s->userlink = $CFG->wwwroot . '/user/profile.php?id=' . $user_stale->id;
             $a_s->userfullname = fullname($user_stale);
             email_to_user($admin, $admin, get_string('clipstale_subject_admin', 'opencast'), get_string('clipstale_body_admin', 'opencast', $a_s));
         }
     }
     $DB->delete_records_select('opencast_uploadedclip', 'status = ' . OPENCAST_CLIP_UPLOADED . ' AND timestamp < ' . $staletime);
     // now, let's deal with the remaining ones, checking one by one if they have been processed
     $pending = [];
     $uploaded = [];
     foreach ($opencasts as $opencast) {
         $uploaded_videos = $DB->get_records('opencast_uploadedclip', ['opencastid' => $opencast->id]);
         if (!$uploaded_videos) {
             continue;
         }
         $series = new mod_opencast_series();
         try {
             // try and fetch the series on the back-end BUT do not halt on error
             $fetch_result = $series->fetch($opencast->id, true, true, false);
             if ($fetch_result == false) {
                 throw new moodle_exception('api_404', 'opencast');
             }
         } catch (Exception $e) {
             // error with this channel: do not halt because we might be processing other jobs (unattended)
             if ($e->errorcode === 'channel_not_found') {
                 // TODO figure out the errorcode for the new API
                 // channel not existing anymore: stop looking for it ever again
                 $opencast->userupload = 0;
                 $DB->update_record('opencast', $opencast);
             }
             continue;
         }
         $series_events = $series->getEvents();
         $series_event_indentifiers = [];
         foreach ($series_events as $series_event) {
             $series_event_indentifiers[] = (string) $series_event->identifier;
         }
         foreach ($uploaded_videos as $uploaded_video) {
             if ($uploaded_video->status == OPENCAST_CLIP_READY) {
                 // encoding finished
                 if (!in_array($uploaded_video->ext_id, $series_event_indentifiers)) {
                     // clip deleted
                     $DB->delete_records('opencast_uploadedclip', ['id' => $uploaded_video->id]);
                 } else {
                     $uploaded[] = $uploaded_video->filename;
                 }
             } else {
                 if (in_array($uploaded_video->ext_id, $series_event_indentifiers)) {
                     // clip being processed: check whether it's ready
                     foreach ($series_events as $series_event) {
                         if ($series_event->identifier == $uploaded_video->ext_id) {
                             if ($series_event->processing_state == OPENCAST_PROCESSING_SUCCEEDED && count($series_event->publications)) {
                                 // it's ready!
                                 $uploaded[] = $uploaded_video->filename;
                                 $uploaded_video->status = OPENCAST_CLIP_READY;
                                 $DB->update_record('opencast_uploadedclip', $uploaded_video);
                                 $user = $DB->get_record('user', ['id' => $uploaded_video->userid]);
                                 if ($user !== false) {
                                     // notify user
                                     $a = new stdClass();
                                     $a->filename = $uploaded_video->filename;
                                     $a->cliptitle = $uploaded_video->title;
                                     $cm = get_coursemodule_from_instance('opencast', $opencast->id);
                                     $a->link = $CFG->wwwroot . '/mod/opencast/view.php?id=' . $cm->id;
                                     email_to_user($user, $admin, get_string('clipready_subject', 'opencast'), get_string('clipready_body', 'opencast', $a));
                                 }
                             }
                         }
                     }
                 } else {
                     // clip still pending
                     $pending[] = $uploaded_video->filename;
                 }
             }
         }
     }
     return [$pending, $uploaded];
 }
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record('course', ['id' => $cm->course]))) {
    print_error('coursemisconf');
}
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule');
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext');
}
if (!has_capability('mod/opencast:isproducer', $context)) {
    print_error('feature_forbidden', 'opencast', $return_channel);
}
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id);
$sc_clip = new mod_opencast_event($sc_obj, $event_identifier, false, $opencast->id);
// Perform action ?
if ($confirm === 1 && confirm_sesskey() && has_capability('mod/opencast:isproducer', $context)) {
    /*
     * $confirm
     * AND sesskey() ok
     * AND $USER has producer rights
     */
    $sc_clip->delete();
    $eventparams = ['context' => $context, 'objectid' => $opencast->id];
    $event = \mod_opencast\event\clip_deleted::create($eventparams);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('opencast', $opencast);
$PAGE->set_url($url);
if (!($cm = get_coursemodule_from_id('opencast', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record('course', ['id' => $cm->course]))) {
    print_error('coursemisconf');
}
$return_course = new moodle_url('/course/view.php', ['id' => $course->id]);
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id);
// Display
$PAGE->set_title(format_string($opencast->name));
$PAGE->set_heading($course->fullname);
$maxbytes = min(mod_opencast_series::getValueForKey('userupload_maxfilesize'), $opencast->userupload_maxfilesize);
$usercontext = context_user::instance($USER->id);
$data = new stdClass();
$data->returnurl = $return_channel;
$options = ['subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => ['video'], 'areamaxbytes' => $maxbytes];
file_prepare_standard_filemanager($data, 'files', $options, $usercontext, 'mod_opencast', 'userfiles', $id);
$mform = new mod_opencast_upload_form($url, ['data' => $data, 'options' => $options]);
if ($mform->is_cancelled()) {
    redirect($return_channel);
} else {
    if ($formdata = $mform->get_data()) {
Example #13
0
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
require_login($course);
require_capability('mod/opencast:use', $context);
$url = base64_decode($url_b64);
$salt = base64_decode($salt_b64);
$token = base64_decode($token_b64);
if ($token == sha1(mod_opencast_series::getValueForKey('default_sysaccount') . $salt . $opencast->id . $url)) {
    $eventparams = ['context' => $context, 'objectid' => $opencast->id];
    $event = \mod_opencast\event\clip_viewed::create($eventparams);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('opencast', $opencast);
    $event->trigger();
    // 1.- request signing of the URL
    $time = time();
    $validity_time_seconds = 60;
    $valid_until = $time + $validity_time_seconds;
    $signing_request_params = ['url' => $url, 'valid-until' => date('Y-m-d', $valid_until) . 'T' . gmdate('H:i:s', $valid_until) . 'Z'];
    if (mod_opencast_series::getValueForKey('use_ipaddr_restriction')) {
        $signing_request_params['valid-source'] = getremoteaddr();
    }
    $signed_url = mod_opencast_apicall::sendRequest('/security/sign', 'POST', $signing_request_params);
    // 2.- redirect to signed URL
    header("Location: " . $signed_url->url);
    exit;
}
print_error('redirfailed', 'opencast');
Example #14
0
 /**
  * Returns a Moodle user ID if one is found with the provided SWITCHaai unique ID
  *
  * @param string $ext_id SWITCHaai unique ID
  *
  * @return int Moodle user ID
  */
 public static function getMoodleUserIdFromExtId($ext_id = '')
 {
     global $DB;
     $moodleid = false;
     if ($ext_id === '') {
         return false;
     }
     $uid_field = mod_opencast_series::getValueForKey('uid_field');
     if (strpos($uid_field, '::') !== false) {
         $params = explode('::', $uid_field);
         $table = $params[0];
         $fieldid = $params[1];
         $u = $DB->get_record_select($table, $DB->sql_compare_text('data') . ' = \'' . (string) $ext_id . '\' AND fieldid = ' . (int) $fieldid, [], '*', IGNORE_MULTIPLE);
         if ($u) {
             $moodleid = $u->userid;
         }
     } else {
         $u = $DB->get_record('user', [$uid_field => (string) $ext_id]);
         if ($u) {
             $moodleid = $u->id;
         }
     }
     return (int) $moodleid;
 }
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Version information
 *
 * @package    mod
 * @subpackage opencast
 * @copyright  2013-2015 Université de Lausanne
 * @author     Nicolas.Dunand@unil.ch
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/opencast/lib.php';
$seriesExtId = required_param('ext_id', PARAM_RAW_TRIMMED);
$sc_user = new mod_opencast_user();
$url = '/series/' . $seriesExtId;
if ($sc_user->getExternalAccount() != '') {
    $runas = true;
} else {
    $runas = false;
}
$series = new mod_opencast_series();
$series->fetch($seriesExtId, false);
//$series = mod_opencast_apicall::sendRequest($url, 'GET', null, null, null, null, $runas);
$channel_details = ['title' => $series->title];
echo json_encode($channel_details);
$PAGE->requires->jquery();
if (!($cm = get_coursemodule_from_id('opencast', $id))) {
    print_error('invalidcoursemodule');
}
if (!($course = $DB->get_record('course', ['id' => $cm->course]))) {
    print_error('coursemisconf');
}
$return_course = new moodle_url('/course/view.php', ['id' => $course->id]);
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
$sc_obj = new mod_opencast_series();
$sc_obj->fetch($opencast->id);
$sc_clip = new mod_opencast_event($sc_obj, $clip_identifier, false, $opencast->id);
// Perform action ?
if (in_array($action, ['edit']) && confirm_sesskey() && has_capability('mod/opencast:isproducer', $context)) {
    /*
     * $confirm
     * AND sesskey() ok
     * AND has producer rights
     */
    if ($action === 'edit') {
        $sc_clip->setTitle(optional_param('title', $sc_clip->getTitle(), PARAM_RAW_TRIMMED));
        $sc_clip->setSubtitle(optional_param('subtitle', $sc_clip->getSubtitle(), PARAM_RAW_TRIMMED));
        $sc_clip->setPresenter(optional_param('presenter', $sc_clip->getPresenter(), PARAM_RAW_TRIMMED));
        $sc_clip->setLocation(optional_param('location', $sc_clip->getLocation(), PARAM_RAW_TRIMMED));
        if ($userid !== 0) {
Example #17
0
}
$return_course = new moodle_url('/course/view.php', ['id' => $course->id]);
require_course_login($course, false, $cm);
if (!($opencast = opencast_get_opencast($cm->instance))) {
    print_error('invalidcoursemodule', null, $return_course);
}
if (!($context = context_module::instance($cm->id))) {
    print_error('badcontext', null, $return_course);
}
if (!in_array($opencast->organization_domain, mod_opencast_series::getEnabledOrgnanizations())) {
    // TODO remove as we're now only using local org (i.e. unil.ch for us)
    //    print_error('badorganization', 'opencast', $return_course);
}
$PAGE->set_title(format_string($opencast->name));
$PAGE->set_heading($course->fullname);
/// Mark as viewed
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$eventparams = ['context' => $context, 'objectid' => $opencast->id];
$event = \mod_opencast\event\course_module_viewed::create($eventparams);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('opencast', $opencast);
$event->trigger();
$allclips = [];
echo $OUTPUT->header();
$renderer = $PAGE->get_renderer('mod_opencast');
$renderer->display_channel_content();
echo $OUTPUT->footer();
mod_opencast_series::processUploadedClips();