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;
}