Commit e5c4b7e4 authored by Francois Gannaz's avatar Francois Gannaz
Browse files

renaming and cleanup

parent 109061b8
......@@ -4,12 +4,14 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
*/
/* @var $DB moodle_database */
/* @var $DB \moodle_database */
namespace mod_labnbook\session;
/**
* Queries on LabNbook info for the current user.
*/
class mod_labnbook_session
class labnbook
{
private static $singleton;
......@@ -40,7 +42,7 @@ class mod_labnbook_session
private $autoCreateUser = true;
/**
* @return \mod_labnbook_session
* @return \\mod_labnbook\session\labnbook
*/
public static function load() {
if (empty(self::$singleton)) {
......@@ -49,7 +51,7 @@ class mod_labnbook_session
return self::$singleton;
}
public function __construct() {
protected function __construct() {
global $CFG, $USER;
$this->url = rtrim($CFG->labnbook_url, '/');
$this->secret = $CFG->labnbook_key;
......@@ -59,7 +61,9 @@ class mod_labnbook_session
/**
* Empties the cache and session, so forces to fetch data from the LabNbook server.
*
* @return mod_labnbook_session
* $refreshedUserId = $session->refresh()->getUserId();
*
* @return \mod_labnbook\session\labnbook
*/
public function refresh() {
global $SESSION;
......@@ -151,7 +155,7 @@ class mod_labnbook_session
global $DB, $SESSION, $USER;
if ($force || !isset($SESSION->labnbook_userid)) {
if (empty($USER) || empty($USER->id)) {
throw new Exception("Please log into Moodle");
throw new \Exception("Please log into Moodle");
}
$userId = $DB->get_field("labnbook_user", "labnbook_userid", ['userid' => $USER->id]);
$knownUser = $userId > 0;
......
<?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/>.
/**
* Redirect the user to the appropiate submission related page.
* Redirect the user to the appropriate submission related page.
*
* @package mod_labnbook
* @category grade
......
<?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/>.
/**
* Display information about all the mod_labnbook modules in the requested course.
......
<?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/>.
/**
* Library of interface functions and constants.
......@@ -105,6 +91,46 @@ function labnbook_delete_instance($id) {
return true;
}
/**
* Given a course_module object, this function returns any
* "extra" information that may be needed when printing
* this activity in a course listing.
*
* See {@link get_array_of_activities()} in course/lib.php
*
* @param stdClass $coursemodule
* @return cached_cm_info Info to customise main page display
*/
function labnbook_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
$instance = $DB->get_record(
LABNBOOK_TABLE,
['id' => $coursemodule->instance],
'id, name, intro, introformat'
);
if (!$instance) {
return null;
}
$info = new cached_cm_info();
$info->name = $instance->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('labnbook', $instance, $coursemodule->id, false);
}
/*
// Configured to open the activity in a new tab
if ($instance->display === RESOURCELIB_DISPLAY_POPUP) {
// ...
$info->target = '_blank';
}
*/
return $info;
}
/**
* Is a given scale used by the instance of mod_labnbook?
*
......
<?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/>.
/**
* The main mod_labnbook configuration form.
......@@ -22,7 +8,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use \mod_labnbook_session as session;
use \mod_labnbook\session\labnbook as labnbookSession;
defined('MOODLE_INTERNAL') || die();
......@@ -45,7 +31,7 @@ class mod_labnbook_mod_form extends moodleform_mod {
$mform = $this->_form;
$missions = session::load()->getMissions();
$missions = labnbookSession::load()->getMissions();
$missionsJs = json_encode($missions);
$refreshUrl = (new moodle_url('/mod/labnbook/refresh.php'))->out(false);
$mform->addElement('html', <<<"EOJS"
......
<?php
use \mod_labnbook_session as session;
use \mod_labnbook\session\labnbook as labnbookSession;
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
$reportId = optional_param('reportId', 0, PARAM_INT);
$lnb = session::load();
$lnb = labnbookSession::load();
if ($reportId) {
header("Location: " . $lnb->createAuthenticatedUrl('/pages/report.php?idr=' . $reportId));
exit();
......
<?php
/*
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
*/
use \mod_labnbook_session as session;
use \mod_labnbook\session\labnbook as labnbookSession;
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
require_login();
$missions = session::load()->refresh()->getMissions();
$missions = labnbookSession::load()->refresh()->getMissions();
header("Content-type: application/json");
echo json_encode(array_values((array) $missions));
<?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 administration pages are defined here.
......
<?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 version and other meta-data are defined here.
......@@ -26,6 +12,6 @@ defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_labnbook';
$plugin->release = '0.1.4';
$plugin->version = 2019020100;
$plugin->version = 2019020101;
$plugin->requires = 2016120500;
$plugin->maturity = MATURITY_ALPHA;
<?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/>.
/**
* Prints an instance of mod_labnbook.
......@@ -24,7 +10,7 @@
/* @var $DB moodle_database */
use \mod_labnbook_session as session;
use \mod_labnbook\session\labnbook as labnbookSession;
use mod_labnbook\ar\teamconfig;
require(__DIR__.'/../../config.php');
......@@ -68,11 +54,11 @@ $PAGE->set_title(format_string($moduleinstance->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($modulecontext);
$lnb = session::load();
$lnb = labnbookSession::load();
if (has_capability('moodle/course:manageactivities', context_course::instance($course->id))) {
// editing teacher view
// ...
$content = "TODO";
$content = "TODO: teacher view";
} else {
// student view
$reportId = $lnb->getReportId($cm->id);
......@@ -80,22 +66,24 @@ if (has_capability('moodle/course:manageactivities', context_course::instance($c
$groupids = groups_get_user_groups($cm->course)[0];
$teamconfig = teamconfig::findForGroups($cm->id, $groupids);
if ($teamconfig->method === teamconfig::METHOD_STUDENTCHOICE) {
redirect('/mod/labnbook/teamchoice.php');
redirect('/mod/labnbook/teamchoice.php?l=' . (int) $moduleinstance->instance);
return;
} else if ($teamconfig->method === teamconfig::METHOD_TEACHERCHOICE) {
// TODO: warn the teacher that this student lacks a team
// TODO: warn the student that the teacher will have to put him in a team
$content = "TODO, no team, manual team creation";
$content = "TODO: no team, manual team creation";
} else if ($teamconfig->method === teamconfig::METHOD_RANDOM) {
// TODO:
// If $teamconfig.teamsmax is not reached and at least teamconfig.sizemin students are teamless, create a new team.
// Else add the user to one of the smallest teams.
// In both cases, create a LnB report matching the Moodle team.
// Then display this report
$content = "TODO, no team, random team creation";
$content = "TODO: no team, random team creation";
} else {
throw new \Exception("Unknown teaming method.");
}
}
if (reportId) {
if ($reportId) {
$data = [
'title' => $moduleinstance->name,
'description' => format_text($moduleinstance->intro, $moduleinstance->introformat, ['context' => $modulecontext]),
......
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