Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 507e9990 authored by Francois Gannaz's avatar Francois Gannaz
Browse files

labnbook_add_instance() saves the LnB team_config

parent 69116fcd
......@@ -49,6 +49,22 @@ class user extends moodlefetcher
return $this->fetch('GET', '/v1/mission')->data;
}
/**
* @param int $missionId
* @param int $courseId
* @param int|null $groupId
* @return object teamconfig
*/
public function useMission(int $missionId, int $courseId, int $groupId = null) {
return $this
->fetch(
'POST',
"/v1/mission/$missionId/use",
['courseid' => $courseId, 'groupid' => $groupId]
)
->data->team_config;
}
/**
* Return the JS code that fetches the missions.
*
......
......@@ -8,6 +8,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_labnbook\fetch;
defined('MOODLE_INTERNAL') || die();
define('LABNBOOK_TABLE', 'labnbook');
......@@ -46,8 +48,17 @@ function labnbook_supports($feature) {
function labnbook_add_instance($moduleinstance, $mform = null) {
global $DB;
$moduleinstance->timecreated = time();
$fetcher = new fetch\user();
$courseid = (int) $moduleinstance->course;
$groupid = (int) $moduleinstance->groupmode === 0 ? null : (int) $moduleinstance->group;
try {
$teamConfig = $fetcher->useMission($moduleinstance->labnbook_missionid, $courseid, $groupid);
} catch (\Exception $e) {
die("fatal error: " . $e->getMessage()); // TODO
}
$moduleinstance->labnbook_teamconfigid = (int) $teamConfig->id_team_config;
$moduleinstance->timecreated = time();
$id = $DB->insert_record(LABNBOOK_TABLE, $moduleinstance);
return $id;
......
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