/** * Return the submissions from the site * * @return PaginatedList */ public function getSubmissions($page = 1) { $record = $this->form->getRecord(); $submissions = $record->getComponents('Submissions', null, "\"Created\" DESC"); $query = DB::query(sprintf("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = '%d'", $record->ID)); $totalCount = 0; foreach ($query as $r) { $totalCount = $r['CountRows']; } $list = new PaginatedList($submissions); $list->setCurrentPage($page); $list->setPageLength(10); $list->setTotalItems($totalCount); return $list; }
/** * 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; }
public function testPrevLink() { $list = new PaginatedList(new ArrayList()); $list->setTotalItems(50); $this->assertNull($list->PrevLink()); $list->setCurrentPage(2); $this->assertContains('start=0', $list->PrevLink()); $list->setCurrentPage(3); $this->assertContains('start=10', $list->PrevLink()); $list->setCurrentPage(5); $this->assertContains('start=30', $list->PrevLink()); // Disable paging $list->setPageLength(0); $this->assertNull($list->PrevLink()); }