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

fixed perf

parent a119c682
No related branches found
No related tags found
No related merge requests found
......@@ -60,11 +60,14 @@ class block_mahara_iena extends block_base
// for teachers
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
// if block is not instanciated, propose du create mahara group(s) for this course
if (count($result) == 0 && $is_mahara_user) {
// create one mahara group for the course
$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>';
// create one mahara group for each moodle group (need groups)
$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>';
......
......@@ -31,7 +31,7 @@ $course_ctx = context_course::instance($course->id);
$students = get_enrolled_users($course_ctx);
$usersTab = array();
$maharaUsers = $connexion->getMaharaUsers();
//Here we check by email, if the student have the same email into mahara and moodle he is add to group
if (count($students) == 0) {
......@@ -39,22 +39,41 @@ if (count($students) == 0) {
.get_string('err_no_stud', 'block_mahara_iena', $CFG->mahara_alias)
."</div>";
} else {
foreach ($maharaUsers->users as $muser) {
foreach ($students as $student) {
if ($student->email == $muser->email){
$role = "member";
//Each students is admin
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $student->id)) {
$role = "admin";
}
array_push($usersTab,array(
'id' => $muser->id,
'username' => $muser->username,
'role' => $role,
));
break;
}
}
// Build user array to pass to mahara api for group inscription
// WARNING : not efficient with to much users in mahara databases
// $maharaUsers = $connexion->getMaharaUsers();
// foreach ($maharaUsers->users as $muser) {
// foreach ($students as $student) {
// if ($student->email == $muser->email){
// $role = "member";
// // Each teacher will be mahara group admin
// if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $student->id)) {
// $role = "admin";
// }
// array_push($usersTab,array(
// 'id' => $muser->id,
// 'username' => $muser->username,
// 'role' => $role,
// ));
// break;
// }
// }
// }
// WARNING : don't try to subscribe every course user to the group with >1000 users in mahara. Juste teacher. Minus 1 user is required to create a group.
// 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;
}
//All params used for mahara_group_create_groups her we can add/change some lines
......@@ -69,8 +88,7 @@ if (count($students) == 0) {
'request' => true,
'public' => false,
'institution' => $CFG->instution_mahara,
'members' =>
$usersTab
'members' => $usersTab
)
)
);
......
......@@ -52,24 +52,39 @@ if (count($students) == 0) {
foreach ($members as $member) {
$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;
}
// 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;
}
}
......@@ -85,8 +100,7 @@ if (count($students) == 0) {
'request' => true,
'public' => false,
'institution' => $CFG->instution_mahara,
'members' =>
$usersTab
'members' => $usersTab
));
array_push($name_groups, array(
......@@ -98,7 +112,7 @@ 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.</p></div>";
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>";
} else {
$params = array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment