Added the ability to change the order the customcert elements are displayed
Note: I did not create a db/upgrade.php script to add the new database column as this module should not be currently used by anyone.
This commit is contained in:
parent
18480d6050
commit
0bc2e186e6
5 changed files with 59 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="mod/customcert/db" VERSION="20130221" COMMENT="XMLDB file for Moodle mod/customcert"
|
<XMLDB PATH="mod/customcert/db" VERSION="20130412" COMMENT="XMLDB file for Moodle mod/customcert"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||||
>
|
>
|
||||||
|
@ -59,6 +59,7 @@
|
||||||
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
||||||
<FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
<FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
||||||
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
||||||
|
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" ENUM="false"/>
|
||||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
|
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
|
|
18
edit.php
18
edit.php
|
@ -32,6 +32,8 @@ require_once($CFG->dirroot . '/mod/customcert/elements/element.class.php');
|
||||||
$cmid = required_param('cmid', PARAM_INT);
|
$cmid = required_param('cmid', PARAM_INT);
|
||||||
$moveup = optional_param('moveup', 0, PARAM_INT);
|
$moveup = optional_param('moveup', 0, PARAM_INT);
|
||||||
$movedown = optional_param('movedown', 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);
|
$deleteelement = optional_param('deleteelement', 0, PARAM_INT);
|
||||||
$deletepage = optional_param('deletepage', 0, PARAM_INT);
|
$deletepage = optional_param('deletepage', 0, PARAM_INT);
|
||||||
$confirm = optional_param('confirm', 0, PARAM_INT);
|
$confirm = optional_param('confirm', 0, PARAM_INT);
|
||||||
|
@ -62,6 +64,22 @@ if ((!empty($moveup)) || (!empty($movedown))) {
|
||||||
$DB->set_field('customcert_pages', 'pagenumber', $swapcertpage->pagenumber, array('id' => $movecertpage->id));
|
$DB->set_field('customcert_pages', 'pagenumber', $swapcertpage->pagenumber, array('id' => $movecertpage->id));
|
||||||
$DB->set_field('customcert_pages', 'pagenumber', $movecertpage->pagenumber, array('id' => $swapcertpage->id));
|
$DB->set_field('customcert_pages', 'pagenumber', $movecertpage->pagenumber, array('id' => $swapcertpage->id));
|
||||||
}
|
}
|
||||||
|
} 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)) {
|
||||||
|
if ($movecertelement = $DB->get_record('customcert_elements', array('id' => $emoveup))) {
|
||||||
|
$swapcertelement = $DB->get_record('customcert_elements', array('sequence' => $movecertelement->sequence - 1));
|
||||||
|
}
|
||||||
|
} else { // Must be moving a element down.
|
||||||
|
if ($movecertelement = $DB->get_record('customcert_elements', array('id' => $emovedown))) {
|
||||||
|
$swapcertelement = $DB->get_record('customcert_elements', array('sequence' => $movecertelement->sequence + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check that there is an element to move, and an element to swap it with.
|
||||||
|
if ($swapcertelement && $movecertelement) {
|
||||||
|
$DB->set_field('customcert_elements', 'sequence', $swapcertelement->sequence, array('id' => $movecertelement->id));
|
||||||
|
$DB->set_field('customcert_elements', 'sequence', $movecertelement->sequence, array('id' => $swapcertelement->id));
|
||||||
|
}
|
||||||
} else if ((!empty($deletepage)) && (!empty($confirm))) { // Check if we are deleting a page.
|
} else if ((!empty($deletepage)) && (!empty($confirm))) { // Check if we are deleting a page.
|
||||||
customcert_delete_page($deletepage);
|
customcert_delete_page($deletepage);
|
||||||
} else if ((!empty($deleteelement)) && (!empty($confirm))) { // Check if we are deleting an element.
|
} else if ((!empty($deleteelement)) && (!empty($confirm))) { // Check if we are deleting an element.
|
||||||
|
|
|
@ -240,7 +240,9 @@ class mod_customcert_edit_form extends moodleform {
|
||||||
// Check that this page is not a newly created one with no data in the database.
|
// Check that this page is not a newly created one with no data in the database.
|
||||||
if (!is_null($page)) {
|
if (!is_null($page)) {
|
||||||
// Check if there are elements to add.
|
// Check if there are elements to add.
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'id ASC')) {
|
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $pageid), 'sequence ASC')) {
|
||||||
|
// Get the total number of elements.
|
||||||
|
$numelements = count($elements);
|
||||||
// Loop through and add the ones present.
|
// Loop through and add the ones present.
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$classfile = "{$CFG->dirroot}/mod/customcert/elements/{$element->element}/lib.php";
|
$classfile = "{$CFG->dirroot}/mod/customcert/elements/{$element->element}/lib.php";
|
||||||
|
@ -250,6 +252,16 @@ class mod_customcert_edit_form extends moodleform {
|
||||||
// Add element header.
|
// Add element header.
|
||||||
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
|
$mform->addElement('header', 'headerelement_' . $element->id, get_string('page', 'customcert', $pagenum) . " - " .
|
||||||
get_string('pluginname', 'customcertelement_' . $element->element));
|
get_string('pluginname', 'customcertelement_' . $element->element));
|
||||||
|
// Only display the move up arrow if it is not the first.
|
||||||
|
if ($element->sequence > 1) {
|
||||||
|
$url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $this->_customdata['cmid'], 'emoveup' => $element->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 ($element->sequence < $numelements) {
|
||||||
|
$url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $this->_customdata['cmid'], 'emovedown' => $element->id));
|
||||||
|
$mform->addElement('html', $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown'))));
|
||||||
|
}
|
||||||
// Add the page number to the element so we can use within the element.
|
// Add the page number to the element so we can use within the element.
|
||||||
$element->pagenum = $pagenum;
|
$element->pagenum = $pagenum;
|
||||||
// Get the classname.
|
// Get the classname.
|
||||||
|
|
|
@ -62,11 +62,36 @@ class customcert_element_base {
|
||||||
$data->colour = '#000000';
|
$data->colour = '#000000';
|
||||||
$data->posx = '250';
|
$data->posx = '250';
|
||||||
$data->posy = '250';
|
$data->posy = '250';
|
||||||
|
$data->sequence = customcert_element_base::get_element_sequence($pageid);
|
||||||
$data->timecreated = time();
|
$data->timecreated = time();
|
||||||
|
|
||||||
$DB->insert_record('customcert_elements', $data);
|
$DB->insert_record('customcert_elements', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the sequence on a specified customcert page for a
|
||||||
|
* newly created element.
|
||||||
|
*
|
||||||
|
* @param int $pageid the id of the page we are adding this element to
|
||||||
|
* @return int the element number
|
||||||
|
*/
|
||||||
|
public static function get_element_sequence($pageid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Set the sequence of the element we are creating.
|
||||||
|
$sequence = 1;
|
||||||
|
// Check if there already elements that exist, if so, overwrite value.
|
||||||
|
$sql = "SELECT MAX(sequence) as maxsequence
|
||||||
|
FROM {customcert_elements}
|
||||||
|
WHERE pageid = :id";
|
||||||
|
// Get the current max sequence on this page and add 1 to get the new sequence.
|
||||||
|
if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) {
|
||||||
|
$sequence = $maxseq->maxsequence + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sequence;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
* Can be overridden if more functionality is needed.
|
* Can be overridden if more functionality is needed.
|
||||||
|
|
2
lib.php
2
lib.php
|
@ -767,7 +767,7 @@ function customcert_generate_pdf($customcert, $userid) {
|
||||||
// Add the page to the PDF.
|
// Add the page to the PDF.
|
||||||
$pdf->AddPage($page->orientation, array($page->width, $page->height));
|
$pdf->AddPage($page->orientation, array($page->width, $page->height));
|
||||||
// Get the elements for the page.
|
// Get the elements for the page.
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id))) {
|
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
||||||
// Loop through and display.
|
// Loop through and display.
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
// Check that the standard class file exists.
|
// Check that the standard class file exists.
|
||||||
|
|
Loading…
Reference in a new issue