All Classes Functions Variables Pages
Automad\Core\Selection Class Reference

Public Member Functions

 __construct ($pages)
 excludePage ($url)
 getSelection ($excludeHidden=true, $offset=0, $limit=NULL)
 filterBreadcrumbs ($url)
 filterByParentUrl ($parent)
 filterByTag ($tag)
 filterByTemplate ($template)
 filterByKeywords ($str)
 filterPrevAndNextToUrl ($url)
 filterRelated ($Page)
 sortPagesByBasename ($order=SORT_ASC)
 sortPages ($var, $order=SORT_ASC)

Private Member Functions

 excludeHidden ()

Private Attributes

 $selection = array()

Detailed Description

The Selection class holds all methods to filter and sort the collection of pages and return them as a new selection.

Every instance can return a filtered and sorted array of pages without hurting the original Automad object. That means the Automad class object has to be created only once. To get multiple different (sorted and filtered) collections, this class can be used by just passing the collection array.

All the filter function directly modify $this->selection. After all modifications to that selection, it can be returned once by $this->getSelection().

Marc Anton Dahmen hello.nosp@m.@mar.nosp@m.cdahm.nosp@m.en.d.nosp@m.e
MIT license -

Definition at line 59 of file selection.php.

Constructor & Destructor Documentation

Automad\Core\Selection::__construct (   $pages)

Pass a set of pages to $this->selection excluding all hidden pages.

array$pages(normally Automad::getCollection() or any other selection array)

Definition at line 78 of file selection.php.

Member Function Documentation

Automad\Core\Selection::excludeHidden ( )

Exclude all hidden pages from the selection.

Definition at line 89 of file selection.php.

Automad\Core\Selection::excludePage (   $url)

Remove a page from the selection.


Definition at line 108 of file selection.php.

Automad\Core\Selection::filterBreadcrumbs (   $url)

Collect all pages along a given URL.


Definition at line 143 of file selection.php.

Automad\Core\Selection::filterByKeywords (   $str)

Filter $this->selection by multiple keywords (a search string), if $str is not empty.


Definition at line 258 of file selection.php.

Automad\Core\Selection::filterByParentUrl (   $parent)

Filter $this->selection by relative url of the parent page.


Definition at line 185 of file selection.php.

Automad\Core\Selection::filterByTag (   $tag)

Filter $this->selection by tag.


Definition at line 206 of file selection.php.

Automad\Core\Selection::filterByTemplate (   $template)

Filter $this->selection by a template, if $template is not empty.


Definition at line 233 of file selection.php.

Automad\Core\Selection::filterPrevAndNextToUrl (   $url)

Filter out the neighbors (previous and next page) to the passed URL under the same parent URL.

$this->selection only holds two pages after completion with the keys ['prev'] and ['next'] instead of the URL-key. If there is only one page in the array (has no siblings), the selection will be empty. For two pages, it will only contain the ['next'] page. For more than two pages, both neighbors will be set in the selection.


Definition at line 306 of file selection.php.

Automad\Core\Selection::filterRelated (   $Page)

Filter all pages having one or more tag in common with $Page. If there are not tags defined for the passed page, the selection will be an empty array. (no tags = no related pages)


Definition at line 361 of file selection.php.

Automad\Core\Selection::getSelection (   $excludeHidden = true,
  $offset = 0,
  $limit = NULL 

Return the array with the selected (filtered and sorted) pages.

array $this->selection

Definition at line 126 of file selection.php.

Automad\Core\Selection::sortPages (   $var,
  $order = SORT_ASC 

Sorts $this->selection based on any variable in the text files. If the $var gets passed empty, $this->sortPagesByBasename() will be used as fallback. If a variable doesn't exist for page, that page's value in $arrayToSortBy will be set to its basename. That allows for simply sorting a selection by original order from the HTML class by passing an invalid var like "-" or "orig" etc.

string$var(any variable from a text file)
string$order(optional: SORT_ASC, SORT_DESC)

Definition at line 420 of file selection.php.

Automad\Core\Selection::sortPagesByBasename (   $order = SORT_ASC)

Sorts the $this->selection based on the file system path's basename.

string$order(optional: SORT_ASC, SORT_DESC)

Definition at line 395 of file selection.php.

Member Data Documentation

Automad\Core\Selection::$selection = array()

Initially holds the whole collection.

$selection is basically the internal working copy of the collection array. It can be sorted and filtered without hurting the Automad::siteCollection.

Definition at line 69 of file selection.php.

The documentation for this class was generated from the following file: