From bb1f9b376d22056454714d535bcd8c4e680607ae Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 12 Dec 2022 15:35:47 +1100 Subject: [PATCH] issue#45: trigger course_module_updated on dates update --- index.php | 4 ++-- lib.php | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 8b9da01..b65e221 100644 --- a/index.php +++ b/index.php @@ -182,7 +182,7 @@ $cm = $cms[$modid]; $mod = report_editdates_mod_date_extractor::make($cm->modname, $course); if ($mod) { - $mod->save_dates($cm, $datesettings); + $mod->save_new_dates($cm, $datesettings); } } @@ -199,7 +199,7 @@ $blockdatextrator = report_editdates_block_date_extractor::make($block->blockname, $course); if ($blockdatextrator) { - $blockdatextrator->save_dates($blockobj, $datesettings); + $blockdatextrator->save_new_dates($blockobj, $datesettings); } } } diff --git a/lib.php b/lib.php index f569753..28ba141 100644 --- a/lib.php +++ b/lib.php @@ -165,6 +165,22 @@ abstract public function get_settings(cm_info $cm); */ abstract public function validate_dates(cm_info $cm, array $dates); + /** + * Save the new dates for this course_module instance. + * + * Having this method final gives us a possibilities to + * add any logic (e.g. triggering events) before or after saving dates for any activity. + * + * @param \cm_info $cm the activity to save the dates for. + * @param array $dates a list of new dates. + * + * @throws \coding_exception + */ + final public function save_new_dates(cm_info $cm, array $dates) { + $this->save_dates($cm, $dates); + \core\event\course_module_updated::create_from_cm($cm)->trigger(); + } + /** * Save the new dates for this course_module instance. * @param cm_info $cm the activity to save the dates for. @@ -281,9 +297,23 @@ abstract public function get_settings(block_base $block); */ abstract public function validate_dates(block_base $block, array $dates); + /** + * Save the new dates for this block instance. + * + * Having this method final gives us a possibilities to + * add any logic (e.g. triggering events) before or after saving dates for any block. + * + * @param \block_base $block the block to save the dates for. + * @param array $dates a list of new dates. + */ + final public function save_new_dates(block_base $block, array $dates) { + $this->save_dates($block, $dates); + } + /** * Save the new dates for this course_module instance. - * @param cm_info $cm the activity to save the dates for. + * @param \block_base $block the block to save the dates for. + * @param array $dates a list of new dates. */ public function save_dates(block_base $block, array $dates) { global $DB; @@ -435,7 +465,7 @@ function report_editdates_update_dates_by_section($courseid, array $sectionnums, $modinstance = report_editdates_mod_data_date_extractor::make($cm->modname, $course); if ($modinstance) { - $modinstance->save_dates($cm, $datesettings); + $modinstance->save_new_dates($cm, $datesettings); } } $transaction->allow_commit();