Source of file CatalogueController.php
Size: 4,841 Bytes - Last Modified: 2021-12-24T05:16:22+00:00
/var/www/docs.ssmods.com/process/src/code/controller/CatalogueController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 | <?php /** * Top level controller that all catalogue controllers should extend. * There are some methods that have to be taken from ContentController * to allow the catalogue module to operate with just the core * framework, or with the CMS. * * @author i-lateral (http://www.i-lateral.com) * @package catalogue */ abstract class CatalogueController extends Controller { protected $dataRecord; /** * Returns the associated database record */ public function data() { return $this->dataRecord; } public function getDataRecord() { return $this->data(); } public function setDataRecord($dataRecord) { $this->dataRecord = $dataRecord; return $this; } public function init() { parent::init(); // Use theme from the site config if (($config = SiteConfig::current_site_config()) && $config->Theme) { Config::inst()->update('SSViewer', 'theme', $config->Theme); } } /** * Return the link to this controller, but force the expanded link to be returned so that form methods and * similar will function properly. * * @param string|null $action Action to link to. * @return string */ public function Link($action = null) { return $this->data()->Link(($action ? $action : true)); } /** * Return the title, description, keywords and language metatags. * * @todo Move <title> tag in separate getter for easier customization and more obvious usage * * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating * @return string The XHTML metatags */ public function MetaTags($includeTitle = true) { $tags = ""; if ($includeTitle === true || $includeTitle == 'true') { $tags .= "<title>" . Convert::raw2xml($this->Title) . "</title>\n"; } $generator = trim(Config::inst()->get('SiteTree', 'meta_generator')); if (!empty($generator)) { $tags .= "<meta name=\"generator\" content=\"" . Convert::raw2att($generator) . "\" />\n"; } $charset = Config::inst()->get('ContentNegotiator', 'encoding'); $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n"; if ($this->MetaDescription) { $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n"; } if ($this->ExtraMeta) { $tags .= $this->ExtraMeta . "\n"; } if (Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this)) && !$this instanceof ErrorPage) { $tags .= "<meta name=\"x-page-id\" content=\"{$this->ID}\" />\n"; $tags .= "<meta name=\"x-cms-edit-link\" content=\"" . $this->CMSEditLink() . "\" />\n"; } $this->extend('MetaTags', $tags); return $tags; } /** * Process and render search results. This has been hacked a bit to load * products into the list (if they exists). Will need to come up with a more * elegant solution to dealing with complex searches of objects though. * * @param array $data The raw request data submitted by user * @param SearchForm $form The form instance that was submitted * @param SS_HTTPRequest $request Request generated for this action */ public function results($data, $form, $request) { $results = $form->getResults(); // For the moment this will also need to be added to your // Page_Controller::results() method (until a more elegant solution can // be found if (class_exists("Product")) { $products = Product::get()->filterAny(array( "Title:PartialMatch" => $data["Search"], "StockID" => $data["Search"], "Content:PartialMatch" => $data["Search"] )); $results->merge($products); } $results = $results->sort("Title", "ASC"); $data = array( 'Results' => PaginatedList::create($results, $this->request), 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results') ); return $this ->owner ->customise($data) ->renderWith(array( 'Page_results', 'SearchResults', 'Page' )); } public function SiteConfig() { if (method_exists($this->dataRecord, 'getSiteConfig')) { return $this->dataRecord->getSiteConfig(); } else { return SiteConfig::current_site_config(); } } } |