Commit 58ea8b78 authored by Simon's avatar Simon

in progress

parent 3d3a6daa
<?php
// debug( getOptions('field', 'Vilnius') );
// debug( getOptions('type', 'Vilnius') );
debug( getOptions('city', '', 'Maitinimas') );
?>
<footer class="l-footer">
<div class="l-inner">
......
......@@ -537,6 +537,25 @@ function start_session() {
}
}
function getAvailableOptions ( $request ) {
$res = array();
$params = $request->get_params();
// if ( !$params ) {
// exit;
// }
// $langID = (int) $params['langID'];
// $divisions = getDivisions($langID);
// $res = getOptions('city', '', 'Maitinimas'); // debug( getOptions('city', '', 'Maitinimas') );
$res = getOptions('field', 'Vilnius'); // debug( getOptions('city', '', 'Maitinimas') );
$res = array_merge(getOptions('field', 'Vilnius'), getOptions('type', 'Vilnius')); // debug( getOptions('city', '', 'Maitinimas') );
return new WP_REST_Response( $res, 200 );
}
function getBiuroDivisions ( $request ) {
$res = array();
$params = $request->get_params();
......@@ -597,6 +616,19 @@ add_action( 'rest_api_init', function () {
]
]
));
register_rest_route( 'api/v1', '/options', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'getAvailableOptions',
// 'args' => array(
// 'langID' => array(
// 'validate_callback' => function($param, $request, $key) {
// return is_string( $param );
// }
// )
// )
));
});
......@@ -807,8 +839,15 @@ function getOptions($taxonomy, $location = '', $str = '') {
endif;
endif;
$location = $location || isset($searchQuery['city']) ? preg_replace('/[\+]/', ' ', $searchQuery['city']) : '';
$search = $str || isset($searchQuery['s']) ? preg_replace('/[\+]/', ' ', $searchQuery['s']) : '';
if ($location == ''):
$location = isset($searchQuery['city']) ? preg_replace('/[\+]/', ' ', $searchQuery['city']) : '';
endif;
if ($str == ''):
$search = isset($searchQuery['s']) ? preg_replace('/[\+]/', ' ', $searchQuery['s']) : '';
else:
$search = $str;
endif;
if ( $location !== '' && $taxonomy !== 'city') :
$city = get_term_by( 'name', $location, 'city' );
......@@ -833,7 +872,7 @@ function getOptions($taxonomy, $location = '', $str = '') {
return getResults($taxonomy, $term, $termID);
}
function getResults($taxonomy, $term, $termID) {
function getResults($taxonomy, $term = '', $termID = '') {
global $wpdb;
$langs = pll_the_languages(array('raw'=>1));
......@@ -842,6 +881,8 @@ function getResults($taxonomy, $term, $termID) {
$today = date('Y-m-d');
$order = ($taxonomy == 'city') ? 'no DESC' : 'total DESC';
$langID = 2;
$condition = ($term && $termID) ? " AND `" . $term . "`.`term_id` = " . $termID : '';
$structure = ($term && $termID) ? " LEFT JOIN `{$prefix}term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `{$prefix}term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '" . $term . "' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
......@@ -909,8 +950,8 @@ function getCities() {
delog($wpdb->last_query);
delog('$terms');
debug($terms);
delog('$cities');
debug($cities);
return [];
......
......@@ -66,6 +66,21 @@ const autocomplete = (str) => {
let isOpen = false;
const updateOptions = (node) => {
console.error(node.id);
console.log(node.value);
fetch('/wp-json/api/v1/options?langID=' + node.dataset.id)
.then((t) => t.json())
.then((data) => {
console.error('data');
console.dir(data);
// initDivisionsMap(node, data);
});
};
const toggle = (status, delay = 0) => {
setTimeout(() => {
isOpen = status;
......@@ -121,7 +136,11 @@ const autocomplete = (str) => {
});
node.addEventListener('awesomplete-selectcomplete', () => {
node.blur();
updateOptions(node);
if (clear) {
clear.classList.remove('u-hidden');
}
......
This diff is collapsed.
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