/**
  * 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;
 }
 /**
  * Expects parameters 'start' and 'limit' to be set, limits items by filter to page length
  *
  *
  * @param \SS_LIst $items
  * @param          $filters
  * @param array    $parameters
  */
 public function sequenceGridListItems(&$items, $filters, &$parameters = [])
 {
     $out = new \ArrayList();
     $start = $parameters[Constraints::StartIndexGetVar];
     $limit = $parameters[Constraints::PageLengthGetVar];
     if (!is_null($limit)) {
         $added = 0;
         if ($allFilter = Application::get_current_page()->FilterAll()) {
             // first add 'all filter' items
             if ($allTag = $allFilter->Filter) {
                 $index = 0;
                 $added = 0;
                 foreach ($items as $item) {
                     $index++;
                     if ($index < $start) {
                         continue;
                     }
                     if ($allTag == 'all' || $item->GridListFilters()->find('ModelTag', $allTag)) {
                         // we don't add all, we're just getting the count
                         // $out->push($item);
                         $added++;
                     }
                     if ($added >= $limit) {
                         break;
                     }
                 }
             }
         }
         // initial number of 'all filter' items loaded in page
         $parameters['AllLoadCount'] = $added;
         foreach ($filters as $filter) {
             if ($tag = $filter->ModelTag) {
                 $index = 0;
                 $added = 0;
                 foreach ($items as $item) {
                     $index++;
                     if ($index < $start) {
                         continue;
                     }
                     if ($item->hasExtension(HasGridListFilters::class_name())) {
                         if ($item->GridListFilters()->find('ModelTag', $tag)) {
                             $out->push($item);
                             $added++;
                         }
                     }
                     if ($added >= $limit) {
                         break;
                     }
                 }
                 // initial number of items loaded in page (may be less than page length)
                 $filter->LoadCount = $added;
             }
         }
         $out->removeDuplicates();
         $items = $out;
     }
 }
 /**
  * Returns all the {@link InlineHelpTopic}s attached to this page.
  *
  * @return InlineHelpTopic[]
  */
 public function getHelpItems()
 {
     $items = new ArrayList();
     $items->merge(InlineHelpTopic::get()->where('"AttachType" = \'All\''));
     $items->merge(InlineHelpTopic::get()->where(sprintf('"AttachType" = \'Type\' AND "AttachPageType" = \'%s\'', $this->owner->class)));
     $items->merge($this->owner->HelpTopics());
     $stack = $this->owner->parentStack();
     array_shift($stack);
     if ($stack) {
         $items->merge(InlineHelpTopic::get()->where(sprintf('"AttachType" = \'Children\' AND "ParentFilterID" IN(%s)', implode(', ', array_map(create_function('$self', 'return $self->ID;'), $stack)))));
     }
     $items->removeDuplicates();
     return $items;
 }
 /**
  * Get all discounts that have been applied to an order.
  *
  * @return ArrayList
  */
 public function Discounts()
 {
     $discounts = Discount::get()->leftJoin("OrderDiscountModifier_Discounts", "\"Discount\".\"ID\" = \"OrderDiscountModifier_Discounts\".\"DiscountID\"")->innerJoin("OrderAttribute", "(\"OrderDiscountModifier_Discounts\".\"OrderDiscountModifierID\" = \"OrderAttribute\".\"ID\")")->filter("OrderAttribute.OrderID", $this->owner->ID);
     $finalDiscounts = new ArrayList();
     foreach ($discounts as $discount) {
         $finalDiscounts->push($discount);
     }
     foreach ($this->owner->Items() as $item) {
         foreach ($item->Discounts() as $discount) {
             $finalDiscounts->push($discount);
         }
     }
     $finalDiscounts->removeDuplicates();
     return $finalDiscounts;
 }
