From ac4abc394e8d1f741cad57a4cca325e1df22d5a4 Mon Sep 17 00:00:00 2001 From: Myriam Delaruelle <Myriam Delaruelle@bdn-un-mdelarue.ad.univ-lorraine.fr> Date: Thu, 9 Sep 2021 10:15:51 +0200 Subject: [PATCH] refonte cron et notifications --- classes/task/sync_task_iena_message.php | 3 ++ entity/course_format_iena_cron_action.php | 56 ++++++++--------------- lib.php | 51 +-------------------- styles.css | 5 +- 4 files changed, 28 insertions(+), 87 deletions(-) diff --git a/classes/task/sync_task_iena_message.php b/classes/task/sync_task_iena_message.php index d83414e..078e166 100644 --- a/classes/task/sync_task_iena_message.php +++ b/classes/task/sync_task_iena_message.php @@ -51,10 +51,13 @@ public function execute() { global $CFG; + mtrace("IENA notifications task started"); + require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_cron_action.php'); $cron_test = new \course_format_iena_cron_action(); // echo 'send message start'; $cron_test->cron_message(); + mtrace("IENA notifications task completed"); // echo 'send message stop'; } diff --git a/entity/course_format_iena_cron_action.php b/entity/course_format_iena_cron_action.php index 5e4bd17..251c750 100644 --- a/entity/course_format_iena_cron_action.php +++ b/entity/course_format_iena_cron_action.php @@ -115,56 +115,39 @@ } /** - * @throws dml_exception - * @throws coding_exception + * Récupère le nombre de jours avant le rendu/présence pour envoyer une notification + * @return type */ public function cron_message() { global $DB, $USER, $CFG; - $sections = $DB->get_records('format_iena'); + + $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'"); foreach ($sections as $section) { - if ($section->day_before || $section->day_same || $section->day_after) { - $requete = $DB->get_record('course_sections', array('id' => $section->id_section)); - $date_notif = $this->is_notif($section); - if ($date_notif == false) { - continue; - } - $this->iena_send_message($requete, $section); - } else { + $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); + } } /** + * Check if it's time to send a notif by comparing the date withe the numbers of days before sending one in the db * @param $section - * @return bool + * @return bool true if it's time to send a notif */ private function is_notif($section) { - $date_notif = null; - $date_now = date_create(date("Y-m-d")); - if ($section->day_before && $section->nb_days_before) { - $date_notif = date('Y-m-d', strtotime($section->date_rendu . " - " . $section->nb_days_before . " days")); - $date_notif = date_create($date_notif); - if ($date_notif == $date_now) { - return true; - } + //On compare la date d'aujourd'hui avec le timestamp - daysnotifs + $date_now=date('Ymd'); + $timenotif=strtotime('-'.$section->daysnotif.' days', $section->daterendu); + $date_notif=date('Ymd', $timenotif); + if($date_notif==$date_now){ + return true; } - if ($section->day_same) { - $date_notif = date_create(date('Y-m-d', strtotime($section->date_rendu))); - if ($date_notif == $date_now) { - return true; - } - } - if ($section->day_after && $section->nb_days_after) { - $date_notif = date('Y-m-d', strtotime($section->date_rendu . " + " . $section->nb_days_after . " days")); - $date_notif = date_create($date_notif); - if ($date_notif == $date_now) { - return true; - } - } - return false; } @@ -177,7 +160,6 @@ private function iena_send_message($requete, $section) { global $DB, $CFG, $USER; - $course_ctx = context_course::instance($requete->course); //À vérifier : on récupère tous les utilisateurs, même les invités @@ -192,8 +174,8 @@ $messageContent .= "<h1>Rappel</h1>"; $messageContent .= "<h2>$course->fullname</h2>"; - $date_jour = date('d/m', strtotime($section->date_rendu)); - $date_heure = date('H:i', strtotime($section->date_rendu)); + $date_jour = date('d/m', strtotime($section->daterendu)); + $date_heure = date('H:i', strtotime($section->daterendu)); // 0 : NC // 1 : work in the classroom diff --git a/lib.php b/lib.php index 8b67a9b..6ade008 100644 --- a/lib.php +++ b/lib.php @@ -51,20 +51,6 @@ ); } if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) { - // $courseconfig = get_config('moodlecourse'); - // $max = $courseconfig->maxsections; - // if (!isset($max) || !is_numeric($max)) { - // $max = 52; - // } - // $sectionmenu = array(); - // for ($i = 0; $i <= $max; $i++) { - // $sectionmenu[$i] = "$i"; - // } - // $courseformatoptionsedit['numsections'] = array( - // 'label' => new lang_string('numberweeks'), - // 'element_type' => 'select', - // 'element_attributes' => array($sectionmenu), - // ); $choiceTab = array(); $choiceTab['1'] = get_string('yes', 'format_iena'); $choiceTab['0'] = get_string('no', 'format_iena'); @@ -130,34 +116,7 @@ ); } - if ($foreditform) { - - - $courseformatoptionsedit = array( - /*'periodduration' => array( - 'label' => 'poury', - - 'element_attributes' => array( - - array(0=>'hello'), - array(1=>'hghgh') - ), - 'element_type' => 'advcheckbox', - ), - 'presence'=>array( - 'label' => 'Modalité', - 'element_type' => 'select', - 'element_attributes' => array ( - array ( - 0 => 'Aucune', - 1 => 'Présentiel', - 2 => 'À distance', - - ) - ))*/ - ); - $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit); - } + return $courseformatoptions; } @@ -222,7 +181,7 @@ $daysarray[] = $mform->createElement('checkbox', 'selectdayscheck', 'Activer'); $mform->addGroup($daysarray, 'groupdays', 'Notification', array(' '), false); $mform->disabledIf('groupdays', 'selectdayscheck'); - + $mform->disabledIf('groupdays', 'daterenducheck2'); if($section_config['presence']){ $mform->setDefault('presence', $section_config['presence']); @@ -243,12 +202,6 @@ $mform->setDefault('selectdayscheck', "1"); } - //$mform->addElement('html', ' </div></fieldset>'); - - - //$mform->setType('numsections', PARAM_INT); - - //array_unshift($elements, $element); } return $elements; diff --git a/styles.css b/styles.css index a260f7b..7e00b87 100644 --- a/styles.css +++ b/styles.css @@ -118,6 +118,9 @@ ul.nav.navbar-nav.ml-auto { .heading-iena .right.side{ margin-top: 0; + padding: 0 6px 0; + text-align: right; + width: auto; } .iena-heading_title { background: #2d2d2d; @@ -367,7 +370,7 @@ ul.nav.navbar-nav.ml-auto { margin-right: 0; display: block; margin-bottom: 5px; - cursor: default; + cursor: default!important; } .iena-progress-legend #caption-iena .caption-status .pointer-help{ -- GitLab