public function testGetIterator() { $collection = new Collection(); $this->assertInstanceOf('\\Iterator', $collection->getIterator()); }
private function _getNewProductPage(Product\Product $product, Page\Page $parent = null, $variantValue = null) { $pageType = array_key_exists($product->type->getName(), $this->_mapping) ? $this->_mapping[$product->type->getName()] : self::PAGE_TYPE; return $this->_pageCreate->create($this->_pageTypes->get($pageType), $product->name . (trim($variantValue) ? ' (' . trim($variantValue) . ')' : ''), $parent); }
/** * Load the results into instances of `Page` and return them. * * @return Page|array[Page] Singular Page object, or array of page objects */ private function _loadPages() { $results = $this->_runQuery(); $pages = $results->bindTo('Message\\Mothership\\CMS\\Page\\PageProxy', [$this->_loaders], false, $this->_pageCache); foreach ($results as $key => $data) { $pages[$key]->visibilitySearch = (bool) $pages[$key]->visibilitySearch; $pages[$key]->visibilityMenu = (bool) $pages[$key]->visibilityMenu; $pages[$key]->visibilityAggregator = (bool) $pages[$key]->visibilityAggregator; // Load the DateRange object for publishDateRange $pages[$key]->publishDateRange = new DateRange($data->publishAt ? new DateTimeImmutable(date('c', $data->publishAt)) : null, $data->unpublishAt ? new DateTimeImmutable(date('c', $data->unpublishAt)) : null); // Get the page type $pages[$key]->type = $this->_pageTypes->get($data->type); if (!isset($pages[$key]->slug) || !$pages[$key]->slug instanceof Slug) { // If the page is the most left page then it is the homepage so // we need to override the slug to avoid unnecessary redirects if ($this->_getMinPositionLeft() == $data->left) { $data->slug = new Slug('/'); } // Test if already set from cache before loading $pages[$key]->slug = new Slug($data->slug); } // Test if already set from cache before loading if (!isset($pages[$key]->type)) { $pages[$key]->type = clone $this->_pageTypes->get($data->type); } // Load authorship details // Test if already set from cache before loading if (!isset($pages[$key]->authorship)) { $pages[$key]->authorship = new Authorship(); $pages[$key]->authorship->create(new DateTimeImmutable(date('c', $data->createdAt)), $data->createdBy); if ($data->updatedAt) { $pages[$key]->authorship->update(new DateTimeImmutable(date('c', $data->updatedAt)), $data->updatedBy); } if ($data->deletedAt) { $pages[$key]->authorship->delete(new DateTimeImmutable(date('c', $data->deletedAt)), $data->deletedBy); } } // If the page is set to inherit it's access then loop through each // parent to find the inherited access level. // Check to see if this has already been loaded first (from cache) if (!isset($pages[$key]->access) || !is_array($pages[$key]->access)) { $pages[$key]->accessInherited = false; $check = $pages[$key]; while ($pages[$key]->access < 0) { $check = $this->_queryBuilderFactory->getQueryBuilder()->select(['access', 'GROUP_CONCAT(page_access_group.group_name SEPARATOR \',\') AS accessGroups'])->from('page')->leftJoin('page_access_group', 'page_access_group.page_id = page.page_id')->where('page.position_left < ?i', [$check->left])->where('page.position_right >= ?i', [$check->left])->where('page.position_depth = ?i - 1', [$check->depth])->getQuery()->run(); $check = $check->bindTo('Message\\Mothership\\CMS\\Page\\Page'); $check = $check[0]; $pages[$key]->access = $check->access; $data->accessGroups = $check->accessGroups; $pages[$key]->accessInherited = true; } // Ensure the page access is at least 0 $pages[$key]->access = max(0, $pages[$key]->access); // Load access groups $groups = array_filter(explode(',', $data->accessGroups)); $pages[$key]->accessGroups = array(); foreach ($groups as $groupName) { if ($group = $this->_userGroups->get(trim($groupName))) { $pages[$key]->accessGroups[$group->getName()] = $group; } } } if (!$this->_loadUnviewable && $this->_authorisation->isViewable($pages[$key], $this->_user)) { unset($pages[$key]); continue; } } return count($pages) == 1 && !$this->_returnAsArray ? array_shift($pages) : $pages; }