Ejemplo n.º 5
0
 function TalksByMemberID($memberID)
 {
     $SpeakerList = new ArrayList();
     // Pull any talks that belong to this Summit and are owned by member
     $talksMemberOwns = $this->Talks("`OwnerID` = " . $memberID . " AND `SummitID` = " . $this->ID);
     $SpeakerList->merge($talksMemberOwns);
     // Now pull any talks that belong to this Summit and the member is listed as a speaker
     $speaker = Speaker::get()->filter('memberID', $memberID)->first();
     if ($speaker) {
         $talksMemberIsASpeaker = $speaker->TalksBySummitID($this->ID);
         // Now merge and de-dupe the lists
         $SpeakerList->merge($talksMemberIsASpeaker);
         $SpeakerList->removeDuplicates('ID');
     }
     return $SpeakerList;
 }
 /**
  * Takes a list of groups and members and return a list of unique member.
  *
  * @param SS_List $groups
  * @param SS_List $members
  *
  * @return ArrayList
  */
 public static function merge_owners(SS_List $groups, SS_List $members)
 {
     $contentReviewOwners = new ArrayList();
     if ($groups->count()) {
         $groupIDs = array();
         foreach ($groups as $group) {
             $familyIDs = $group->collateFamilyIDs();
             if (is_array($familyIDs)) {
                 $groupIDs = array_merge($groupIDs, array_values($familyIDs));
             }
         }
         array_unique($groupIDs);
         if (count($groupIDs)) {
             $groupMembers = DataObject::get("Member")->where("\"Group\".\"ID\" IN (" . implode(",", $groupIDs) . ")")->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
             $contentReviewOwners->merge($groupMembers);
         }
     }
     $contentReviewOwners->merge($members);
     $contentReviewOwners->removeDuplicates();
     return $contentReviewOwners;
 }
Ejemplo n.º 7
0
 /**
  * Get a member SQLMap of members in specific groups
  * 
  * If no $groups is passed, all members will be returned
  * 
  * @param mixed $groups - takes a SS_List, an array or a single Group.ID
  * @return SQLMap Returns an SQLMap that returns all Member data.
  * @see map()
  */
 public static function map_in_groups($groups = null)
 {
     $groupIDList = array();
     if ($groups instanceof SS_List) {
         foreach ($groups as $group) {
             $groupIDList[] = $group->ID;
         }
     } elseif (is_array($groups)) {
         $groupIDList = $groups;
     } elseif ($groups) {
         $groupIDList[] = $groups;
     }
     // No groups, return all Members
     if (!$groupIDList) {
         return Member::get()->sort(array('Surname' => 'ASC', 'FirstName' => 'ASC'))->map();
     }
     $membersList = new ArrayList();
     // This is a bit ineffective, but follow the ORM style
     foreach (Group::get()->byIDs($groupIDList) as $group) {
         $membersList->merge($group->Members());
     }
     $membersList->removeDuplicates('ID');
     return $membersList->map();
 }
 /**
  * Returns the filters which should show in-page gathered via provideGridListFilters. These are composed of those specifically set on the GridList first
  * and then those for the current page which may have an alternate strategy to provide them, such as most popular filters from child pages.
  *
  * @return \ArrayList
  */
 protected function filters($mode)
 {
     static $filters;
     if (!$filters) {
         $providers = $this->providers();
         $filters = new \ArrayList();
         foreach ($providers as $provider) {
             // first get filters which have been added specifically to the GridList, e.g. via a HasGridListFilters extendiong on the extended class
             // this will return an array of SS_Lists
             $lists = $provider->extend('provideGridListFilters');
             foreach ($lists as $list) {
                 $filters->merge($list);
             }
             $filters->removeDuplicates();
             $items = $this->items($mode);
             $provider->extend('constrainGridListFilters', $items, $filters);
         }
     }
     return $filters;
 }
 /**
  * Gets all orphans from "Stage" and "Live" stages.
  * 
  * @param string $class
  * @param string $filter
  * @param string $sort
  * @param string $join
  * @param int|array $limit
  * @return SS_List
  */
 public function getOrphanedPages($class = 'SiteTree', $filter = '', $sort = null, $join = null, $limit = null)
 {
     $filter .= $filter ? ' AND ' : '';
     $filter .= sprintf("\"%s\".\"ParentID\" != 0 AND \"Parents\".\"ID\" IS NULL", $class);
     $orphans = new ArrayList();
     foreach (array('Stage', 'Live') as $stage) {
         $joinByStage = $join;
         $table = $class;
         $table .= $stage == 'Live' ? '_Live' : '';
         $stageOrphans = Versioned::get_by_stage($class, $stage, $filter, $sort, null, $limit)->leftJoin($table, "\"{$table}\".\"ParentID\" = \"Parents\".\"ID\"", "Parents");
         $orphans->merge($stageOrphans);
     }
     $orphans->removeDuplicates();
     return $orphans;
 }
