Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/CEP-838_857'
Browse files Browse the repository at this point in the history
  • Loading branch information
svenhoutmeyers committed May 8, 2015
2 parents b6fffac + 1da2954 commit 87c9299
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 45 deletions.
17 changes: 11 additions & 6 deletions culturefeed_agenda/culturefeed_agenda.module
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,20 @@ function culturefeed_agenda_url_outbound_alter(&$path, &$options, $original_path
$city_parts = explode(' ', $location);

// The search contains a zip code. Search city by zip + name.
if (is_numeric($city_parts[0])) {
if (is_numeric($city_parts[0]) && isset($city_parts[1])) {

// Search on city or city + (city)
if (count($city_parts) == 2) {
// Static cache the result.
if (!isset($city_slugs[$city_parts[0]][$city_parts[1]])) {
$city_slugs[$city_parts[0]][$city_parts[1]] = db_query('SELECT slug FROM {culturefeed_search_cities} WHERE zip = :zip AND name = :name', array(':zip' => $city_parts[0], ':name' => $city_parts[1]))->fetchField();
}
$location_slug = $city_slugs[$city_parts[0]][$city_parts[1]];
$name = $city_parts[1];
}
else {
$name = $city_parts[1] . ' ' . $city_parts[2];
}
// Static cache the result.
if (!isset($city_slugs[$city_parts[0]][$city_parts[1]])) {
$city_slugs[$city_parts[0]][$city_parts[1]] = db_query('SELECT slug FROM {culturefeed_search_cities} WHERE zip = :zip AND name = :name', array(':zip' => $city_parts[0], ':name' => $name))->fetchField();
}
$location_slug = $city_slugs[$city_parts[0]][$city_parts[1]];
}
// The search contains only a city / region name. Search on full name.
else {
Expand Down
1 change: 1 addition & 0 deletions culturefeed_pages/theme/theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function culturefeed_pages_preprocess_culturefeed_page(&$variables) {
$member['relation'] = check_plain($membership->relation);
$member['role'] = check_plain($membership->role);
$member['picture'] = check_plain($membership->user->depiction);
$member['validated'] = $membership->validated;

$variables['members'][] = $member;
}
Expand Down
22 changes: 22 additions & 0 deletions culturefeed_search/includes/helpers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,28 @@ function culturefeed_search_get_category_by_slug($slug, $domain = '') {

}

/**
* Get a category by name.
*/
function culturefeed_search_get_category_by_name($name, $domain = '') {

$query = db_select('culturefeed_search_terms', 'ct');
$query->condition('name', $name);
$query->range(0, 1);
$query->addField('ct', 'tid');
$query->addField('ct', 'slug');
$query->addField('ct', 'p1');
$query->addField('ct', 'p2');
$query->addField('ct', 'p3');
$query->addField('ct', 'p4');
if (!empty($domain)) {
$query->condition('did', $domain);
}

return $query->execute()->fetchObject();

}

/**
* Get a city by slug.
*/
Expand Down
86 changes: 47 additions & 39 deletions culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,50 +445,58 @@ protected function addFacetFilters($params) {
// Add the location facet. Only use the location if a distance is set.
// all other cases will search for a category Id of the type flandersregion
// or workingregion.
if (!empty($params['regId']) && !isset($params['distance'])) {

$regFilter = array();
$regFilter[] = $params['regId'];

if (!empty($params['wregIds'])) {
$regFilter[] = array_shift($params['wregIds']);

$wregFilters = array();
foreach ($params['wregIds'] as $wregId) {
$wregFilters[] = $wregId;
if (!empty($params['regId']) || !empty($params['location'])) {

if (!isset($params['distance'])) {

$regFilter = array();

if (empty($params['regId']) && !empty($params['location'])) {
$location = culturefeed_search_get_category_by_name($params['location']);
$params['regId'] = $location->tid;
}
}

$regFilterQuery = '(';
$regFilterQuery .= 'category_id:(' . implode(' OR ', $regFilter) .')';
if (!empty($wregFilters)) {
$regFilterQuery .= ' OR exact_category_id:(' . implode(' OR ', $wregFilters) . ')';
}
$regFilterQuery .= ')';
$this->parameters[] = new Parameter\FilterQuery($regFilterQuery);

}
elseif (!empty($params['location'])) {

// Check if postal was present.
$city_parts = explode(' ', $params['location']);
if (is_numeric($city_parts[0])) {
$distance = isset($params['distance']) ? $params['distance'] : FALSE;

// If category_actortype_id we assume that we search on pages (on day we have to fix)
if (isset($params['facet']['category_actortype_id'])) {
$this->parameters[] = new Parameter\FilterQuery('zipcode' . ':' . $city_parts[0]);

if (!empty($params['wregIds'])) {
$regFilter[] = array_shift($params['wregIds']);

$wregFilters = array();
foreach ($params['wregIds'] as $wregId) {
$wregFilters[] = $wregId;
}
}
else {
$this->parameters[] = new Parameter\Spatial\Zipcode($city_parts[0], $distance);

if (empty($_GET['only-wregs'])) {
$regFilter[] = $params['regId'];
}


$regFilterQuery = '(';
$regFilterQuery .= 'category_id:(' . implode(' OR ', $regFilter) .')';
if (!empty($wregFilters)) {
$regFilterQuery .= ' OR exact_category_id:(' . implode(' OR ', $wregFilters) . ')';
}
$regFilterQuery .= ')';
$this->parameters[] = new Parameter\FilterQuery($regFilterQuery);

}
else {
$location = '"' . str_replace('"', '\"', $params['location']) . '"';
$this->parameters[] = new Parameter\FilterQuery('category_flandersregion_name' . ':' . $location);
elseif (!empty($params['location'])) {

// Check if postal was present.
$city_parts = explode(' ', $params['location']);
if (is_numeric($city_parts[0]) && empty($params['wregIds'])) {
$distance = isset($params['distance']) ? $params['distance'] : FALSE;

// If category_actortype_id we assume that we search on pages (on day we have to fix)
if (isset($params['facet']['category_actortype_id'])) {
$this->parameters[] = new Parameter\FilterQuery('zipcode' . ':' . $city_parts[0]);
}
else {
$this->parameters[] = new Parameter\Spatial\Zipcode($city_parts[0], $distance);
}

}

}

}

// Calculate actor if available.
Expand Down

0 comments on commit 87c9299

Please sign in to comment.