mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-57924 mod_data: Move update record code to new function
This commit is contained in:
parent
61c640c13a
commit
df0c549f88
2 changed files with 41 additions and 28 deletions
|
@ -181,34 +181,7 @@ if ($datarecord = data_submitted() and confirm_sesskey()) {
|
||||||
|
|
||||||
if ($processeddata->validated) {
|
if ($processeddata->validated) {
|
||||||
// Enough data to update the record.
|
// Enough data to update the record.
|
||||||
|
data_update_record_fields_contents($data, $record, $context, $datarecord, $processeddata);
|
||||||
// Obtain the record to be updated.
|
|
||||||
|
|
||||||
// Reset the approved flag after edit if the user does not have permission to approve their own entries.
|
|
||||||
if (!has_capability('mod/data:approve', $context)) {
|
|
||||||
$record->approved = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the parent record.
|
|
||||||
$record->timemodified = time();
|
|
||||||
$DB->update_record('data_records', $record);
|
|
||||||
|
|
||||||
// Update all content.
|
|
||||||
foreach ($processeddata->fields as $fieldname => $field) {
|
|
||||||
$field->update_content($rid, $datarecord->$fieldname, $fieldname);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger an event for updating this record.
|
|
||||||
$event = \mod_data\event\record_updated::create(array(
|
|
||||||
'objectid' => $rid,
|
|
||||||
'context' => $context,
|
|
||||||
'courseid' => $course->id,
|
|
||||||
'other' => array(
|
|
||||||
'dataid' => $data->id
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$event->add_record_snapshot('data', $data);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
$viewurl = new moodle_url('/mod/data/view.php', array(
|
$viewurl = new moodle_url('/mod/data/view.php', array(
|
||||||
'd' => $data->id,
|
'd' => $data->id,
|
||||||
|
|
|
@ -1226,3 +1226,43 @@ function data_add_fields_contents_to_new_record($data, $context, $recordid, $fie
|
||||||
$event->add_record_snapshot('data', $data);
|
$event->add_record_snapshot('data', $data);
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the fields contents of an existing record.
|
||||||
|
*
|
||||||
|
* @param stdClass $data database object
|
||||||
|
* @param stdClass $record record to update object
|
||||||
|
* @param stdClass $context context object
|
||||||
|
* @param stdClass $datarecord the submitted data
|
||||||
|
* @param stdClass $processeddata pre-processed submitted fields
|
||||||
|
* @since Moodle 3.3
|
||||||
|
*/
|
||||||
|
function data_update_record_fields_contents($data, $record, $context, $datarecord, $processeddata) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Reset the approved flag after edit if the user does not have permission to approve their own entries.
|
||||||
|
if (!has_capability('mod/data:approve', $context)) {
|
||||||
|
$record->approved = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the parent record.
|
||||||
|
$record->timemodified = time();
|
||||||
|
$DB->update_record('data_records', $record);
|
||||||
|
|
||||||
|
// Update all content.
|
||||||
|
foreach ($processeddata->fields as $fieldname => $field) {
|
||||||
|
$field->update_content($record->id, $datarecord->$fieldname, $fieldname);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger an event for updating this record.
|
||||||
|
$event = \mod_data\event\record_updated::create(array(
|
||||||
|
'objectid' => $record->id,
|
||||||
|
'context' => $context,
|
||||||
|
'courseid' => $data->course,
|
||||||
|
'other' => array(
|
||||||
|
'dataid' => $data->id
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$event->add_record_snapshot('data', $data);
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue