/** * Updates the template list * * @param $templateDir */ protected function refreshTemplateList($templateDir) { $repository = $this->getRepository('template'); $templates = $repository->findAll(); $templateList = array(); foreach ($templates as $template) { $templateList[$template->getTemplate()] = $template; } $dirs = new DirectoryIterator($templateDir); foreach ($dirs as $dirInfo) { if ($dirInfo->isDot() || !$dirInfo->isDir()) { continue; } $dirName = $dirInfo->getFilename(); if (in_array($dirName, array('.svn')) || is_numeric($dirName) || strpos($dirName, '_') === 0 ) { continue; } $templateData = array(); $templateFile = $dirInfo->getPathname() . '/info.json'; if (file_exists($templateFile)) { $templateData = (array)Zend_Json::decode(file_get_contents($templateFile)); } if(!isset($templateData['version'])) { $templateData['version'] = strpos($dirName, 'emotion_') !== 0 ? 1 : 2; } if (isset($templateList[$dirName])) { $template = $templateList[$dirName]; } else { $template = new Shopware\Models\Shop\Template(); $templateData['template'] = $dirName; if (empty($templateData['name'])) { $templateData['name'] = ucwords(str_replace('_', ' ', $dirName)); } } $template->fromArray($templateData); Shopware()->Models()->persist($template); } Shopware()->Models()->flush(); }
/** * Create a new template * * @param array|string $options * @return \Shopware\Models\Shop\Template */ public function createTemplate($options) { if(is_string($options)) { $options = array('template' => $options); } $template = $this->Payments()->findOneBy(array( 'template' => $options['template'] )); if($template === null) { $template = new \Shopware\Models\Shop\Template(); if(!isset($options['name'])) { $options['name'] = ucfirst($options['template']); } } $template->fromArray($options); $plugin = $this->Plugin(); $plugin->getTemplates()->add($template); $template->setPlugin($plugin); return $template; }