Exemple #1
0
                    array('id' => $course->id)));
}

$total_wiziq_records = count($wiziqs);
$noerror = get_string('noerror','wiziq');
$params = array(
    'objectid' => $total_wiziq_records,
    'relateduserid' => $USER->id,
    'courseid' => $course->id,
    'context' => $coursecontext,
    'other' => array(
        'error' => '',
        'sesskey' => sesskey()
    )
);
$event = \mod_wiziq\event\wiziq_classlisting::create($params);
$event->trigger();

#------- Creation of table starts------
$table = new flexible_table('manageclasses');
$refresh_txt = get_string('refresh_page', 'wiziq');
$statusicon = '<img src="'.$CFG->wwwroot.'/mod/wiziq/pix/refresh.png" alt='.$refresh_txt.'/>';
$stausimage = '<a href="javascript:location.reload(true)"';
$stausimage .= ' title="'.$refresh_txt.'">'.$statusicon.'</a>';
$statusheading = 'Status'." ".$stausimage;
$table->define_columns(array('name', 'date_time', 'presenter',
    'status', 'manage', 'dnldrec', 'viewrec', 'attendance_report'));
$table->column_style_all('text-align', 'left');
$table->define_headers(array(get_string('name', 'wiziq'),
    get_string('date_time', 'wiziq'), get_string('presenter', 'wiziq'),
    $statusheading, get_string('manage', 'wiziq'),
/**
 * Generates the data for class secheduled by soap api for index page. 
 *
 * @param integer $courseid the course id in which the class is scheduled.
 * @param array $sessioncodes the sessioncode of old classes scheduled by soap api.
 */
function wiziq_get_data_by_sessioncode_manage($courseid, $coursecontext, $sessioncodes) {
    global $CFG, $DB, $USER;
    $wiziq_secretacesskey = $CFG->wiziq_secretacesskey;
    $wiziq_access_key = $CFG->wiziq_access_key;
    $wiziq_webserviceurl = $CFG->wiziq_webserviceurl;
    require_once("authbase.php");
    $wiziq_authbase = new wiziq_authbase($wiziq_secretacesskey, $wiziq_access_key);
    $method = "get_data_by_sessionCodes";
    $requestparameters["signature"]=$wiziq_authbase->wiziq_generatesignature($method,
                                                                             $requestparameters);
    $requestparameters["multiple_session_code"] = implode(',', $sessioncodes);
    $requestparameters["page_size"] = WIZIQ_DEFAULT_PAGESIZE;
    $requestparameters["columns"] = "session_code, class_id, time_zone, status";
    $wiziq_httprequest=new wiziq_httprequest();
    try {
        $xmlreturn=$wiziq_httprequest->wiziq_do_post_request(
                                            $wiziq_webserviceurl.'?method=get_data_by_sessionCodes',
                                            $requestparameters);
        libxml_use_internal_errors(true);
        $xmldata = new SimpleXmlElement($xmlreturn, LIBXML_NOCDATA);
        $attribnode= (string)$xmldata->attributes();
        if ($attribnode=="ok") {
            $get_data = $xmldata->get_data_by_sessionCodes->record_list;
            foreach ($get_data->record as $record) {
                if (isset($record->status)) {
                    $status = (string)$record->status;
                } else {
                    $status = get_string('deletefromwiziq', 'wiziq');
                }
                $sessions_xml = (string)$record->session_code;
                $class_id_from_xml[$sessions_xml] = array('status' => $status,
                                                          'time_zone' => (string)$record->time_zone,
                                                          'class_id'  => (string)$record->class_id
                                                    );
            }
            foreach ($sessioncodes as $key => $value) {
                /*
                 * we use isset for performance knowing the the
                 * value for particular key will never be null
                 */
                if (isset($class_id_from_xml[$value])) {
                    $updates = new stdClass(); //just enough data for updating the submission
                    $updates->id = $key;
                    $updates->class_id = $class_id_from_xml[$value]['class_id'];
                    $updates->class_timezone = $class_id_from_xml[$value]['time_zone'];
                    $updates->class_status = $class_id_from_xml[$value]['status'];
                    $DB->update_record('wiziq', $updates);
                }
            }
        } else if ($attribnode=="fail") {
            $att = 'msg';
            $code = 'code';
            $error_code = (string)$xmldata->error->attributes()->$code;
            $error_msg = (string)$xmldata->error->attributes()->$att; //can be used while debug
            $error = $error_code." ".$error_msg;
            $paramslog = array(
                    'objectid' => $courseid,
                    'relateduserid' => $USER->id,
                    'courseid' => $courseid,
                    'context' => $coursecontext,
                    'other' => array(
                        'error' => $error
                    )
            );
            $event = \mod_wiziq\event\wiziq_classlisting::create($paramslog);
            $event->trigger();
            print_error('1', '', '', $error);
        }
    } catch (Exception $e) {
        if (property_exists($e, 'errorcode')) {
            notify($e->a);
        } else {
            $errormsg = get_string('errorinservice', 'wiziq');
            $paramslog = array(
                    'objectid' => $courseid,
                    'relateduserid' => $USER->id,
                    'courseid' => $courseid,
                    'context' => $coursecontext,
                    'other' => array(
                        'error' => $errormsg
                    )
            );
            $event = \mod_wiziq\event\wiziq_classlisting::create($paramslog);
            $event->trigger();
            notify($errormsg);
        }
    }
}