Skip to content
Snippets Groups Projects
Commit 7f7de3d1 authored by CORDEL Yannick's avatar CORDEL Yannick
Browse files

Ajout de la personnalisation du message de notification

parent 8b32ed9b
No related merge requests found
......@@ -51,14 +51,14 @@
{
global $DB, $USER, $CFG;
$sections = $DB->get_records_sql("SELECT fo1.sectionid, fo1.value daysnotif, fo2.value daterendu, fo3.value presence FROM {course_format_options} fo1 LEFT JOIN {course_format_options} fo2 ON fo1.sectionid = fo2.sectionid LEFT JOIN {course_format_options} fo3 ON fo1.sectionid = fo3.sectionid WHERE fo1.format='iena' AND fo1.name ='daysnotif' AND (fo1.value IS NOT NULL) AND fo1.value != -1 AND fo2.name='daterendu' AND fo3.name='presence'");
$sections = $DB->get_records_sql("SELECT fo1.sectionid, fo1.value daysnotif, fo2.value daterendu, fo3.value presence, fo4.value msg FROM {course_format_options} fo1 LEFT JOIN {course_format_options} fo2 ON fo1.sectionid = fo2.sectionid LEFT JOIN {course_format_options} fo3 ON fo1.sectionid = fo3.sectionid LEFT JOIN {course_format_options} fo4 ON fo1.sectionid = fo4.sectionid WHERE fo1.format='iena' AND fo1.name ='daysnotif' AND (fo1.value IS NOT NULL) AND fo1.value != -1 AND fo2.name='daterendu' AND fo3.name='presence' AND fo4.name='msg'");
foreach ($sections as $section) {
$requete = $DB->get_record('course_sections', array('id' => $section->sectionid));
$date_notif = $this->is_notif($section);
if ($date_notif == false) {
continue;
}
$this->iena_send_message($requete, $section);
$this->iena_send_message($requete, $section, $section->msg);
}
}
......@@ -86,7 +86,7 @@
* @throws coding_exception
* @throws dml_exception
*/
private function iena_send_message($requete, $section)
private function iena_send_message($requete, $section, $message)
{
global $DB, $CFG, $USER;
$course_ctx = context_course::instance($requete->course);
......@@ -94,7 +94,6 @@
//À vérifier : on récupère tous les utilisateurs, même les invités
//2. $students = get_role_users(5 , $context) (the 5 represents the role-id with role.shortname = 'student')
//
$students = get_enrolled_users($course_ctx);
$course = $DB->get_record('course', array('id' => $requete->course), '*', MUST_EXIST);
......@@ -110,9 +109,11 @@
// 1 : work in the classroom
// 2 : online work
if ( $section->presence < 2 ) {
$messageContent .= "<p>La séance de cours <strong>$requete->name</strong> aura lieu le $date_jour à $date_heure.</p>";
//$messageContent .= "<p>La séance de cours <strong>$requete->name</strong> aura lieu le $date_jour à $date_heure.</p>";
$messageContent .= "$message";
} else if ( $section->presence == 2 ) {
$messageContent .= "<p>Le travail de la séance de cours à distance <strong>$requete->name</strong> est à finir pour le $date_jour à $date_heure.</p>";
//$messageContent .= "<p>Le travail de la séance de cours à distance <strong>$requete->name</strong> est à finir pour le $date_jour à $date_heure.</p>";
$messageContent .= "$message";
}
$messageContent .= "<p>Lien vers le cours : <a href='" . $CFG->wwwroot . "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a></p>";
......@@ -145,4 +146,4 @@
}
}
\ No newline at end of file
}
......@@ -95,5 +95,8 @@ By definition an unnamed section is displayed as <strong>section [N]</strong>.';
$string['table_progress']="Tracking";
$string['displayInfos']="Display course informations";
$string['hideInfos']="Hide course informations";
$string['message_pres']="presential learning mail";
$string['message_dist']="distance learning mail";
$string['message_default_dist']="Default message distance learning";
$string['message_default_pres']="Default message presential learning";
......@@ -95,5 +95,9 @@ By definition an unnamed section is displayed as <strong>section [N]</strong>.';
$string['table_progress']="Suivi des étudiants";
$string['displayInfos']="Afficher les infos du cours";
$string['hideInfos']="Masquer les infos du cours";
$string['message_pres']="Message présentiel";
$string['message_dist']="Message distanciel";
$string['message_default_dist']="message par défaut distance";
$string['message_default_pres']="message par defaut pres";
......@@ -100,7 +100,6 @@
if ($courseformatoptions === false) {
$courseformatoptions = array(
'presence'=>array(
'label'=>"Présence",
'type'=>PARAM_INT
......@@ -112,8 +111,11 @@
'daysnotif'=>array(
'label'=>"Notification",
'type'=>PARAM_INT
)
),
'msg'=>array(
'label'=>"Message",
'type'=>PARAM_RAW
),
);
}
......@@ -134,105 +136,132 @@
public function create_edit_form_elements(&$mform, $forsection = false) {
global $COURSE;
global $PAGE;
$elements = parent::create_edit_form_elements($mform, $forsection);
if ($forsection) {
$mform->removeElement('presence', false);
$mform->removeElement('daterendu', false);
$mform->removeElement('daysnotif', false);
$mform->removeElement('msg', false);
$sectionclass = new stdClass();
$sectionclass->id=optional_param('id', 0, PARAM_INT);
$section_config=$this->get_format_options($sectionclass);
$mform->addElement('header', 'nameforyourheaderelement', 'Format hybride');
$radioarray=array();
//Modalité
$radioarray=array();
$radioarray[] = $mform->createElement('radio', 'presence', '', 'Distance', 2);
$radioarray[] = $mform->createElement('radio', 'presence', '', 'Présentiel', 1);
$radioarray[] = $mform->createElement('radio', 'presence', '', 'Aucune', 0);
$mform->addGroup($radioarray, 'modalite', 'Modalité', array(' '), false);
$mform->addHelpButton('modalite', 'modalite', 'format_iena');
//Date cours à distance
$datearray=array();
$datearray[] = $mform->createElement('date_time_selector', 'daterendu', '');
$datearray[] = $mform->createElement('checkbox', 'daterenducheck', 'Activer');
$mform->addGroup($datearray, 'groupdate', 'Date d\'échéance', array(' '), false);
$mform->disabledIf('groupdate', 'daterenducheck');
//On montre le groupe seulement si à distance
$mform->hideIf('groupdate', 'presence', 'neq', 2);
//$mform->hideIf('groupdate', 'id_presence_2', 'notchecked');
//Date cours présentiel
$datearray=array();
$datearray[] = $mform->createElement('date_time_selector', 'daterendu2', '');
$datearray[] = $mform->createElement('checkbox', 'daterenducheck2', 'Activer');
$mform->addGroup($datearray, 'groupdate2', 'Date du cours', array(' '), false);
$mform->disabledIf('groupdate2', 'daterenducheck2');
//On montre le groupe si pas distance
$mform->hideIf('groupdate2', 'presence', 'eq', 2);
//On montre le groupe si à présentiel
$mform->hideIf('groupdate2', 'presence', 'neq', 1);
//On cache cet élément si on n'est pas à distance
//Notification distanciel
$daysarray=array();
$days=array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
$daysarray[]=$mform->createElement('html', '<div class="form-group fitem">');
$daysarray[] = $mform->createElement('select', 'daysnotif', "jours avant la séance", $days);
$daysarray[]=$mform->createElement('html', ' <span id="days-text" style="margin:0 20px 0 5px;">jours avant la séance</span>');
$daysarray[]=$mform->createElement('html', '</div>');
$daysarray[]=$mform->createElement('html', ' <span id="days-text">jours avant la séance</span>');
$daysarray[] = $mform->createElement('checkbox', 'selectdayscheck', 'Activer');
$mform->addGroup($daysarray, 'groupdays', 'Notification', array(' '), false);
$mform->disabledIf('groupdays', 'selectdayscheck');
$mform->hideIf('groupdays', 'daterenducheck');
$mform->disabledIf('groupdays', 'daterenducheck');
$mform->hideIf('groupdays', 'presence', 'neq', 2);
$mform->hideIf('groupdays', 'daterenducheck');
$daysarray=array();
$daysarray[]=$mform->createElement('html', '<div class="form-group fitem">');
//Notification présentiel
$daysarray=array();
$daysarray[] = $mform->createElement('select', 'daysnotif2', "jours avant le rendu", $days);
$daysarray[]=$mform->createElement('html', ' <span id="days-text" style="margin:0 20px 0 5px;">jours avant le rendu</span>');
$daysarray[]=$mform->createElement('html', '</div>');
$daysarray[]= $mform->createElement('html', ' <span id="days-text">jours avant le rendu</span>');
$daysarray[] = $mform->createElement('checkbox', 'selectdayscheck2', 'Activer');
$mform->addGroup($daysarray, 'groupdays2', 'Notification', array(' '), false);
$mform->disabledIf('groupdays2', 'selectdayscheck2');
$mform->disabledIf('groupdays2', 'daterenducheck2');
$mform->hideIf('groupdays2', 'presence', 'neq', 1);
$mform->hideIf('groupdays2', 'daterenducheck2');
$mform->hideIf('groupdays2', 'presence', 'eq', 2);
//on ne peut pas activer des notifs s'il n'y a pas de date de rendu/date de cours
//Message présentiel
//$mform->addElement('textarea', 'msg_pres', 'Message présentiel');
//$mform->disabledIf('msg_pres', 'selectdayscheck2');
//$mform->hideIf('msg_pres', 'presence', 'neq', 1);
//$mform->hideIf('msg_pres', 'selectdayscheck2');
//$mform->hideIf('msg_pres', 'daterenducheck2');
$msg_pres_grp=array();
$msg_pres_grp[] = $mform->createElement('editor', 'msg_pres', get_string('message_pres', 'format_iena'));
$mform->setType('msg_pres', PARAM_RAW);
$mform->setDefault('msg_pres', array('text'=>get_string('message_default_pres', 'format_iena')));
$mform->addGroup($msg_pres_grp, 'msg_pres_grp', get_string('message_pres', 'format_iena'), ' ', false);
//$mform->addRule('msg_pres_grp', get_string('err_minlength'), 'minlength', 50, 'client');
$mform->hideIf('msg_pres_grp', 'presence', 'neq', 1);
$mform->hideIf('msg_pres_grp', 'selectdayscheck2');
$mform->hideIf('msg_pres_grp', 'daterenducheck2');
//Message distanciel
//$mform->addElement('textarea', 'msg_dist', 'Message distanciel');
//$mform->disabledIf('msg_dist', 'selectdayscheck');
//$mform->hideIf('msg_dist', 'presence', 'neq', 2);
//$mform->hideIf('msg_dist', 'selectdayscheck');
//$mform->hideIf('msg_dist', 'daterenducheck');
$msg_dist_grp=array();
$msg_dist_grp[] = $mform->createElement('editor', 'msg_dist', get_string('message_dist', 'format_iena'));
$mform->setType('msg_dist', PARAM_RAW);
$mform->setDefault('msg_dist', array('text'=>get_string('message_default_dist', 'format_iena')));
$mform->addGroup($msg_dist_grp, 'msg_dist_grp', get_string('message_dist', 'format_iena'), ' ', false);
$mform->hideIf('msg_dist_grp', 'presence', 'neq', 2);
$mform->hideIf('msg_dist_grp', 'selectdayscheck');
$mform->hideIf('msg_dist_grp', 'daterenducheck');
//on ne peut pas activer des notifs s'il n'y a pas de date de rendu/date de cours
//on prérempli le formulaire si des données existent en BDD
if($section_config['presence']){
$mform->setDefault('presence', $section_config['presence']);
}
if($section_config['daterendu']){
//cas distance
if(isset($section_config['presence']) && $section_config['presence']==2){
$mform->setDefault('daterendu', $section_config['daterendu']);
$mform->setDefault('daterenducheck', "1");
if(isset($section_config['daysnotif']) && $section_config['daysnotif'] > -1){
$mform->setDefault('daysnotif', $section_config['daysnotif']);
$mform->setDefault('selectdayscheck', "1");
//$mform->setDefault('msg_dist', $section_config['msg']);
$mform->setDefault('msg_dist', array('text'=>$section_config['msg']));
}
}
else if(isset($section_config['presence'])){
//cas présence
else if(isset($section_config['presence']) && $section_config['presence']==1){
$mform->setDefault('daterendu2', $section_config['daterendu']);
$mform->setDefault('daterenducheck2', "1");
}
}
if(isset($section_config['daysnotif']) && $section_config['daysnotif'] > -1){
//Si on est à distance : il faut activer daysnotif et selectdayscheck
if(isset($section_config['presence']) && $section_config['presence']==2){
$mform->setDefault('daysnotif', $section_config['daysnotif']);
$mform->setDefault('selectdayscheck', "1");
}
//si on est en présence, il faut activer daysnotif2 et selectdayscheck2
else if(isset($section_config['presence']) && $section_config['presence']==1){
$mform->setDefault('daysnotif2', $section_config['daysnotif']);
$mform->setDefault('selectdayscheck2', "1");
}
if(isset($section_config['daysnotif']) && $section_config['daysnotif'] > -1){
$mform->setDefault('daysnotif2', $section_config['daysnotif']);
$mform->setDefault('selectdayscheck2', "1");
//$mform->setDefault('msg_pres', $section_config['msg']);
$mform->setDefault('msg_pres', array('text'=>$section_config['msg']));
}
}
}
}
return $elements;
......@@ -263,19 +292,24 @@
if(!isset($data['daterenducheck']) && !isset($data['daterenducheck2'])){
if(array_key_exists('daterendu', $section_config) && !empty($section_config['daterendu'])){
$data['daterendu']=NULL;
}
else{
} else{
unset($data['daterendu']);
}
}
else if(isset($data['daterenducheck2'])){
} else if(isset($data['daterenducheck2'])){
$data['daterendu']=$data['daterendu2'];
}
if (isset($data['daysnotif']) && ($data['presence']==2)){
$data['msg']=$data['msg_dist']['text'];
} else if (isset($data['daysnotif2']) && ($data['presence']==1)){
$data['msg']=$data['msg_pres']['text'];
}
/* De base daysnotifs est vide et daysnotifs2 n'existe pas */
// Le système de notification n'a jamais été activé et on veut l'activer
// Si c'est en présence
if(isset($data['daysnotif2']) && isset($data['selectdayscheck2']) && $data['presence'] == 1){
$data['daysnotif']=$data["daysnotif2"];
}
......@@ -283,6 +317,7 @@
if(empty($data['daysnotif']) || (!isset($data['selectdayscheck']) && !isset($data['selectdayscheck2']))){
if(array_key_exists('daysnotif', $section_config) && $section_config['daysnotif']>-1){
$data['daysnotif']=-1;
$data['msg']=NULL;
}
else{
unset($data['daysnotif']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment