#134 Renamed duplicate() function and modified behaviour
This commit is contained in:
parent
e6d9b708ed
commit
6d02679ad2
3 changed files with 14 additions and 17 deletions
|
@ -313,24 +313,13 @@ class template {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles duplicating the template.
|
* Handles copying this template into another.
|
||||||
*
|
*
|
||||||
* @param int|null $copytotemplateid The template id to copy to, null if creating a new template
|
* @param int $copytotemplateid The template id to copy to
|
||||||
*/
|
*/
|
||||||
public function duplicate($copytotemplateid = null) {
|
public function copy_to_template($copytotemplateid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (is_null($copytotemplateid)) {
|
|
||||||
// Create another template at the same level.
|
|
||||||
$template = new \stdClass();
|
|
||||||
$template->name = $this->name . ' (' . strtolower(get_string('duplicate', 'customcert')) . ')';
|
|
||||||
$template->contextid = $this->contextid;
|
|
||||||
$template->timecreated = time();
|
|
||||||
$template->timemodified = $template->timecreated;
|
|
||||||
|
|
||||||
$copytotemplateid = $DB->insert_record('customcert_templates', $template);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the pages for the template, there should always be at least one page for each template.
|
// Get the pages for the template, there should always be at least one page for each template.
|
||||||
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) {
|
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) {
|
||||||
// Loop through the pages.
|
// Loop through the pages.
|
||||||
|
|
|
@ -62,7 +62,7 @@ if ($confirm && confirm_sesskey()) {
|
||||||
$DB->delete_records('customcert_pages', array('templateid' => $template->get_id()));
|
$DB->delete_records('customcert_pages', array('templateid' => $template->get_id()));
|
||||||
|
|
||||||
// Copy the items across.
|
// Copy the items across.
|
||||||
$loadtemplate->duplicate($template->get_id());
|
$loadtemplate->copy_to_template($template->get_id());
|
||||||
|
|
||||||
// Redirect.
|
// Redirect.
|
||||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||||
|
|
|
@ -99,8 +99,16 @@ if ($tid) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplicate the template.
|
// Create another template to copy the data to.
|
||||||
$template->duplicate();
|
$newtemplate = new \stdClass();
|
||||||
|
$newtemplate->name = $template->get_name() . ' (' . strtolower(get_string('duplicate', 'customcert')) . ')';
|
||||||
|
$newtemplate->contextid = $template->get_contextid();
|
||||||
|
$newtemplate->timecreated = time();
|
||||||
|
$newtemplate->timemodified = $newtemplate->timecreated;
|
||||||
|
$newtemplateid = $DB->insert_record('customcert_templates', $newtemplate);
|
||||||
|
|
||||||
|
// Copy the data to the new template.
|
||||||
|
$template->copy_to_template($newtemplateid);
|
||||||
|
|
||||||
// Redirect back to the manage templates page.
|
// Redirect back to the manage templates page.
|
||||||
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
||||||
|
|
Loading…
Reference in a new issue