/** * 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; }