Commit 1be7bd66 authored by Francois Gannaz's avatar Francois Gannaz
Browse files

session::createAuthenticatedUrl()

parent 9a3c3633
......@@ -39,6 +39,9 @@ class mod_labnbook_session
private $autoCreateUser = true;
/**
* @return \mod_labnbook_session
*/
public static function load() {
if (empty(self::$singleton)) {
self::$singleton = new self;
......@@ -53,6 +56,9 @@ class mod_labnbook_session
$this->userId = $this->fetchUserId($USER->id);
}
/**
* Empties the cache and session, so forces to fetch data from the LabNbook server.
*/
public function refresh() {
global $SESSION;
unset($this->userId);
......@@ -76,6 +82,9 @@ class mod_labnbook_session
return $this->userId;
}
/**
* @return array mission[]
*/
public function getMissions() {
if (!isset($this->missions)) {
$this->missions = $this->fetchMissions();
......@@ -83,10 +92,37 @@ class mod_labnbook_session
return $this->missions;
}
/**
* @global moodle_database $DB
*
* @param int $instanceId
* @return int|null
*/
public function instanceIdToMissionId($instanceId) {
global $DB;
return $DB->get_field("labnbook", "labnbook_missionid", ['id' => $instanceId]);
}
/**
* Return an URL that will authenticate the user in LabNbook
*
* @param string $urlPath final URL
* @return string URL with added parameters
*/
public function createAuthenticatedUrl($urlPath) {
$params = [
'key' => $this->secret,
'userid' => $this->getUserId(),
'redirect' => $urlPath,
];
return "{$this->url}'/auth/api/login.php?" . http_build_query($params);
}
/**
* @global moodle_database $DB
* @global object $SESSION
* @global object $USER
*
* @param boolean $force
* @return int
*/
......@@ -121,6 +157,7 @@ class mod_labnbook_session
/**
* @global object $SESSION
*
* @param boolean $force
* @return array assoc: ID => name
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment