Skip to content
Snippets Groups Projects
Commit 386eaa6d authored by Thomas Fradet's avatar Thomas Fradet
Browse files

fixed multi group creation

parent f4921dae
No related branches found
No related tags found
No related merge requests found
...@@ -37,56 +37,34 @@ if (count($students) == 0) { ...@@ -37,56 +37,34 @@ if (count($students) == 0) {
} else { } else {
$groups = groups_get_all_groups($COURSE->id); $groups = groups_get_all_groups($COURSE->id);
$maharaUsers = $connexion->getMaharaUsers(); // $maharaUsers = $connexion->getMaharaUsers();
$mahara_groups = array(); $mahara_groups = array();
$name_groups = array(); $name_groups = array();
foreach ($groups as $group) { $user_group_ids = groups_get_user_groups($COURSE->id, $USER->id)[0];
$usersTab = array(); foreach ($groups as $group) {
$members = groups_get_members($group->id);
if ( count($members) == 0 ) { // if current group id is not in USER group ids : skip this group
if ( !in_array($group->id, $user_group_ids) ) {
continue; continue;
} }
foreach ($members as $member) { $usersTab = array();
// WARNING : not efficient with too big mahara user database (>1000)
// $course_roles = get_user_roles($course_ctx, $member->id, false);
// $role = "member";
// foreach ($course_roles as $course_role) {
// if ($course_role->shortname == "teacher" || $course_role->shortname == "editingteacher") {
// $role = "admin";
// break;
// }
// }
// foreach ($maharaUsers->users as $muser) {
// if ($member->email == $muser->email){
// array_push($usersTab,array(
// 'id' => $muser->id,
// 'username' => $muser->username,
// 'role' => $role,
// ));
// break;
// }
// }
// Subscribe only the teacher to the mahara group because of lake of efficiency with too big mahara user database (>1000)
// get mahara user by mail (teacher)
$mahara_user = $connexion->get_mahara_user_by_mail($USER->email);
// if user is not a mahara user, there will be an error : it's not supposed to be because mahara account is checked before to have a button to go in this page but... but.
if ( !$mahara_user->error ) {
array_push($usersTab,array(
'id' => $mahara_user[0]->id,
'username' => $mahara_user[0]->username,
'role' => "admin",
));
} else {
echo "<p style='color: red;'>You must have a Mahara account to do that.</p>";
die;
}
// Subscribe only the teacher to the mahara group because of lake of efficiency with too big mahara user database (>1000)
// get mahara user by mail (teacher)
$mahara_user = $connexion->get_mahara_user_by_mail($USER->email);
// if user is not a mahara user, there will be an error : it's not supposed to be because mahara account is checked before to have a button to go in this page but... but.
if ( !$mahara_user->error ) {
array_push($usersTab,array(
'id' => $mahara_user[0]->id,
'username' => $mahara_user[0]->username,
'role' => "admin",
));
} else {
echo "<p style='color: red;'>You must have a Mahara account to do that.</p>";
die;
} }
if ( count($usersTab) == 0 ) { if ( count($usersTab) == 0 ) {
...@@ -109,10 +87,8 @@ if (count($students) == 0) { ...@@ -109,10 +87,8 @@ if (count($students) == 0) {
)); ));
} }
// var_dump($name_groups);
// die;
if ( count($mahara_groups) == 0 ) { if ( count($mahara_groups) == 0 ) {
echo "<div class=\"alert alert-warning\" role=\"alert\"><p><strong>Erreur : tous les groupes du cours sont vides. </strong></p><p>Pour utiliser cette fonctionnalité, il faut au préalable créer des groupes dans le cours et y ajouter des étudiants ou des enseignants. prout</p></div>"; echo "<div class=\"alert alert-warning\" role=\"alert\"><p><strong>Erreur : vous devez faire partie d'au moins un groupe de ce cours. Inscrivez-vous dans un groupe puis recommencez.</p></div>";
} else { } else {
$params = array( $params = array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment