Ejemplo n.º 1
0
/**
 * Updates an instance of the wiziq in the database
 *
 * 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 $wiziq An object from the form in mod_form.php
 * 
 * @return boolean Success/Fail
 */
function wiziq_update_instance($wiziq) {
    global $CFG, $DB, $USER;
    $wiziq_webserviceurl= $CFG->wiziq_webserviceurl;
    $wiziq_access_key= $CFG->wiziq_access_key;
    $wiziq_secretacesskey = $CFG->wiziq_secretacesskey;
    $class_id = $wiziq->class_id;
    $wiziq->lasteditorid = $USER->id;
    $coursecontext = context_course::instance($wiziq->course);
    if (property_exists($wiziq, 'insescod')) {
        $session = $wiziq->insescod;
    }
    if (!isset($class_id)) {
        wiziq_get_data_by_sessioncode($wiziq->course, $coursecontext, $session, $class_id, $wiziq->id,
                              $presenter_id, $presenter_name, $presenter_url, $start_time,
                              $time_zone, $create_recording, $status, $language_culture_name,
                              $duration, $recording_url);
    } else {
        wiziq_get_data($wiziq->course, $coursecontext, $class_id, $presenter_id, $presenter_name, $presenter_url,
                       $start_time, $time_zone, $create_recording, $status,
                       $language_culture_name, $duration, $recording_url);
    }
    
    $class_status = ltrim(rtrim($status));
    if (($class_status) != 'expired') {
        $wiziq->timemodified = time();
        $wiziq->id = $wiziq->instance;
        if (! $class_id = $DB->get_field('wiziq', 'class_id', array('id' => $wiziq->id))) {
            return false;
        }
        if (property_exists($wiziq, 'schedule_for_now')) {
            if ($wiziq->schedule_for_now == true) {
                $wiziq->wiziq_datetime = $wiziq->timenow;
            }
        }
        if (property_exists($wiziq, 'scheduleforother')) {
            if ($wiziq->scheduleforother == true) {
                $userid = $wiziq->presenter_id;
                $userfirstname = $DB->get_field_select('user', 'firstname', 'id='.$userid);
                $usersecondname = $DB->get_field_select('user', 'lastname', 'id='.$userid);
                $username = $userfirstname." ".$usersecondname;
            }
        } else if (property_exists($wiziq, 'scheduleforself')) {
            if ($wiziq->scheduleforself == true) {
                $userid = $USER->id;
                $userfirstname = $DB->get_field_select('user', 'firstname', 'id='.$userid);
                $usersecondname = $DB->get_field_select('user', 'lastname', 'id='.$userid);
                $username = $userfirstname." ".$usersecondname;
            }
        } else {
                $userid = $DB->get_field('wiziq', 'presenter_id', array('id' => $wiziq->id));
                $userfirstname = $DB->get_field_select('user', 'firstname', 'id='.$userid);
                $usersecondname = $DB->get_field_select('user', 'lastname', 'id='.$userid);
                $username = $userfirstname." ".$usersecondname;
                $wiziq->presenter_id = $userid;
        }
        if (0 !=($wiziq->groupingid)) {
            $eventtype = 'group';
        } else if (1==$wiziq->course) {
            $eventtype = 'site';
        } else {
            $eventtype = 'course';
        }
        if (1 == $wiziq->recording) {
            $recording = "true";
        } else {
            $recording = "false";
        }
        $class_duration = $wiziq->duration;
        $title = $wiziq->name;
        $presenter_id = $userid;
        $presenter_name = $username;
        $wiziq_datetime = wiziq_converttime($wiziq->wiziq_datetime, $wiziq->wiziq_timezone);
        $vc_language = $wiziq->vc_language;
        $intro= $wiziq->intro;
        $wiziqtimezone = $wiziq->wiziq_timezone;
        $wiziqclass_id = "";
        $errormsg = "";
        $attribnode = "";
        wiziq_modifyclass($wiziq->course, $wiziq_secretacesskey, $wiziq_access_key,
                $wiziq_webserviceurl, $class_id, $title, $presenter_id, $presenter_name,
                $wiziq_datetime, $wiziqtimezone, $class_duration, $vc_language, $recording,
                $intro, $attribnode, $wiziqclass_id, $errormsg);
        if ($attribnode == "ok") {
            # You may have to add extra stuff in here #
            $wiziq->class_status = "upcoming";
            $wiziq->recording_link = "";
            $wiziq->recording_link_status = "0";
            $wiziq->view_recording_link = $recording_url;
            $wiziq->class_timezone = $wiziq->wiziq_timezone;
            $DB->update_record('wiziq', $wiziq);
            $event = new stdClass();
            $event->id = $DB->get_field('event', 'id',
                    array('modulename'=>'wiziq', 'instance'=>$wiziq->id));

            if ($event->id) {

                $event->name        = format_string($wiziq->name);
                $event->description = format_module_intro('wiziq', $wiziq, $wiziq->coursemodule);
                $event->courseid    = $wiziq->course;
                $event->groupid     = $wiziq->groupingid;
                $event->userid      = $userid;
                $event->modulename  = 'wiziq';
                $event->eventtype   = $eventtype;
                $event->timestart   = $wiziq->wiziq_datetime;
                $event->timeduration = $wiziq->duration;
                $calendarevent = calendar_event::load($event->id);
                $calendarevent->update($event);
                return true;
            } else {
                    print_error($errormsg);
            }
        }
    } else {
        print_error("error in case of expired class");
    }
}
Ejemplo n.º 2
0
}
foreach ($slice as $wiziq) {
    $userid = $wiziq->presenter_id;
    $userfirstname = $DB->get_field_select('user', 'firstname', 'id='.$userid);
    $usersecondname = $DB->get_field_select('user', 'lastname', 'id='.$userid);
    $presenter_name = $userfirstname." ".$usersecondname;
    #------  if recording is opted for------
    $wiziqmodulecontext = context_module::instance($wiziq->coursemodule);
    $newwiziq = $DB->get_record('wiziq', array('id' => $wiziq->id));
    if (!isset($newwiziq->class_id)) {
        $title = $newwiziq->name;
        $start_time = '';
    } else {
        $title = html_writer::link( new moodle_url('/mod/wiziq/view.php',
                array('id' => $wiziq->coursemodule)), format_string($newwiziq->name, true));
        $start_time = wiziq_converttime($newwiziq->wiziq_datetime, $newwiziq->class_timezone);
    }
    $wiziq_completed = ($newwiziq->class_status == 'completed');
    
    if (isset($newwiziq->class_id)) {
        if ($wiziq_completed && ($wiziq->class_id > 1)) {
                wiziq_downloadrecording($id, $wiziqmodulecontext, $newwiziq->class_id,
                                        $download_recording_link, $errormsg);
            if ($download_recording_link != null) {
                $updates = new stdClass(); //just enough data for updating the submission
                $updates->id = $wiziq->id;
                $updates->recording_link_status = WIZIQ_RECORDING_AVAILABLE;
                $updates->recording_link = $download_recording_link;
                $DB->update_record('wiziq', $updates);
                if (has_capability('mod/wiziq:wiziq_download_rec', $wiziqmodulecontext)) {
                    $dnld_rec = html_writer::link( new moodle_url($download_recording_link),