public function setModifiers(array $modifiers) { if (($extras = array_diff($modifiers, array('not', 'nocase', 'case'))) != array()) { throw new InvalidArgumentException(get_class($this) . ' does not accept ' . implode(', ', $extras) . ' as modifiers'); } parent::setModifiers($modifiers); }
public function preDispatch(Zend_Controller_Request_Abstract $request) { if ('company' == $request->getControllerName()) { $tsn = $request->tsn ? $request->tsn : $_COOKIE['tsn']; if ($tsn) { $token = Token::create($tsn); $token->update_sync_time(); } else { $token = Token::create_abstract('123'); } if ($token->is_logined() == true) { if ($token->is_expire()) { $token->destroy(); include_once LIB_PATH . '/view_helper/BuildUrl.php'; $url_builder = new Zend_View_Helper_BuildUrl(); $referer = SearchFilter::slashes($url_builder->buildUrl($request->getActionName(), $request->getControllerName(), $request->getModuleName())); $login_url = $url_builder->buildUrl('login', 'auth', 'index', array('redirect' => $referer)); $redirector = new Zend_Controller_Action_Helper_Redirector(); $redirector->gotoUrl($login_url); return; } $token->register(); } else { if ('auth' != $request->getActionName()) { $token->destroy(); $request->setModuleName('index'); $request->setControllerName('auth'); $request->setActionName('login'); } } } }
static function _buildSingleSearchFilter($filterField, $val) { $searchFilter = new SearchFilter(); if (isset($filterField['meta'])) { $searchFilter->setField($filterField['meta']); } else { return NULL; } $searchFilter->setComparison($filterField['operator']); $filterVal = $val; if (isset($filterField['format']) && ($filterField['format'] == 'date' || $filterField['format'] == 'datetime')) { $filterVal = Helper_Date::formatSqlDateTime(strtotime($val)); } $searchFilter->setValue($filterVal); return $searchFilter; }
public function actionIndex() { $C = new CDbCriteria(array("condition" => "t.topics BETWEEN 80 AND 89 AND book.ac_read = 'a'", "order" => "t.cdate desc")); $filter = new SearchFilter("announces"); $filter->setAttributes($_GET, true); if ($filter->validate()) { if ($filter->cat) { $n = count($filter->category->mp); $C->addCondition("cat.mp[1:{$n}] = '{" . join(",", $filter->category->mp) . "}'"); } if ($filter->s_lang != 0) { $C->addCondition("book.s_lang = {$filter->s_lang}"); } if ($filter->t_lang != 0) { $C->addCondition("book.t_lang = {$filter->t_lang}"); } if ($filter->ready == 1) { $C->addCondition("book.n_verses != 0 AND book.d_vars >= book.n_verses"); } elseif ($filter->ready == 2) { $C->addCondition("book.n_verses != 0 AND book.d_vars < book.n_verses"); } elseif ($filter->ready == 3) { $C->addCondition("book.n_vars != 0 AND book.d_vars < book.n_verses"); } if ($filter->gen) { $C->addCondition("book.ac_read = 'a' AND book.ac_gen = 'a'"); } if ($filter->tr) { $C->addCondition("book.ac_tr = 'a'"); } if ($filter->topic) { $C->addCondition("t.topics = '{$filter->topic}'"); } } $dp = new CActiveDataProvider(Announce::model()->with("book.cat", "book.owner", "seen"), array("criteria" => $C, "pagination" => array("pageSize" => 20))); $this->side_view = array("index_side" => array("filter" => $filter)); $this->render("index", array("dp" => $dp)); }
/** * This implementation allows for a list of columns to be passed into MATCH() instead of just one. * * @example * <code> * MyDataObject::get()->filter('SearchFields:fulltext', 'search term') * </code> * * @throws Exception * @return string */ public function getDbName() { $indexes = Config::inst()->get($this->model, "indexes"); if (is_array($indexes) && array_key_exists($this->getName(), $indexes)) { $index = $indexes[$this->getName()]; if (is_array($index) && array_key_exists("value", $index)) { return $this->prepareColumns($index['value']); } else { // Parse a fulltext string (eg. fulltext ("ColumnA", "ColumnB")) to figure out which columns // we need to search. if (preg_match('/^fulltext\\s+\\((.+)\\)$/i', $index, $matches)) { return $this->prepareColumns($matches[1]); } else { throw new Exception(sprintf("Invalid fulltext index format for '%s' on '%s'", $this->getName(), $this->model)); } } } return parent::getDbName(); }
function __construct($fullName, $value = false, array $modifiers = array()) { Deprecation::notice('3.1', 'Use StartsWithFilter instead.'); parent::__construct($fullName, $value, $modifiers); }
/** * Adds a instance of {@link SearchFilter}. * * @param SearchFilter $filter */ public function addFilter($filter) { $this->filters[$filter->getFullName()] = $filter; }
function __construct($fullName, $value = false, array $modifiers = array()) { Deprecation::notice('3.1', 'Use ExactMatchFilter:not instead.'); $modifiers[] = 'not'; parent::__construct($fullName, $value, $modifiers); }
public function __construct($fullName, $value = false) { Deprecation::notice('3.0', 'PartialMatchFilter instead.'); SearchFilter::__construct($fullName, $value); }
public function index() { ClassLoader::import('application.model.presentation.CategoryPresentation'); $this->getAppliedFilters(); // presentation if ($theme = CategoryPresentation::getThemeByCategory($this->getCategory())) { if ($theme->getTheme()) { $this->application->setTheme($theme->getTheme()); } if ($layout = $theme->listStyle->get()) { $this->request->set('layout', strtolower($layout)); $this->config->set('LIST_LAYOUT', $layout); $this->config->set('ALLOW_SWITCH_LAYOUT', false); } } // pagination $currentPage = $this->request->get('page', 1); $listLayout = $this->getListLayout(); $perPage = $this->getProductLimitCount($listLayout); $offsetStart = ($currentPage - 1) * $perPage + 1; $offsetEnd = $currentPage * $perPage; $selectFilter = new ARSelectFilter(); $selectFilter->setLimit($perPage, $offsetStart - 1); $this->application->processInstancePlugins('productFilter', $selectFilter); // create new search filter $query = $this->request->get('q'); if ($query) { $searchFilter = new SearchFilter($query); $this->filters[] = $searchFilter; // search by category names $f = new ARSelectFilter(); foreach (array($this->locale->getLocaleCode(), $this->application->getDefaultLanguageCode()) as $handle) { $langHandle = MultiLingualObject::getLangSearchHandle(new ARFieldHandle('Category', 'name'), $handle); $f->mergeCondition(new LikeCond($langHandle, '%' . $query . '%')); } $foundCategories = ActiveRecordModel::getRecordSet('Category', $f, Category::LOAD_REFERENCES); foreach ($foundCategories as $category) { $category->getPathNodeSet(); } $cleanedQuery = $searchFilter->getCleanedQuery($query); $this->logSearchQuery($cleanedQuery); } // root category? if ($this->getCategory()->isRoot() && !$this->filters && !$this instanceof IndexController && !$this->request->get('includeSub') && $currentPage > 1) { return new ActionRedirectResponse('index', 'index'); } // sorting $sort = array(); $opts = $this->config->get('ALLOWED_SORT_ORDER'); if ($opts) { foreach ($opts as $opt => $status) { $sort[strtolower($opt)] = $this->translate($opt); } } foreach ($this->getCategory()->getSpecificationFieldArray() as $field) { if ($field['isSortable']) { $sortName = $field['dataType'] == SpecField::DATATYPE_NUMBERS ? '_sort_num' : '_sort_text'; $sort[$field['ID'] . '-' . $field['handle'] . '_asc'] = $this->maketext($sortName . '_asc', $field['name_lang']); $sort[$field['ID'] . '-' . $field['handle'] . '_desc'] = $this->maketext($sortName . '_desc', $field['name_lang']); } } $order = $this->request->get('sort'); $defOrder = strtolower($this->config->get('SORT_ORDER')); if (!$order) { $order = $defOrder; } $this->applySortOrder($selectFilter, $order); // setup ProductFilter $productFilter = new ProductFilter($this->getCategory(), $selectFilter); if ($this->config->get('INCLUDE_SUBCATEGORY_PRODUCTS')) { $productFilter->includeSubcategories(); } $this->productFilter = $productFilter; foreach ($this->filters as $filter) { $productFilter->applyFilter($filter); if ($filter instanceof SearchFilter) { $productFilter->includeSubcategories(); $searchQuery = $filter->getKeywords(); } } if ($this->getCategory()->isRoot() && $this->filters || $this->filters || $this->request->get('includeSub')) { $productFilter->includeSubcategories(); } $products = $this->getProductsArray($productFilter); $this->hasProducts = count($products) > 0; // pagination $count = new ProductCount($this->productFilter, $this->application); $totalCount = $count->getCategoryProductCount($productFilter); $offsetEnd = min($totalCount, $offsetEnd); $this->totalCount = $totalCount; // narrow by subcategories $subCategories = $this->getCategory()->getSubCategoryArray(Category::LOAD_REFERENCES); $categoryNarrow = array(); if ((!empty($searchQuery) || $this->getCategory()->isRoot() || $this->filters) && $products) { $categoryNarrow = $this->getSubCategoriesBySearchQuery($productFilter->getSelectFilter(), $subCategories); } $categoryArray = $this->getCategory()->toArray(); if (!$this->getCategory()->isRoot()) { $this->redirect301($this->request->get('cathandle'), createHandleString($categoryArray['name_lang'])); } // if all the results come from one category, redirect to this category if (count($categoryNarrow) == 1 && count($this->filters) == 1 && empty($foundCategories)) { $canNarrow = true; foreach ($products as $product) { if ($product['Category']['ID'] == $this->getCategoryId()) { $canNarrow = false; } } if ($canNarrow) { while (count($categoryNarrow) == 1) { if ($categoryNarrow[0]['searchCount'] != $totalCount) { break; } $this->category = Category::getInstanceByID($categoryNarrow[0]['ID'], Category::LOAD_DATA); $subCategories = $this->getCategory()->getSubCategoryArray(Category::LOAD_REFERENCES); if ($subCategories) { $subCategories[] = $categoryArray; } $categoryNarrow = $this->getSubCategoriesBySearchQuery($selectFilter, $subCategories); } include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; if (!$this->getCategory()->isRoot()) { return new RedirectResponse(createCategoryUrl(array('data' => $this->getCategory()->toArray(), 'filters' => $this->filters), $this->application)); } } } // get subcategory-subcategories if ($subCategories && $this->config->get('CAT_MENU_SUBS')) { $this->getSubSubCategories($subCategories); } // get subcategory featured products $subCatFeatured = array(); if ($subCategories && !$products || $this instanceof IndexController) { $subCatFeatured = $this->getSubCatFeaturedProducts(); } // if there were no products found, include subcategories in filter counts... except home page if (!$products || $this->getCategory()->isRoot()) { $selectFilter->removeCondition(new EqualsCond(new ARFieldHandle('Product', 'categoryID'), $this->getCategory()->getID())); $this->productFilter->includeSubcategories(); } // search redirects // no products found, but found one category name - redirect to this category if (isset($foundCategories) && 1 == $foundCategories->size() && !$products) { include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; return new RedirectResponse(createCategoryUrl(array('data' => $foundCategories->get(0)->toArray()), $this->application)); } $filterArray = array(); foreach ($this->filters as $filter) { $filterArray[] = $filter->toArray(); } if ($this->config->get('DISPLAY_CATEGORY_FEATURED')) { $this->getFeaturedMainCategoryProducts($subCategories); $this->getFeaturedMainCategoryProducts($categoryNarrow); } $response = new ActionResponse(); $response->set('id', $this->getCategoryId()); $response->set('products', $products); $response->set('count', $totalCount); $response->set('offsetStart', $offsetStart); $response->set('offsetEnd', $offsetEnd); $response->set('perPage', $perPage); $response->set('currentPage', $currentPage); $response->set('category', $categoryArray); $response->set('subCategories', $subCategories); $response->set('currency', $this->getRequestCurrency()); $response->set('sortOptions', $sort); $response->set('sortForm', $this->buildSortForm($order)); $response->set('sortField', $order); $response->set('categoryNarrow', $categoryNarrow); $response->set('subCatFeatured', $subCatFeatured); //$response->set('allFilters', $filters); //$response->set('showAll', $showAll); $response->set('appliedFilters', $filterArray); $response->set('layout', $listLayout); $response->set('listAttributes', $this->getListAttributes()); $filterChainHandle = $this->setUpBreadCrumbAndReturnFilterChainHandle($currentPage); $response->set('url', $this->getCategoryPageUrl(array('page' => '_000_', 'filters' => $filterChainHandle))); $response->set('layoutUrl', $this->getCategoryPageUrl(array('filters' => $filterChainHandle, 'query' => array('layout' => '')))); $response->set('filterChainHandle', $filterChainHandle); if (isset($searchQuery)) { $response->set('searchQuery', $searchQuery); } if (isset($foundCategories)) { $response->set('foundCategories', $foundCategories->toArray()); } // look for manufacturer filter foreach ($this->filters as $filter) { if ($filter instanceof ManufacturerFilter) { $response->set('manufacturerFilter', $filter->toArray()); } } if (1 == $currentPage && $query) { $searchCon = new SearchController($this->application); $response->set('modelSearch', $searchCon->searchAll($cleanedQuery)); } return $response; }
public function actionIndex() { $filter = new SearchFilter("search"); // Критерий с условиями поиска $C = new CDbCriteria(); $C->with = array("owner", "cat"); $filter->setAttributes($_GET, true); if ($filter->validate()) { if ($_GET["from"] == "header" && mb_substr($filter->t, 0, 1) == "@") { $this->redirect("/users/go?login="******"/", "", $filter->t); if ($filter->t != "") { $words = explode(" ", $filter->t); $words_cnt = 0; foreach ($words as $i => $w) { $w = trim($w); if (mb_strlen($w) <= 2) { continue; } $param = "word_" . $i; $w = pg_escape_string($w); $C->addCondition("s_title ILIKE :{$param} OR t_title ILIKE :{$param}"); $C->params[$param] = '%' . $w . '%'; $words_cnt++; } if ($words_cnt == 0) { $filter->t = ""; } } if ($filter->cat) { $n = count($filter->category->mp); $C->addCondition("cat.mp[1:{$n}] = '{" . join(",", $filter->category->mp) . "}'"); } if ($filter->s_lang != 0) { $C->addCondition("s_lang = {$filter->s_lang}"); } if ($filter->t_lang != 0) { $C->addCondition("t_lang = {$filter->t_lang}"); } if ($filter->ready) { $C->addCondition("t.n_verses != 0 AND t.d_vars >= t.n_verses"); } if ($filter->gen) { $C->addCondition("t.ac_read = 'a' AND t.ac_gen = 'a'"); } if ($filter->tr) { $C->addCondition("ac_tr = 'a'"); } } $C->order = SearchFilter::$sortSQL[$filter->sort]; $dp = new CActiveDataProvider(Book::model()->with("owner"), array("criteria" => $C, "pagination" => array("pageSize" => 50))); if ($filter->doSearch) { $dp->totalItemCount = Yii::app()->db->createCommand("SELECT COUNT(*) FROM books t LEFT JOIN catalog cat ON t.cat_id = cat.id WHERE {$C->condition}")->queryScalar($C->params); // Пишем в логи if ($dp->totalItemCount > 0 && $_GET["from"] != "stop" && $filter->t != "") { Yii::app()->db->createCommand("INSERT INTO search_history (ip, request) VALUES (:ip, :request)")->execute(array(":ip" => $_SERVER["HTTP_X_REAL_IP"] ? $_SERVER["HTTP_X_REAL_IP"] : $_SERVER["REMOTE_ADDR"], ":request" => $filter->t)); } } $this->side_view = array("index_side" => array("filter" => $filter)); $this->render("index", array("filter" => $filter, "dp" => $dp)); }