/** * Recursively create a set of {@link Product} pages * that belong to this ProductGroup as a child, related * Product, or through one of this ProductGroup's nested * ProductGroup pages. * * @param string $extraFilter Additional SQL filters to apply to the Product retrieval * @param array $permissions * @return DataObjectSet */ function ProductsShowable($extraFilter = '', $permissions = array("Show All Products")) { $filter = "`ShowInMenus` = 1"; if ($extraFilter) { $filter .= " AND {$extraFilter}"; } $products = new DataObjectSet(); $childProducts = DataObject::get('Product', "`ParentID` = {$this->ID} AND {$filter}"); $relatedProducts = $this->getManyManyComponents('Products', $filter); if ($childProducts) { $products->merge($childProducts); } if ($relatedProducts) { $products->merge($relatedProducts); } if (in_array($this->ChildGroupsPermission, $permissions)) { if ($childGroups = $this->ChildGroups()) { foreach ($childGroups as $childGroup) { $products->merge($childGroup->ProductsShowable($extraFilter, $permissions)); } } } $products->removeDuplicates(); return $products; }
/** * Collate permissions for this and all parent folders. * * @return DataObjectSet */ function AllGroupPermissions() { $groupSet = new DataObjectSet(); $groups = $this->owner->GroupPermissions(); foreach ($groups as $group) { $groupSet->push($group); } if ($this->owner->ParentID) { $groupSet->merge($this->owner->InheritedGroupPermissions()); } $groupSet->removeDuplicates(); return $groupSet; }
/** * Collate permissions for this and all parent folders. * * @return DataObjectSet */ function AllMemberPermissions() { $memberSet = new DataObjectSet(); $members = $this->owner->MemberPermissions(); foreach ($members as $member) { $memberSet->push($member); } if ($this->owner->ParentID) { $memberSet->merge($this->owner->InheritedMemberPermissions()); } $memberSet->removeDuplicates(); return $memberSet; }
/** * Refreshes the file list. If passed an array of IDs in the request, * it augments the list with those files. * * @param SS_HTTPRequest * @return SSViewer */ public function refresh(SS_HTTPRequest $r) { if ($r->requestVar('ids')) { $ids = array_unique($r->requestVar('ids')); $files = new DataObjectSet(); $implodestring = implode(',', $ids); $implodestring = preg_replace("/^[,]/", "", $implodestring); if ($set = DataObject::get("File", "`ID` IN ({$implodestring})")) { foreach ($set as $file) { $this->processFile($file); $files->push($file); } $files->merge($this->Files()); $files->removeDuplicates(); } else { die("File {$id} doesn't exist"); } } else { $files = $this->Files(); } return $this->customise(array('Files' => $files))->renderWith($this->AttachedFilesTemplate); }
/** * 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 DataObjectSet */ 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 DataObjectSet(); foreach (array('Stage', 'Live') as $stage) { $joinByStage = $join; $table = $class; $table .= $stage == 'Live' ? '_Live' : ''; $joinByStage .= sprintf("LEFT JOIN \"%s\" AS \"Parents\" ON \"%s\".\"ParentID\" = \"Parents\".\"ID\"", $table, $table); $stageOrphans = Versioned::get_by_stage($class, $stage, $filter, $sort, $joinByStage, $limit); $orphans->merge($stageOrphans); } $orphans->removeDuplicates(); return $orphans; }
function testRemoveDuplicates() { // Note that PageComment and DataObjectSetTest_TeamComment are both descendants of DataObject, and don't // share an inheritance relationship below that. $pageComments = DataObject::get('DataObjectSetTest_TeamComment'); $teamComments = DataObject::get('DataObjectSetTest_TeamComment'); /* Test default functionality (remove by ID). We'd expect to loose all our * team comments as they have the same IDs as the first three page comments */ $allComments = new DataObjectSet(); $allComments->merge($pageComments); $allComments->merge($teamComments); $this->assertEquals($allComments->Count(), 6); $allComments->removeDuplicates(); $this->assertEquals($allComments->Count(), 3, 'Standard functionality is to remove duplicate base class/IDs'); /* Now test removing duplicates based on a common field. In this case we shall * use 'Name', so we can get all the unique commentators */ $comment = new DataObjectSetTest_TeamComment(); $comment->Name = "Bob"; $allComments->push($comment); $this->assertEquals($allComments->Count(), 4); $allComments->removeDuplicates('Name'); $this->assertEquals($allComments->Count(), 3, 'There are 3 uniquely named commentators'); // Ensure that duplicates are removed where the base data class is the same. $mixedSet = new DataObjectSet(); $mixedSet->push(new SiteTree(array('ID' => 1))); $mixedSet->push(new Page(array('ID' => 1))); // dup: same base class and ID $mixedSet->push(new Page(array('ID' => 1))); // dup: more than one dup of the same object $mixedSet->push(new Page(array('ID' => 2))); // not dup: same type again, but different $mixedSet->push(new SiteTree(array('ID' => 1))); // dup: another dup, not consequetive. $mixedSet->removeDuplicates('ID'); $this->assertEquals($mixedSet->Count(), 2, 'There are 3 unique data objects in a very mixed set'); }
function getContextNav() { if($this->ID > 0) { $pages = new DataObjectSet(); $pages->push($this->Parent()); $pages->merge($this->getPagesBySibling()); $pages->merge($this->getPagesByKeyword()); $pages->merge($this->getPagesByBlogTags()); $pages->merge($this->getPagesByReferer()); $pages->removeDuplicates(); $currentPage = $pages->find('ID', $this->ID); if($currentPage) $pages->remove($currentPage); return $pages; } else { return false; } }
/** * Return the Sticky Threads * @return DataObjectSet */ function getStickyTopics($include_global = true) { $standard = DataObject::get("ForumThread", "\"ForumThread\".\"ForumID\" = {$this->ID} AND \"ForumThread\".\"IsSticky\" = 1", "MAX(\"PostList\".\"Created\") DESC", "INNER JOIN \"Post\" AS \"PostList\" ON \"PostList\".\"ThreadID\" = \"ForumThread\".\"ID\""); if (!$standard || !$standard->count()) { $standard = new DataObjectSet(); } if ($include_global) { // We have to join posts through their forums to their holders, and then restrict the holders to just the parent of this forum. $global = DataObject::get("ForumThread", "\"ForumThread\".\"IsGlobalSticky\" = 1", "MAX(\"PostList\".\"Created\") DESC", "INNER JOIN \"Post\" AS \"PostList\" ON \"PostList\".\"ThreadID\" = \"ForumThread\".\"ID\""); if (!$global || !$global->count()) { $global = new DataObjectSet(); } $standard->merge($global); $standard->removeDuplicates(); } if ($standard->count()) { $standard->sort('PostList.Created'); } return $standard; }
public static function get_by_publisher($class, $publisher, $status = null) { // To ensure 2.3 and 2.4 compatibility $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; if ($status) { $statusStr = "'" . implode("','", $status) . "'"; } $classes = (array) ClassInfo::subclassesFor($class); $classesSQL = implode("','", $classes); // build filter $filter = "{$bt}WorkflowRequest{$bt}.{$bt}ClassName{$bt} IN ('{$classesSQL}') "; if ($status) { $filter .= "AND {$bt}WorkflowRequest{$bt}.{$bt}Status{$bt} IN (" . $statusStr . ")"; } $onDraft = Versioned::get_by_stage("SiteTree", "Stage", $filter, "{$bt}SiteTree{$bt}.{$bt}LastEdited{$bt} DESC", "LEFT JOIN {$bt}WorkflowRequest{$bt} ON {$bt}WorkflowRequest{$bt}.{$bt}PageID{$bt} = {$bt}SiteTree{$bt}.{$bt}ID{$bt} "); $onLive = Versioned::get_by_stage("SiteTree", "Live", $filter, "{$bt}SiteTree_Live{$bt}.{$bt}LastEdited{$bt} DESC", "LEFT JOIN {$bt}WorkflowRequest{$bt} ON {$bt}WorkflowRequest{$bt}.{$bt}PageID{$bt} = {$bt}SiteTree_Live{$bt}.{$bt}ID{$bt} "); $return = new DataObjectSet(); $return->merge($onDraft); $return->merge($onLive); $return->removeDuplicates(); $canPublish = SiteTree::batch_permission_check($return->column('ID'), $publisher->ID, 'CanPublishType', 'SiteTree_PublisherGroups', 'canPublish'); foreach ($return as $page) { if (!isset($canPublish[$page->ID]) || !$canPublish[$page->ID]) { $return->remove($page); } } return $return; }