/**
  * normally returns TRUE, but returns FALSE when it, or its parent is in the list.
  * todo: add products in other product categories
  * @param SiteTree $page
  * @return Boolean
  */
 function canBeDiscounted(SiteTree $page)
 {
     if ($this->owner->PageIDs) {
         $allowedPageIDs = explode(',', $this->owner->PageIDs);
         $checkPages = new ArrayList(array($page));
         $alreadyCheckedPageIDs = array();
         while ($checkPages->Count()) {
             $page = $checkPages->First();
             if (array_search($page->ID, $allowedPageIDs) !== false) {
                 return true;
             }
             $alreadyCheckedPageIDs[] = $page->ID;
             $checkPages->remove($page);
             // Parents list update
             if ($page->hasMethod('AllParentGroups')) {
                 $parents = new ArrayList($page->AllParentGroups()->toArray());
             } else {
                 $parents = new ArrayList();
             }
             $parent = $page->Parent();
             if ($parent && $parent->exists()) {
                 $parents->unshift($parent);
             }
             foreach ($parents as $parent) {
                 if (array_search($parent->ID, $alreadyCheckedPageIDs) === false) {
                     $checkPages->push($parent);
                 }
             }
             $checkPages->removeDuplicates();
         }
         return false;
     }
     return true;
 }
 /**
  * Combines the main image and the secondary images
  * @return ArrayList
  */
 function AllImages()
 {
     $list = new ArrayList($this->owner->AdditionalImages()->sort('SortOrder')->toArray());
     $main = $this->owner->Image();
     if ($main && $main->exists()) {
         $list->unshift($main);
     }
     return $list;
 }
 /**
  * @return ArrayList
  */
 function getBreadcrumbs()
 {
     $out = new ArrayList();
     $cur = $this;
     while ($cur && $cur->exists()) {
         $out->unshift($cur);
         $cur = $cur->ParentSearchID > 0 ? $cur->ParentSearch() : null;
     }
     return $out;
 }
예제 #4
0
 /**
  * Returns top level navigation of projects.
  *
  * @param int $limit
  *
  * @return ArrayList
  */
 public function Navigation($limit = 5)
 {
     $navigation = new ArrayList();
     $currentProject = $this->getCurrentProject();
     $projects = $this->getStarredProjects();
     if ($projects->count() < 1) {
         $projects = $this->DNProjectList();
     } else {
         $limit = -1;
     }
     if ($projects->count() > 0) {
         $activeProject = false;
         if ($limit > 0) {
             $limitedProjects = $projects->limit($limit);
         } else {
             $limitedProjects = $projects;
         }
         foreach ($limitedProjects as $project) {
             $isActive = $currentProject && $currentProject->ID == $project->ID;
             if ($isActive) {
                 $activeProject = true;
             }
             $navigation->push(array('Project' => $project, 'IsActive' => $currentProject && $currentProject->ID == $project->ID));
         }
         // Ensure the current project is in the list
         if (!$activeProject && $currentProject) {
             $navigation->unshift(array('Project' => $currentProject, 'IsActive' => true));
             if ($limit > 0 && $navigation->count() > $limit) {
                 $navigation->pop();
             }
         }
     }
     return $navigation;
 }
예제 #5
0
 /**
  * Returns top level navigation of projects.
  *
  * @param int $limit
  *
  * @return ArrayList
  */
 public function Navigation($limit = 5)
 {
     $navigation = new ArrayList();
     $currentProject = $this->getCurrentProject();
     $currentEnvironment = $this->getCurrentEnvironment();
     $actionType = $this->getCurrentActionType();
     $projects = $this->getStarredProjects();
     if ($projects->count() < 1) {
         $projects = $this->DNProjectList();
     } else {
         $limit = -1;
     }
     if ($projects->count() > 0) {
         $activeProject = false;
         if ($limit > 0) {
             $limitedProjects = $projects->limit($limit);
         } else {
             $limitedProjects = $projects;
         }
         foreach ($limitedProjects as $project) {
             $isActive = $currentProject && $currentProject->ID == $project->ID;
             if ($isActive) {
                 $activeProject = true;
             }
             $isCurrentEnvironment = false;
             if ($project && $currentEnvironment) {
                 $isCurrentEnvironment = (bool) $project->DNEnvironmentList()->find('ID', $currentEnvironment->ID);
             }
             $navigation->push(['Project' => $project, 'IsCurrentEnvironment' => $isCurrentEnvironment, 'IsActive' => $currentProject && $currentProject->ID == $project->ID, 'IsOverview' => $actionType == self::PROJECT_OVERVIEW && !$isCurrentEnvironment && $currentProject->ID == $project->ID]);
         }
         // Ensure the current project is in the list
         if (!$activeProject && $currentProject) {
             $navigation->unshift(['Project' => $currentProject, 'IsActive' => true, 'IsCurrentEnvironment' => $currentEnvironment, 'IsOverview' => $actionType == self::PROJECT_OVERVIEW && !$currentEnvironment]);
             if ($limit > 0 && $navigation->count() > $limit) {
                 $navigation->pop();
             }
         }
     }
     return $navigation;
 }
 /**
  * Push a single field onto the beginning of this FieldList instance.
  *
  * @param FormField $item The FormField to add
  */
 public function unshift($item)
 {
     $this->onBeforeInsert($item);
     $item->setContainerFieldList($this);
     return parent::unshift($item);
 }
예제 #7
0
 /**
  * manipulates the parts the pages breadcrumbs if a product detail view is 
  * requested.
  *
  * @param int    $maxDepth       maximum depth level of shown pages in breadcrumbs
  * @param bool   $unlinked       true, if the breadcrumbs should be displayed without links
  * @param string $stopAtPageType name of pagetype to stop at
  * @param bool   $showHidden     true, if hidden pages should be displayed in breadcrumbs
  *
  * @return ArrayList
  * 
  * @author Sebastian Diel <*****@*****.**>, Patrick Schneider <*****@*****.**>
  * @since 09.10.2012
  */
 public function BreadcrumbParts($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false)
 {
     $parts = new ArrayList();
     $page = $this;
     while ($page && (!$maxDepth || $parts->count() < $maxDepth) && (!$stopAtPageType || $page->ClassName != $stopAtPageType)) {
         if ($showHidden || $page->ShowInMenus || $page->ID == $this->ID) {
             if ($page->hasMethod('OriginalLink')) {
                 $link = $page->OriginalLink();
             } else {
                 $link = $page->Link();
             }
             if ($page->ID == $this->ID) {
                 $isActive = true;
             } else {
                 $isActive = false;
             }
             $parts->unshift(new ArrayData(array('MenuTitle' => $page->MenuTitle, 'Title' => $page->Title, 'Link' => $link, 'Parent' => $page->Parent, 'IsActive' => $isActive)));
         }
         $page = $page->Parent;
     }
     return $parts;
 }