Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/categories/categories_event_handler.php
Show First 20 Lines • Show All 495 Lines • ▼ Show 20 Line(s) | |||||
$type_clauses['product_related']['having_filter'] = false; | $type_clauses['product_related']['having_filter'] = false; | ||||
} | } | ||||
$type_clauses['menu']['include'] = '%1$s.IsMenu = 1'; | $type_clauses['menu']['include'] = '%1$s.IsMenu = 1'; | ||||
$type_clauses['menu']['except'] = '%1$s.IsMenu = 0'; | $type_clauses['menu']['except'] = '%1$s.IsMenu = 0'; | ||||
$type_clauses['menu']['having_filter'] = false; | $type_clauses['menu']['having_filter'] = false; | ||||
/** @var kSearchHelper $search_helper */ | |||||
$search_helper = $this->Application->recallObject('SearchHelper'); | |||||
if (in_array('search', $types) || in_array('search', $except_types)) { | if (in_array('search', $types) || in_array('search', $except_types)) { | ||||
$event_mapping = Array ( | $event_mapping = Array ( | ||||
'simple' => 'OnSimpleSearch', | 'simple' => 'OnSimpleSearch', | ||||
'subsearch' => 'OnSubSearch', | 'subsearch' => 'OnSubSearch', | ||||
'advanced' => 'OnAdvancedSearch' | 'advanced' => 'OnAdvancedSearch' | ||||
); | ); | ||||
$keywords = $event->getEventParam('keyword_string'); | $keywords = $event->getEventParam('keyword_string'); | ||||
$type = $this->Application->GetVar('search_type', 'simple'); | $type = $this->Application->GetVar('search_type', 'simple'); | ||||
if ( $keywords ) { | if ( $keywords ) { | ||||
// processing keyword_string param of ListProducts tag | // processing keyword_string param of ListProducts tag | ||||
$this->Application->SetVar('keywords', $keywords); | $this->Application->SetVar('keywords', $keywords); | ||||
$type = 'simple'; | $type = 'simple'; | ||||
} | } | ||||
$search_event = $event_mapping[$type]; | $search_event = $event_mapping[$type]; | ||||
$this->$search_event($event); | $this->$search_event($event); | ||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | /* @var $object kDBList */ | ||||
$search_sql = ' FROM ' . TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search | $search_sql = ' FROM ' . $search_helper->getSearchTable() . ' search_result | ||||
search_result JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; | JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; | ||||
$sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); | $sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); | ||||
$object->SetSelectSQL($sql); | $object->SetSelectSQL($sql); | ||||
$object->addCalculatedField('Relevance', 'search_result.Relevance'); | $object->addCalculatedField('Relevance', 'search_result.Relevance'); | ||||
$type_clauses['search']['include'] = '1'; | $type_clauses['search']['include'] = '1'; | ||||
$type_clauses['search']['except'] = '0'; | $type_clauses['search']['except'] = '0'; | ||||
$type_clauses['search']['having_filter'] = false; | $type_clauses['search']['having_filter'] = false; | ||||
} | } | ||||
$search_helper = $this->Application->recallObject('SearchHelper'); | |||||
/* @var $search_helper kSearchHelper */ | |||||
$search_helper->SetComplexFilter($event, $type_clauses, implode(',', $types), implode(',', $except_types)); | $search_helper->SetComplexFilter($event, $type_clauses, implode(',', $types), implode(',', $except_types)); | ||||
} | } | ||||
/** | /** | ||||
* Adds filter, that uses *.VIEW permissions to determine if an item should be shown to a user. | * Adds filter, that uses *.VIEW permissions to determine if an item should be shown to a user. | ||||
* | * | ||||
* @param kDBList $object Object. | * @param kDBList $object Object. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 1893 Lines • ▼ Show 20 Line(s) | |||||
* Makes simple search for categories | * Makes simple search for categories | ||||
* based on keywords string | * based on keywords string | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSimpleSearch($event) | function OnSimpleSearch($event) | ||||
{ | { | ||||
$event->redirect = false; | $event->redirect = false; | ||||
$search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; | |||||
$keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | $keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | ||||
$query_object = $this->Application->recallObject('HTTPQuery'); | $query_object = $this->Application->recallObject('HTTPQuery'); | ||||
/* @var $query_object kHTTPQuery */ | /* @var $query_object kHTTPQuery */ | ||||
/** @var kSearchHelper $search_helper */ | |||||
$search_helper = $this->Application->recallObject('SearchHelper'); | |||||
$search_table = $search_helper->getSearchTable(); | |||||
$sql = 'SHOW TABLES LIKE "'.$search_table.'"'; | $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; | ||||
if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) { | if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) { | ||||
// used when navigating by pages or changing sorting in search results | // used when navigating by pages or changing sorting in search results | ||||
return; | return; | ||||
} | } | ||||
if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length')) | if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length')) | ||||
{ | { | ||||
$this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); | $search_helper->ensureEmptySearchTable(); | ||||
$this->Application->SetVar('keywords_too_short', 1); | $this->Application->SetVar('keywords_too_short', 1); | ||||
return; // if no or too short keyword entered, doing nothing | return; // if no or too short keyword entered, doing nothing | ||||
} | } | ||||
$this->Application->StoreVar('keywords', $keywords); | $this->Application->StoreVar('keywords', $keywords); | ||||
$this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | |||||
$search_config_map[ $field_list[$key.'_primary'] ] = $field; | $search_config_map[ $field_list[$key.'_primary'] ] = $field; | ||||
} | } | ||||
$field_list[$key] = $local_table.'.'.$field_list[$key]; | $field_list[$key] = $local_table.'.'.$field_list[$key]; | ||||
$search_config_map[ $field_list[$key] ] = $field; | $search_config_map[ $field_list[$key] ] = $field; | ||||
} | } | ||||
} | } | ||||
// keyword string processing | // Keyword string processing. | ||||
$search_helper = $this->Application->recallObject('SearchHelper'); | |||||
/* @var $search_helper kSearchHelper */ | |||||
$where_clause = Array (); | $where_clause = Array (); | ||||
foreach ($field_list as $field) { | foreach ($field_list as $field) { | ||||
if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { | if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { | ||||
// local real field | // local real field | ||||
$filter_data = $search_helper->getSearchClause($object, $regs[1], $keywords, false); | $filter_data = $search_helper->getSearchClause($object, $regs[1], $keywords, false); | ||||
if ($filter_data) { | if ($filter_data) { | ||||
$where_clause[] = $filter_data['value']; | $where_clause[] = $filter_data['value']; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | |||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSubSearch($event) | function OnSubSearch($event) | ||||
{ | { | ||||
// keep search results from other items after doing a sub-search on current item type | // keep search results from other items after doing a sub-search on current item type | ||||
$this->Application->SetVar('do_not_drop_search_table', true); | $this->Application->SetVar('do_not_drop_search_table', true); | ||||
$ids = Array (); | /** @var kSearchHelper $search_helper */ | ||||
$search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; | $search_helper = $this->Application->recallObject('SearchHelper'); | ||||
$search_table = $search_helper->getSearchTable(); | |||||
$sql = 'SHOW TABLES LIKE "' . $search_table . '"'; | $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; | ||||
$ids = array(); | |||||
if ( $this->Conn->Query($sql) ) { | if ( $this->Conn->Query($sql) ) { | ||||
$item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); | $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); | ||||
// 1. get ids to be used as search bounds | // 1. get ids to be used as search bounds | ||||
$sql = 'SELECT DISTINCT ResourceId | $sql = 'SELECT DISTINCT ResourceId | ||||
FROM ' . $search_table . ' | FROM ' . $search_table . ' | ||||
WHERE ItemType = ' . $item_type; | WHERE ItemType = ' . $item_type; | ||||
▲ Show 20 Lines • Show All 399 Lines • Show Last 20 Lines |