Maintenance Gitlab - Jeudi 09 Décembre 2021 à partir de 10h - Mises à jour de sécurité

Commit 9ecc8654 authored by Thomas Fradet's avatar Thomas Fradet
Browse files

Initial commit

parents
# Block Groups : Moodle - Mahara
This Moodle plugin create group(s) in Mahara, based on Moodle course users. You can either create one Mahara group per Moodle course user groups.
## Authors
- Vrignaud Camille *(cvrignaud@softia.fr)*
- Lebeau Michaël *(mlebeau@softia.fr)*
- Thomas Fradet *(thomas.fradet@univ-lorraine.fr)*
## Compatibility and support
The plugin was tested in Moodle 3.3, 3.4 and 3.5.
For more information contact : support_git@softia.fr or iena-contact@univ-lorraine.fr.
## Installation
The plugin installs with the classical way but require a specific configuration to link moodle and mahara.
Installation :
- Trough the Moodle Administration section "Plugin" -> Add plugin
- Add block in edit mode
Configuration :
???
## Functionalities
By clicking a button in this block, editing teachers can create one mahara group within every student enrolled in the moodle course will become members of the mahara group. Moodle course enrolled users with the role of "teacher" and "editingteacher" will have the role of "admin" in the mahara group, other will be simple members.
After group creation, every user enrolled in this moodle cours will be able to see and click a button witch grand access to the mahara group previously created.
Alternatively, if they are user groups within the moodle cours, teacher can choose to create one mahara group per moodle course group. In this case, students and teachers will be enroll in the mahara group witch correspond to they moodle group. Warning : if one user is in two groups in moodle course, only the first will be considerated by this plugin to grand access to mahara group.
Usecase : place 3 groups with 1 teacher and n students in a moodle course and create in one click 3 mahara groups where each teacher will be able to administrate his mahara group and each student will be able to access the right group in mahara, based on the moodle group.
## Warning
This plugin is currently under development.
This plugin does not support groupments (moodle group of group) in addition to the creation of a mahara group for each moodle group. If you have groupments in moodle, choose to create on mahara group for all the moodle course participants or place the groupes in groupment 0.
In the case of generating one mahara group for each moodle group, if one user is in two groups in moodle course, only the first will be considerated by this plugin to grand access to mahara group.
<?php
class block_mahara_iena extends block_base
{
public function init()
{
global $CFG;
$this->title = get_string('title_plugin', 'block_mahara_iena', $CFG->mahara_alias);
}
function instance_allow_multiple() {
return false;
}
/**
* Set the applicable formats for this block to all
* @return array
*/
function applicable_formats() {
return array('course' => true);
}
/**
* Allow the user to configure a block instance
* @return bool Returns true
*/
function instance_allow_config() {
return true;
}
function has_config() {
return true;
}
public function get_content() {
global $CFG;
global $COURSE;
global $USER;
global $DB;
if ($this->content !== null) {
return $this->content;
}
if (empty($this->config)) {
$this->config = new stdClass();
}
$this->content = new stdClass();
// check if user is a mahara user and can be or become a member of a mahara group
require_once ('entity/block_mahara_iena_connexion.php');
$connexion = new block_mahara_iena_connexion($CFG->wstoken,$CFG->base_mahara);
$is_mahara_user = $connexion->ensure_user_exists_in_mahara($USER);
$result = $DB->get_records_sql('SELECT * FROM {block_mahara_iena} WHERE course = ?', array($COURSE->id));
// var_dump($result);
// for teachers
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
if (count($result) == 0 && $is_mahara_user) {
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/mahara_iena/mahara_iena.php?courseid='
. $COURSE->id . '" class="btn btn-block btn-primary iena-btn-big">' . get_string('create_group', 'block_mahara_iena', $CFG->mahara_alias) . '</a><p class="text-muted">Créer un groupe dans '.$CFG->mahara_alias.'.</p>';
$groups = groups_get_all_groups($COURSE->id);
if ( $groups == null) {
$this->content->text .= '<button type="button" class="btn btn-block btn-primary iena-btn-big" disabled >' . get_string('create_groups_groups', 'block_mahara_iena', $CFG->mahara_alias) . '</button><p class="text-muted text-warning">Créer un groupe dans '.$CFG->mahara_alias.' pour chaque groupe du cours. <strong>Les groupes doivent exister dans le cours.</strong></p>';
} else {
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_groups.php?courseid='
. $COURSE->id . '" class="btn btn-block btn-primary iena-btn-big">' . get_string('create_groups_groups', 'block_mahara_iena', $CFG->mahara_alias) . '</a><p class="text-muted">Créer un groupe dans '.$CFG->mahara_alias.' pour chaque groupe du cours. Les groupes doivent exister dans le cours et ne pas tous être vides.</p>';
}
} elseif ( count($result) == 0 && ! $is_mahara_user ) {
// connect and create account in mahara for teacher before he can create groupes
$this->content->text .= '<a target="_blank" href="'.$CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_link.php?courseid=' . $COURSE->id.'&connect_mahara=true" class="btn btn-block btn-success iena-btn-big">Connexion à '.$CFG->base_mahara.'</a><p class="text-muted">Vous devez vous connecter à '.$CFG->base_mahara.' pour y initialiser votre compte avant d\'utiliser ce block.</p>';
// $this->content->text .= "<div class=\"alert alert-warning\">Vous devez avoir un compte sur <a href=\"$CFG->base_mahara\" target=\"_blank\">$CFG->base_mahara</a> avant de pouvoir créer des groupes sur cette plateforme.</div>";
}
}
// for teachers and students
if (count($result) == 0) {
$this->content->text .= '<button type="button" class="btn btn-block btn-primary iena-btn-big" disabled >'.get_string('acces_group', 'block_mahara_iena', $CFG->mahara_alias).'</button><p class="text-muted">Aucun groupe '.$CFG->mahara_alias.' n\'a encore été créé par l\'enseignant.</p>';
}
elseif ($is_mahara_user) {
// check if they are one mahara group per moodle group of juste one group and set link
// user will be placed or will access the first group he has (no multiple group access)
$user_groups = groups_get_user_groups($COURSE->id, $USER->id);
$has_groups = false;
foreach ($result as $group) {
if ( $group->moodle_group_id != 0 ) {
$has_groups = true;
break;
}
}
// if moodle group is not 0, their is multiple mahara groupes ($has_groups)
// if ($has_groups) {
// $result_for_group = $DB->get_records_sql('SELECT * FROM {block_mahara_iena} WHERE course = ? AND moodle_group_id = ?', array($COURSE->id, $user_groups[0][0]));
// }
// if their is one mahara group per moodle group and student have no group, display decline message
if ( $has_groups && count($user_groups[0]) == 0 ) {
$this->content->text .= '<button type="button" class="btn btn-block btn-primary iena-btn-big" disabled >Accéder au groupe sur '.$CFG->mahara_alias."</button><p class=\"text-muted\">Vous n'avez pas accès à un groupe sur <a href=\"$CFG->base_mahara\" target=\"_blank\">$CFG->base_mahara</a> car vous n'avez été placé dans aucun groupe de ce cours.</p>";
} elseif ( $has_groups ) {
// $mahara_group_id = reset($result_for_group)->mahara_group_id;
// if it's null, group will be created
// during connexion in mahara_iena_link.php, script ensure user is member of it's mahara group
// $this->content->text .= '<a target="_blank" href="'.$CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_link.php?courseid=' . $COURSE->id.'&mahara_group='.$mahara_group_id.'" class="btn btn-block btn-primary iena-btn-big">Accéder au groupe sur '.$CFG->mahara_alias.'</a>';
/* accumule les liens vers le linker */
$ma_links = [];
/* pour chaque groupe moodle de l'utilisateur */
foreach ($user_groups[0] as $user_group) {
$mo_ma_exists = false;
/* pour chaque association existante */
foreach ($result as $mo_ma) {
/* si le groupe moodle est associé à un groupe mahara */
if ( $mo_ma->moodle_group_id == $user_group ) {
/* stocker le nom du groupe moodle et l'id du groupe mahara */
$ma_links[] = ["mo_gr_name" => groups_get_group_name($user_group), "mo_gr_id" => $user_group, "ma_group_id" => $mo_ma->mahara_group_id];
$mo_ma_exists = true;
}
}
/* si aucune association n'existe déjà */
if ( $mo_ma_exists == false ) {
/* stocker le nom du groupe moodle et un id vide du groupe mahara : le linker créera le groupe */
$ma_links[] = ["mo_gr_name" => groups_get_group_name($user_group), "mo_gr_id" => $user_group, "ma_group_id" => ""];
}
}
/* afficher la liste des groupes s'il y en a (on est déjà dans une condition où il y en a toujours en théorie) */
if ( count($ma_links) != 0 ) {
if ( count($ma_links) == 1 ) {
/* si il n'y a qu'un groupe, on affiche un bouton */
$this->content->text .= "<a target='_blank' class='btn btn-block btn-primary iena-btn-big' href='$CFG->wwwroot/blocks/mahara_iena/mahara_iena_link.php?courseid=$COURSE->id&mahara_group=" . $ma_links[0]['ma_group_id'] . "&moodle_group=" . $ma_links[0]['mo_gr_id'] . "'>Aller à mon groupe sur ".$CFG->mahara_alias."</a><p class='alert alert-secondary'>Mon groupe : ".$ma_links[0]['mo_gr_name'].".</p>";
} elseif ( count($ma_links) > 1 && count($ma_links) <= 5 ) {
/* si il y a entre 2 et 5 groupes inclus, on affiche une liste */
$this->content->text .= "<p style='border-left: 2px solid #1177d1;padding-left: 0.5rem;font-weight: 600;margin-bottom: 0.5rem;'>Accéder à mon groupe sur $CFG->mahara_alias&nbsp;: </p>
<ul class='iena-dashed p-l-0'>";
foreach ($ma_links as $ma_link) {
$this->content->text .= "<li>Groupe : <a target='_blank' href='$CFG->wwwroot/blocks/mahara_iena/mahara_iena_link.php?courseid=$COURSE->id&mahara_group=" . $ma_link['ma_group_id'] . "&moodle_group=" . $ma_link['mo_gr_id'] . "'>" . $ma_link['mo_gr_name'] . "</a></li>";
}
$this->content->text .= "</ul>";
} elseif ( count($ma_links) > 5 ) {
/* si il y a plus de 5 groupes, on affiche une liste pour 3 d'entre-eux puis un lien pour déplier le reste de la liste en JS */
$this->content->text .= "<p style='border-left: 2px solid #1177d1;padding-left: 0.5rem;font-weight: 600;margin-bottom: 0.5rem;'>Accéder à mon groupe sur $CFG->mahara_alias&nbsp;: </p>
<ul class='iena-dashed p-l-0' style='margin-bottom: 0.3rem;'>";
$i = 0;
foreach ($ma_links as $ma_link) {
if ( $i <= 2 ) {
$this->content->text .= "<li>Groupe : <a target='_blank' href='$CFG->wwwroot/blocks/mahara_iena/mahara_iena_link.php?courseid=$COURSE->id&mahara_group=" . $ma_link['ma_group_id'] . "&moodle_group=" . $ma_link['mo_gr_id'] . "'>" . $ma_link['mo_gr_name'] . "</a></li>";
} else {
$this->content->text .= "<li class='d-none iena-ma_group'>Groupe : <a target='_blank' href='$CFG->wwwroot/blocks/mahara_iena/mahara_iena_link.php?courseid=$COURSE->id&mahara_group=" . $ma_link['ma_group_id'] . "&moodle_group=" . $ma_link['mo_gr_id'] . "'>" . $ma_link['mo_gr_name'] . "</a></li>";
}
$i++;
}
$this->content->text .= "</ul>";
$this->content->text .= "<a href='#' style='margin-bottom: 1rem;display: inline-block;' onclick='iena_ma_group(event)'>Voir toute la liste</a><script type='text/javascript'>function iena_ma_group(e){e.preventDefault();var lis=document.querySelectorAll('.iena-ma_group');for(var i=0;i<lis.length;i++){if(lis[i].getAttribute('class')=='d-none iena-ma_group'){lis[i].setAttribute('class', 'd-inherit iena-ma_group')}else{lis[i].setAttribute('class', 'd-none iena-ma_group')}}}</script>";
}
}
} else {
/* quand un seul groupe mahara pour tout le cours ($hasgroup à false) */
$this->content->text .= "<a target='_blank' class='btn btn-block btn-primary iena-btn-big' href='$CFG->wwwroot/blocks/mahara_iena/mahara_iena_link.php?courseid=$COURSE->id&mahara_group=" . reset($result)->mahara_group_id . "&moodle_group=nogroups'>Aller au groupe sur ".$CFG->mahara_alias."</a>";
}
/* permet à l'enseignant de créer tous les groupes mahara en fonction des groupes moodle existant à un temps t. Ca n'inscrit pas les utilisateurs à part lui. */
if ( $has_groups && has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id) ) {
$this->content->text .= '<a href="'.$CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_groups_all.php?courseid=' . $COURSE->id . '&create_all_groups=1" class="btn btn-block btn-warning iena-btn-big">Créer tous les groupes</a><p class="text-muted">Créer manuellement tous les groupes sur '.$CFG->mahara_alias.' liés à ce cours et s\'y inscrire en tant qu\'enseignant.</p>';
// $this->content->text .= '<a href="'.$CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_groups_all.php?courseid=' . $COURSE->id . '" class="btn btn-block btn-warning iena-btn-big">S\'inscrire dans tous les groupes</a><p class="text-muted">S\'inscrire en tant qu\'enseignant dans tous les groupes '.$CFG->mahara_alias.' liés à ce cours.</p>';
/* POUR PLUS TARD : liste les groupes moodle liés à mahara qui n'existent plus dans moodle */
// foreach ($result as $record) {
// var_dump($record->moodle_group_id);
// var_dump(groups_group_exists($record->moodle_group_id)); /* @return bool */
// }
}
}
else {
/* si n'est pas membre de mahara (car sinon quand on essaie d'inscrire dans un groupe par l'api un user qui n'existe pas ça bug). Si le groupe existe déjà, l'utilisateur y est inscrit. */
$this->content->text .= '<a onclick="ma_register_click()" target="_blank" href="'.$CFG->wwwroot . '/blocks/mahara_iena/mahara_iena_link.php?courseid=' . $COURSE->id.'&connect_mahara=true" class="btn btn-block btn-success iena-btn-big">Créer son compte sur '.$CFG->mahara_alias . '</a><p class="alert alert-warning mt-2">Pour accéder au groupe '.$CFG->mahara_alias.' lié à ce cours, vous devez d\'abord vous inscrire sur '.$CFG->mahara_alias.' en cliquant sur le bouton ci-dessus, puis revenir sur cette page.</p>';
/* recharge la page quand on y revient après avoir cliqué sur le bouton pour aller sur mahara se créer un compte */
$this->content->text .= '<script type="text/javascript">var ma_register_clicked = false;function ma_register_click(){ma_register_clicked = true;}window.addEventListener("focus",function(){if(ma_register_clicked===true){location.reload();}});</script>';
}
return $this->content;
}
}
?>
<?php
$capabilities = array(
'block/mahara_iena:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/mahara_iena:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
?>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/mahara_iena/db" VERSION="20180710" COMMENT="XMLDB file for Moodle blocks/mahara_iena"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="block_mahara_iena" COMMENT="Table du block mahara_iena">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="course" TYPE="int" LENGTH="8" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="mahara_group_id" TYPE="int" LENGTH="8" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="moodle_group_id" TYPE="int" LENGTH="8" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
<?php
if (!defined('MOODLE_INTERNAL'))
die('Direct access to this script is forbidden.');
class block_mahara_iena_edit_form extends block_edit_form {
function specific_definition($mform) {
$mform->addElement('header','configheader', get_string('blocksettings', 'block'));
}
}
?>
<?php
/**
* Created by PhpStorm.
* User: softia
* Date: 11/04/18
* Time: 16:23
*/
class block_mahara_iena_connexion
{
public $wstoken;
public $base;
public $url;
/**
* block_mahara_iena_connexion constructor.
* @param $wstoken
* @param $url
*/
public function __construct($wstoken, $base)
{
$this->wstoken = $wstoken;
if ( substr($base, -1) !== "/" ) {
$base = $base . "/";
}
$this->base = $base . "webservice/rest/server.php";
}
public function httpPost($params, $url)
{
$ch = curl_init();
$postdata = htmlspecialchars_decode(urldecode($params)); //Il faut absolument faire ça car il faut enlever les ;amp ect ...
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
function httpGet($url)
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// curl_setopt($ch,CURLOPT_HEADER, false);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
public function create_url($function){
return $this->base."?wstoken=".$this->wstoken."&wsfunction=".$function."&alt=json";
}
public function getMaharaGroups(){
$getMaharaGroupes = "mahara_group_get_groups_by_id";
$url = $this->create_url($getMaharaGroupes);
return json_decode($this->httpGet($url));
}
public function getMaharaUsers(){
$getMaharaUsers = "mahara_user_get_users";
$url = $this->create_url($getMaharaUsers);
return json_decode($this->httpGet($url));
}
/**
* Return list of member of a mahara group
* @param $id: mahara group id
* @return mahara group members or error
*/
public function get_mahara_users_in_mahara_group_by_id($id) {
$params = array (
'groups' =>
array (
0 =>
array (
'id' => $id
)
)
);
$params = http_build_query($params);
$mahara_group_get_groups_by_id = "mahara_group_get_groups_by_id";
$url = $this->create_url($mahara_group_get_groups_by_id);
$res = json_decode($this->httpPost($params, $url), true);
return $res[0]->members;
}
public function get_mahara_user_by_mail($email) {
// var_dump($email);
$params = array (
'users' =>
array (
0 =>
array (
'email' => $email
)
)
);
$params = http_build_query($params);
$mahara_user_get_users_by_id = "mahara_user_get_users_by_id";
$url = $this->create_url($mahara_user_get_users_by_id);
return json_decode($this->httpPost($params, $url));
}
/**
* Get a mahara user by id
* @param $ma_user_id: mahara user id
* @return mahara user
*/
public function get_mahara_user_by_id($ma_user_id) {
$params = array (
'users' =>
array (
0 =>
array (
'id' => $ma_user_id
)
)
);
$params = http_build_query($params);
$mahara_user_get_users_by_id = "mahara_user_get_users_by_id";
$url = $this->create_url($mahara_user_get_users_by_id);
return json_decode($this->httpPost($params, $url));
}
/**
* Return role for mahara group based on role in moodle course : teacher and editingteacher will be admin and other will be member
* @param $mo_user_id: moodle user id
* @return string: role (admin or member)
*/
public function get_user_role($mo_user_id) {
global $COURSE;
$course_ctx = context_course::instance($COURSE->id);
$course_roles = get_user_roles($course_ctx, $mo_user_id, false);
$role = "member";
foreach ($course_roles as $course_role) {
if ($course_role->shortname == "teacher" || $course_role->shortname == "editingteacher") {
$role = "admin";
break;
}
}
return $role;
}
/**
* Add a user in a mahara group
* @param $ma_user_id: mahara user id
* @param $mo_user: moodle user object
* @param $ma_group_id: mahara group id
* @return boolean: succeed or error
*/
public function mahara_group_update_group_members($ma_user_id, $ma_group_id, $mo_user) {
$user = new stdClass();
$user->id = $ma_user_id;
$user->role = $this->get_user_role($mo_user->id);
$user->action = "add";
$group = new stdClass();
$group->id = $ma_group_id;
$group->members = array(
0 => $user
);
$params = array (
'groups' =>
array (
0 => $group
)
);
$params = http_build_query($params);
$url = $this->create_url("mahara_group_update_group_members");
$res = json_decode($this->httpPost($params, $url));
if ($res == null) {
return true;
} else {
return false;
}
}
/**
* block_mahara_iena_connexion constructor.
* @param $mo_user: moodle user object
* @param $ma_group_id: mahara group id
*/
public function ensure_user_is_mahara_group_member($mo_user, $ma_group_id) {
global $COURSE, $CFG, $DB;
// if ma_group_id is null, mahara group does not exist : create it and add the user to this new mahara group
// else, check if user is member of it's mahara group or add him to this mahara group
if ( $ma_group_id == null || $ma_group_id == "" ) {
$mo_user_groups = groups_get_user_groups($COURSE->id, $mo_user->id);
$mo_user_group_id = $mo_user_groups[0][0]; // first groupment, first group
$mo_group_name = groups_get_group_name($mo_user_group_id);
$group = new stdClass();
$group->name = get_string('course_group', 'block_mahara_iena') . " " . $COURSE->shortname . " – " . $mo_group_name;
$group->description = get_string('course_group', 'block_mahara_iena') . " " . $COURSE->shortname . " – " . $mo_group_name;
$group->grouptype = 'course';
$group->request = true;
$group->public = false;
$group->institution = $CFG->instution_mahara;
$user = new stdClass();
$user->id = $this->get_mahara_user_by_mail($mo_user->email)[0]->id;
$user->username = $mo_user->username;
$user->role = $this->get_user_role($mo_user->id);
$group->members = array(
0 => $user
);
$params = array (
'groups' =>
array (
0 => $group
)
);
$params = http_build_query($params);
$url = $this->create_url("mahara_group_create_groups");
$res = json_decode($this->httpPost($params, $url));
if ($res->error) {
return false;
} else {
$record = new stdClass();
$record->course = $COURSE->id;
$record->mahara_group_id = $res[0]->id;
$record->moodle_group_id = $mo_user_group_id;
$DB->insert_records('block_mahara_iena', array( 0 => $record ), false);
return true;
}
} else {
$ma_group_members = $this->get_mahara_users_in_mahara_group_by_id($ma_group_id);
$is_in_group = false;
foreach ($ma_group_members as $member) {
if ( $mo_user->email == $this->get_mahara_user_by_id($member->id)[0]->email ) {
$is_in_group = true;
break;
}
}
if ( ! $is_in_group ) {
$ma_user = $this->get_mahara_user_by_mail($mo_user->email);
return $this->mahara_group_update_group_members($ma_user[0]->id, $ma_group_id, $mo_user->id);
} else {
return true;
}
}
}
/**
* block_mahara_iena_connexion constructor.
* @param $user: moodle user object
* @return boolean: this user is a mahara user (comparison with email)
*/
public function ensure_user_exists_in_mahara($user) {
$is_a_mahara_user = $this->get_mahara_user_by_mail($user->email);
if ( $is_a_mahara_user->error ) {
return false;
} else {
return true;
}
}
/**
* Fonction duplique un bout de ensure_user_is_mahara_group_member et est utilisée pour créer des groupes mahara à partir de groupes moodle par le fichier mahara_iena_groups_all avec le get create_all_groups pour créer des groupes mahara pour chaque groupe moodle existant. Cette fonction n'est disponible que pour l'enseignant.
* @param $mo_group : le groupe moodle à créer dans mahara avec au moins les clefs id et le name
* @param $mo_user : l'utilisateur à inscrire dans le groupe (il en faut forcément un), dans ce cas, l'enseignant qui a demandé la création de tous les groupes.
*/
public function create_mahara_group($mo_group, $mo_user) {
global $COURSE, $CFG, $DB;
// $mo_user_groups = groups_get_user_groups($COURSE->id, $mo_user->id);
// $mo_user_group_id = $mo_user_groups[0][0];
$mo_user_group_id = $mo_group->id;
// $mo_group_name = groups_get_group_name($mo_user_group_id);
$mo_group_name = $mo_group->name;
$group = new stdClass();
$group->name = get_string('course_group', 'block_mahara_iena') . " " . $COURSE->shortname . " – " . $mo_group_name;
$group->description = get_string('course_group', 'block_mahara_iena') . " " . $COURSE->shortname . " – " . $mo_group_name;
$group->grouptype = 'course';
$group->request = true;
$group->public = false;
$group->institution = $CFG->instution_mahara;
$user = new stdClass();
$user->id = $this->get_mahara_user_by_mail($mo_user->email)[0]->id;
$user->username = $mo_user->username;
$user->role = $this->get_user_role($mo_user->id);
$group->members = array(
0 => $user
);
$params = array (
'groups' =>
array (
0 => $group
)
);