Exemplo n.º 1
0
function get_remote_coursemodule_from_instance($modulename, $instance, $location, $courseid = 0, $sectionnum = false, $strictness = IGNORE_MISSING)
{
    global $DB, $CFG, $USER;
    $eCache = new EclassCache();
    //$eCache->expire("events".$SESSION->cal_show_global.$SESSION->cal_show_groups.$SESSION->cal_show_course.$SESSION->cal_show_user);
    $data = $eCache->getData($modulename . $instance . $location);
    if ($data != ECLASS_CACHE_EXPIRED) {
        return $data;
    }
    require_once $CFG->dirroot . '/local/eclass/lib/session_storage.php';
    $satellites = eclass_getUserInstances($USER->username);
    //set web service url server => token need to be passed in the url
    $response = false;
    foreach ($satellites as $satellite) {
        if ($location == $satellite->url) {
            $serverurl = $satellite->url . "/webservice/xmlrpc/server.php" . '?wstoken=' . $satellite->token;
            //create the xmlrpc client instance
            require_once 'Zend/XmlRpc/Client.php';
            $xmlrpcclient = new Zend_XmlRpc_Client($serverurl);
            $params = array('modulename' => $modulename, 'instance' => $instance);
            //make the web service call
            $function = 'eclass_get_cm';
            try {
                $response = $xmlrpcclient->call($function, $params);
            } catch (Exception $e) {
                var_dump($e);
            }
        }
    }
    $response = (object) $response;
    $eCache = new EclassCache();
    $eCache->setData($modulename . $instance . $location, 5, $response);
    return $response;
}
/**
 * Lookup list of instances associated with this user
 * @param username value of username in moodle, currently this is ccid
 *
 * @return array list of instance records associated with user. array( stdClass, ...) stdClass->id, stdClass->url, stdClass->token, stdClass->sourceid
 */
function eclass_getUserInstances($username)
{
    global $DB, $CFG;
    //using default cache name
    $eCache = new EclassCache();
    $data = $eCache->getData(INSTANCES_DATAKEY);
    if ($data != ECLASS_CACHE_EXPIRED) {
        return $data;
    }
    //otherwise do a query
    $dbman = $DB->get_manager();
    //check if our tables exist
    if (!$dbman->table_exists("eclass_instances") || !$dbman->table_exists("eclass_user_instances")) {
        return array();
    }
    $records = $DB->get_records_sql("select i.* from {eclass_instances} AS i JOIN {eclass_user_instances} AS ui ON (i.id = ui.instance_id) where ui.userid = :userid", array('userid' => $username));
    $eCache->setData(INSTANCES_DATAKEY, 5, $records);
    $instances = Instance::wrapRecords($records);
    debugging("User Instances Found: " . print_r($records, true), DEBUG_DEVELOPER);
    return $instances;
}