Skip to content

Commit

Permalink
Add delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen Herbert committed Dec 6, 2023
1 parent 661b6ff commit 3443ed9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions override.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@

// Check if an ID is provided
$id = optional_param('id', null, PARAM_INT);
$delete = optional_param('delete', null, PARAM_BOOL);

// Set the PAGE URL (and mandatory context). Note the ID being recorded, this is important.
$PAGE->set_context(context_system::instance());
$PAGE->set_url(new moodle_url('/admin/tool/heartbeat/override.php', ['id' => $id]));

// Instantiate a persistent object if we received an ID. Typically receiving an ID
// means that we are going to be updating an object rather than creating a new one.
$persistent = null;
$override = null;

if (!empty($id)) {
$persistent = new override($id);
$override = new override($id);
}

// Handle deletion
if (!empty($id) && !empty($delete) && $delete) {
$override->delete();
redirect(new moodle_url('/admin/tool/heartbeat/status.php'));
}

// Create the form instance. We need to use the current URL and the custom data.
$customdata = [
'persistent' => $persistent,
'persistent' => $override,
'usermodified' => $USER->id // For the hidden userid field.
];

Expand All @@ -61,12 +68,12 @@
try {
if (empty($data->id)) {
// If there is no ID we need to create a new persistent.
$persistent = new Override(0, $data);
$persistent->create();
$override = new Override(0, $data);
$override->create();
} else {
// If we have an ID we need to update the persistent.
$persistent->from_record($data);
$persistent->update();
$override->from_record($data);
$override->update();
}
\core\notification::success(get_string('changessaved'));
} catch (Exception $e) {
Expand Down

0 comments on commit 3443ed9

Please sign in to comment.