From d848bc73e8be6ff625c4330ded016c7e04d7bd29 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sat, 20 Feb 2016 17:12:32 +0800 Subject: [PATCH] Keep action links consistent --- classes/edit_form.php | 16 ++++--- edit.php | 102 +++++++++++++++++++++--------------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/classes/edit_form.php b/classes/edit_form.php index 4cdb961..7578a97 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -197,12 +197,12 @@ class edit_form extends \moodleform { // Place the ordering arrows. // Only display the move up arrow if it is not the first. if ($page->pagenumber > 1) { - $url = new \moodle_url($editlink, $editlinkparams + array('moveup' => $page->id)); + $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmoveup', 'aid' => $page->id)); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup')))); } // Only display the move down arrow if it is not the last. if ($page->pagenumber < $this->numpages) { - $url = new \moodle_url($editlink, $editlinkparams + array('movedown' => $page->id)); + $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmovedown', 'aid' => $page->id)); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown')))); } @@ -256,20 +256,22 @@ class edit_form extends \moodleform { 'action' => 'edit')); $icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit'))); // Link to delete the element. - $link = new \moodle_url($editlink, $editlinkparams + array('id' => $element->id, - 'deleteelement' => $element->id)); + $link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement', + 'aid' => $element->id)); $icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete'))); // Now display any moving arrows if they are needed. if ($numelements > 1) { // Only display the move up arrow if it is not the first. $moveicons = ''; if ($element->sequence > 1) { - $url = new \moodle_url($editlink, $editlinkparams + array('emoveup' => $element->id)); + $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emoveup', + 'aid' => $element->id)); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup'))); } // Only display the move down arrow if it is not the last. if ($element->sequence < $numelements) { - $url = new \moodle_url($editlink, $editlinkparams + array('emovedown' => $element->id)); + $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emovedown', + 'aid' => $element->id)); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown'))); } $icons .= $moveicons; @@ -289,7 +291,7 @@ class edit_form extends \moodleform { // Add option to delete this page if there is more than one page. if ($this->numpages > 1) { // Link to delete the element. - $deletelink = new \moodle_url($editlink, $editlinkparams + array('deletepage' => $page->id)); + $deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id)); $deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'), array('href' => $deletelink->out(false), 'class' => 'deletebutton')); $mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton'))); } diff --git a/edit.php b/edit.php index 0284f47..134675f 100644 --- a/edit.php +++ b/edit.php @@ -25,12 +25,10 @@ require_once('../../config.php'); $tid = optional_param('tid', 0, PARAM_INT); -$moveup = optional_param('moveup', 0, PARAM_INT); -$movedown = optional_param('movedown', 0, PARAM_INT); -$emoveup = optional_param('emoveup', 0, PARAM_INT); -$emovedown = optional_param('emovedown', 0, PARAM_INT); -$deleteelement = optional_param('deleteelement', 0, PARAM_INT); -$deletepage = optional_param('deletepage', 0, PARAM_INT); +$action = optional_param('action', '', PARAM_ALPHA); +if ($action) { + $actionid = required_param('aid', PARAM_INT); +} $confirm = optional_param('confirm', 0, PARAM_INT); // Edit an existing template. @@ -78,51 +76,53 @@ if ($tid && $DB->count_records('customcert_templates', array('contextid' => CONT $deleting = false; if ($tid) { - // Check if they are moving a custom certificate page. - if ((!empty($moveup)) || (!empty($movedown))) { - // Check if we are moving a page up. - if (!empty($moveup)) { - $template->move_page_up($moveup); - } else { // Must be moving a page down. - $template->move_page_down($movedown); - } - } else if ((!empty($emoveup)) || (!empty($emovedown))) { // Check if we are moving a custom certificate element. - // Check if we are moving an element up. - if (!empty($emoveup)) { - $template->move_element_up($emoveup); - } else { // Must be moving a element down. - $template->move_element_down($emovedown); - } - } else if (!empty($deletepage)) { // Check if we are deleting a page. - if (!empty($confirm)) { // Check they have confirmed the deletion. - $template->delete_page($deletepage); - } else { - // Set deletion flag to true. - $deleting = true; - // Create the message. - $message = get_string('deletepageconfirm', 'customcert'); - // Create the link options. - $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); - $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, - 'deletepage' => $deletepage, - 'confirm' => 1, - 'sesskey' => sesskey())); - } - } else if (!empty($deleteelement)) { // Check if we are deleting an element. - if (!empty($confirm)) { // Check they have confirmed the deletion. - $template->delete_element($deleteelement); - } else { - // Set deletion flag to true. - $deleting = true; - // Create the message. - $message = get_string('deleteelementconfirm', 'customcert'); - // Create the link options. - $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); - $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, - 'deleteelement' => $deleteelement, - 'confirm' => 1, - 'sesskey' => sesskey())); - } + switch ($action) { + case 'pmoveup' : + $template->move_page_up($actionid); + break; + case 'pmovedown' : + $template->move_page_down($actionid); + break; + case 'emoveup' : + $template->move_element_up($actionid); + break; + case 'emovedown' : + $template->move_element_down($actionid); + break; + case 'deletepage' : + if (!empty($confirm)) { // Check they have confirmed the deletion. + $template->delete_page($actionid); + } else { + // Set deletion flag to true. + $deleting = true; + // Create the message. + $message = get_string('deletepageconfirm', 'customcert'); + // Create the link options. + $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, + 'action' => 'deletepage', + 'aid' => $actionid, + 'confirm' => 1, + 'sesskey' => sesskey())); + } + break; + case 'deleteelement' : + if (!empty($confirm)) { // Check they have confirmed the deletion. + $template->delete_element($actionid); + } else { + // Set deletion flag to true. + $deleting = true; + // Create the message. + $message = get_string('deleteelementconfirm', 'customcert'); + // Create the link options. + $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, + 'action' => 'deleteelement', + 'aid' => $actionid, + 'confirm' => 1, + 'sesskey' => sesskey())); + } + break; } }