Пример #1
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'));
     }
 }
// 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);
Пример #3
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @param object $opencast Moodle {opencast} table DB record
 *
 * @return bool true if everything went well
 */
function opencast_update_instance($opencast)
{
    global $DB;
    $opencast->id = $opencast->instance;
    $opencast->timemodified = time();
    $scast = new mod_opencast_series();
    $scast->fetch($opencast->id);
    //$scast->setCourseId();
    //    $scast->setLicense($opencast->license);
    //    $scast->setDepartment($opencast->department);
    $scast->setAllowAnnotations($opencast->allow_annotations == OPENCAST_ANNOTATIONS);
    $scast->setIvt($opencast->is_ivt);
    if (!isset($opencast->inviting) || $opencast->is_ivt == false) {
        $opencast->inviting = false;
    }
    $scast->setInvitingPossible($opencast->inviting);
    // Existing channel
    $scast->setExtId($opencast->ext_id);
    $mod_opencast_update = $scast->update();
    $opencast->ext_id = $scast->getExtId();
    if (empty($opencast->timerestrict)) {
        $opencast->timeopen = 0;
        $opencast->timeclose = 0;
    }
    $moodle_update = $DB->update_record('opencast', $opencast);
    return $mod_opencast_update && $moodle_update;
}
Пример #4
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();
Пример #5
0
    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;
}
Пример #6
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];
 }
Пример #7
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;
 }