diff --git a/entity/block_mahara_iena_connexion.php b/entity/block_mahara_iena_connexion.php index 38f6e9ef419d16d194392d1bf2c0cb54020848a9..94db26277ba2eca7e8577e6d407baa16a92ad373 100644 --- a/entity/block_mahara_iena_connexion.php +++ b/entity/block_mahara_iena_connexion.php @@ -416,7 +416,91 @@ class block_mahara_iena_connexion } + public function createCourseGroupRequest($maharaUser, $courseShortName, $insitutionMahara){ + + // 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. + $usersTab = array(); + if ( isset($maharaUser->error) ) { + echo "<p style='color: red;'>You must have a Mahara account to do that.</p>"; + die; + } else { + array_push($usersTab,array( + 'id' => $maharaUser[0]->id, + 'username' => $maharaUser[0]->username, + 'role' => "admin", + )); + } + $courseName=block_mahara_iena_getCourseName($courseShortName); + //All params used for mahara_group_create_groups her we can add/change some lines + $params = array ( + 'groups' => + array ( + 0 => + array ( + 'name' => $courseName, + 'description' => get_string('course_group', 'block_mahara_iena') . " " . $courseName, + 'grouptype' => 'course', + 'request' => true, + 'public' => false, + 'institution' => $insitutionMahara, + 'members' => $usersTab, + 'editroles' => 'all' + ) + ) + ); + //Convert arrays into string for send to mahara api + $params = http_build_query($params); + $url = $this->create_url("mahara_group_create_groups"); + $resultPost = json_decode($this->httpPost($params, $url)); + + return $resultPost; + + } + /** + * [createCourseGroup Créé un groupe unique pour le cours] + * TODO : Refaire ça sous forme de template, c'est horrible avec le code html dans le php + * @param [object] $maharaUser [représente l'utilisateur (en l'occurrence ce sera l'enseignant)] + * @return [string] $msg [message d'erreur ou de réussite] + */ + public function createCourseGroup($maharaUser){ + global $COURSE, $CFG, $DB; + $msg=""; + // '@' is use because json_decode some time cause fatal error + $data=$this->createCourseGroupRequest($maharaUser, $COURSE->shortname, $CFG->instution_mahara); + $result = $DB->get_records_sql('SELECT * FROM {block_mahara_iena} WHERE course = ?', array($COURSE->id)); + // IF json_decode fail we stop all + if ($data == null){ + $msg = 'error'; + } else { + // if $data is array the api call is done (OK) + if (is_array($data)) { + // if the query is empty we add new line + if (!$result) { + $record = new stdClass(); + $record->course = $COURSE->id; + $record->mahara_group_id = $data[0]->id; + $record->moodle_group_id = 0; + $r = $DB->insert_record('block_mahara_iena',$record,false); + if ( substr($CFG->base_mahara, -1) !== "/" ) { + $base = $CFG->base_mahara . "/"; + } else { + $base = $CFG->base_mahara; + } + $msg = "<div class=\"alert alert-success\" role=\"alert\">" + .get_string('this_grp', 'block_mahara_iena', $CFG->mahara_alias)." " + .$COURSE->shortname." " + .get_string('just_add_grp', 'block_mahara_iena')." " + ."<a target=\"_blank\" href='".$base."group/view.php?id=".$data[0]->id."'>" + .get_string('mahara_grp', 'block_mahara_iena', $CFG->mahara_alias)."</a></div>"; + } + // If the query is not empty we leave the choice to set the "code" value + } elseif ($data->error) { + $msg = "<div class=\"alert alert-danger\" role=\"alert\"> ".get_string('error', 'block_mahara_iena').$data->error_message."</div>"; + } + } + return $msg; + } } diff --git a/mahara_iena.php b/mahara_iena.php index b692f4ca0c480118da45711a4086a7c70e86c39d..a19bca0aca60d21444c06ad022fe561057fa36b0 100644 --- a/mahara_iena.php +++ b/mahara_iena.php @@ -64,8 +64,10 @@ if (count($students) == 0) { // 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); + $message=$connexion->createCourseGroup($mahara_user); + echo $message; // 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 ( isset($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 { @@ -74,9 +76,8 @@ if (count($students) == 0) { 'username' => $mahara_user[0]->username, 'role' => "admin", )); - } - $course_name=block_mahara_iena_getCourseName($COURSE->shortname); - //All params used for mahara_group_create_groups her we can add/change some lines + }*/ + /*$course_name=block_mahara_iena_getCourseName($COURSE->shortname); $params = array ( 'groups' => array ( @@ -92,23 +93,20 @@ if (count($students) == 0) { 'editroles' => 'all' ) ) - ); + );*/ //Convert arrays into string for send to mahara api - $params = http_build_query($params); + /*$params = http_build_query($params); $function = "mahara_group_create_groups"; - $resultPost = $connexion->httpPost($params, $connexion->create_url($function)); + $resultPost = $connexion->httpPost($params, $connexion->create_url($function));*/ // '@' is use because json_decode some time cause fatal error - $data = @json_decode($resultPost); + /*$data = @json_decode($resultPost); $result = $DB->get_records_sql('SELECT * FROM {block_mahara_iena} WHERE course = ?', array($COURSE->id)); - // IF json_decode fail we stop all if ($data == null){ echo 'error'; } else { - // if $data is array the api call is done (OK) if (is_array($data)) { - // if the query is empty we add new line if (!$result) { $record = new stdClass(); $record->course = $COURSE->id; @@ -131,7 +129,8 @@ if (count($students) == 0) { } elseif ($data->error) { echo "<div class=\"alert alert-danger\" role=\"alert\"> ".get_string('error', 'block_mahara_iena').$data->error_message."</div>"; } - } + }*/ + } echo "<p><a href=\"".$CFG->wwwroot."/course/view.php?id=".$COURSE->id." \" class=\"btn btn-primary\" role=\"button\">".get_string('back_course', 'block_mahara_iena')."</a></p>"; diff --git a/mahara_iena_manage.php b/mahara_iena_manage.php index 766882bc776b667cf7b3dc276afe00ce0a142768..ce5028f6908d6282ca44868680882804da9af2ac 100644 --- a/mahara_iena_manage.php +++ b/mahara_iena_manage.php @@ -42,6 +42,7 @@ $mahara_groups=[]; foreach ($mo_ma_groups as $mo_ma_group) { + var_dump($mo_ma_group); //Si le moodle_group_id=0 c'est une espace de cours unique if($mo_ma_group->moodle_group_id ==0){ //Si le groupe est archivé on l'ajoute au tableau correspondant @@ -124,8 +125,8 @@ foreach ($mo_ma_groups as $mo_ma_group) { $tab = optional_param('t', 1, PARAM_INT); $tabs = []; -$tab1_title="Espace Compact unique"; -$tab2_title="Espaces Compact par groupes"; +$tab1_title="Espaces Compact par groupes"; +$tab2_title="Espace Compact unique"; $tab3_title="Groupes archivés"; $url="http://localhost/moodle/blocks/mahara_iena/mahara_iena_manage.php?courseid=7#tab-content"; $tabs[] = new tabobject(1, new moodle_url($url, ['t'=>1]), $tab1_title); diff --git a/templates/manage_archived_groups.mustache b/templates/manage_archived_groups.mustache index 8d82475f759e02343849fc5dc191d1cd517eaa8d..accb3ad26dd5eb422c038aa138ea0ba14def44eb 100644 --- a/templates/manage_archived_groups.mustache +++ b/templates/manage_archived_groups.mustache @@ -1,4 +1,18 @@ <div id="tab-content"> -Hello c'est pour les groupes archivés + +<div class="mahara-iena course-group"> + + {{#archived_groups}} + {{name}} + {{/archived_groups}} + {{^archived_groups}} + Vous n'avez pas de groupes Mahara archivés. + {{/archived_groups}} + +</div> + + + + </div> diff --git a/templates/manage_course_group.mustache b/templates/manage_course_group.mustache index f7c475abfc5ef64c5cebc3efd94508adcbb492b7..edf5a1ba98a0eb0f5e2bae462cfbae77a65aceb6 100644 --- a/templates/manage_course_group.mustache +++ b/templates/manage_course_group.mustache @@ -1,4 +1,18 @@ <div id="tab-content"> -Hello c'est pour le groupe unique du cours + + <div class="mahara-iena course-group"> + + {{#course_group}} + Vous avez bien un espace pour le cours : y accéder + Bouton pour l'archiver + {{/course_group}} + {{^course_group}} + Vous n'avez pas encore de groupe Mahara pour le cours. + Bouton pour créer un cours + {{/course_group}} + + </div> + + </div> diff --git a/templates/manage_groups.mustache b/templates/manage_groups.mustache index fd1b0c2be4741ab4e7380965e5b75eab0fcf8eb3..b56670e465c2324221571ee4061f1afc6a6df24c 100644 --- a/templates/manage_groups.mustache +++ b/templates/manage_groups.mustache @@ -1,24 +1,16 @@ <div id="tab-content"> <table class='table table-iena'> - <tr><th>Groupe du cours</th><th style='border-right: 2px solid #dee2e6;'>Inscription</th><th>Groupe sur {{mahara_alias}}</th><th>Inscription</th></tr> + <tr><th>Groupe du cours</th><th style='border-right: 2px solid #dee2e6;'>Inscription</th></tr> {{#course_groups}} <tr> - <td>{{bla}}<strong>{{name}}</strong> — <a href='{{url}}'>Paramètres</a>, <a href='{{members}}'>Membres</a></td> - <td style='border-right: 2px solid #dee2e6;'><button class='btn-sm btn-warning'>Désinscription</button></td> + <td><strong>{{name}}</strong> — <a href='{{url}}'>Paramètres</a>, <a href='{{members}}'>Membres</a></td> {{#mahara_group_id}} - {{#is_ma_group_member}} - <td><a target='_blank' href='{{url_link}}'>{{mahara_group_name}}</a></td> - <td><button class='btn-sm btn-warning'>Désinscription</button><br><a href='#' class='small' data-toggle='modal' data-target='#exampleModal'>Changer</a></td> - {{/is_ma_group_member}} - {{^is_ma_group_member}} - <td>{{mahara_group_name}}</a></td> - <td><button class='btn-sm btn-success'>Inscription</button><br><a href='#' class='small'>Changer</a></td> - {{/is_ma_group_member}} + <td>Ce groupe est synchronisé</td> {{/mahara_group_id}} {{^mahara_group_id}} - <td><p class='text-muted'>Créer et s'inscrire dans ce groupe sur <em>{{mahara_alias}}</em> ?</p></td> - <td><button class='btn-sm btn-primary'>Créer et m'inscrire</button><br><a href='#' class='small'>Changer</a></td> + + <td><button class='btn-sm btn-primary'>Créer et m'inscrire</button><br></td> {{/mahara_group_id}} </tr> @@ -26,30 +18,7 @@ </table> -<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> - <div class="modal-dialog" role="document"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="exampleModalLabel">Changer le groupe associé</h5> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"> - <span aria-hidden="true">×</span> - </button> - </div> - <div class="modal-body"> - <p>Sélectionner un autre groupe <em>{{mahara_alias}}</em> à associer avec ce groupe du cours.</p> - <p>Vos groupes <em>{{mahara_alias}}</em> : </p> - <select name="" id="change-group-sel" style="width: 100%;"> - <option value="test">test</option> - <option value="test">test test test test test test test test t test test test test tesst test test test test test dhjieopa jdiep jdiuepaz huipref nuipad uipeaz</option> - </select> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button> - <button type="button" class="btn btn-primary">Valider</button> - </div> - </div> - </div> -</div> + </div>