Huge refactor

1) Every certificate is a template. Before a user would create a certificate then had
the option to save it as a template. This could potentially be chaotic with numerous
users creating templates, making the template system a mess. Now, rather than creating
a certificate first, then saving it as a template, you are always creating a template.
Each template is associated with a context, so depending on where you are creating it
the context is different. This means users in the CONTEXT_MODULE context are creating
a template specific to that module, where as a user creating a template in the
CONTEXT_SYSTEM context would be creating a general template that can be used by others.
This meant we can remove the 'customcert_template_*' db tables. Yay - no duplicated
tables.
2) Created new helper classes and moved functionality there.
3) Moved files to classes/ for autoloading.
4) General tidy up.
This commit is contained in:
Mark Nelson 2016-02-16 17:03:34 +08:00
parent 54584a113c
commit 43d20c0d1b
59 changed files with 2028 additions and 1815 deletions

View file

@ -40,7 +40,7 @@ class element extends \mod_customcert\element {
/**
* This function renders the form elements when adding a customcert element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function render_form_elements($mform) {
// Get the possible date options.
@ -129,7 +129,7 @@ class element extends \mod_customcert\element {
// Ensure that a date has been set.
if (!empty($date)) {
parent::render_content($pdf, $this->get_date_format_string($date, $dateformat));
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_date_format_string($date, $dateformat));
}
}
@ -138,6 +138,8 @@ class element extends \mod_customcert\element {
*
* This function is used to render the element when we are using the
* drag and drop interface to position it.
*
* @return string the html
*/
public function render_html() {
// If there is no element data, we have nothing to display.
@ -149,13 +151,13 @@ class element extends \mod_customcert\element {
$dateinfo = json_decode($this->element->data);
$dateformat = $dateinfo->dateformat;
return parent::render_html_content($this->get_date_format_string(time(), $dateformat));
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
}
/**
* Sets the data on the form when editing an element.
*
* @param \mod_customcert_edit_element_form $mform the edit_form instance
* @param \mod_customcert\edit_element_form $mform the edit_form instance
*/
public function definition_after_data($mform) {
// Set the item and format for this element.
@ -209,7 +211,7 @@ class element extends \mod_customcert\element {
* @param string $dateformat
* @return string
*/
private function get_date_format_string($date, $dateformat) {
protected function get_date_format_string($date, $dateformat) {
switch ($dateformat) {
case 1:
$certificatedate = userdate($date, '%B %d, %Y');
@ -238,7 +240,7 @@ class element extends \mod_customcert\element {
* @param int $day the day of the month
* @return string the suffix.
*/
private function get_ordinal_number_suffix($day) {
protected function get_ordinal_number_suffix($day) {
if (!in_array(($day % 100), array(11, 12, 13))) {
switch ($day % 10) {
// Handle 1st, 2nd, 3rd.