/** * @param \Cms\Data\TemplateSnippet * @param array $attributes */ protected function setAttributesToTemplateSnippet(DataTemplateSnippet $snippet, array $attributes) { if (isset($attributes['name'])) { $snippet->setName($attributes['name']); } if (isset($attributes['description'])) { $snippet->setDescription($attributes['description']); } if (isset($attributes['category'])) { $snippet->setCategory($attributes['category']); } if (isset($attributes['content'])) { $contentString = is_array($attributes['content']) ? \Zend_Json::encode($attributes['content']) : $attributes['content']; $snippet->setContent($contentString); } }
/** * @param string $websiteId * @param string $id * @param SourceItem $sourceItem * @param \stdClass $manifest * @param string $lastUpdate * @param string $previewImageUrl * * @return DataTemplateSnippet */ protected function loadDataObject($websiteId, $id, SourceItem $sourceItem, \stdClass $manifest, $lastUpdate, $previewImageUrl) { $snippet = new DataTemplateSnippet(); $snippet->setWebsiteid($websiteId); $snippet->setId($id); $snippet->setReadonly($sourceItem->isReadonly()); $snippet->setSourceType($sourceItem->getType()); $snippet->setLastupdate($lastUpdate); if (!empty($previewImageUrl)) { $snippet->setPreviewImageUrl($previewImageUrl); } if (property_exists($manifest, 'name')) { $snippet->setName($manifest->name); } if (property_exists($manifest, 'description')) { $snippet->setDescription($manifest->description); } if (property_exists($manifest, 'category')) { $snippet->setCategory($manifest->category); } if (property_exists($manifest, 'content')) { $snippet->setContent($manifest->content); } if (property_exists($manifest, 'baseLayout')) { $snippet->setBaseLayout($manifest->baseLayout); } if (property_exists($manifest, 'pageTypes') && is_array($manifest->pageTypes)) { $snippet->setPageTypes($manifest->pageTypes); } return $snippet; }
/** * @param string $count * @param string $suffix * @param array $attributes * * @return \Cms\Data\TemplateSnippet[] */ protected function createDataSnippets($count, $suffix, $attributes = array()) { $snippets = array(); for ($i = 1; $i <= $count; $i++) { $snippet = new DataTemplateSnippet(); if (array_key_exists('websiteid', $attributes)) { $snippet->setWebsiteid($attributes['websiteid']); } if (array_key_exists('id', $attributes)) { $snippet->setId($attributes['id']); } else { $snippet->setNewGeneratedId(); } if (array_key_exists('name', $attributes)) { $snippet->setName($attributes['name']); } else { $snippet->setName(sprintf('name_%04d%s', $i, $suffix)); } if (array_key_exists('description', $attributes)) { $snippet->setDescription($attributes['description']); } else { $snippet->setDescription(sprintf('description_%04d%s', $i, $suffix)); } if (array_key_exists('category', $attributes)) { $snippet->setCategory($attributes['category']); } else { $snippet->setCategory(sprintf('category_%04d%s', $i, $suffix)); } if (array_key_exists('content', $attributes)) { $snippet->setContent($attributes['content']); } else { $snippet->setCategory(json_encode(array(array('attribute' => sprintf('content_%04d%s', $i, $suffix))))); } if (array_key_exists('readonly', $attributes)) { $snippet->setReadonly($attributes['readonly']); } else { $snippet->setReadonly(false); } if (array_key_exists('sourcetype', $attributes)) { $snippet->setSourceType($attributes['sourcetype']); } else { $snippet->setSourceType($snippet::SOURCE_LOCAL); } if (array_key_exists('overwritten', $attributes)) { $snippet->setOverwritten($attributes['overwritten']); } else { $snippet->setOverwritten(false); } if (array_key_exists('lastupdate', $attributes)) { $snippet->setLastupdate($attributes['lastupdate']); } else { $snippet->setLastupdate(time()); } $snippets[] = $snippet; } return $snippets; }