Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue#45: trigger course_module_updated on dates update #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
34 changes: 32 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no real reason to do have this new method for for the block instance. It's done for consistency.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure what you mean by consistence here. Consistency with what?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we added save_new_dates method to modules related class, hence I'd like to keep it consistent for blocks as well. But technically there is no reason to do so as we don't trigger anything for the blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If even Cameron does not understand what is giong on here, then you need to improve the comment (instead of answering in github comment which will neve be seen again.)

You also need to write your pull request to explain what you are doing and why. Yiou may konw, but I am not telepathic.

Copy link
Author

@dmitriim dmitriim Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated a pull request description to explain what's happening in the code. As well as added comment to explain a new method a little bit more. Please have a look and let me know if that's better now.

$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;
Expand Down Expand Up @@ -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();
Expand Down