Beispiel #1
0
/**
 * Saves a new instance of the wiziq into the database
 *
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will create a new instance and return the id number
 * of the new instance.
 *
 * @param object $wiziq An object from the form in mod_form.php
 * 
 * @return int The id of the newly inserted wiziq record
 */
function wiziq_add_instance(stdClass $wiziq, mod_wiziq_mod_form $mform = null) {
    global $CFG, $DB, $USER;
    $wiziq_webserviceurl= $CFG->wiziq_webserviceurl;
    $wiziq_access_key= $CFG->wiziq_access_key;
    $wiziq_secretacesskey = $CFG->wiziq_secretacesskey;
    $coursecontext = context_course::instance($wiziq->course);
    $wiziq->timecreated = time();
    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 {
            $userid = $USER->id;
            $userfirstname = $USER->firstname;
            $usersecondname = $USER->lastname;
            $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;
    $courseid = $wiziq->course;
    $intro= $wiziq->intro;
    $wiziqtimezone = $wiziq->wiziq_timezone;
    $wiziqclass_id = "";
    $errormsg = "";
    $attribnode = "";
    wiziq_scheduleclass($wiziq_secretacesskey, $wiziq_access_key, $wiziq_webserviceurl,
            $title, $presenter_id, $presenter_name, $wiziq_datetime, $wiziqtimezone,
            $class_duration, $vc_language, $recording, $courseid,
            $intro, $attribnode, $wiziqclass_id, $errormsg, $view_recording_url);
    if ($attribnode == "ok") {
        $wiziq->class_id = $wiziqclass_id;
        $wiziq->class_status = "upcoming";
        $wiziq->class_timezone = $wiziqtimezone;
        $wiziq->recording_link = "";
        $wiziq->view_recording_link = $view_recording_url;
        $wiziq->recording_link_status = "0";
	
        $returnid =  $DB->insert_record('wiziq', $wiziq);
        $event = new stdClass();
        $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->instance    = $returnid;
        $event->eventtype   = $eventtype;
        $event->timestart   = $wiziq->wiziq_datetime;
        $event->timeduration = $wiziq->duration;
        calendar_event::create($event);
        return $returnid;
    } else {
        $params = array(
            'objectid' => $wiziq->timecreated,
            'relateduserid' => $USER->id,
            'courseid' => $wiziq->course,
            'context' => $coursecontext,
            'other' => array(
            'error' => $errormsg
            )
        );
        $eventee = \mod_wiziq\event\wiziq_classadd::create($params);
        $eventee->trigger();
        print_error($errormsg);
    }
}
/**
 * Makes a call to api for scheduling class after authentication from authbase file.
 *
 * @param string $wiziq_secretacesskey secret access key generated during wiziq download.
 * @param string $wiziq_access_key the access key generated during wiziq download.
 * @param string $wiziq_webserviceurl url to ping for xml return for scheduling class.
 * @param string $title title of the class scheduled.
 * @param int $presenter_id the id of the presenter who will be present for the class.
 * @param string $presenter_name name of the presenter.
 * @param int $wiziq_datetime the time at which the class is scheduled.
 * @param string $wiziqtimezone the timezone for which class is scheduled.
 * @param int $class_duration duration in minutes for scheduling class.
 * @param string $vc_language the language in which the class will be launched.
 * @param string $recording wheteher recording is opted or not.
 * @param integer $courseid id of the course for which the class is scheduled.
 * @param string $intro description of the class scheduled.
 * @param string $attribnode the attribute is ok then the class is scheduled.
 * @param integer $wiziqclass_id class_id returned that is stored in wiziq table.
 * @param string $errormsg error message in case there is some error in scheduling class.
 * @param string $view_recording_url recording link for viewing the class.
 */
function wiziq_scheduleclass($wiziq_secretacesskey, $wiziq_access_key,
                      $wiziq_webserviceurl, $title, $presenter_id, $presenter_name, $wiziq_datetime,
                      $wiziqtimezone, $class_duration, $vc_language, $recording, $courseid, $intro,
                      &$attribnode, &$wiziqclass_id, &$errormsg, &$view_recording_url) {
    global $CFG, $wiziq_secretacesskey, $wiziq_access_key, $wiziq_webserviceurl, $USER;
    $wiziq_secretacesskey = $CFG->wiziq_secretacesskey;
    $wiziq_access_key = $CFG->wiziq_access_key;
    $wiziq_webserviceurl = $CFG->wiziq_webserviceurl;
    $coursecontext = context_course::instance($courseid);
    require_once("authbase.php");
    $wiziq_authbase = new wiziq_authbase($wiziq_secretacesskey, $wiziq_access_key);
    $method = "create";
    $requestparameters["signature"] = $wiziq_authbase->wiziq_generatesignature($method,
                                                                    $requestparameters);
    $requestparameters["course_id"] = $courseid;
    $requestparameters["title"] = $title; //Required
    $requestparameters["description"] = $intro;
    $requestparameters["presenter_id"] = $presenter_id;
    $requestparameters["presenter_name"] = $presenter_name;
    $requestparameters["start_time"] = $wiziq_datetime;
    $requestparameters["duration"] = $class_duration; //optional
    $requestparameters["time_zone"] = $wiziqtimezone;//"Asia/Kolkata"; //optional
    $requestparameters["create_recording"]= $recording; //optional
    $requestparameters["return_url"] = ""; //optional
    $requestparameters["status_ping_url"] = ""; //optional
    $requestparameters["language_culture_name"] = $vc_language;
    $requestparameters["app_version"] = $CFG->release;
    $wiziq_httprequest=new wiziq_httprequest();
    try {
        $xmlreturn=$wiziq_httprequest->wiziq_do_post_request(
                                            $wiziq_webserviceurl.'?method=create',
                                            $requestparameters);
        libxml_use_internal_errors(true);
        $objdom = new SimpleXMLElement($xmlreturn, LIBXML_NOCDATA);
        $attribnode = (string)$objdom->attributes();
        if ($attribnode=="ok") {
            $class_detaial = $objdom->create->class_details;
            $wiziqclass_id=(string)$class_detaial->class_id;
            $view_recording_url=(string)$class_detaial->recording_url;
            $params = array(
                'objectid' => $wiziqclass_id,
                'relateduserid' => $USER->id,
                'courseid' => $courseid,
                'context' => $coursecontext,
                'other' => array(
                    'error' => ''
                )
            );
            $event = \mod_wiziq\event\wiziq_classadd::create($params);
            $event->trigger();
        } else if ($attribnode=="fail") {
            $att = 'msg';
            $code = 'code';
            $error_code = (string)$objdom->error->attributes()->$code;
            $error_msg = (string)$objdom->error->attributes()->$att; //can be used while debug
            $errormsg = $error_code." ".$error_msg;
            $params = array(
                'objectid' => $courseid,
                'relateduserid' => $USER->id,
                'courseid' => $courseid,
                'context' => $coursecontext,
                'other' => array(
                    'error' => $errormsg
                )
            );
            $event = \mod_wiziq\event\wiziq_classadd::create($params);
            $event->trigger();
        }//end if
    } catch (Exception $e) {
        // in case no xml is returned
        $errormsg = $e->getMessage()."<br/>".get_string('errorinservice', 'wiziq');
        $params = array(
                'objectid' => $courseid,
                'relateduserid' => $USER->id,
                'courseid' => $courseid,
                'context' => $coursecontext,
                'other' => array(
                    'error' => $errormsg
                )
        );
        $event = \mod_wiziq\event\wiziq_classadd::create($params);
        $event->trigger();
    }
}//end function