Ejemplo n.º 1
0
 /**
  * @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;
 }