diff --git a/mahara_iena_groups.php b/mahara_iena_groups.php index c0fb6cf0da15e75d8555c7af12f04a3f65cf2950..d1c3e71d73d9a02d71aaef1735666a0f218cc79d 100644 --- a/mahara_iena_groups.php +++ b/mahara_iena_groups.php @@ -37,56 +37,34 @@ if (count($students) == 0) { } else { $groups = groups_get_all_groups($COURSE->id); - $maharaUsers = $connexion->getMaharaUsers(); + // $maharaUsers = $connexion->getMaharaUsers(); $mahara_groups = array(); $name_groups = array(); - foreach ($groups as $group) { + $user_group_ids = groups_get_user_groups($COURSE->id, $USER->id)[0]; - $usersTab = array(); - $members = groups_get_members($group->id); + foreach ($groups as $group) { - 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; } - foreach ($members as $member) { - - // 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; - } + $usersTab = array(); + // 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 ) { @@ -109,10 +87,8 @@ if (count($students) == 0) { )); } - // var_dump($name_groups); - // die; 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 { $params = array(