/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendPagesModel::existsTemplate($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init var $success = false; // get template (we need the title) $item = BackendPagesModel::getTemplate($this->id); // valid template? if (!empty($item)) { // delete the page $success = BackendPagesModel::deleteTemplate($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id)); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); } // page is deleted, so redirect to the overview if ($success) { $this->redirect(BackendModel::createURLForAction('templates') . '&theme=' . $item['theme'] . '&report=deleted-template&var=' . urlencode($item['label'])); } else { $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing'); } } else { $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing'); } }
/** * Load the record * * @return void */ private function loadData() { // get record $this->id = $this->getParameter('id', 'int'); // validate id if ($this->id === null || !BackendPagesModel::existsTemplate($this->id)) { $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing'); } // get the record $this->record = BackendPagesModel::getTemplate($this->id); // unserialize $this->record['data'] = unserialize($this->record['data']); // assign $this->tpl->assign('template', $this->record); // is the template being used $inUse = BackendPagesModel::isTemplateInUse($this->id); // determine if deleting is allowed $deleteAllowed = true; if ($this->record['id'] == BackendModel::getModuleSetting($this->getModule(), 'default_template')) { $deleteAllowed = false; } elseif (count(BackendPagesModel::getTemplates()) == 1) { $deleteAllowed = false; } elseif ($inUse) { $deleteAllowed = false; } // assign $this->tpl->assign('inUse', $inUse); $this->tpl->assign('deleteAllowed', $deleteAllowed); }