From 7daf6af619a49c8cfe83c113f99e5bc4d541c730 Mon Sep 17 00:00:00 2001 From: Thomas Fradet <t.fradet8@gmail.com> Date: Thu, 20 Jun 2019 15:59:59 +0200 Subject: [PATCH] v3.7 --- block_mahara_iena.php | 8 ++++---- entity/block_mahara_iena_connexion.php | 10 +++++----- mahara_iena.php | 8 ++++---- mahara_iena_groups.php | 8 ++++---- mahara_iena_link.php | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/block_mahara_iena.php b/block_mahara_iena.php index 639e24c..1104c79 100644 --- a/block_mahara_iena.php +++ b/block_mahara_iena.php @@ -64,7 +64,7 @@ class block_mahara_iena extends block_base 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=' + $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) @@ -141,10 +141,10 @@ class block_mahara_iena extends block_base 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>"; + $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 : </p> + $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 : </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>"; @@ -170,7 +170,7 @@ class block_mahara_iena extends block_base } 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>"; + $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) ) { diff --git a/entity/block_mahara_iena_connexion.php b/entity/block_mahara_iena_connexion.php index f59fc7b..ac34f74 100644 --- a/entity/block_mahara_iena_connexion.php +++ b/entity/block_mahara_iena_connexion.php @@ -88,7 +88,7 @@ class block_mahara_iena_connexion $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; + return $res[0]['members']; } public function get_mahara_user_by_mail($email) { @@ -254,7 +254,7 @@ class block_mahara_iena_connexion */ 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 ) { + if ( isset($is_a_mahara_user->error) ) { return false; } else { return true; @@ -299,7 +299,7 @@ class block_mahara_iena_connexion $params = http_build_query($params); $url = $this->create_url("mahara_group_create_groups"); $res = json_decode($this->httpPost($params, $url)); - if ($res->error) { + if ( isset($res->error) ) { return false; } else { $record = new stdClass(); @@ -358,7 +358,7 @@ class block_mahara_iena_connexion $params = http_build_query($params); $url = $this->create_url("mahara_group_create_groups"); $res = json_decode($this->httpPost($params, $url)); - if ($res->error) { + if ( isset($res->error) ) { return false; } else { $record = new stdClass(); @@ -373,7 +373,7 @@ class block_mahara_iena_connexion $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 ) { + if ( $mo_user->email == $this->get_mahara_user_by_id($member['id'])[0]->email ) { $is_in_group = true; break; } diff --git a/mahara_iena.php b/mahara_iena.php index 488cbb5..efb9217 100644 --- a/mahara_iena.php +++ b/mahara_iena.php @@ -65,15 +65,15 @@ if (count($students) == 0) { // 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 ) { + if ( isset($mahara_user->error) ) { + echo "<p style='color: red;'>You must have a Mahara account to do that.</p>"; + die; + } else { 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 diff --git a/mahara_iena_groups.php b/mahara_iena_groups.php index d1c3e71..b780fae 100644 --- a/mahara_iena_groups.php +++ b/mahara_iena_groups.php @@ -56,15 +56,15 @@ if (count($students) == 0) { // 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 ) { + if ( isset($mahara_user->error) ) { + echo "<p style='color: red;'>You must have a Mahara account to do that.</p>"; + die; + } else { 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 ) { diff --git a/mahara_iena_link.php b/mahara_iena_link.php index 59dba10..8fd2a30 100644 --- a/mahara_iena_link.php +++ b/mahara_iena_link.php @@ -15,7 +15,7 @@ require_login($courseid, false, NULL); $content = ""; -if ( $_GET['connect_mahara'] == true ) { +if ( isset($_GET['connect_mahara']) && $_GET['connect_mahara'] == true ) { // connect the user to mahara to create his account with moodle/mahara existing link $mnetauth = get_auth_plugin('mnet'); $target_url = "/"; @@ -31,7 +31,7 @@ if ( $_GET['connect_mahara'] == true ) { //ensure user is member of it's mahara group : true if already or succeed // $all_right = $connexion->ensure_user_is_mahara_group_member($USER, $_GET['mahara_group']); - if ( $_GET['connect_direct'] == true ) { + if ( isset($_GET['connect_direct']) && $_GET['connect_direct'] == true ) { $all_right = true; } else { $all_right = $connexion->ensure_user_is_mahara_group_member_new($USER, $_GET['mahara_group'], $_GET['moodle_group']); -- GitLab