Source of file ListSorterOption.php
Size: 2,137 Bytes - Last Modified: 2021-12-24T06:34:52+00:00
/var/www/docs.ssmods.com/process/src/src/ListSorterOption.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?php namespace SilverShop\ListSorter; use SilverStripe\Control\HTTP; use SilverStripe\View\ViewableData; /** * Encapsulate sort option title, sorting SQL, * GET parameter key, and reverse option. */ class ListSorterOption extends ViewableData { protected $title; protected $id; protected $sortSet; protected $reverseOption; public function __construct($title, $sortset, ListSorterOption $reverseOption = null) { $this->title = $title; $this->setID($title); $this->sortSet = $sortset; if ($reverseOption) { $this->setReverseOption($reverseOption); } } public function getTitle() { return $this->title; } public function setTitle($title) { $this->title = $title; return $this; } public function getSortSet() { return $this->sortSet; } public function setReverseOption(ListSorterOption $option) { $this->reverseOption = $option; if (!$option->isReversable()) { if ($this->getID() === $option->getID()) { $option->setID((string)$option . "_rev"); } $option->setReverseOption($this); } return $this; } public function getReverseOption() { return $this->reverseOption; } public function isReversable() { return (bool)$this->reverseOption; } public function setID($id) { $this->id = strtolower(trim($id)); return $this; } public function getID() { return $this->id; } public function __toString() { return $this->id; } public function getLink() { return $this->generateLink($this->getID()); } /** * Helper for creating sort links * * @param $id * @return string */ private function generateLink($id) { $url = Http::setGetVar('sort', $id, null, '&'); //TODO: strip "start" pagination parameter, //as most users won't want to remain on paginated page when sorting return $url; } } |