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 b49c18fb authored by Francois Gannaz's avatar Francois Gannaz
Browse files

mod_form basic (user binding checks, mission selector)

parent 1638ccd5
......@@ -24,7 +24,7 @@ class institution extends moodlefetcher
*/
public function loginUser() : int {
try {
$response = $this->fetch("POST", "/v1/auth/login");
$this->fetch("POST", "/v1/auth/login");
} catch (\Exception $e) {
$error = $this->fetcher->getLastError();
return (isset($error->code) ? (int) $error->code : 0);
......@@ -43,7 +43,7 @@ class institution extends moodlefetcher
public function createUser($user) {
try {
$response = $this->fetch("PUT", "/v1/user/create", ['data' => $user]);
$this->fetch("PUT", "/v1/user/create", ['data' => $user]);
} catch (\Exception $e) {
$error = $this->fetcher->getLastError();
if ($error->code === self::ERROR_CREATION_FAILED) {
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin strings are defined here.
......@@ -42,12 +28,26 @@ $string['pluginname'] = 'LabNbook';
$string['privacy:metadata'] = 'LabNbook does not store any personal data';
$string['view'] = 'View';
// settings
$string['labnbook_api_url'] = "LabNbook URL";
$string['labnbook_api_url_descr'] = "The URL to the root of labnbook, with a trailing slash. E.g. https://uga.labnbook.fr/";
$string['labnbook_api_key'] = "LabNbook Key";
$string['labnbook_api_key_descr'] = "The secret key that grants Moodle access to the API of LabNbook. This key is provided by the LabNbook instance.";
// form
$string['instancename'] = "Header";
$string['instancename_help'] = "This text will appear in the course content.";
$string['mission'] = "Mission";
$string['mission_help'] = "Select a mission among those you own in LabNbook. If you create a new mission in LabNbook, the 'refresh' button will update the drop-down list.";
$string['labnbook_url'] = "LabNbook URL";
$string['labnbook_url_descr'] = "The URL to the root of labnbook, with a trailing slash. E.g. https://uga.labnbook.fr/";
$string['labnbook_key'] = "LabNbook Key";
$string['labnbook_key_descr'] = "The secret key that grants Moodle access to the API of LabNbook. This key is provided by the LabNbook instance.";
$string['refresh'] = "refresh";
$string['teaming'] = "Team settings";
$string['method'] = "Method";
$string['method_help'] = "With the first choice, students will chose their own team if they don't have any.\n\nWith the second choice, they will be randomly assigned to a new or existing team when they begin their activity.\n\nThe number of teams and their sizes are controlled by the next settings.";
$string['teamconfigmethod_students'] = "Students' choice";
$string['teamconfigmethod_random'] = "Random distribution";
$string['teams_max'] = "Max number of teams";
$string['teams_max_help'] = "There will never be more than this number of teams, unless a teacher manually creates more teams.";
$string['size_opt'] = "Optimal size";
$string['size_opt_help'] = "The team size that would be optimal. The maximum and minimum sizes will be inferred from this value if they are not given.";
$string['size_max'] = "Maximal size";
$string['size_min'] = "Minimal size";
......@@ -17,6 +17,9 @@ require_once($CFG->dirroot.'/course/moodleform_mod.php');
// short-cut before loading the form, see `course/modedit.php`
requireLabnbookAuthentication();
define('TEAMCONFIG_METHOD_STUDENTS', 1);
define('TEAMCONFIG_METHOD_RANDOM', 3);
/**
* Module instance settings form.
*
......@@ -111,13 +114,11 @@ EOJS
// Adding the standard "name" field.
$mform->addElement('text', 'name', get_string('instancename', 'mod_labnbook'), ['size' => '64']);
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'instancename', 'mod_labnbook');
......@@ -129,6 +130,22 @@ EOJS
$this->add_intro_editor();
}
$mform->addElement('header', 'teaming', get_string('teaming', 'mod_labnbook'));
$options = [
"" => "-",
TEAMCONFIG_METHOD_STUDENTS => get_string('teamconfigmethod_students', 'mod_labnbook'),
TEAMCONFIG_METHOD_RANDOM => get_string('teamconfigmethod_random', 'mod_labnbook'),
];
$mform->addElement('select', 'method', get_string('method', 'mod_labnbook'), $options);
$mform->addHelpButton('method', 'method', 'mod_labnbook');
$mform->addRule("method", null, 'required', null, 'client');
$this->addInputInt('teams_max', true);
$this->addInputInt('size_opt', true);
$this->addInputInt('size_max', false);
$this->addInputInt('size_min', false);
// Add standard grading elements.
$this->standard_grading_coursemodule_elements();
......@@ -139,6 +156,15 @@ EOJS
$this->add_action_buttons();
}
private function addInputInt($name, $required) {
$this->_form->addElement('text', $name, get_string($name, 'mod_labnbook'), ['size' => '3']);
$this->_form->setType($name, PARAM_INT);
if ($required) {
$this->_form->addRule($name, null, 'required', null, 'client');
$this->_form->addHelpButton($name, $name, 'mod_labnbook');
}
}
function definition_after_data() {
parent::definition_after_data();
if ($this->_form->getElementValue('update')) {
......@@ -153,8 +179,18 @@ function requireLabnbookAuthentication() {
return;
}
$institutionFetcher = new fetch\institution;
if ($institutionFetcher->loginUser() === fetch\institution::OK) {
return;
switch ($institutionFetcher->loginUser()) {
case fetch\institution::OK:
return;
case fetch\institution::ERROR_LOGIN_UNKNOWN:
redirect(
"/mod/labnbook/user-binding.php?courseid={$COURSE->id}&return="
. base64_encode($_SERVER['REQUEST_URI'])
);
break;
case fetch\institution::ERROR_TOKEN_NOTVALID:
throw new \moodle_exception("Internal error with LabNbook");
default:
throw new \moodle_exception("Unknown error with LabNbook");
}
redirect("/mod/labnbook/user-binding.php?courseid={$COURSE->id}&return=" . base64_encode($_SERVER['REQUEST_URI']));
}
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