예제 #1
0
 private function createDefaultContent($domain, $em)
 {
     //Create contentType
     $contentType = new ContentType();
     $contentType->setCreatedBy('Install');
     $contentType->setModifiedBy('Install');
     $contentType->setHideFromMenus(false);
     $contentType->setName('Default content type');
     $contentType->setSlug(array('en' => 'default'));
     $em->persist($contentType);
     //Create Field
     $wyswigFieldType = $this->getDoctrine()->getRepository('SSoneCMSBundle:FieldType')->findOneBy(array('variableName' => 'wysiwyg'));
     $wyswigField = new Field();
     $wyswigField->setName('WYSIWIG Content');
     $wyswigField->setCreatedBy('Install');
     $wyswigField->setModifiedBy('Install');
     $wyswigField->setSort(1);
     $wyswigField->setVariableName('defaultVariable');
     $wyswigField->setIsRepeatable(false);
     $wyswigField->setIsRequired(false);
     $wyswigField->setContentTypeByVariable($contentType);
     $wyswigField->setLabel('Default Label');
     $wyswigField->setFieldType($wyswigFieldType);
     $fieldTypeOptions = $this->getDoctrine()->getRepository('SSoneCMSBundle:FieldSetupOptions')->getAllFieldSetupOptions();
     foreach ($fieldTypeOptions as $fieldType) {
         $fieldTypeOptionsFormatted[$fieldType['fieldTypeVariableName']] = array();
         foreach ($fieldType['options'] as $k => $settings) {
             $value = '';
             if ($settings['inputType'] == 'checkbox') {
                 $value = false;
             }
             $fieldTypeOptionsFormatted[$fieldType['fieldTypeVariableName']][$k] = $value;
         }
     }
     $wyswigField->setFieldTypeSettings($fieldTypeOptionsFormatted);
     $em->persist($wyswigField);
     //Create content
     $content = new Content();
     $content->setCreatedBy('Install');
     $content->setModifiedBy('Install');
     $content->setName('Default Content');
     $content->setContentType($contentType);
     $content->setSlug(array('en' => 'default'));
     $em->persist($content);
     //Create Blocks
     $block = new Block();
     $block->setCreatedBy('Install');
     $block->setModifiedBy('Install');
     $block->setContent($content);
     $block->setSort(1);
     $block->setField($wyswigField);
     $em->persist($block);
     //Create BlockFields
     $blockField = new BlockField();
     $blockField->setCreatedBy('Install');
     $blockField->setModifiedBy('Install');
     $blockField->setBlock($block);
     $blockField->setFieldContent(array('defaultVariable' => '<p>Welcome to One CMS</p>'));
     $em->persist($blockField);
     //Create Menu
     $menu = new Menu();
     $menu->setCreatedBy('Install');
     $menu->setModifiedBy('Install');
     $menu->setDomain($domain);
     $menu->setName('Default Menu');
     $menu->setSort(1);
     $menu->setMenuTemplatePosition('A');
     $menu->setDrawAllGrandChildren(true);
     $menu->setGrandChildrenTemplatePosition('A');
     $menu->setGrandChildrenRelativePosition('inline');
     $em->persist($menu);
     //Create menuitem
     $menuItem = new MenuItem();
     $menuItem->setCreatedBy('Install');
     $menuItem->setModifiedBy('Install');
     $menuItem->setContent($content);
     $menuItem->setPageClass('default');
     $menuItem->setName(array('en' => 'Default Home Menu'));
     $menuItem->setSort(1);
     $menuItem->setMode('single');
     $menuItem->setRoot($menu);
     $menuItem->setDrawAllGrandChildren(true);
     $menuItem->setGrandChildrenTemplatePosition('A');
     $menuItem->setGrandChildrenRelativePosition('inline');
     $menuItem->setHideEmptyCategories(false);
     $menuItem->setDrawListItemsAsMenuItems(false);
     $menuItem->setSlug(array('en' => ''));
     $em->persist($menuItem);
     $em->flush();
     $this->cacheContent($content->getId(), $em);
 }
예제 #2
0
 /**
  * Check for changes to the content type - add remove content blocks as necessary
  * @param $contentType
  */
 public function contentTypeBlockManager($contentType)
 {
     //get fields for this content type
     $fields = $contentType->getAttributeFields();
     //get blocks for this content type
     $blocks = $contentType->getBlocks();
     //Check if field has been removed and remove blocks as necessary
     foreach ($blocks as $b) {
         $foundBlock = false;
         foreach ($fields as $f) {
             if ($f->getVariableName() == $b->getField()->getVariableName()) {
                 $foundBlock = true;
             }
         }
         if (!$foundBlock) {
             $contentType->removeBlock($b);
         }
     }
     //check if new field has been added and add block as necessary and set block sorts
     foreach ($fields as $f) {
         $foundBlock = false;
         foreach ($blocks as $b) {
             //if($b->getLocale() != $locale) continue;
             if ($b->getField()->getVariableName() == $f->getVariableName()) {
                 $foundBlock = true;
                 $b->setSort($f->getSort());
             }
         }
         if (!$foundBlock) {
             $newBlock = new Block();
             $newBlock->setField($f);
             $newBlock->setSort($f->getSort());
             $newBlockField = new BlockField();
             $newBlockField->setBlock($newBlock);
             $newBlock->addBlockField($newBlockField);
             $newBlock->setContentType($contentType);
             $contentType->addBlock($newBlock);
         }
     }
 }