setRedirectable (true); } abstract protected function onFormSubmit (array $formdata); abstract protected function getQuery (Sql_Template $query); function run ($page) { if ($this->isFormSubmit ()) { $this->setInputParams (Input::instance ()->post ()); } else { $this->setInputParams (Input::instance ()->get ()); } $formdata = $this->processUserInput (); $this->catchRedirectableSearches (); if ($this->isFormSubmit ()) { $this->onFormSubmit ($formdata); } foreach ($this->getTemplateVariables () as $key => $value) { $this->getView ()->addGlobalVar ($key, $value); } if ($this->getMacrophage ()) { foreach ($this->getMacros() as $name => $value) { $this->getMacrophage ()->addMacro ($name, $value); } } $this->fetchResults ($page); } protected function fetchResults ($page) { { $query = new Sql_Template (); $query->addWhere ("`:prefix:templates`.disabled = 0"); $this->getQuery ($query); $limit = COLS * ROWS; $offset = ($page - 1) * $limit; $query->setLimit ($limit); $query->setOffset ($offset); } $searchcluster = ORM::factory ('templatesearch'); $templates = $searchcluster->getTemplatesByRequest ($query); $view = $this->getView (); { $view->templates = $templates ['templates']; $view->searchresult = $templates ['templates']; $view->url = '/' . preg_replace ('~/.*~', '', url::current ()); $templates_count = $templates ['records_total']; $view->search_count = $templates_count; $max_page = ceil ($templates_count / $limit); $view->max_page = $max_page; $view->page = $page; $view->pattern = ''; $view->catalog_type = ''; $view->alias = ''; if ($this->getFuzzy ()) { $view->similar = true; } } } private function isFormSubmit () { if (Input::instance ()->post ()) { return true; } if (Input::instance ()->post ('search') == 'advanced') { return true; } } private function catchRedirectableSearches () { if ($this->getRedirectable ()) { $template_variables = $this->getTemplateVariables (); if (count ($template_variables) == 1) { $parameter_name = current (array_keys ($template_variables)); $parameter_value = current (array_values ($template_variables)); if ($parameter_name == SearchCriterion_Type::PARAM_TYPE) { $type = ORM::factory ('templatetype', $parameter_value); $type_link = new Theme_Link_Catalog_Type (); $type_link->setUrlPattern (Setting_Model::get(Setting_Model::S_ROUTE_TYPE_FIRST)); $macrophage = new Theme_Macrophage (); $macrophage->addMacro ('PAGE-NUMBER', 1); $type_link->setMacrophage ($macrophage); $type_link->setRecord ($type); url::newurl ($type_link->getUrl ()); } elseif ($parameter_name == SearchCriterion_Category::PARAM_CATEGORY) { $category = ORM::factory ('templatecategory', $parameter_value); $category_link = new Theme_Link_Catalog_Category (); $category_link->setUrlPattern (Setting_Model::get(Setting_Model::S_ROUTE_CATEGORY_FIRST)); $macrophage = new Theme_Macrophage (); $macrophage->addMacro ('PAGE-NUMBER', 1); $category_link->setMacrophage ($macrophage); $category_link->setRecord ($category); url::newurl ($category_link->getUrl (), 301); } } } } function setRedirectable ($_redirectable) { $this->_redirectable = $_redirectable; } function getRedirectable () { return $this->_redirectable; } function setMacrophage ($macrophage) { $this->macrophage = $macrophage; } function getMacrophage () { return $this->macrophage; } }