-
CORDEL Yannick authoredCORDEL Yannick authored
course_format_iena_groups.php 2.92 KiB
<?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/>.
/**
*
* course_format_iena_sections
*
* @package format_iena
* @copyright 2018 Softia/Université lorraine
* @author vrignaud camille / Michaël Lebeau
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_format_iena_groups {
/** @var int id of group */
public $id;
/** @var int id of course */
public $idcourse;
/** @var string idnumber of group */
public $idnumber;
/** @var string name of group */
public $name;
/** @var string description of group */
public $description;
/** @var array<userid> */
public $listuserid;
/**
* @param $id_course
* @return array
* @throws dml_exception
*/
public function get_groups_by_id_course($idcourse) {
global $DB;
$requete = $DB->get_records_sql('SELECT id
FROM {groups}
WHERE courseid = ?',
array($idcourse));
$groups = array();
$i = 0;
foreach ($requete as $value) {
$group = new course_format_iena_groups();
$group->get_group_by_id_group($value->id);
$groups[$i] = $group;
$i++;
}
return $groups;
}
/**
* @param $id_section
* @throws dml_exception
*/
public function get_group_by_id_group($idgroup) {
global $DB;
$requete = $DB->get_record_sql('SELECT *
FROM {groups}
WHERE id = ?',
array($idgroup));
$this->id = $requete->id;
$this->idcourse = $requete->courseid;
$this->idnumber = "id_groupe".$requete->id;
$this->name = $requete->name;
$this->description = $requete->description;
$this->listuserid = $DB->get_records_sql('SELECT userid
FROM {groups_members}
WHERE groupid = ?',
array($idgroup));
}
/**
*
* @gparam $id_course
* @return array
*/
public function get_students_group($idcourse) {
global $DB;
$studentsgroup = $DB->get_records_sql('SELECT gm.userid, gm.groupid
FROM {groups} g
INNER JOIN {groups_members} gm ON gm.groupid=g.id
WHERE g.courseid = ?',
array($idcourse));
return $studentsgroup;
}
}