示例#1
0
 public function copyToTargetCategory(StackCategory $category)
 {
     $list = new StackList();
     $list->filterByStackCategory($this);
     $stacks = $list->get();
     foreach ($stacks as $stack) {
         $stack->duplicate($category->getPage());
     }
 }
示例#2
0
 protected function setupMultilingualStackList(\Concrete\Core\Page\Stack\StackList $list)
 {
     if (\Core::make('multilingual/detector')->isEnabled()) {
         $category = StackCategory::getCategoryFromMultilingualSection($this->getSelectedLanguage());
         if (!is_object($category)) {
             // we have to create the category
             $category = StackCategory::createFromMultilingualSection($this->getSelectedLanguage());
             // now we copy all the stacks into it
             $default = StackCategory::getFromDefaultMultilingualSection();
             $default->copyToTargetCategory($category);
         }
         $list->filterByStackCategory($category);
     }
 }
示例#3
0
 /**
  * @param string $stackName
  * @param int    $type
  *
  * @return Page
  */
 public static function addStack($stackName, $type = 0)
 {
     $data = array();
     $parent = Page::getByPath(STACKS_PAGE_PATH);
     $data = array();
     $data['name'] = $stackName;
     if (!$stackName) {
         $data['name'] = t('No Name');
     }
     $pagetype = PageType::getByHandle(STACKS_PAGE_TYPE);
     $page = $parent->add($pagetype, $data);
     // we have to do this because we need the area to exist before we try and add something to it.
     Area::getOrCreate($page, STACKS_AREA_NAME);
     // finally we add the row to the stacks table
     $db = Database::connection();
     $stackCID = $page->getCollectionID();
     $v = array($stackName, $stackCID, $type);
     $db->Execute('insert into Stacks (stName, cID, stType) values (?, ?, ?)', $v);
     $stack = static::getByID($stackCID);
     // If the multilingual add-on is enabled, we need to take this stack and copy it into all non-default stack categories.
     if (Core::make('multilingual/detector')->isEnabled()) {
         $list = Section::getList();
         foreach ($list as $section) {
             if (!$section->isDefaultMultilingualSection()) {
                 $category = StackCategory::getCategoryFromMultilingualSection($section);
                 if (!is_object($category)) {
                     $category = StackCategory::createFromMultilingualSection($section);
                 }
                 $stack->duplicate($category->getPage());
             }
         }
         StackList::rescanMultilingualStacks();
     }
     return $stack;
 }
示例#4
0
 public function filterByStackCategory(StackCategory $category)
 {
     $this->filterByParentID($category->getPage()->getCollectionID());
 }
示例#5
0
 /**
  * @param string $stackName
  * @param int    $type
  *
  * @return Page
  */
 public static function addStack($stackName, $type = 0, $multilingualStackToReturn = self::MULTILINGUAL_CONTENT_SOURCE_CURRENT)
 {
     $return = false;
     $db = \Database::connection();
     if (Core::make('multilingual/detector')->isEnabled()) {
         $returnFromSection = Stack::getMultilingualSectionFromType($multilingualStackToReturn);
         $list = Section::getList();
         foreach ($list as $section) {
             $cID = $db->GetOne('select cID from Stacks where stName = ? and stMultilingualSection = ?', array($stackName, $section->getCollectionID()));
             if (!$cID) {
                 $category = StackCategory::getCategoryFromMultilingualSection($section);
                 if (!is_object($category)) {
                     $category = StackCategory::createFromMultilingualSection($section);
                 }
                 $stack = Stack::addStackToCategory($category->getPage(), $stackName, $type);
                 if (is_object($returnFromSection) && $returnFromSection->getCollectionID() == $section->getCollectionID()) {
                     $return = $stack;
                 }
             }
         }
         StackList::rescanMultilingualStacks();
     } else {
         $parent = \Page::getByPath(STACKS_PAGE_PATH);
         $return = Stack::addStackToCategory($parent, $stackName, $type);
     }
     return $return;
 }