Skip to content

Commit

Permalink
Add updated events for reposition elements (#599)
Browse files Browse the repository at this point in the history
When using drag and drop to reposition elements trigger element_updated
and template_updated events on save.
  • Loading branch information
leonstr authored and mdjnelson committed Jan 30, 2024
1 parent 28533f4 commit 9209286
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
$element->posx = $value->posx;
$element->posy = $value->posy;
$DB->update_record('customcert_elements', $element);
\mod_customcert\event\element_updated::create_from_id($element->id, $template)->trigger();
}

\mod_customcert\event\template_updated::create_from_template($template)->trigger();
17 changes: 17 additions & 0 deletions classes/event/element_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ public static function create_from_element(\mod_customcert\element $element): el
return self::create($data);
}

/**
* Create instance of event for the specified element.
*
* @param int $elementid ID of the element.
* @param \mod_customcert\template $template Template containing the above
* element.
* @return element_updated
*/
public static function create_from_id(int $elementid, \mod_customcert\template $template): element_updated {
$data = [
'contextid' => $template->get_contextid(),
'objectid' => $elementid,
];

return self::create($data);
}

/**
* Returns relevant URL.
* @return \moodle_url
Expand Down

0 comments on commit 9209286

Please sign in to comment.