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

cleanup and enhance code style

parent c8097088
......@@ -11,8 +11,6 @@
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/upgradelib.php');
/**
* Execute mod_labnbook upgrade from the given old version.
*
......
<?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 upgrade helper functions are defined here.
*
* @package mod_labnbook
* @category upgrade
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Helper function used by the upgrade.php file.
*/
function mod_labnbook_helper_function() {
global $DB;
// Please note that you should always be performing any task using raw (low
// level) database access exclusively, avoiding any use of the Moodle APIs.
//
// For more information please read the available Moodle documentation:
// https://docs.moodle.org/dev/Upgrade_API
}
......@@ -9,41 +9,37 @@
*/
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
require_course_login($course);
$coursecontext = context_course::instance($course->id);
$event = \mod_labnbook\event\course_module_instance_list_viewed::create(array(
$event = \mod_labnbook\event\course_module_instance_list_viewed::create([
'context' => $modulecontext
));
]);
$event->add_record_snapshot('course', $course);
$event->trigger();
$PAGE->set_url('/mod/labnbook/index.php', array('id' => $id));
$PAGE->set_url('/mod/labnbook/index.php', ['id' => $id]);
$PAGE->set_title(format_string($course->fullname));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($coursecontext);
echo $OUTPUT->header();
$modulenameplural = get_string('modulenameplural', 'mod_labnbook');
echo $OUTPUT->heading($modulenameplural);
$labnbooks = get_all_instances_in_course('labnbook', $course);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('modulenameplural', 'mod_labnbook'));
if (empty($labnbooks)) {
notice(get_string('nonewmodules', 'mod_labnbook'), new moodle_url('/course/view.php', array('id' => $course->id)));
notice(get_string('nonewmodules', 'mod_labnbook'), new moodle_url('/course/view.php', ['id' => $course->id]));
}
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($course->format == 'weeks') {
$table->head = array(get_string('week'), get_string('name'));
$table->align = array('center', 'left');
......@@ -54,25 +50,26 @@ if ($course->format == 'weeks') {
$table->head = array(get_string('name'));
$table->align = array('left', 'left', 'left');
}
foreach ($labnbooks as $labnbook) {
if (!$labnbook->visible) {
$link = html_writer::link(
new moodle_url('/mod/labnbook/view.php', array('id' => $labnbook->coursemodule)),
new moodle_url('/mod/labnbook/view.php', ['id' => $labnbook->coursemodule]),
format_string($labnbook->name, true),
array('class' => 'dimmed'));
['class' => 'dimmed']
);
} else {
$link = html_writer::link(
new moodle_url('/mod/labnbook/view.php', array('id' => $labnbook->coursemodule)),
format_string($labnbook->name, true));
new moodle_url('/mod/labnbook/view.php', ['id' => $labnbook->coursemodule]),
format_string($labnbook->name, true)
);
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array($labnbook->section, $link);
if ($course->format === 'weeks' || $course->format === 'topics') {
$table->data[] = [$labnbook->section, $link];
} else {
$table->data[] = array($link);
$table->data[] = [$link];
}
}
echo html_writer::table($table);
echo $OUTPUT->footer();
......@@ -84,7 +84,12 @@ function labnbook_update_instance($moduleinstance, $mform = null) {
$courseid = (int) $moduleinstance->course;
$groupid = (int) $moduleinstance->groupmode === 0 ? null : (int) $moduleinstance->group;
try {
$fetcher->updateMissionUse($moduleinstance->labnbook_missionid, $moduleinstance->labnbook_teamconfigid, $courseid, $groupid);
$fetcher->updateMissionUse(
$moduleinstance->labnbook_missionid,
$moduleinstance->labnbook_teamconfigid,
$courseid,
$groupid
);
} catch (\Exception $e) {
die("fatal error: " . $e->getMessage()); // TODO
}
......
<?php
/*
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
*/
require(dirname(__DIR__) . '/../../config.php');
require_once(dirname(__DIR__) . '/lib.php');
// Course_module ID
$id = empty($_GET['id']) ? null : (int) $_GET['id'];
if ($id <= 0) {
http_response_code(402);
echo '["error":"The parameter id is required."]';
exit();
}
$cm = get_coursemodule_from_id("labnbook", $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$moduleinstance = $DB->get_record(LABNBOOK_TABLE, array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm);
header("Content-type: application/json");
$action = required_param('action', PARAM_ALPHA);
switch($action) {
case "getTeams":
$groupid = empty($_GET['groupid']) ? null : (int) $_GET['groupid'];
$missionid = empty($_GET['missionid']) ? null : (int) $_GET['missionid'];
if ($missionid <= 0) {
http_response_code(402);
echo '["error":"The parameter missionid is required."]';
exit();
}
echo json_encode(getTeams($groupid, $missionid));
break;
case "selectTeam":
break;
}
function getTeams() {
return [
'settings' => new stdClass(),
'teams' => [
["id_report" => 1, "name" => "Équipe 1", "members" => ["Paulo", "Theresa"]],
],
'status' => [
"allowCreation" => true,
"allowMoreThanOpt" => false,
"numTeams" => 0,
"usersInClass" => 0,
"usersInTeams" => 0
],
'selectedTeam' => null,
];
}
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