Ejemplo n.º 10
0
    function FlickrBucketsByDate()
    {
        // in 3.1 data list is immutable, hence the chaining
        $sqlbucketidsinorder = 'select distinct FlickrBucketID from (
	  select FlickrBucketID, FlickrPhoto.TakenAt from FlickrBucket
		INNER JOIN FlickrPhoto_FlickrBuckets ON FlickrBucketID = FlickrBucket.ID
		INNER JOIN FlickrPhoto ON FlickrPhoto.ID = FlickrPhoto_FlickrBuckets.FlickrPhotoID
		WHERE (FlickrSetID = ' . $this->ID . ')
		order by FlickrPhoto.TakenAt
	  ) as OrderedBuckets';
        $buckets = FlickrBucket::get()->filter(array('FlickrSetID' => $this->ID))->innerJoin('FlickrPhoto_FlickrBuckets', 'FlickrBucketID = FlickrBucket.ID')->innerJoin('FlickrPhoto', 'FlickrPhotoID = FlickrPhoto.ID')->sort('TakenAt');
        $result = new ArrayList();
        foreach ($buckets->getIterator() as $bucket) {
            $result->push($bucket);
        }
        $result->removeDuplicates();
        return $result;
    }
 /**
  * Gets all orphans from "Stage" and "Live" stages.
  *
  * @param string $class
  * @param array $filter
  * @param string $sort
  * @param string $join
  * @param int|array $limit
  * @return SS_List
  */
 public function getOrphanedPages($class = 'SiteTree', $filter = array(), $sort = null, $join = null, $limit = null)
 {
     // Alter condition
     if (empty($filter)) {
         $where = array();
     } elseif (is_array($filter)) {
         $where = $filter;
     } else {
         $where = array($filter);
     }
     $where[] = array("\"{$class}\".\"ParentID\" != ?" => 0);
     $where[] = '"Parents"."ID" IS NULL';
     $orphans = new ArrayList();
     foreach (array('Stage', 'Live') as $stage) {
         $joinByStage = $join;
         $table = $class;
         $table .= $stage == 'Live' ? '_Live' : '';
         $stageOrphans = Versioned::get_by_stage($class, $stage, $where, $sort, null, $limit)->leftJoin($table, "\"{$table}\".\"ParentID\" = \"Parents\".\"ID\"", "Parents");
         $orphans->merge($stageOrphans);
     }
     $orphans->removeDuplicates();
     return $orphans;
 }
 /**
  * Returns all member recipient objects.
  *
  * @return ArrayList
  */
 public function getRecipients()
 {
     $set = new ArrayList();
     $set->merge($this->RecipientMembers());
     foreach ($this->RecipientGroups() as $group) {
         $set->merge($group->Members());
     }
     $set->removeDuplicates();
     return $set;
 }
Ejemplo n.º 13
0
 /**
  * Returns a list of all Members that are assigned to this instance, either directly or via a group.
  *
  * @todo   This could be made more efficient.
  * @return ArrayList
  */
 public function getAssignedMembers()
 {
     $list = new ArrayList();
     $groups = $this->Groups();
     $list->merge($this->Users());
     foreach ($groups as $group) {
         $list->merge($group->Members());
     }
     $list->removeDuplicates();
     return $list;
 }
