Commit a63dcfa0 authored by Simonas's avatar Simonas

City & Categories ordering, optimization

parent 781f20f5
......@@ -91,8 +91,8 @@
<script src="/wp-content/themes/biuro/js/main.min.js" async></script>
<?php
global $time_start;
delog((microtime(true) - $time_start), 'Lorem ipsum');
// global $time_start;
// delog((microtime(true) - $time_start), 'Lorem ipsum');
?>
<?php wp_footer(); ?>
</body>
......
......@@ -460,7 +460,7 @@ function start_session() {
session_start();
}
if(!isset($_SESSION['referer']) && $_SERVER['HTTP_REFERER'] != null) {
if(!isset($_SESSION['referer']) && $_SERVER['HTTP_REFERER'] !== null) {
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
}
}
......@@ -484,7 +484,7 @@ function getDivisions ( $request ) {
while ( $divisions->fetch() ) :
$slug = $divisions->display( 'city.slug' );
if ($lang != pll_get_post_language( $divisions->display( 'ID' ) ) || !$divisions->display( 'lat' ) || !$divisions->display( 'lng' )):
if ($lang !== pll_get_post_language( $divisions->display( 'ID' ) ) || !$divisions->display( 'lat' ) || !$divisions->display( 'lng' )):
continue;
endif;
......@@ -572,11 +572,11 @@ function getPageTerm($keys) {
$val = trim($value);
$taxonomy = substr($val, 20);
if ( '_' == $val{0} || substr($val, 0, 20) != 'built_in_taxonomies_' || !$taxonomy):
if ( '_' == $val{0} || substr($val, 0, 20) !== 'built_in_taxonomies_' || !$taxonomy):
continue;
endif;
$res = get_post_custom_values( $val, $ID );
$res = get_post_custom_values( $val );
if ( !$res ) :
continue;
......@@ -602,7 +602,7 @@ function template_include($template) {
wp_parse_str( $query_string, $searchQuery );
if (!$searchQuery || !$searchQuery['s']):
if (!$searchQuery || !isset($searchQuery['s'])):
return $template;
endif;
......@@ -615,14 +615,13 @@ function template_include($template) {
return $template;
}
// Redirect to single job page by LIVAS Job ID
function livas_job_id_redirect() {
global $query_string;
wp_parse_str( $query_string, $searchQuery );
if ($searchQuery['name'] == 'livas-id' && is_numeric($searchQuery['page'])):
if (isset($searchQuery['name']) && $searchQuery['name'] == 'livas-id' && isset($searchQuery['page']) && is_numeric($searchQuery['page'])):
$jobs = pods( 'job', array(
'where' => 'livas-id.meta_value = "' . $searchQuery['page'] . '"',
......@@ -665,7 +664,7 @@ function jobs_livas_id_search( $wp ) {
global $pagenow;
// If it's not the post listing return
if( 'edit.php' != $pagenow )
if( 'edit.php' !== $pagenow )
return;
// If it's not a search return
......@@ -673,7 +672,7 @@ function jobs_livas_id_search( $wp ) {
return;
// If it's a search but there's no prefix, return
if( '#' != substr( $wp->query_vars['s'], 0, 1 ) )
if( '#' !== substr( $wp->query_vars['s'], 0, 1 ) )
return;
// Validate the numeric value
......@@ -723,105 +722,63 @@ wp_reset_query();
define('positionsPage', $positionsPage);
function getRecords($taxonomy) {
global $wpdb;
function getOptions($taxonomy, $location = '', $str = '') {
global $query_string;
// if ($searchQuery['city']):
// $city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' );
// endif;
// if ($searchQuery['s']):
// $field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' );
// $type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' );
// endif;
// if ($taxonomy == 'city'):
// if ( $field ) :
// $counter = $counter . ' AND field.term_id = ' . $field->term_id;
// elseif ( $type ) :
// $counter = $counter . ' AND type.term_id = ' . $type->term_id;
// else:
// $counter = $counter . ' AND (t.post_title LIKE "%' . $searchQuery['s'] . '%" OR t.post_content LIKE "%' . $searchQuery['s'] . '%")';
// endif;
// if ( $city && $city->term_id == $termID ) :
// $active = true;
// endif;
// elseif ($taxonomy == 'type' || $taxonomy == 'field'):
// if ( $city ) :
// $counter = $counter . ' AND city.term_id = ' . $city->term_id;
// endif;
// endif;
$langs = pll_the_languages(array('raw'=>1));
$langID = $langs[pll_current_language('slug')]['id'];
$prefix = $wpdb->prefix;
$today = date('Y-m-d');
$order = ($taxonomy == 'city') ? 'no DESC' : 'total DESC';
$additional = '';
$and = '';
$term = '';
$termID = '';
wp_parse_str( $query_string, $searchQuery );
$pageTerms = getPageTerm(get_post_custom_keys());
if ($pageTerms):
// if ($taxonomy == 'city' && ($pageTerms->taxonomy == 'type' || $pageTerms->taxonomy == 'field')):
if ($pageTerms->taxonomy === 'city' && ($taxonomy == 'type' || $taxonomy == 'field') || $taxonomy == 'city' && ($pageTerms->taxonomy == 'type' || $pageTerms->taxonomy == 'field')):
$additional = "
LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '" . $pageTerms->taxonomy . "' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
LEFT JOIN `wp_terms` AS `" . $pageTerms->taxonomy . "` ON `" . $pageTerms->taxonomy . "`.`term_id` = `rel_tt_term2`.`term_id`
";
$and = "
AND `" . $pageTerms->taxonomy . "`.`term_id` = " . $pageTerms->term_id
;
return getResults($taxonomy, $pageTerms->taxonomy, $pageTerms->term_id);
endif;
endif;
// LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
// LEFT JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = 'city' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
// LEFT JOIN `wp_terms` AS `city` ON `city`.`term_id` = `rel_tt_term2`.`term_id`
$location = $location || isset($searchQuery['city']) ? preg_replace('/[\+]/', ' ', $searchQuery['city']) : '';
$search = $str || isset($searchQuery['s']) ? preg_replace('/[\+]/', ' ', $searchQuery['s']) : '';
// WHERE ( ( `valid`.`meta_value` > "2019-05-29" AND `field`.`term_id` = 297 AND `city`.`term_id` = 285 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )
if ( $location !== '' && $taxonomy !== 'city') :
$city = get_term_by( 'name', $location, 'city' );
if ($city):
return getResults($taxonomy, $city->taxonomy, $city->term_id);
endif;
elseif ( $search !== '' && $taxonomy !== 'field' && $taxonomy !== 'type') :
$field = get_term_by( 'name', $search, 'field' );
if ($field):
return getResults($taxonomy, $field->taxonomy, $field->term_id);
endif;
$type = get_term_by( 'name', $search, 'type' );
// WHERE ( ( `valid`.`meta_value` &gt; "2019-05-29" AND `field`.`term_id` = 297 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )
if ($type):
return getResults($taxonomy, $type->taxonomy, $type->term_id);
endif;
// if ($taxonomy == 'city' && ($pageTerms->taxonomy == 'type' || $pageTerms->taxonomy == 'field')) {
// }
// if ($taxonomy == 'city' && ($pageTerms->taxonomy == 'type' || $pageTerms->taxonomy == 'field')) {
// if ($taxonomy == 'city' && ($pageTerms->taxonomy === 'type' || $pageTerms->taxonomy === 'field') || $taxonomy != 'city' && $pageTerms->taxonomy === 'city') {
// }
// } else if ($taxonomy != 'city' && $pageTerms->taxonomy === 'city') {
// && ($pageTerms->taxonomy === 'type' || $pageTerms->taxonomy === 'field' || $pageTerms->taxonomy === 'city')
// if ($pageTerms->taxonomy === 'type'):
// $additional = 'AND `type`.`term_id` = 297';
// elseif ($pageTerms->taxonomy === 'field'):
// $additional = 'AND `field`.`term_id` = 297';
// // $searchQuery['s'] = $pageTerms->name;
// elseif ($pageTerms->taxonomy === 'city'):
// $additional = 'AND `city`.`term_id` = 297';
// // $searchQuery['city'] = $pageTerms->name;
// endif;
endif;
return getResults($taxonomy, $term, $termID);
}
function getResults($taxonomy, $term, $termID) {
global $wpdb;
$condition = ($term && $termID) ? " AND `" . $term . "`.`term_id` = " . $termID : '';
$structure = ($term && $termID) ? " LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '" . $term . "' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
LEFT JOIN `wp_terms` AS `" . $term . "` ON `" . $term . "`.`term_id` = `rel_tt_term2`.`term_id` " : '';
$langs = pll_the_languages(array('raw'=>1));
$langID = $langs[pll_current_language('slug')]['id'];
$prefix = $wpdb->prefix;
$today = date('Y-m-d');
$order = ($taxonomy == 'city') ? 'no DESC' : 'total DESC';
$sql = "SELECT * FROM (SELECT term.name, count(*) as total, CAST(`termmeta`.`meta_value` as INT) as no, `termpage`.`meta_value` as pageID, `term`.`term_id` as termID, `pages`.`post_title` as title
$sql = "SELECT * FROM (SELECT term.name, count(*) as total, CAST(`termmeta`.`meta_value` as INT) as no, `termpage`.`meta_value` as pageID, `term`.`term_id` as termID, `pages`.`post_title` as title, `pages`.`post_status` as status
FROM `{$prefix}posts` AS `t`
LEFT JOIN `{$prefix}postmeta` AS `valid` ON `valid`.`meta_key` = 'valid' AND `valid`.`post_id` = `t`.`ID`
......@@ -832,29 +789,11 @@ function getRecords($taxonomy) {
LEFT JOIN `{$prefix}termmeta` AS `termmeta` ON termmeta.term_id = term.term_id AND termmeta.meta_key = 'order'
LEFT JOIN `{$prefix}termmeta` AS `termpage` ON termpage.term_id = term.term_id AND termpage.meta_key = 'page-id'
LEFT JOIN `{$prefix}posts` AS `pages` ON `pages`.`ID` = `termpage`.`meta_value`
{$additional}
{$structure}
LEFT JOIN `{$prefix}term_relationships` AS `polylang_languages` ON `polylang_languages`.`object_id` = `t`.`ID` AND `polylang_languages`.`term_taxonomy_id` = $langID
WHERE ( ( `valid`.`meta_value` >= '{$today}' {$and} ) AND ( `t`.`post_type` = 'job' ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( 'publish' ) ) )
WHERE ( ( `valid`.`meta_value` >= '{$today}' {$condition} ) AND ( `t`.`post_type` = 'job' ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( 'publish' ) ) )
GROUP BY term.name) records
ORDER BY $order, name ASC";
// if ($taxonomy == 'field'):
// var_dump($sql);
// // delog($additional, '$additional');
// // delog($and, '$and');
// // delog($taxonomy, '$taxonomy');
// // // // delog('$searchQuery');
// // // // debug($searchQuery);
// // // // delog('$pageTerms');
// // // // debug($pageTerms);
// // // // delog('$Query');
// // // debug($wpdb->get_results($sql, ARRAY_A));
// endif;
return $wpdb->get_results($sql, ARRAY_A);
}
// WHERE ( ( `valid`.`meta_value` &gt; "2019-05-29" AND `field`.`term_id` = 297 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )
<?php
global $time_start;
$time_start = microtime(true);
// getRecords('city');
// getRecords('field');
// getRecords('type');
// global $time_start;
// $time_start = microtime(true);
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
......
......@@ -49,52 +49,18 @@ get_header(); ?>
<div class="c-divisions">
<?php
if ( 1 < $divisions->total() ):
/*
$divisionsPage = new WP_Query( array(
'numberposts' => 1,
'post_type' => 'page',
'meta_key' => 'page',
'meta_value' => 'employees-contacts'
) );
if ( $divisionsPage->have_posts() ) :
while( $divisionsPage->have_posts() ) :
$divisionsPage->the_post();
?>
<a class="c-division <?php if ( $total == 0 ) { echo 'c-division--active'; } ?>" href="<?php the_permalink(); ?>"><?php _e('All', 'biuro'); ?></a>
<?php
endwhile;
else:
*/
?>
<span class="js-division c-division"><?php _e('All', 'biuro'); ?></span>
<?php
/*
endif;
*/
wp_reset_query();
endif;
while ( $divisions->fetch() ) :
$slug = $divisions->display( 'city.slug' );
if ( !in_array($slug, $cities) && $divisions->display( 'name' ) ) :
/*
$page = $divisions->field( 'page-id' );
if ( !empty( $page ) ):
?>
<a class="js-division c-division <?php if ( $pageID == $page['ID'] ) { echo 'c-division--active'; } ?>" data-id="<?php echo $slug; ?>" href="<?php echo esc_url( get_permalink( $page['ID'] ) ); ?>"><?php echo $divisions->display( 'city' ); ?></a>
<?php
else:
*/
?>
<span class="js-division c-division" data-id="<?php echo $slug; ?>"><?php echo $divisions->display( 'city' ); ?></span>
<?php
/*
endif;
*/
array_push($cities, $slug);
endif;
endwhile;
......
......@@ -125,7 +125,7 @@ get_header(); ?>
continue;
endif;
$res = get_post_custom_values( $val, $ID );
$res = get_post_custom_values( $val );
if ( !$res ) :
continue;
......
......@@ -74,7 +74,6 @@ get_header(); ?>
<?php
global $query_string;
$ID = get_the_ID();
$keys = get_post_custom_keys();
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '"';
......@@ -120,7 +119,7 @@ get_header(); ?>
continue;
endif;
$res = get_post_custom_values( $val, $ID );
$res = get_post_custom_values( $val );
if ( !$res ) :
continue;
......
......@@ -28,12 +28,6 @@ if ( get_post_type() == 'page' ):
endif;
?>
<?php
// $res = getRecords('city', $searchQuery);
// debug($res);
// exit();
?>
<form id="search" class="c-search" action="<?php echo home_url(); ?>" method="get">
......@@ -43,16 +37,14 @@ endif;
</svg>
<datalist id="search-cities">
<?php
$res = getRecords('city', $searchQuery);
foreach ( $res as $r ):
foreach ( getOptions('city') as $r ):
?>
<option value="<?php echo $r['name']; ?>"><?php echo $r['name']; ?> (<?php echo $r['total']; ?>)</option>
<?php
endforeach;
?>
</datalist>
<input list="search-cities" id="search-city" name="city" value="<?php echo ($searchQuery && $searchQuery['city']) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" />
<input list="search-cities" id="search-city" name="city" value="<?php echo (isset($searchQuery['city'])) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" />
</div><!-- .c-search--col c-search--col-location -->
<div class="c-search--col c-search--col-keyword">
......@@ -62,15 +54,14 @@ endif;
<datalist id="search-queries">
<?php
$options = array_merge(getRecords('field', $searchQuery), getRecords('type', $searchQuery));
foreach ( $options as $option ):
foreach ( array_merge(getOptions('field'), getOptions('type')) as $option ):
?>
<option value="<?php echo $option['name']; ?>"><?php echo $option['name']; ?> (<?php echo $option['total']; ?>)</option>
<?php
endforeach;
?>
</datalist>
<input list="search-queries" id="search-query" name="s" value="<?php echo ($searchQuery && $searchQuery['s']) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" />
<input list="search-queries" id="search-query" name="s" value="<?php echo (isset($searchQuery['s'])) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" />
</div><!-- .c-search--col c-search--col-keyword -->
<button class="o-btn c-btn--main <?php if ( is_front_page() ): ?>c-btn--search<?php else: ?>c-btn--search-small<?php endif; ?>" type="submit" value="1">
<svg xmlns="http://www.w3.org/2000/svg" width="17px" height="17px" viewBox="0 0 17 17" class="c-ico--search">
......
......@@ -17,6 +17,7 @@ global $jobs;
$i = 0;
while ( $jobs->fetch() ) :
$ID = $jobs->display( 'ID' );
$name = $jobs->display( 'name' );
//Primary city id
$primaryCities = get_post_meta($ID, '_yoast_wpseo_primary_city');
......@@ -25,7 +26,7 @@ global $jobs;
?>
<tr <?php if ( $i % 2 != 0 ) { echo 'class="c-jobs--row-odd"'; } ?>>
<td class="c-jobs--col c-jobs--col-position">
<a class="c-jobs--anchor" href="<?php echo get_post_permalink( $ID ); ?>" title="<?php echo $jobs->display( 'name' ); ?>"><?php echo $jobs->display( 'name' ); ?></a>
<a class="c-jobs--anchor" href="<?php echo get_post_permalink( $ID ); ?>" title="<?php echo $name; ?>"><?php echo $name; ?></a>
</td>
<td class="c-jobs--col c-jobs--col-city">
<?php
......
......@@ -16,157 +16,14 @@ function getPageURL($taxonomy, $pageURL, $searchQuery, $termID) {
return $pageURL;
}
function getSiteTree2($taxonomy, $section, $searchQuery) {
$terms = get_terms( array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( !empty( $terms ) && ! is_wp_error( $terms ) ):
$res = array();
if ($searchQuery['city']):
$city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' );
endif;
if ($searchQuery['s']):
$field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' );
$type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' );
endif;
foreach ( $terms as $term ):
$termID = $term->term_id;
$active = false;
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '" AND ' . $taxonomy . '.term_id = ' . $termID;
$counter = $where;
if ($taxonomy == 'city'):
if ( $field ) :
$counter = $counter . ' AND field.term_id = ' . $field->term_id;
elseif ( $type ) :
$counter = $counter . ' AND type.term_id = ' . $type->term_id;
else:
$counter = $counter . ' AND (t.post_title LIKE "%' . $searchQuery['s'] . '%" OR t.post_content LIKE "%' . $searchQuery['s'] . '%")';
endif;
if ( $city && $city->term_id == $termID ) :
$active = true;
endif;
elseif ($taxonomy == 'type' || $taxonomy == 'field'):
if ( $city ) :
$counter = $counter . ' AND city.term_id = ' . $city->term_id;
endif;
if ( $field && $field->term_id == $termID || $type && $type->term_id == $termID) :
$active = true;
endif;
endif;
$params = array(
'where' => $where,
'limit' => -1
);
$jobsIn = pods( 'job', $params );
$custom = array(
'where' => $counter,
'limit' => -1
);
$jobsCounter = pods( 'job', $custom );
// global $wpdb;
// if ($taxonomy == 'field') {
// delog($wpdb->last_query, 'last_query');
// debug($wpdb->last_result);
// }
if ( 0 < $jobsIn->total() ):
$page = get_term_meta( $termID, 'page-id', true);
$order = intval(get_term_meta( $termID, 'order', true));
if ( $page && $page['post_status'] === 'publish') :
array_push($res, array(
'name' => $page['post_title'],
'href' => getPageURL($taxonomy, get_page_link( $page['ID'] ), $searchQuery, $termID),
'order' => $order,
'total' => $jobsCounter->total(),
'active' => $active
));
endif;
endif;
endforeach;
if (count($res) == 0) {
return '';
}
usort($res, function($a, $b) {
$o = $b['order'] - $a['order'];
if ($o):
return $o;
endif;
$t = $b['total'] - $a['total'];
if ($t):
return $t;
endif;
return $a['name'] > $b['name'];
});
$classCSS = 'c-jobs-section';
$isClosed = count($res) > 3;
if ($isClosed):
$classCSS .= ' c-jobs-section--is-closed';
endif;
echo '<div class="' . $classCSS . '">';
echo '<h3 class="c-jobs-section--heading">' . $section . '</h3>';
echo '<div class="c-jobs-section--content">';
echo '<ul class="c-jobs-section--list">';
foreach ( $res as $r ):
?>
<li class="c-jobs-section--item <?php if ($r['active']): echo 'c-jobs-section--item-active'; endif; ?>"><a href="<?php echo $r['href']; ?>" title="<?php echo $r['name']; ?>" class="c-jobs-section--anchor"><?php echo $r['name'] . ' (' . $r['total'] . ')'; ?></a></li>
<?php
endforeach;
echo '</ul>';
echo '</div>';
if ($isClosed):
echo '<a href="#" class="js-expand-jobs-section c-jobs-section--expand">' . __('More ...', 'biuro') . ' </a>';
endif;
echo '</div>';
endif;
}
function getSiteTree($type, $section, $searchQuery, $term) {
$res = array();
$termID = $term ? $term->term_id : '';
$termID = $term != '' ? $term->term_id : '';
$pages = getRecords($type, $searchQuery);
$pages = getOptions($type);
foreach ( $pages as $page ):
if ($page['pageID']) :
if ($page['pageID'] && $page['status'] == 'publish') :
array_push($res, array(
'name' => $page['title'],
'href' => getPageURL($type, get_page_link( $page['pageID'] ), $searchQuery, $page['termID']),
......@@ -227,11 +84,15 @@ function getSiteTree($type, $section, $searchQuery, $term) {
endif;
endif;
if ($searchQuery['city']):
$city = '';
$field = '';
$type = '';
if (isset($searchQuery['city'])):
$city = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['city']), 'city' );
endif;
if ($searchQuery['s']):
if (isset($searchQuery['s'])):
$field = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'field' );
$type = get_term_by( 'name', preg_replace('/[\+]/', ' ', $searchQuery['s']), 'type' );
endif;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment