Skip to content

Commit bb1f9b3

Browse files
committed
issue#45: trigger course_module_updated on dates update
1 parent 2c47928 commit bb1f9b3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
$cm = $cms[$modid];
183183
$mod = report_editdates_mod_date_extractor::make($cm->modname, $course);
184184
if ($mod) {
185-
$mod->save_dates($cm, $datesettings);
185+
$mod->save_new_dates($cm, $datesettings);
186186
}
187187
}
188188

@@ -199,7 +199,7 @@
199199
$blockdatextrator =
200200
report_editdates_block_date_extractor::make($block->blockname, $course);
201201
if ($blockdatextrator) {
202-
$blockdatextrator->save_dates($blockobj, $datesettings);
202+
$blockdatextrator->save_new_dates($blockobj, $datesettings);
203203
}
204204
}
205205
}

lib.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ abstract public function get_settings(cm_info $cm);
165165
*/
166166
abstract public function validate_dates(cm_info $cm, array $dates);
167167

168+
/**
169+
* Save the new dates for this course_module instance.
170+
*
171+
* Having this method final gives us a possibilities to
172+
* add any logic (e.g. triggering events) before or after saving dates for any activity.
173+
*
174+
* @param \cm_info $cm the activity to save the dates for.
175+
* @param array $dates a list of new dates.
176+
*
177+
* @throws \coding_exception
178+
*/
179+
final public function save_new_dates(cm_info $cm, array $dates) {
180+
$this->save_dates($cm, $dates);
181+
\core\event\course_module_updated::create_from_cm($cm)->trigger();
182+
}
183+
168184
/**
169185
* Save the new dates for this course_module instance.
170186
* @param cm_info $cm the activity to save the dates for.
@@ -281,9 +297,23 @@ abstract public function get_settings(block_base $block);
281297
*/
282298
abstract public function validate_dates(block_base $block, array $dates);
283299

300+
/**
301+
* Save the new dates for this block instance.
302+
*
303+
* Having this method final gives us a possibilities to
304+
* add any logic (e.g. triggering events) before or after saving dates for any block.
305+
*
306+
* @param \block_base $block the block to save the dates for.
307+
* @param array $dates a list of new dates.
308+
*/
309+
final public function save_new_dates(block_base $block, array $dates) {
310+
$this->save_dates($block, $dates);
311+
}
312+
284313
/**
285314
* Save the new dates for this course_module instance.
286-
* @param cm_info $cm the activity to save the dates for.
315+
* @param \block_base $block the block to save the dates for.
316+
* @param array $dates a list of new dates.
287317
*/
288318
public function save_dates(block_base $block, array $dates) {
289319
global $DB;
@@ -435,7 +465,7 @@ function report_editdates_update_dates_by_section($courseid, array $sectionnums,
435465

436466
$modinstance = report_editdates_mod_data_date_extractor::make($cm->modname, $course);
437467
if ($modinstance) {
438-
$modinstance->save_dates($cm, $datesettings);
468+
$modinstance->save_new_dates($cm, $datesettings);
439469
}
440470
}
441471
$transaction->allow_commit();

0 commit comments

Comments
 (0)