Backend\Modules\Extensions\Engine\Model::getTemplates PHP Method

getTemplates() public static method

Get templates
public static getTemplates ( string $theme = null ) : array
$theme string The theme we want to fetch the templates from.
return array
    public static function getTemplates($theme = null)
    {
        $db = BackendModel::getContainer()->get('database');
        $theme = \SpoonFilter::getValue((string) $theme, null, BackendModel::get('fork.settings')->get('Core', 'theme', 'Core'));
        $templates = (array) $db->getRecords('SELECT i.id, i.label, i.path, i.data
            FROM themes_templates AS i
            WHERE i.theme = ? AND i.active = ?
            ORDER BY i.label ASC', array($theme, 'Y'), 'id');
        $extras = (array) self::getExtras();
        $half = (int) ceil(count($templates) / 2);
        $i = 0;
        foreach ($templates as &$row) {
            $row['data'] = unserialize($row['data']);
            $row['has_block'] = false;
            // reset
            if (isset($row['data']['default_extras_' . BL::getWorkingLanguage()])) {
                $row['data']['default_extras'] = $row['data']['default_extras_' . BL::getWorkingLanguage()];
            }
            // any extras?
            if (isset($row['data']['default_extras'])) {
                foreach ($row['data']['default_extras'] as $value) {
                    if (\SpoonFilter::isInteger($value) && isset($extras[$value]) && $extras[$value]['type'] == 'block') {
                        $row['has_block'] = true;
                    }
                }
            }
            // validate
            if (!isset($row['data']['format'])) {
                throw new Exception('Invalid template-format.');
            }
            $row['html'] = self::buildTemplateHTML($row['data']['format']);
            $row['htmlLarge'] = self::buildTemplateHTML($row['data']['format'], true);
            $row['json'] = json_encode($row);
            if ($i == $half) {
                $row['break'] = true;
            }
            ++$i;
        }
        return (array) $templates;
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // load record
     $this->loadData();
     // add js
     $this->header->addJS('jstree/jquery.tree.js', null, false);
     $this->header->addJS('jstree/lib/jquery.cookie.js', null, false);
     $this->header->addJS('jstree/plugins/jquery.tree.cookie.js', null, false);
     // add css
     $this->header->addCSS('/src/Backend/Modules/Pages/Js/jstree/themes/fork/style.css', null, true);
     // get the templates
     $this->templates = BackendExtensionsModel::getTemplates();
     // set the default template as checked
     $this->templates[$this->record['template_id']]['checked'] = true;
     // homepage?
     if ($this->id == 1) {
         // loop and set disabled state
         foreach ($this->templates as &$row) {
             $row['disabled'] = $row['has_block'];
         }
     }
     // get the extras
     $this->extras = BackendExtensionsModel::getExtras();
     $this->loadForm();
     $this->loadDrafts();
     $this->loadRevisions();
     $this->validateForm();
     $this->parse();
     $this->display();
 }
All Usage Examples Of Backend\Modules\Extensions\Engine\Model::getTemplates