Ejemplo n.º 14
0
 public static function all_accessible_sites($includeMainSite = true, $mainSiteTitle = "Main site", $member = null)
 {
     // Rationalise member arguments
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return new ArrayList();
     }
     if (!is_object($member)) {
         $member = DataObject::get_by_id('Member', $member);
     }
     $subsites = new ArrayList();
     // Collect subsites for all sections.
     $menu = CMSMenu::get_viewable_menu_items();
     foreach ($menu as $candidate) {
         if ($candidate->controller) {
             $accessibleSites = singleton($candidate->controller)->sectionSites($includeMainSite, $mainSiteTitle, $member);
             // Replace existing keys so no one site appears twice.
             $subsites->merge($accessibleSites);
         }
     }
     $subsites->removeDuplicates();
     return $subsites;
 }
Ejemplo n.º 15
0
 /**
  * Return paginated results in class
  * Only returns items that contain Link()
  * Limited to 1000 results per page
  *
  * @param string
  * @return ArrayList
  */
 public static function get_items($className, $page = 1)
 {
     $items = self::get_filtered_results($className);
     $list = new PaginatedList($items);
     $list->setPageLength(1000);
     $list->setCurrentPage($page);
     $output = new ArrayList();
     /* only push items with a link */
     foreach ($list as $item) {
         $item->ChangeFrequency = self::get_frequency_for_class($className);
         $item->GooglePriority = self::get_priority_for_class($className);
         if ($item->hasMethod('SitemapAbsoluteURL')) {
             $item->SitemapAbsoluteURL = $SitemapAbsoluteURL->SitemapAbsoluteURL();
             $output->push($item);
         } elseif ($item->hasMethod('Link')) {
             $item->SitemapAbsoluteURL = Director::absoluteURL($item->Link());
             $output->push($item);
         }
     }
     /* Make sure we only include one of each link, and no external links (ie: redirector pages */
     $output->removeDuplicates('SitemapAbsoluteURL');
     $external_links = array();
     $base_url = preg_quote(Director::absoluteBaseURL(), '/');
     foreach ($output as $item) {
         if (!preg_match('/^' . $base_url . '/', $item->SitemapAbsoluteURL)) {
             array_push($external_links, $item->SitemapAbsoluteURL);
         }
     }
     if (count($external_links) > 0) {
         $output = $output->exclude('SitemapAbsoluteURL', $external_links);
     }
     return $output;
 }
 /**
  * Mark duplicate attributes
  *
  * @param SS_List $list
  * @return SS_List
  */
 private function markDuplicates($list)
 {
     $duplicates = $this->findDuplicates($list, 'MetaTitle')->map('ID', 'ID')->toArray();
     $duplicateList = new ArrayList();
     foreach ($list as $item) {
         if (in_array($item->ID, $duplicates)) {
             $item->IsDuplicate = true;
             $duplicateList->push($item);
         }
     }
     $duplicates = $this->findDuplicates($list, 'MetaDescription')->map('ID', 'ID')->toArray();
     foreach ($list as $item) {
         if (in_array($item->ID, $duplicates)) {
             $item->IsDuplicate = true;
             if (!$list->byID($item->ID)) {
                 $duplicateList->push($item);
             }
         }
     }
     $duplicateList->merge($list);
     $duplicateList->removeDuplicates();
     return $duplicateList;
 }
Ejemplo n.º 17
0
 /**
  * Get list of CMS grid versioned pages
  *
  * @since version 1.0.0
  *
  * @return object
  **/
 private function getVersionedPages()
 {
     $list = new ArrayList();
     $stage = Versioned::get_by_stage($this->modelClass, 'Stage');
     foreach ($stage as $stage) {
         $list->push($stage);
     }
     $live = Versioned::get_by_stage($this->modelClass, 'Live');
     foreach ($live as $live) {
         $list->push($live);
     }
     $list->removeDuplicates('ID');
     return $list;
 }