Created
March 2, 2018 16:37
-
-
Save juanrules/568d95ea83c0e7e1013572231c027a3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: SuperMan | |
* Date: 02/03/2018 | |
* Time: 15:57 | |
*/ | |
namespace BOI\jaja\Controller; | |
class CludoSearch | |
{ | |
private $customerId; | |
private $engineId; | |
private $searchUrl; | |
private $language = "'en'"; | |
private $searchInputs = "['cludo_search_form', 'cludo_search_form_header']"; | |
private $type; | |
private $hideSearchFilters; | |
private $searchApiUrl = "'https://api-eu1.cludo.com/api/v3'"; | |
private $hideResultsCount; | |
private $cludoQueryParameter; | |
public function __construct() | |
{ | |
// Assembling cludo parameters and passing them in to the cludo object | |
$this->customerId = $this->getAcfField('cludo_customer_id', '1994'); | |
$this->engineId = $this->getAcfField('cludo_engine', '9774'); | |
$this->searchUrl = $this->getAcfField('cludo_search_results_url', get_site_url() . '/search'); | |
$this->type = $this->getAcfField('cludo_type', 'inline'); | |
$this->hideSearchFilters = $this->getAcfField('cludo_hide_search_filtersText', "true"); | |
$this->hideResultsCount = $this->getAcfField('cludo_hide_results_count', "true"); | |
$this->cludoQueryParameter = $this->getAcfField('cludo_query_parameter', "cludoquery"); | |
} | |
/*** | |
* This to return the script assembled | |
* @return string | |
*/ | |
public function returnCludoScript() | |
{ | |
return " | |
<script> | |
cludoSearchSettings($this->customerId , $this->engineId ,'$this->searchUrl' , $this->language , $this->searchInputs , '$this->type' , $this->hideSearchFilters , $this->searchApiUrl , $this->hideResultsCount ); | |
</script> | |
"; | |
} | |
/*** | |
* @param $key | |
* @param $defaultValue | |
* @return mixed|null|void | |
*/ | |
private function getAcfField($key, $defaultValue) | |
{ | |
if (function_exists('get_field')) { | |
$value = get_field($key, 'options'); | |
$value = !empty($value) ? $value : $defaultValue; | |
} else { | |
$value = $defaultValue; | |
} | |
return $value; | |
} | |
/*** | |
* To get the Search results URL | |
* @return mixed|null|void | |
*/ | |
public function getSearchResultsUrl() | |
{ | |
return $this->searchUrl; | |
} | |
/*** | |
* @return mixed|null|void | |
*/ | |
public function getUrlQueryParameter() | |
{ | |
return $this->cludoQueryParameter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment