MDL-49463 tool_lp: New form base class for persistent models
This commit is contained in:
@@ -28,6 +28,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
|
||||
|
||||
$framework = null;
|
||||
if (!empty($id)) {
|
||||
// Always use the context from the framework when it exists.
|
||||
$framework = new \tool_lp\competency_framework($id);
|
||||
@@ -43,7 +44,6 @@ require_capability('tool/lp:competencymanage', $context);
|
||||
// We keep the original context in the URLs, so that we remain in the same context.
|
||||
$url = new moodle_url("/admin/tool/lp/editcompetencyframework.php", array('id' => $id, 'pagecontextid' => $pagecontextid));
|
||||
$frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
|
||||
$formurl = new moodle_url("/admin/tool/lp/editcompetencyframework.php", array('pagecontextid' => $pagecontextid));
|
||||
|
||||
$title = get_string('competencies', 'tool_lp');
|
||||
if (empty($id)) {
|
||||
@@ -60,7 +60,7 @@ $PAGE->set_url($url);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
$output = $PAGE->get_renderer('tool_lp');
|
||||
$form = new \tool_lp\form\competency_framework($formurl->out(false), array('id' => $id, 'context' => $context));
|
||||
$form = new \tool_lp\form\competency_framework($url->out(false), array('context' => $context, 'persistent' => $framework));
|
||||
|
||||
if ($form->is_cancelled()) {
|
||||
redirect($frameworksurl);
|
||||
@@ -71,19 +71,14 @@ echo $output->heading($pagetitle);
|
||||
|
||||
$data = $form->get_data();
|
||||
if ($data) {
|
||||
// Save the changes and continue back to the manage page.
|
||||
// Massage the editor data.
|
||||
$data->descriptionformat = $data->description['format'];
|
||||
$data->description = $data->description['text'];
|
||||
require_sesskey();
|
||||
if (empty($data->id)) {
|
||||
// Create new framework.
|
||||
require_sesskey();
|
||||
$data->contextid = $context->id;
|
||||
\tool_lp\api::create_framework($data);
|
||||
echo $output->notification(get_string('competencyframeworkcreated', 'tool_lp'), 'notifysuccess');
|
||||
echo $output->continue_button($frameworksurl);
|
||||
} else {
|
||||
require_sesskey();
|
||||
\tool_lp\api::update_framework($data);
|
||||
echo $output->notification(get_string('competencyframeworkupdated', 'tool_lp'), 'notifysuccess');
|
||||
echo $output->continue_button($frameworksurl);
|
||||
|
||||
Reference in New Issue
Block a user