Commit 72794fbf authored by Francois Gannaz's avatar Francois Gannaz
Browse files

draft of team creation

parent 92887093
<?php
/**
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
*/
namespace mod_labnbook\ar;
/* @var $DB \moodle_database */
/**
* AR class that map the "labnbook_teamconfig" table in the DB.
*/
class teamconfig
{
const METHOD_STUDENTCHOICE = 0;
const METHOD_TEACHERCHOICE = 1;
const METHOD_RANDOM = 2;
public $id;
public $instanceid;
public $groupid;
public $method;
public $sizeopt;
public $sizemin;
public $sizemax;
public $teamsmax;
public $starttime;
public $endtime;
public $sendteacher;
public $sendteam;
public $sendclass;
public $sendld;
public $sendmission;
public $saveld;
public $importld;
public $nameprefix;
public $timemodified;
public function __construct(array $record = [])
{
foreach (['id', 'instanceid', 'groupid', 'method', 'sizeopt', 'sizemin', 'sizemax', 'teamsmax', 'importld', 'starttime', 'endtime', 'timemodified'] as $field) {
if (empty($record[$field])) {
$this->$field = null;
} else {
$this->$field = (int) $record[$field];
}
}
foreach (['sendteacher', 'sendteam', 'sendclass', 'sendld', 'senmission', 'saveld'] as $field) {
if (empty($record[$field])) {
$this->$field = true;
} else {
$this->$field = (boolean) $record[$field];
}
}
$this->nameprefix = empty($record['nameprefix']) ? '' : (string) $record['nameprefix'];
}
public static function find(array $criteria)
{
global $DB;
$record = $DB->get_record("labnbook_teamconfig", $criteria, '*');
return new self($record);
}
public static function findForGroups($instanceid, array $groupids)
{
global $DB;
$sql = "SELECT * "
. "FROM {labnbook_teamconfig} tc"
. " WHERE tc.instanceid = ?";
$params = [(int) $instanceid];
if ($groupids) {
$sql .= " AND (groupID IN (" . join(",", array_fill(0, count($groupids) - 1, "?")) . ") OR groupid IS NULL)";
foreach ($groupids as $id) {
$params[] = $id;
}
$sql .= " ORDER BY (groupid IS NULL) ASC";
} else {
$sql .= " AND groupid IS NULL";
}
$sql .= " LIMIT 1";
$record = $DB->get_record_sql($sql, $params);
if ($record) {
return new teamconfig((array) $record);
} else {
return null;
}
}
}
......@@ -8,7 +8,6 @@ require_once(__DIR__.'/lib.php');
$reportId = optional_param('reportId', 0, PARAM_INT);
$lnb = session::load();
var_dump($reportId);
if ($reportId) {
header("Location: " . $lnb->createAuthenticatedUrl('/pages/report.php?idr=' . $reportId));
exit();
......
......@@ -22,7 +22,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/* @var $DB moodle_database */
use \mod_labnbook_session as session;
use mod_labnbook\ar\teamconfig;
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
......@@ -65,21 +68,43 @@ $PAGE->set_title(format_string($moduleinstance->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($modulecontext);
echo $OUTPUT->header();
$lnb = session::load();
if (has_capability('moodle/course:manageactivities', context_course::instance($course->id))) {
// editing teacher view
// ...
$content = "TODO";
} else {
// student view
$reportId = $lnb->getReportId($cm->id);
$data = [
'title' => $moduleinstance->name,
'description' => format_text($moduleinstance->intro, $moduleinstance->introformat, ['context' => $modulecontext]),
'url' => new moodle_url('/mod/labnbook/redirect.php', ['reportId' => $reportId]),
];
echo $OUTPUT->render_from_template('mod_labnbook/view_student', $data);
if (empty($reportId)) {
$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');
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";
} 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";
}
}
if (reportId) {
$data = [
'title' => $moduleinstance->name,
'description' => format_text($moduleinstance->intro, $moduleinstance->introformat, ['context' => $modulecontext]),
'url' => new moodle_url('/mod/labnbook/redirect.php', ['reportId' => $reportId]),
];
$content = $OUTPUT->render_from_template('mod_labnbook/view_student', $data);
}
}
echo $OUTPUT->header();
echo $content;
echo $OUTPUT->footer();
Supports Markdown
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