| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
|
| 7 |
if ( ! class_exists( 'OsSearchController' ) ) : |
| 8 |
|
| 9 |
|
| 10 |
class OsSearchController extends OsController { |
| 11 |
|
| 12 |
private $booking; |
| 13 |
|
| 14 |
function __construct(){ |
| 15 |
parent::__construct(); |
| 16 |
$this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'search/'; |
| 17 |
} |
| 18 |
|
| 19 |
function query_results(){ |
| 20 |
$query = trim($this->params['query']); |
| 21 |
if(!$query) return; |
| 22 |
$sql_query = '%'.$query.'%'; |
| 23 |
|
| 24 |
|
| 25 |
$bookings = new OsBookingModel(); |
| 26 |
$bookings = $bookings->filter_allowed_records()->where(['booking_code' => strtoupper($query)])->get_results_as_models(); |
| 27 |
$this->vars['bookings'] = $bookings; |
| 28 |
|
| 29 |
$customers = new OsCustomerModel(); |
| 30 |
$customers->filter_allowed_records()->where(array('OR' => array('CONCAT (first_name, " ", last_name) LIKE ' => $sql_query, 'email LIKE' => $sql_query, 'phone LIKE' => $sql_query)))->set_limit(6); |
| 31 |
|
| 32 |
$customers = $customers->get_results_as_models(); |
| 33 |
$this->vars['customers'] = $customers; |
| 34 |
$this->vars['query'] = $query; |
| 35 |
|
| 36 |
if(OsRolesHelper::can_user('service__view')){ |
| 37 |
$services = new OsServiceModel(); |
| 38 |
$services = $services->filter_allowed_records()->where(array('name LIKE ' => $sql_query))->set_limit(6)->get_results_as_models(); |
| 39 |
$this->vars['services'] = $services; |
| 40 |
} |
| 41 |
if(OsRolesHelper::can_user('agent__view')) { |
| 42 |
$agents = new OsAgentModel(); |
| 43 |
$agents = $agents->filter_allowed_records()->where(array('OR' => array('CONCAT (first_name, " ", last_name) LIKE ' => $sql_query, 'email LIKE' => $sql_query, 'phone LIKE' => $sql_query)))->set_limit(6)->get_results_as_models(); |
| 44 |
$this->vars['agents'] = $agents; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
$this->format_render(__FUNCTION__); |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
endif; |