existsTemplate() public static method

Check if a template exists
public static existsTemplate ( integer $id ) : boolean
$id integer The Id of the template to check for existence.
return boolean
Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendExtensionsModel::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 = BackendExtensionsModel::getTemplate($this->id);
         // valid template?
         if (!empty($item)) {
             // delete the page
             $success = BackendExtensionsModel::deleteTemplate($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id));
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&theme=' . $item['theme'] . '&report=deleted-template&var=' . urlencode($item['label']));
         } else {
             $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
         }
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
     }
 }
Example #2
0
 /**
  * Load the record
  */
 private function loadData()
 {
     // get record
     $this->id = $this->getParameter('id', 'int');
     // validate id
     if ($this->id === null || !BackendExtensionsModel::existsTemplate($this->id)) {
         $this->redirect(BackendModel::createURLForAction('ThemeTemplates') . '&error=non-existing');
     }
     // get the record
     $this->record = BackendExtensionsModel::getTemplate($this->id);
     // unserialize
     $this->record['data'] = unserialize($this->record['data']);
     $this->names = $this->record['data']['names'];
     if (isset($this->record['data']['default_extras_' . BL::getWorkingLanguage()])) {
         $this->extras = $this->record['data']['default_extras_' . BL::getWorkingLanguage()];
     } elseif (isset($this->record['data']['default_extras'])) {
         $this->extras = $this->record['data']['default_extras'];
     }
     if (!array_key_exists('image', (array) $this->record['data'])) {
         $this->record['data']['image'] = false;
     }
     // assign
     $this->tpl->assign('template', $this->record);
     // is the template being used
     $inUse = BackendExtensionsModel::isTemplateInUse($this->id);
     // determine if deleting is allowed
     $deleteAllowed = true;
     if ($this->record['id'] == $this->get('fork.settings')->get('Pages', 'default_template')) {
         $deleteAllowed = false;
     } elseif (count(BackendExtensionsModel::getTemplates()) == 1) {
         $deleteAllowed = false;
     } elseif ($inUse) {
         $deleteAllowed = false;
     }
     // assign
     $this->tpl->assign('inUse', $inUse);
     $this->tpl->assign('allowExtensionsDeleteThemeTemplate', $deleteAllowed);
 }