Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('base_front_end.php');
- use Foolz\SphinxQL\SphinxQL;
- use Foolz\SphinxQL\Drivers\Pdo\Connection;
- /**
- * Class Search
- */
- class Search extends base_front_end
- {
- public function __construct()
- {
- error_reporting(0);
- parent::__construct();
- $this->render_options['is_twig'] = TRUE;
- // init configs
- /*$loader = new Twig_Loader_Filesystem(TWIG_TEMPLATE_PATH);
- $this->twig = new Twig_Environment($loader,array(
- 'debug' => true,
- ));
- $this->twig->addExtension(new Twig_Extension_Debug());
- $this->twig->addExtension(new Twig_Extensions_Extension_Text());*/
- $this->load->model('admin_model');
- $this->load->model('category_model');
- $this->load->library('NewsRSS');
- $this->load->library('PTagCloudGenerator');
- $this->load->library('phpbbparser');
- $this->load->library('bbcodeparser');
- $this->load->library('image_lib');
- $this->load->model('forum_model');
- $this->load->model('home_model');
- $this->load->model('login_model');
- $this->load->model('register_model');
- $this->load->model('doctorprofile');
- $this->load->model('news_model');
- $this->load->model('pages_model');
- $this->load->model('user_model');
- $this->load->model('video_model');
- $this->load->model('gallery_model');
- $this->load->model('review_model');
- $this->load->model('booking_model');
- $this->load->model('questions_model');
- $this->load->model('keyword_model');
- $this->load->model('procedure_model');
- $this->load->model('procedure_slider_model');
- $this->load->helper(array(
- 'form',
- 'url',
- 'youtube',
- ));
- $this->load->helper('vimeo');
- $this->load->helper('text');
- $this->load->helper('date');
- $this->load->library('pagination');
- //$this->load->library('MY_Pagination');
- $this->load->library('form_validation');
- $this->load->library('user_agent');
- $this->load->library('auth');
- $this->load->helper('string');
- $this->load->helper('cookie');
- $this->load->library('session');
- $this->load->library('email');
- $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
- $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
- $this->output->set_header('Pragma: no-cache');
- $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- }
- public function index($query){
- $data['title'] = 'Search';
- $data['canonical'] = base_url();
- $cat = $query = $limit = null;
- $get = $this->input->get();
- $zip = isset($get['zipcode']) ? $get['zipcode'] : null;
- $order = isset($get['sort']) ? $get['sort'] : null;
- $limit = (isset($get['limit']) && !empty($get['limit'])) ? $get['limit'] : 25;
- $data['search_state'] = $get['state'];
- $data['city'] = $get['city'];
- $data['rankin_page'] = $this->review_model->get_ranking_page();
- $data['query'] = trim($get['query']);
- $data['zip'] = $zip;
- $data['per_page'] = $limit;
- $data['sort'] = isset($get['order']) && !empty($get['order']) ? $get['order'] : $order;
- $data['articles_hidden'] = isset($get['articles_hidden']) ? $get['articles_hidden'] : false;
- if(empty($get['query'])) $query=" ";
- $data['availableTypes'] = array('procedure', 'articles', 'photos', 'doctors', 'videos', 'questions');
- if($get['cat']=="news"){
- $data['type'] = array("articles");
- }
- else{
- $data['type'] = $get['type'];
- }
- if (count($data['type']) == 0) {
- if(isset($get['cat']) && !empty($get['cat']) && $get['cat']!='all'){
- $data['type'] = (array)$get['cat'];
- } else {
- $data['type'] = $data['availableTypes'];
- }
- }
- if(count($get['type'])==1){
- $get['cat'] = $get['type'][0];
- }
- $data['type_article'] = !is_null($get['type_article']) ? $get['type_article'] : array('news', 'articles'); // && !empty($get['type_article'])
- if(!in_array('articles', $data['type']) || $get['articles_hidden']=='true'){
- $data['type_article'] = array();
- $data['type'] = array_diff($data['type'], ['articles']);
- }
- $data['showAllTypes'] = false;
- if (count(array_diff($data['availableTypes'], $data['type'])) == 0) {
- $data['showAllTypes'] = true;
- }
- $state = null;
- if (isset($get['cat']) && count($get['type']>1)) {
- $data['cat'] = $get['cat'] == '' ? 'all' : $get['cat'];
- }
- if (isset($get['query'])) {
- $pos = stripos($get['query'], '–');
- if($pos !== false) {
- $query = $get['query'] == '' ? null : preg_replace('/[^ \w]+/', '', $get['query']);
- } else {
- $query = $get['query'];
- }
- $remove[] = "'";
- $remove[] = '"';
- $query = str_replace( $remove, "", $query );
- }
- if(!isset($limit)){
- $limit = 25;
- }
- $offset = $get['per_page'] == '' ? 0 : $get['per_page'];
- $page = 1;
- $data['ajax_pagination'] = true;
- $data['all'] = array();
- if(isset($get['cat'])){
- if($get['cat']=='all' OR $get['cat']==''){
- $type = array('procedure', 'questions', 'photos');
- } else {
- $type = (array)$get['cat'];
- }
- } else {
- $type = array('procedure', 'questions', 'photos');
- }
- if(!in_array('photos', $type)){
- array_push($type, 'photos');
- }
- foreach($type as $cat) {
- $data['resultCount'] = $this->getAllSearchCount($query, null, $zip);
- $data['result'][$cat] = $this->getSearchResult($query, $cat, null, null, null, null, null, null, null, null, null, $state, null, null, null, null, $order, $zip);
- if ($cat == 'photos') {
- $data['galleryPictures'] = array();
- if (is_array($data['result']['photos'])) {
- foreach ($data['result']['photos'] as $key=>$val) {
- $ids = $val['id'];
- $data1['galleryPicture'] = $this->gallery_model->get_gallery_pictures($ids);
- if (!empty($data1['galleryPicture'])) {
- $allPic = array();
- foreach ($data1['galleryPicture'] as $galleryPic) {
- if (is_file(ROOT_PATH . '/uploads/gallery/' . $galleryPic->image)) {
- array_push($allPic, $galleryPic);
- }
- }
- $data['doctor'][$ids] = $this->login_model->getnewUserData('doctor', $val['users_id']);
- if (!empty($data['doctor'][$ids])) {
- if (!empty($allPic)) {
- $val['galleryPictures'] = $allPic;
- array_push($data['galleryPictures'], $val);
- }
- $data['countPictures'][] = count($allPic);
- $data['result'][$cat][] = $val;
- $data['category'] = $this->gallery_model->getProcedure($val['category_id']);
- $data['doctor_rating'][$ids] = $this->review_model->get_avg_doctor_rating($val['users_id']);
- $data['count_review'][$ids] = $this->review_model->get_count_review_by_doctor($val['users_id']);
- }
- } else {
- unset($val[$key]);
- }
- $data['photosCount'] = count($data['galleryPictures']);
- }
- }
- }
- }
- if(isset($get['search_dr']) && $get['search_dr']==true){
- $proceduresListId = array_diff(isset($get['procedure_list_c']) && !empty($get['procedure_list_c']) ? explode(',', $get['procedure_list_c']) : $procedure,array('','undefined'));
- $proceduresList=array();
- foreach($proceduresListId as $pid){
- $proceduresList[] = $this->category_model->getProcedureNameById($pid);
- }
- $proceduresList = array_diff($proceduresList,array(null));
- }
- $from = array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part');
- if(!in_array('doctors', $data['type'])){
- $from = array_diff($from, array('doctors_part'));
- $from = array_diff($from, array('claim_part'));
- }
- if(!in_array('articles',$data['type_article']) || $get['articles_hidden']=='true'){
- $from = array_diff($from, ['articles_part']);
- }
- if(!in_array('videos', $data['type'])){
- $from = array_diff($from, ['videos_part']);
- }
- if(!in_array('news',$data['type_article']) || $get['articles_hidden']=='true'){
- $from = array_diff($from, ['news_part']);
- }
- if(!in_array('news', $data['type_article'])){
- $from = array_diff($from, ['news_part']);
- }
- if(!empty($from)) {
- $all_main_search = $this->getAllSearch($query, null, 0, $order, $zip, $from,null,$proceduresList);
- $countArt = 0;
- $countNews = 0;
- foreach ($all_main_search as &$ms) {
- if($ms['search_category']=='article'){
- $countArt++;
- }
- if($ms['search_category']=='news'){
- $countNews++;
- }
- $ms['category'] = $cat;
- array_push($data['all'], $ms);
- }
- $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, $from,null,$proceduresList);
- foreach ($main_search as &$ms) {
- $ms['category'] = $cat;
- array_push($data['all'], $ms);
- }
- }
- $url = parse_url(current_url());
- parse_str($url['query'], $str_url);
- unset($str_url['per_page']);
- if(!isset($countArt) || empty($countArt)) {
- $countArt = $this->getAllSearchCount($query, array('articles_part'), $zip);
- }
- if(!isset($countNews) || empty($countNews)) {
- $countNews = $this->getAllSearchCount($query, array('news_part'), $zip);
- }
- $data['countArt'] = $countArt;
- $data['countNews'] = $countNews;
- $data['countArticles'] = $countArt + $countNews;
- $data['countVideos'] = $this->getAllSearchCount($query, array('videos_part'), $zip);
- $data['countDoctors'] = $this->getAllSearchCount($query, array('doctors_part', 'claim_part'), $zip);
- $data['allResultCount'] = 0;
- $data['allPaginationCount'] = 0;
- // if(in_array('articles', $data['type'])){
- if(in_array('articles', $data['type_article']) or is_null($data['type_article'])) {
- $data['allResultCount'] += $data['countArt'];
- $data['allPaginationCount'] += $data['countArt'];
- }
- if(in_array('news', $data['type_article']) or is_null($data['type_article'])) {
- $data['allResultCount'] += $data['countNews'];
- $data['allPaginationCount'] += $data['countNews'];
- }
- // }
- if(in_array('videos', $data['type'])){
- $data['allResultCount'] += $data['countVideos'];
- $data['allPaginationCount'] += $data['countVideos'];
- }
- if(in_array('doctors', $data['type'])){
- $data['allResultCount'] += $data['countDoctors'];
- $data['allPaginationCount'] += $data['countDoctors'];
- }
- if(in_array('photos', $data['type'])){
- $data['allResultCount'] += $data['photosCount'];
- }
- if(in_array('procedure', $data['type'])){
- $data['allResultCount'] += count($data['result']['procedure']);
- }
- if(in_array('question', $data['type'])){
- $data['allResultCount'] += count($data['result']['questions']);
- }
- $config['base_url'] = base_url().'search?'.http_build_query($str_url);
- if($get['cat']=='photos'){
- $config['total_rows'] = $data['photosCount'];
- } else {
- $config['total_rows'] = $data['allPaginationCount'];
- }
- $config['per_page'] = $limit;
- $config['enable_query_strings']= true;
- $config['page_query_string'] = true;
- $config['next_link'] = "<img class=\"img-next\" src=\"/img/select.png\">";
- $config['first_link'] = FALSE;
- $config['last_link'] = FALSE;
- $config['prev_link'] = "<img class=\"img-prev\" src=\"/img/select.png\">";
- $this->pagination->initialize($config);
- $data["links"] = $this->pagination->create_links();
- $data['currentPage'] = $page;
- $data['lastPage'] = round($data['resultCount']/$limit);
- $data['page'] = $offset!==0 ? round($config['total_rows']/$offset) : 1;
- if ($this->session->userdata('front_user')) {
- $data['front_user'] = $this->session->userdata('front_user');
- }
- $procedure = $this->category_model->get_procedure_list_by_name($query);
- if(!empty($procedure)) {
- $data['top_doc_near_you'] = $this->procedure_model->get_sponsored_doctors($procedure[0]->id);
- foreach ($data['top_doc_near_you'] as &$td) {
- $pos = strpos($td->profile_image_small_thumb, 'https://lorempixel.com');
- if (!empty($td->profile_image_small_thumb)) {
- if ($pos === false) {
- $td->profile_image_small_thumb = base_url() . 'uploads/users/profilepic/thumbs/' . $td->profile_image_small_thumb;
- if (empty($td->profile_image_small_thumb)) {
- $td->profile_image_small_thumb = '/images/frontend/profilepic/profile.png';
- }
- } else {
- $td->profile_image_small_thumb = $td->profile_image_small_thumb;
- }
- } else {
- $td->profile_image_small_thumb = '/images/frontend/profilepic/profile.png';
- }
- if (isset($td->user_id)) {
- $userData = $this->login_model->getnewUserData('doctor', $td->user_id);
- if (!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score * 0.25, 1);
- $td->rating = $rankin;
- }else{
- $td->rating = 0;
- }
- }
- }
- }
- $this->load->model('category_model');
- $procedure_photo = $this->category_model->get_procedure_list_by_name($query);
- $category_id = 0;
- foreach ($procedure_photo as $p) {
- $procedure_parent = $this->category_model->getTopParrentIdByProc($p->id);
- if($procedure_parent){
- $category_id = $this->category_model->getCategoryByProc($procedure_parent);
- }
- }
- $data['procedure_photo'] = $this->category_model->getPhotoCategoryById($category_id);
- if(!$this->input->is_ajax_request()){
- $data['hide_main_search'] = (!isset($get['cat'])) ? true : false;
- $header_data = array_merge($this->header_config, ['cat' => $data['cat'], 'title' => $data['title'], 'canonical'=> $data['canonical'], 'hide_main_search' => $data['hide_main_search']], $this->login_model->checkHeaderLinks());
- $options = [
- 'header' => [
- 'data' => $header_data,
- 'is_visible' => TRUE,
- ],
- ];
- }else{
- $options = [];
- }
- if(strtolower($this->uri->segment(2))=='map' OR ((!isset($get['cat']) && !isset($get['type'])) && !isset($get['state'])) OR isset($get['search_dr'])) {
- $lat = null;
- $lng = null;
- if (isset($get['state'])) {
- $state_code = explode(',', $get['state']);
- $state_name = array();
- foreach ($state_code as $sc) {
- $s_name = $this->user_model->select_state_by_code(trim($sc));
- if (!isset($s_name->state)) {
- $data['city'] = trim($sc);
- } else {
- array_push($state_name, $s_name->state);
- $data['state_code'] = $s_name->state_code;
- $data['state_name'] = $s_name->state;
- }
- }
- if (isset($get['city'])) {
- $coordinates = $this->user_model->get_coordinates_by_city($get['city']);
- } else {
- if (isset($data['state_name'])) {
- $coordinates = $this->user_model->get_coordinates_by_state($s_name->state);
- }
- }
- if (isset($coordinates) && !empty($coordinates)) {
- $lat = $coordinates->latitude;
- $lng = $coordinates->longitude;
- }
- $state_name_str = implode('||', $state_name);
- $state = isset($get['state']) ? str_replace(',', '||', $get['state']) : null;
- if (!empty($state_name_str)) {
- $state = $state_name_str . '||' . $state;
- }
- }
- $score = isset($get['score']) ? explode(',', $get['score']) : null;
- $rating = isset($get['rating']) ? $get['rating'] : null;
- $distance = isset($get['distance']) ? explode(',', $get['distance']) : array(0, 100);
- $specialty = isset($get['specialty']) ? $get['specialty'] : null;
- $procedure = isset($get['procedure']) ? $get['procedure'] : null;
- $procedure = isset($get['procedure_list_c']) && !empty($get['procedure_list_c']) ? explode(',', $get['procedure_list_c']) : $procedure;
- if(empty($procedure)){
- $procedure = $this->procedure_model->get_procedure_by_name($get['query']);
- }
- $data['procedure'] = $procedure;
- if(!empty($data['procedure'])){
- $procedure_name = $this->procedure_model->get_procedure($data['procedure'][0]);
- $data['procedure_name'] = $procedure_name->name;
- }
- $gallery_boolean = isset($get['gallery_boolean']) ? $get['gallery_boolean'] : 'all';
- $order_field = isset($get['order_field']) ? $get['order_field'] : null;
- $order = isset($get['order']) ? $get['order'] : null;
- $limit = isset($get['limit']) ? $get['limit'] : null;
- $data['ajax_pagination'] = (isset($get['ajax_pagination']) && $get['ajax_pagination'] == 'false') ? null : true;
- if(strtolower($this->uri->segment(2))=='map') {
- $query = $get['query'];
- $search_dr = isset($get['search_dr']) ? true : false;
- $data['result'] = array();
- $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, array('doctors_part', 'claim_part'), $state);
- foreach ($main_search as &$ms) {
- $ms['category'] = $cat;
- array_push($data['result'], $ms);
- }
- $url = parse_url(current_url());
- parse_str($url['query'], $str_url);
- unset($str_url['per_page']);
- $data['resultCount'] = $this->getAllSearchCount($query, array('doctors_part', 'claim_part'), $zip, $state);
- $data['hide_main_search'] = true;
- $data['states'] = $this->user_model->get_state();
- if($this->input->is_ajax_request()){
- echo json_encode($data['result']);
- die();
- } else {
- $this->render(['search-map'], array_merge($data, ['google_maps_key' => GOOGLE_MAPS_KEY, 'base_url' => base_url(), 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH, 'front_css_path' => FRONT_CSS_PATH, 'css_path' => CSS_PATH]), $options);
- }
- }else if(!isset($get['cat']) && !isset($get['state']) || isset($get['search_dr'])) {
- $data['query']=$query = $get['query'];
- $search_dr = isset($get['search_dr']) ? true : false;
- $data['top_doc_cities'] = $this->doctorprofile->get_top_doc_cities();
- $data['featured'] = $this->doctorprofile->get_featured_doctor(6);
- foreach($data['featured'] as &$featured){
- $result_d = $this->login_model->getnewUserData('doctor', $featured->id);
- $score = $result_d[0]->niche + $result_d[0]->page_rank + $result_d[0]->review + $result_d[0]->publication;
- $featured->rankin = round($score*0.25, 1);
- }
- $data['featured'] = array_chunk($data['featured'], 3);
- $data['result'] = array();
- $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, array('doctors_part','claim_part'), $state,$proceduresList);
- foreach ($main_search as &$ms) {
- $ms['category'] = $cat;
- array_push($data['result'], $ms);
- }
- $url = parse_url(current_url());
- parse_str($url['query'], $str_url);
- unset($str_url['per_page']);
- $data['resultCount'] = $this->getAllSearchCount($query, array('doctors_part','claim_part'), $zip, $state,$proceduresList);
- $data['hide_main_search'] = true;
- $data['states'] = $this->user_model->get_state();
- if (isset($get['city']))
- $data['city'] = $get['city'];
- if (isset($get['search_dr'])) {
- if ($this->input->is_ajax_request()) {
- $this->render(['find-a-doctor-item'], array_merge($data, ['google_maps_key' => GOOGLE_MAPS_KEY, 'base_url' => base_url(), 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH]),
- [
- 'header' => [
- 'is_visible' => FALSE,
- ],
- 'footer' => [
- 'is_visible' => FALSE,
- ]
- ]);
- } else {
- $this->render(['find-a-doctor'], array_merge($data, ['google_maps_key' => GOOGLE_MAPS_KEY, 'base_url' => base_url(), 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH, 'front_css_path' => FRONT_CSS_PATH, 'css_path' => CSS_PATH]),
- [
- 'header' => [
- 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
- ]
- ],
- $options);
- }
- } else {
- $data['hide_main_search'] = false;
- $this->render(['search-first'],
- array_merge($data, ['base_url' => base_url(), 'jquey_path' => JQUERY_PATH, 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH, 'front_css_path' => FRONT_CSS_PATH, 'css_path' => CSS_PATH]),
- [
- 'header' => [
- 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
- ]
- ],
- $options);
- }
- }
- } else {
- $data['hide_main_search'] = false;
- if ($this->input->is_ajax_request()) {
- $this->render(['search-all-item'], array_merge($data, ['base_url' => base_url()]),
- [
- 'header' => false,
- 'footer' => false
- ]);
- } else {
- if ($get['cat'] == 'photos') {
- $data['allResultCount'] = $data['photosCount'];
- if ($data['allResultCount'] <= $data['per_page']) {
- $data['countPage'] = 1;
- } else {
- $data['countPage'] = (int)round($data['photosCount'] / $data['per_page']);
- $data['galleryPictures'] = array_slice($data['galleryPictures'], $offset, $limit);
- }
- $this->render(['search-all-photos'],
- array_merge($data, ['base_url' => base_url(), 'front_css_path' => FRONT_CSS_PATH, 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH, 'style_bootstrap_path' => STYLE_BOOTSTRAP_PATH]),
- [
- 'header' => [
- 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
- ]
- ],
- $options);
- }else {
- $this->render(['search-all'],
- array_merge($data, ['base_url' => base_url(), 'front_css_path' => FRONT_CSS_PATH, 'js_path' => JS_PATH, 'jquery_path' => JQUERY_PATH, 'style_bootstrap_path' => STYLE_BOOTSTRAP_PATH]),
- [
- 'header' => [
- 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
- ]
- ],
- $options);
- }
- }
- }
- }
- public function getAllSearch($query, $limit, $offset=0, $order=null,$zip=null, $from=null, $state=null,$procedure=null)
- {
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- if (!is_array($query)) {
- $query = htmlentities($query);
- $query = str_replace('amp;', '', $query);
- } else {
- $query = implode(' ', $query);
- }
- $select = array('*');
- $procedure = implode("|",$procedure);
- $search_by_name = $this->search_by_type($query, 'name');
- $search_by_procedure = $this->search_by_type($query, 'procedure');
- $search_by_location = $this->search_by_type($query, 'location');
- $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
- $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
- $user_loc = $this->user_model->get_user_location_by_ip($ip);
- $date_diff = 0;
- if(!empty($user_loc)) {
- $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
- }
- if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
- $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
- $user_loc = new StdClass;
- $user_loc->lat = $user_location['lat'];
- $user_loc->lng = $user_location['lng'];
- $user_loc->city_name = $user_location['city_name'];
- }
- if(!empty($user_loc)) {
- $user_lat = $user_loc->lat;
- $user_lng = $user_loc->lng;
- $user_city_name = $user_loc->city_name;
- }
- if(!empty($state)){
- $user_city_name = $state;
- }
- $city_pos = strpos($user_city_name, '||');
- if($city_pos!==false){
- $city_array = explode('||', trim($user_city_name));
- }
- if ((isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && ($search_by_name['success']==false && $search_by_location['success']==false
- && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true)||
- (empty($state) && $search_by_location['success'] == false && isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name)))) {
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if(((($search_by_name['success']==true || $search_by_procedure['success']==true) && !empty($state)) || !empty($user_city_name)) && !isset($city_array)){
- $user_city_filter = 'IF(';
- $user_city_filter .= " str_state = '".$user_city_name."' OR user_state = '".$user_city_name."' OR str_city = '".$user_city_name."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $user_city_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $user_city_filter);
- }
- if(isset($city_array) && !empty($city_array)){
- $user_city_filter = 'IF(';
- $user_city_filter .= " str_state = '".$city_array[0]."' OR str_state = '".$city_array[1]."' OR user_state = '".$city_array[0]."' OR user_state = '".$city_array[1]."'
- OR str_city = '".$city_array[0]."' OR str_city = '".$city_array[1]."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $user_city_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $user_city_filter);
- }
- if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if($search_by_location['success']==true && $search_by_name['success']==false && $search_by_procedure['success']==false && isset($search_by_location['lat']) && isset($search_by_location['lng'])){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if(!empty($zip)) {
- $zip_filter = 'IF(';
- $zip_filter.= " zip == ".$zip;
- $zip_filter.=",1,0) AS zip_filter ";
- array_push($select, $zip_filter);
- }
- $doctor_filter = 'IF(';
- $doctor_filter .= "(search_category = 'doctor' OR search_category= 'doctor_claim') AND user_id > 0 ";
- $doctor_filter .= ",1,0) AS doctor_filter ";
- array_push($select,$doctor_filter);
- $doctorFilter=1;
- $res = SphinxQL::create($conn)->select($select);
- if(!empty($from)){
- $res->from($from);
- } else {
- $res->from(array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part'));
- }
- if(!empty($query)){
- $res->match(['str_first_name', 'str_last_name', 'title', 'content', 'user_state', 'str_city', 'str_state'], $query);
- }
- if(!empty($procedure)){
- $res->match('str_treatment_name', $procedure, true);
- }
- if(!empty($zip)){
- $res->where('zip_filter', '=', 1);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if($doctorFilter==1){
- // $res->where('doctor_filter', '=', 1);
- }
- if($search_by_name['success']==false && ((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_by_name['success']==false
- || $search_by_loc_proc['success'] == true) || (!empty($user_lat) && !empty($user_lng)))){
- if(!($state)){
- $res->where('distance_filter', '=', 1);
- $res->orderBy('distance', 'ASC');
- }
- $res->orderBy('user_city_filter', 'DESC');
- $res->orderBy('str_city', 'ASC');
- }
- if(!empty($state)){
- $res->orderBy('user_city_filter', 'DESC');
- }
- if(!empty($state)){
- $res->where('user_city_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else {
- $res->limit(0, 1000);
- }
- if(in_array('doctors',$from)){
- $res->orderBy('title', 'ASC');
- }
- else if($order){
- if($order=='DATE'){
- $res->orderBy('date_updated', 'DESC');
- }else {
- $res->orderBy('title', $order);
- }
- }else{
- $res->orderBy('date_updated', 'DESC');
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateAllSearchResult($result);
- }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- }
- public function favorite_doc(){
- $data['front_user'] = $this->session->userdata('front_user');
- if (!empty($data['front_user'])) {
- $post = $this->input->post();
- $data['front_user'] = $this->session->userdata('front_user');
- $this->load->model('doctorprofile');
- $result = $this->doctorprofile->favorite_doc($data['front_user']['user_id'], $post['doctor_id']);
- if($result===true) {
- echo json_encode(array('result' => $result, 'message'=>'Doctor is saved successfully.'));
- die;
- }else{
- echo json_encode(array('result' => 'exist', 'message'=>'The doctor has already been added.'));
- die;
- }
- }else{
- echo json_encode(array('result'=>false));
- die;
- }
- }
- public function getAllSearchCount($query, $from=null, $zip, $state=null,$procedure=null)
- {
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- if (!is_array($query)) {
- $query = htmlentities($query);
- $query = str_replace('amp;', '', $query);
- } else {
- $query = implode(' ', $query);
- }
- $select = array('*');
- $procedure = implode("|",$procedure);
- $search_by_name = $this->search_by_type($query, 'name');
- $search_by_procedure = $this->search_by_type($query, 'procedure');
- $search_by_location = $this->search_by_type($query, 'location');
- $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
- $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
- $user_loc = $this->user_model->get_user_location_by_ip($ip);
- $date_diff = 0;
- if(!empty($user_loc)) {
- $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
- }
- if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
- $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
- $user_loc = new StdClass;
- $user_loc->lat = $user_location['lat'];
- $user_loc->lng = $user_location['lng'];
- $user_loc->city_name = $user_location['city_name'];
- }
- if(!empty($user_loc)) {
- $user_lat = $user_loc->lat;
- $user_lng = $user_loc->lng;
- $user_city_name = $user_loc->city_name;
- }
- if(isset($state)){
- $user_city_name = $state;
- }
- $city_pos = strpos($user_city_name, '||');
- if($city_pos!==false){
- $city_array = explode('||', trim($user_city_name));
- }
- if ((isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name) && ($search_by_name['success']==false && $search_by_location['success']==false
- && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true)||
- (empty($state) && $search_by_location['success'] == false && isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name)))) {
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if(((($search_by_name['success']==true || $search_by_procedure['success']==true) && !empty($state)) || !empty($user_city_name)) && !isset($city_array)){
- $user_city_filter = 'IF(';
- $user_city_filter .= " str_state = '".$user_city_name."' OR user_state = '".$user_city_name."' OR str_city = '".$user_city_name."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $user_city_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $user_city_filter);
- }
- if(isset($city_array) && !empty($city_array)){
- $user_city_filter = 'IF(';
- $user_city_filter .= " str_state = '".$city_array[0]."' OR str_state = '".$city_array[1]."' OR user_state = '".$city_array[0]."' OR user_state = '".$city_array[1]."'
- OR str_city = '".$city_array[0]."' OR str_city = '".$city_array[1]."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $user_city_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $user_city_filter);
- }
- if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if($search_by_location['success']==true && $search_by_name['success']==false && $search_by_procedure['success']==false && isset($search_by_location['lat']) && isset($search_by_location['lng'])){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if(!empty($zip)) {
- $zip_filter = 'IF(';
- $zip_filter.= " zip == ".$zip;
- $zip_filter.=",1,0) AS zip_filter ";
- array_push($select, $zip_filter);
- }
- $doctorFilter=0;
- if(isset($from) && in_array("doctors_part",$from)){
- $doctor_filter = 'IF(';
- $doctor_filter .= "search_category = 'doctor' AND user_id > 0 ";
- $doctor_filter .= ",1,0) AS doctor_filter ";
- array_push($select,$doctor_filter);
- $doctorFilter=1;
- }
- else{
- $doctor_filter = 'IF(';
- $doctor_filter .= "search_category = 'doctor' AND user_id > 0 ";
- $doctor_filter .= ",1,0) AS doctor_filter ";
- array_push($select,$doctor_filter);
- $doctorFilter=1;
- }
- $res = SphinxQL::create($conn)->select($select);
- if(isset($from)){
- $res->from($from);
- } else {
- $res->from(array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part'));
- }
- if(!empty($query)){
- $res->match(['str_first_name', 'str_last_name', 'title', 'content', 'user_state', 'str_city', 'str_state'], $query);
- }
- if(!empty($procedure)){
- $res->match('str_treatment_name', $procedure, true);
- }
- if(!empty($zip)){
- $res->where('zip_filter', '=', 1);
- }
- if($doctorFilter==1){
- // $res->where('doctor_filter', '=', 1);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if($search_by_name['success']==false && ((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_by_name['success']==false
- || $search_by_loc_proc['success'] == true) || (!empty($user_lat) && !empty($user_lng)))){
- if(!$state){
- $res->where('distance_filter', '=', 1);
- $res->orderBy('distance', 'ASC');
- }
- $res->orderBy('user_city_filter', 'DESC');
- $res->orderBy('str_city', 'ASC');
- }
- if($search_by_name['success']==false && !empty($state)){
- $res->orderBy('user_city_filter', 'DESC');
- }
- if(!empty($state)){
- $res->where('user_city_filter', '=', 1);
- }
- $res->limit(0, 1000);
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->getCount();
- return $result;
- }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- }
- public function generateAllSearchResult($result)
- {
- $results = [];
- foreach ($result as $r) {
- if ($r['search_category'] == 'doctor' || $r['search_category'] == 'doctor_claim') {
- if($r['search_category'] == 'doctor') {
- $user_id = $this->user_model->get_doctor_id_by_slug($r['str_slug']);
- $r['user_id'] = $user_id->id;
- } else {
- $claim_id = $this->user_model->get_doctor_id_by_slug($r['str_slug'], true);
- $r['id'] = $claim_id->id;
- }
- $pos = strpos($r['profile_image_small_thumb'], 'https://lorempixel.com');
- $doctor_score = 0;
- if (isset($r['user_id'])) {
- $userData = $this->login_model->getnewUserData('doctor', $r['user_id']);
- if (!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score * 0.25, 1);
- }
- $badges = $this->admin_model->getDoctorBadges($r['user_id']);
- } else if (isset($r['id'])){
- $userData = $this->login_model->getClaimData($r['id']);
- if (!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score * 0.25, 1);
- }
- $badges = $this->admin_model->getClaimBadges($r['id']);
- }
- if (!empty($r['str_first_name']) && !empty($r['str_last_name'])) {
- if ($pos === false) {
- $profile_image = base_url().'/uploads/users/profilepic/thumbs/' . $r['profile_image_small_thumb'];
- if(empty($r['profile_image_small_thumb'])){
- $profile_image = '/images/frontend/profilepic/profile.png';
- }
- } else {
- $profile_image = $r['profile_image_small_thumb'];
- }
- if (!isset($r['user_id'])) {
- $user_id = $this->user_model->get_doctor_id_by_slug($r['str_slug'], $claim = null);
- $r['user_id'] = $user_id->id;
- }
- $res = [
- 'id' => isset($r['user_id']) ? $r['user_id'] : $r['id'],
- 'title' => ucfirst($r['str_first_name']) . ' ' . ucfirst($r['str_last_name']) . ', ' . strtoupper($r['title']),
- 'doctor_title' => isset($r['title']) ? $r['title'] : '',
- 'search_category' => $r['search_category'],
- 'user_lat' => $r['user_lat'],
- 'user_lng' => $r['user_lng'],
- 'countarticles' => isset($r['countarticles']) ? $r['countarticles'] : 0,
- 'countreviews' => isset($r['countreviews']) ? $r['countreviews'] : 0,
- 'sumrating' => isset($r['sumrating']) ? $r['sumrating'] : 0,
- 'doc_rating' => isset($r['sumrating']) ? $r['sumrating'] : 0,
- 'countvideos' => isset($r['countvideos']) ? $r['countvideos'] : 0,
- 'content' => $r['str_address'],
- 'content2' => $r['str_city'] . ', ' . $r['str_state'] . ' ' . $r['str_zip'],
- 'address' => $r['str_state'] . ', ' . $r['str_address'],
- 'zip' => $r['zip'],
- 'link' => base_url() . 'doctor/' . $r['str_user_slug'],
- 'page' => base_url() . 'doctor/' . $r['str_user_slug'],
- 'read_more' => 'VISIT DOCTOR ',
- 'distance' => isset($r['distance']) ? $r['distance'] : '',
- 'user_city_filter' => isset($r['user_city_filter']) ? $r['user_city_filter'] : '',
- 'rating' => $rankin,
- 'profile_image' => $profile_image,
- 'str_slug' => $r['str_slug'],
- 'board_certification' => $r['board_certification'],
- 'badges' => $badges,
- 'practice_name' => $r['str_practice_name']
- ];
- array_push($results, $res);
- }
- } else
- if ($r['search_category'] == 'article') {
- $parent_id = $this->category_model->getParentCategoryById($r['procedure_id']);
- if ($parent_id) {
- $r['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
- } else {
- $proc = $this->doctorprofile->getProcedureById($r['procedure_id']);
- $r['procedure_name'] = $proc->category_slug;
- }
- if (stripos($r['content'], 'data-oembed_provider="vimeo"')) {
- $r['content'] = strip_tags($r['content']);
- }
- $res = [
- 'id' => $r['id'],
- 'title' => $r['title'],
- 'category_slug' => $r['category_slug'],
- 'search_category' => $r['search_category'],
- 'content' => strip_tags((strlen($r['content']) > 500) ? substr(trim($r['content']), 0, 500) . ' ...' : $r['content']),
- 'link' => base_url() . 'journal/' . $r['procedure_name'] . '/' . $r['article_slug'],
- 'page' => base_url() . 'journal',
- 'tags' => $r['tags'],
- 'zip' => $r['zip'],
- 'str_slug' => $r['str_slug'],
- ];
- array_push($results, $res);
- } else
- if ($r['search_category'] == 'video') {
- $video_image = 'https://img.youtube.com/vi/mqdefault.jpg';
- $video_path = $r['profile_image_small_thumb'];
- if(!empty($r['profile_image'])) $video_image=$r['profile_image'];
- if (strpos($video_path,'youtube') !== false || strpos($video_path,'youtu.be') !== false) {
- $video_image="https://img.youtube.com/vi/".getYoutubeVideoId($video_path)."/mqdefault.jpg";
- $video_type="youtube";
- $video_id=getYoutubeVideoId($video_path);
- }
- else if(strpos($video_path,'vimeo') !== false){
- $vimeoInfo=getVimeoVideoInfo($video_path);
- $video_image=$vimeoInfo['thumbnail'];
- $video_type="vimeo";
- $video_id=$vimeoInfo['videoId'];
- }
- else if (strpos($video_path,'cloudinary') !== false) {
- $video_image=base_url()."uploads/videos/".$video_image;
- $video_type="cloudinary";
- $video_id="";
- }
- else{
- $video_image=base_url()."uploads/videos/".$video_image;
- $video_path=base_url()."uploads/videos/".$video_path;
- $video_type="local";
- $video_id="";
- }
- $res = [
- 'title' => $r['title'],
- 'category_slug' => $r['category_slug'],
- 'search_category' => $r['search_category'],
- 'video_image' => $video_image,
- 'video_type' => $video_type,
- 'video_id' => $video_id,
- 'str_slug' => $r['str_slug'],
- 'zip' => $r['zip'],
- 'content' => strip_tags((strlen($r['content']) > 500) ? substr($r['content'], 0, 500) . ' ...' : $r['content']),
- 'link' => base_url() . 'video/' . $r['video_slug'],
- 'page' => base_url() . 'video/' . $r['video_slug'],
- 'read_more' => 'VIEW VIDEO '
- ];
- array_push($results, $res);
- } else {
- $parent_id = $this->category_model->getParentCategoryById($r['procedure_id']);
- if ($parent_id) {
- $r['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
- } else {
- $proc = $this->doctorprofile->getProcedureById($r['procedure_id']);
- $r['procedure_name'] = $proc->category_slug;
- }
- if (stripos($r['content'], 'data-oembed_provider="vimeo"')) {
- $r['content'] = strip_tags($r['content']);
- }
- $res = [
- 'title' => $r['title'],
- 'search_category' => $r['search_category'],
- 'news_image' => '/uploads/news/'.$r['profile_image'],
- 'content' => strip_tags((strlen($r['content']) > 250) ? substr(trim($r['content']), 0, 250) . ' ...' : $r['content']),
- 'link' => base_url() . 'news/'. $r['str_slug'],
- 'page' => base_url() . 'news',
- 'tags' => $r['tags'],
- 'str_slug' => $r['str_slug'],
- 'read_more' => 'VIEW ARTICLE '
- ];
- array_push($results, $res);
- }
- }
- return $results;
- }
- public function get_video_image($video_path, $video_img, $video_type){
- $data = array();
- $this->load->model('video_model');
- if($this->video_model->is_not_local_video($video_path)) {
- if(empty($video_img)){
- $data['video_img'] = $this->video_model->get_video_image($video_path);
- }
- if (strpos($video_path, 'youtu')){
- $tmp = explode('/', $video_img);
- $tmp = explode('?', end($tmp));
- $image = explode('&', $tmp[0]);
- $data['video_img'] = 'https://img.youtube.com/vi/' . $image[0] . '/' . $video_type . '.jpg';
- } else {
- if(!empty($video_img)){
- $data['video_img'] = base_url().'uploads/videos/'.$video_img;
- }else{
- $data['video_img'] = 'https://img.youtube.com/vi/mqdefault.jpg';
- }
- }
- } else {
- $data['video_img'] = base_url().'uploads/videos/'.$video_img;
- }
- return $data;
- }
- public function searchByState()
- {
- $data = array();
- $get = $this->input->get();
- $data['title'] = 'Search';
- $data['hide_main_search'] = true;
- $state_name = $this->user_model->select_state_by_code($get['state']);
- $data['state'] = !empty($state_name) ? $state_name->state_code : $get['state'];
- $data['state_name'] = !empty($state_name) ? $state_name->state : $get['state'];
- if(isset($get['state']) && !empty($state_name)){
- $data['cities'] = $this->user_model->select_state_city($state_name->state_code);
- $this->render(['search-second'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
- 'header' => [
- 'data' => array_merge($this->header_config, ['title' => $data['title'], 'hide_main_search' => $data['hide_main_search'], 'base_url' => base_url(), 'jquey_path'=>JQUERY_PATH], $this->login_model->checkHeaderLinks()),
- ]
- ]);
- }else{
- $data['procedures'] = $this->category_model->getSubCategoryListItems('name');
- $this->render(['search-third'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
- 'header' => [
- 'data' => array_merge($this->header_config, ['title' => $data['title'], 'hide_main_search' => $data['hide_main_search'], 'base_url' => base_url(), 'jquey_path'=>JQUERY_PATH], $this->login_model->checkHeaderLinks()),
- ]
- ]);
- }
- }
- public function searchByCity()
- {
- $data = array();
- $get = $this->input->get();
- $data['title'] = 'Search';
- $data['hide_main_search'] = true;
- $state_name = $this->user_model->select_state_by_code($get['state']);
- $data['state'] = !empty($state_name) ? $state_name->state_code : $get['state'];
- $data['state_name'] = !empty($state_name) ? $state_name->state : $get['state'];
- $data['main_procedures'] = $this->category_model->getParentCategoryListItems();
- foreach($data['main_procedures'] as &$proc){
- $proc->sub_proc= $this->category_model->getCategorySubItems($proc->id);
- }
- $this->render(['search-third'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
- 'header' => [
- 'data' => array_merge($this->header_config, ['title' => $data['title'], 'hide_main_search' => $data['hide_main_search'], 'base_url' => base_url(), 'jquey_path'=>JQUERY_PATH], $this->login_model->checkHeaderLinks()),
- ]
- ]);
- }
- public function keywords()
- {
- $get = $this->input->get();
- if (isset($get['search'])) {
- $query = $get['search'] == '' ? null : trim($get['search']);
- }
- $sString = $query;
- $query = explode(' ', $query);
- $search = array_pop($query);
- $limit = 5;
- $result = $this->keyword_model->getKeywords($query, $search, $limit, $sString);
- echo json_encode($result);
- die;
- }
- public function doctor()
- {
- if ($this->session->userdata('front_user')) {
- redirect('/');
- } else {
- $data = array();
- $data['method'] = $this->uri->segment(2);
- $data['states'] = $this->user_model->get_state();
- $data['board_certification'] = $this->register_model->get_board_certification();
- if (isset($_GET['query'])) {
- $queryDisplay = $_GET['query'] == '' ? null : $_GET['query'];
- $query = str_replace('+', ' ', $queryDisplay);
- $query = str_replace('\\', '\\\\', $query);
- $limit = 10;
- $page = (isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 1;
- if ($page == 1) {
- $start = 0;
- } else {
- $start = $page * $limit - ($limit);
- }
- $data['cat'] = 'doctors';
- $data['query'] = $queryDisplay;
- $limit = is_numeric($limit) ? $limit : 0;
- $data['result'] = $this->getSearchResult($query, $data['cat'], $limit, $start);
- $data['resultCount'] = count($this->getSearchResult($query, $data['cat'], null, null));
- }
- $this->render(['search-doctor'], array_merge($data, $this->header_config, ['base_url' => base_url()]));
- }
- }
- public function page()
- {
- if (isset($_GET['query'])) {
- $query = $_GET['query'] == '' ? null : $_GET['query'];
- $query = str_replace('+', ' ', $query);
- $limit = 10;
- $page = (isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 1;
- if($page==1){
- $start = 0;
- }else {
- $start = $page * $limit - ($limit);
- }
- $data['cat'] = 'doctors';
- $data['query'] = $query;
- $limit = is_numeric($limit) ? $limit : 0;
- $data['result'] = $this->getSearchResult($query, $data['cat'], $limit, $start);
- echo $this->twig->render('search-doctor-item.twig', array_merge($data, $this->headerConfig, ['base_url' => base_url()]));
- }
- }
- /**
- * @param $query
- * @param $cat
- * @return array
- */
- private function getCount($query, $cat, $score=null, $rating=null, $lat=null, $lng=null, $distance=null)
- {
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- $cat = strtolower($cat);
- $query = htmlentities($query);
- switch ($cat) {
- case 'all':
- /*$query = SphinxQL::create($conn)->select('*')
- ->from('all')
- ->match(array('forum_name',
- 'forum_desc',
- 'post_subject',
- 'post_text',
- 'auth_name',
- 'page_title',
- 'content',
- 'category_slug',
- 'article_slug',
- 'gallery_title',
- 'gallery_description',
- 'gallery_slug',
- 'first_name',
- 'last_name',
- 'video_title',
- 'video_description',
- 'video_slug'), $query
- );
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'all');
- */
- $result = [];
- $items = [
- 'articles',
- 'photos',
- 'doctors',
- 'videos',
- 'forum'
- ];
- foreach ($items as $item) {
- $res = $this->getSearchResult($query, $item);
- if (!empty($res))
- $result = array_merge($result, $res);
- }
- return $result;
- break;
- case 'guides':
- $query = SphinxQL::create($conn)->select('*')
- ->from('guides')
- ->match('content', $query);
- $query->option('max_matches', 1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'guides');
- break;
- case 'articles':
- $query = SphinxQL::create($conn)->select('*')
- ->from('articles')
- ->match('status_id', 1)
- ->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug'], $query);
- $query->option('max_matches', 1000);
- $query->limit(1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'articles');
- break;
- case 'photos':
- $query = SphinxQL::create($conn)->select('*')
- ->from('photos')
- ->match(['title', 'description', 'gallery_slug'], $query);
- $query->option('max_matches', 1000);
- $query->limit(1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'photos');
- break;
- case 'doctors':
- $serchQuery = $query;
- $query = SphinxQL::create($conn)->select('*')
- ->from('doctors')
- ->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'str_city', 'str_state', 'str_zip'], $query)
- ->option('field_weights', array('str_first_name'=>5, 'str_last_name'=>6, 'str_treatment_name'=>4, 'str_city'=>3, 'str_state'=>2, 'str_zip'=>1));
- $query->option('max_matches', 1000);
- $query->limit(1000);
- $result = $query->execute()->fetchAllAssoc();
- $searchResult = $this->generateSearchResult($result, 'doctors');
- $resClaim = $this->getSearchResult($serchQuery, 'claim');
- if (!empty($resClaim)){
- $searchResult = array_merge($searchResult, $resClaim);
- }
- return $searchResult;
- break;
- case 'videos':
- $query = SphinxQL::create($conn)->select('*')
- ->from('videos')
- ->match(['title', 'descriptopn', 'video_slug'], $query);
- $query->option('max_matches', 1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'videos');
- break;
- case 'forum':
- $query = SphinxQL::create($conn)->select('*')
- ->from('forum')
- ->match(['text','title'], $query);
- $query->option('max_matches', 1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'forum');
- break;
- case 'claim':
- $query = SphinxQL::create($conn)->select('*')
- ->from('claim_users')
- ->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'str_city', 'str_state', 'str_zip'], $query);
- $query->option('max_matches', 1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'claim_users');
- break;
- case 'questions':
- $query = SphinxQL::create($conn)->select('*')
- ->from('questions')
- ->match(['first_name', 'last_name', 'str_question', 'city', 'state', 'state_name'], "$query");
- $query->option('max_matches', 1000);
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'questions');
- break;
- default:
- return [];
- break;
- }
- } catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- }
- public function search_by($query, $type)
- {
- if($type =='name') {
- $this_name = $this->user_model->this_name(trim($query));
- if ($this_name) {
- return array('success'=>true);
- }
- }else if($type == 'procedure') {
- $this_procedure = $this->user_model->this_procedure(trim($query));
- if ($this_procedure) {
- return array('success'=>true);
- }
- }else if($type == 'location'){
- $this_location = $this->user_model->this_location(trim($query));
- if($this_location){
- return array('success'=>true, 'lat'=>$this_location->latitude, 'lng'=>$this_location->longitude, 'name'=>isset($this_location->city) ? $this_location->city : $this_location->state_name);
- }
- }else if($type == 'proc_&_loc') {
- $this_proc_loc = $this->user_model->this_proc_loc(trim($query));
- if ($this_proc_loc) {
- return array('success'=>true);
- }
- }
- }
- public function search_by_type($query, $type)
- {
- $str = $query;
- if(!is_array($query)) {
- if(!empty($query)) {
- $res = $this->search_by($query, $type);
- if(!empty($res)){
- return $res;
- }
- }
- $str = explode(' ', $query);
- }
- foreach ($str as $s)
- {
- if(!empty($s)) {
- $res = $this->search_by($s, $type) ;
- if(!empty($res)){
- return $res;
- }
- }
- }
- return array('success'=>false);
- }
- public function get_doctors_distance($query, $cat, $limit = null, $offset = null, $score=null, $rating=null, $lat=null, $lng=null, $distance=null, $specialty=null, $procedure=null, $state=null, $page=null, $search_dr=null, $gallery_boolean=null)
- {
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- $cat = strtolower($cat);
- if (!is_array($query)) {
- $query = htmlentities($query);
- $query = str_replace('amp;', '', $query);
- } else {
- $query = implode(' ', $query);
- }
- $select = array('*');
- $distance_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - $lat) * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS($lat * 3.14/180) * POW(SIN((user_lng -$lng) * 3.14/180 / 2), 2) ))";
- $dist = " ceil(3956 * 2 * SIN(SQRT(POW(SIN((user_lat - $lat) * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS($lat * 3.14/180) * POW(SIN((user_lng -$lng) * 3.14/180 / 2), 2) ))) as distance";
- $dist_filter = " IF( ";
- $dist_filter.= " $distance_miles >= ".$distance[0]." AND $distance_miles <".$distance[1]." "; //AND
- $dist_filter.=",1,0) AS dist_filter ";
- array_push($select, $dist_filter);
- array_push($select, $dist);
- if(!empty($score)) {
- $score_filter = 'IF(';
- $score_filter.= " doctor_total_score >= ".$score[0]." AND doctor_total_score <= ".$score[1]."";
- $score_filter.=",1,0) AS score_filter ";
- array_push($select, $score_filter);
- }
- if(!empty($specialty)) {
- $specialty_filter = 'IF(';
- foreach($specialty as $k=>$spec) {
- if (count($specialty) > 1 && $k < count($specialty) - 1){
- $specialty_filter .= " specialty_id = $spec OR ";
- }else {
- $specialty_filter.= " specialty_id = $spec";
- $specialty_filter.=",1,0) AS spec_filter ";
- }
- }
- array_push($select, $specialty_filter);
- }
- $res = SphinxQL::create($conn)->select($select);
- $res->from('doctors');
- if(!empty($query)){
- $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'proc_all', 'user_state', 'str_city', 'str_state'], $query);
- }
- if(!empty($query) && !empty($state)) {
- $res->option('field_weights', array('str_first_name' => 6, 'str_last_name' => 7, 'str_treatment_name' => 5, 'str_city' => 4, 'str_state' => 3, 'str_zip' => 1, 'user_state' => 2));
- }
- if(!empty($rating)) {
- foreach($rating as &$r){
- $r = (int)$r;
- }
- $res->where('doctor_rating', 'IN', $rating);
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($gallery_boolean) && $gallery_boolean=='no') {
- $res->where('gallery_true', '=', 0);
- }else if(!empty($gallery_boolean) && $gallery_boolean=='yes') {
- $res->where('gallery_true', '>', 0);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedures_id', 'IN', $procedure);
- $res->where('secondary_procedures_id', 'IN', $procedure);
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- $res->where('dist_filter', '=', 1);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $result;
- }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- }
- /**
- * get search result
- * @param $query
- * @param $cat
- * @param null $limit
- * @return \Foolz\SphinxQL\Drivers\ResultSetInterface
- */
- public function getSearchResult($query, $cat, $limit = null, $offset = null, $score=null, $rating=null, $lat=null, $lng=null, $distance=null, $specialty=null, $procedure=null, $state=null, $page=null, $search_dr=null, $gallery_boolean=null, $order_field=null, $order=null, $zip=null)
- {
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- $cat = strtolower($cat);
- if(!is_array($query)){
- $query = htmlentities($query);
- $query = str_replace('amp;', '', $query);
- }else{
- $query = implode(' ', $query);
- }
- $select = array('*');
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $distance_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - $lat) * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS($lat * 3.14/180) * POW(SIN((user_lng -$lng) * 3.14/180 / 2), 2) ))";
- $dist_filter = 'IF(';
- $dist_filter.= " $distance_miles >= ".$distance[0]." AND $distance_miles <=".$distance[1]."";
- $dist_filter.=",1,0) AS dist_filter ";
- array_push($select, $dist_filter);
- }
- if($cat == 'doctors' || $cat == 'claim' || $cat == 'doctor_name') {
- $search_by_name = $this->search_by_type($query, 'name');
- $search_by_procedure = $this->search_by_type($query, 'procedure');
- $search_by_location = $this->search_by_type($query, 'location');
- $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
- $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
- $user_loc = $this->user_model->get_user_location_by_ip($ip);
- $date_diff = 0;
- if(!empty($user_loc)) {
- $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
- }
- if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
- $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
- $user_loc = new StdClass;
- $user_loc->lat = $user_location['lat'];
- $user_loc->lng = $user_location['lng'];
- $user_loc->city_name = $user_location['city_name'];
- }
- if(isset($lat) && isset($lng)){
- $user_lat = $lat;
- $user_lng = $lng;
- $user_city_name = $state;
- }else if(!empty($user_loc)) {
- $user_lat = $user_loc->lat;
- $user_lng = $user_loc->lng;
- $user_city_name = $user_loc->city_name;
- }
- if ((isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name) && ($search_by_name['success']==false && $search_by_location['success']==false
- && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true) && $search_dr != true ||
- ($search_dr == true && empty($state) && $search_by_location['success'] == false && isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name)))) {
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- $distance_filter = 'IF(';
- $distance_filter .= " user_state = '".$user_city_name."' OR str_city = '".$user_city_name."'";
- $distance_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $distance_filter);
- }
- if($search_by_name['success']==true && $search_dr == true && !empty($state)){
- $distance_filter = 'IF(';
- $distance_filter .= " user_state = '".$user_city_name."' OR str_city = '".$user_city_name."'";
- $distance_filter .= ",1,0) AS user_city_filter ";
- array_push($select, $distance_filter);
- }
- if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$user_lat.") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$user_lat." * 3.14/180) * POW(SIN((user_lng -".$user_lng.") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- if($search_by_location['success']==true && $search_by_name['success']==false && $search_by_procedure['success']==false && isset($search_by_location['lat']) && isset($search_by_location['lng'])){
- $distance_dist = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) )) AS distance ";
- array_push($select, $distance_dist);
- $distance_in_miles = " 3956 * 2 * SIN(SQRT(POW(SIN((user_lat - ".$search_by_location['lat'].") * 3.14/180 / 2), 2) +COS(user_lat * 3.14/180) * COS(".$search_by_location['lat']." * 3.14/180) * POW(SIN((user_lng -".$search_by_location['lng'].") * 3.14/180 / 2), 2) ))";
- $distance_filter = 'IF( ';
- $distance_filter .= $distance_in_miles." <= 100";
- $distance_filter .= ",1,0) AS distance_filter ";
- array_push($select, $distance_filter);
- }
- }
- if(!empty($score)) {
- $score_filter = 'IF(';
- $score_filter.= " doctor_total_score >= ".$score[0]." AND doctor_total_score <= ".$score[1]."";
- $score_filter.=",1,0) AS score_filter ";
- array_push($select, $score_filter);
- }
- if(!empty($specialty)) {
- $specialty_filter = 'IF(';
- foreach($specialty as $k=>$spec) {
- if (count($specialty) > 1 && $k < count($specialty) - 1){
- $specialty_filter .= " specialty_id = $spec OR ";
- }else {
- $specialty_filter.= " specialty_id = $spec";
- $specialty_filter.=",1,0) AS spec_filter ";
- }
- }
- array_push($select, $specialty_filter);
- }
- if(!empty($zip)) {
- $zip_filter = 'IF(';
- $zip_filter.= " zip == ".$zip;
- $zip_filter.=",1,0) AS zip_filter ";
- array_push($select, $zip_filter);
- }
- switch ($cat) {
- case 'all':
- $result = [];
- $items = [
- 'procedure',
- 'articles',
- 'photos',
- 'doctors',
- 'videos',
- 'news',
- 'forum'
- ];
- foreach ($items as $item) {
- $res = $this->getSearchResult($query, $item, null, null, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state);
- if (!empty($res))
- $result = array_merge($result, $res);
- }
- return $result;
- break;
- case 'guides':
- $res = SphinxQL::create($conn)->select('*')
- ->from('guides')
- ->match('content', $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_of_publication', $order);
- }
- }
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'guides');
- break;
- case 'procedure':
- $proc_filter = 'IF(';
- $proc_filter .= " procedure_name = '".$query."' OR fact_sheet_name = '".$query."'";
- $proc_filter .= ",1,0) AS procedure_filter ";
- array_push($select, $proc_filter);
- $res = SphinxQL::create($conn)->select($select);
- $res->from('procedure');
- $res->match(['procedure_name', 'fact_sheet_name', 'content'], $query);
- // $res->compile()
- // ->getCompiled();
- if(!empty($zip)) {
- $res->where('zip_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- $res->orderBy('procedure_filter', 'DESC');
- if($order_field && $order) {
- $res->orderBy($order_field, $order);
- }else {
- $res->orderBy('procedure_name', 'ASC');
- }
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'procedure', $query, $page);
- break;
- case 'articles':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('articles');
- if(!empty($state)){
- $res->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug', 'status_id', 'user_state', 'user_city'], $query);
- $res->match(['user_state', 'user_city'], $state);
- }else {
- $res->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug', 'status_id', 'user_state', 'user_city'], $query);
- }
- if(!empty($rating)) {
- $res->where('doctor_rating', '=', (int)$rating);
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedure_id', 'IN', $procedure);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- if(!is_null($order)) {
- if(!is_null($order_field)) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_of_public', $order);
- }
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'articles', $query, $page);
- break;
- case 'news':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('news');
- $res->match(['title', 'description', 'tags', 'news_slug', 'category_slug', 'user_state', 'user_city'], $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_posted', $order);
- }
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'news', $query, $page);
- break;
- case 'photos':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('photos');
- if(!empty($state)){
- $res->match(['title', 'gallery_slug', 'procedure_name'], $query);
- $res->match(['user_state', 'user_city', 'user_city'], $state);
- }else {
- $res->match(['title', 'gallery_slug', 'procedure_name'], $query);
- }
- if(!empty($rating)) {
- $res->where('doctor_rating', '=', (int)$rating);
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($zip)) {
- $res->where('zip_filter', '=', 1);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedure_id', 'IN', $procedure);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }
- else{
- $res->limit(1000);
- }
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_create', $order);
- }
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'photos');
- break;
- case 'doctors':
- $serchQuery = $query;
- $res = SphinxQL::create($conn)->select($select);
- $res->from('doctors');
- if(!empty($query) && !empty($state)) {
- $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'proc_all', 'user_state', 'str_city', 'str_state', 'str_degree_title', 'user_state', 'str_city', 'str_state'], $query);
- $res->option('field_weights', array('str_first_name' => 6, 'str_last_name' => 7, 'str_treatment_name' => 5, 'str_city' => 4, 'str_state' => 3, 'str_zip' => 1, 'user_state' => 2, 'str_degree_title'=>0));
- } else
- if(!empty($query)){
- $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'proc_all', 'user_state', 'str_city', 'str_state', 'str_degree_title'], $query);
- } else
- if(!empty($state)){ // && empty($distance)
- $res->match(['user_state', 'str_city', 'str_state'], $state);
- }
- if(!empty($rating)) {
- foreach($rating as &$r){
- $r = (int)$r;
- }
- $res->where('doctor_rating', 'IN', $rating);
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($gallery_boolean) && $gallery_boolean=='no') {
- $res->where('gallery_true', '=', 0);
- }else if(!empty($gallery_boolean) && $gallery_boolean=='yes') {
- $res->where('gallery_true', '>', 0);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedures_id', 'IN', $procedure);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_dr != true && $search_by_name['success']==false
- || $search_by_loc_proc['success'] == true) || ($search_dr == true && empty($state) && !empty($user_lat) && !empty($user_lng)) ){ // && ($search_dr==false || $search_dr==null)
- $res->where('location_flag', '=', 1);
- $res->where('distance_filter', '=', 1);
- $res->orderBy('user_city_filter', 'DESC');
- $res->orderBy('distance', 'ASC');
- $res->orderBy('str_city', 'ASC');
- }
- if($search_by_name['success']==true && $search_dr == true && !empty($state)){
- // $res->where('user_city_filter', '=', 1);
- $res->orderBy('user_city_filter', 'DESC');
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- // $res->compile()
- // ->getCompiled();
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_updated', $order);
- }
- }
- $result = $res->execute()->fetchAllAssoc();
- $ids = array();
- foreach($result as $r){
- array_push($ids, $r['id']);
- }
- $count_diff = 0;
- if(!is_null($limit)) {
- $count_diff = $limit - count($result);
- }
- if($count_diff>0 || is_null($limit)) {
- if ($gallery_boolean != 'yes') {
- $claim_res = $this->getSearchResult($serchQuery, 'claim', $count_diff, null, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
- if (!empty($claim_res)) {
- $claim_ids = array();
- foreach ($claim_res as &$rc) {
- array_push($claim_ids, $rc['id']);
- if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
- array_unshift($result, $rc);
- array_push($ids, $rc->id);
- } else {
- array_push($result, $rc);
- }
- }
- }
- }
- if (($search_by_location['success'] == true && $search_by_name['success'] == true && $search_dr !== true) || ($search_by_loc_proc['success'] == true && $search_by_name['success'] == true) || $search_by_name['success'] == true) { // && $search_by_procedure['success']==true
- $result_by_name = $this->getSearchResult($serchQuery, 'doctor_name', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
- foreach ($result as $res) {
- array_push($ids, $res['id']);
- }
- if (!empty($result_by_name)) {
- foreach ($result_by_name as &$rbn) {
- if (!in_array($rbn['id'], $ids)) {
- array_push($result, $rbn);
- }
- }
- }
- }
- if ($search_by_loc_proc['success'] == true) {
- $result_by_loc = $this->getSearchResult($serchQuery, 'doctor_location', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr);
- foreach ($result as $res) {
- array_push($ids, $res['id']);
- }
- if (!empty($result_by_loc)) {
- foreach ($result_by_loc as &$rbl) {
- if (!in_array($rbl['id'], $ids)) {
- array_push($result, $rbl);
- }
- }
- }
- }
- if (!empty($lat) && !empty($lng) && $search_by_name['success'] == false) {
- if (!isset($distance)) {
- $distance = array(0, 100);
- }
- $result_dist = $this->get_doctors_distance($query, $cat, $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, $page, $search_dr, $gallery_boolean, true);
- foreach ($result as $res) {
- array_push($ids, $res['id']);
- }
- if (!empty($result_dist)) {
- foreach ($result_dist as &$rd) {
- if (!in_array($rd['id'], $ids)) {
- array_push($result, $rd);
- }
- }
- }
- }
- }
- $searchResult = $this->generateSearchResult($result, 'doctors');
- return $searchResult;
- break;
- case 'doctor_name':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('doctors');
- $res->match(['str_first_name', 'str_last_name'], $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- $result = $res->execute()->fetchAllAssoc();
- $claim_res = $this->getSearchResult($query, 'claim_name', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
- if (!empty($claim_res)){
- foreach($claim_res as &$rc) {
- if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
- array_unshift($result, $rc);
- } else {
- array_push($result, $rc);
- }
- }
- }
- return $result;
- break;
- case 'claim_name':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('claim_users');
- $res->match(['str_first_name', 'str_last_name'], $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- $result = $res->execute()->fetchAllAssoc();
- return $result;
- break;
- case 'doctor_location':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('doctors');
- $res->match(['user_state', 'str_city', 'str_state'], $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- $result = $res->execute()->fetchAllAssoc();
- $claim_res = $this->getSearchResult($query, 'claim_location', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state);
- if (!empty($claim_res)){
- foreach($claim_res as &$rc) {
- if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
- array_unshift($result, $rc);
- } else {
- array_push($result, $rc);
- }
- }
- }
- return $result;
- break;
- case 'claim_location':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('claim_users');
- $res->match(['user_state', 'str_city', 'str_state'], $query);
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(0, 1000);
- }
- $result = $res->execute()->fetchAllAssoc();
- return $result;
- break;
- case 'videos':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('videos');
- if(!empty($state)){
- $res->match(['title', 'descriptopn', 'video_slug','user_state', 'user_city', 'str_state'], $query);
- $res->match(['user_state', 'user_city', 'str_state'], $state);
- }else {
- $res->match(['title', 'descriptopn', 'video_slug','user_state', 'user_city', 'str_state'], $query);
- }
- if(!empty($rating)) {
- $res->where('doctor_rating', '=', (int)$rating);
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedure_id', 'IN', $procedure);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('date_updated', $order);
- }
- }
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'videos');
- break;
- case 'forum':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('forum');
- if(!empty($state)){
- $res->match(['text', 'title', 'user_state', 'user_city', 'str_state'], $query);
- $res->match(['user_state', 'user_city', 'str_state'], $state);
- }else {
- $res->match(['text', 'title', 'user_state', 'user_city', 'str_state'], $query);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- if($order) {
- if($order_field) {
- $res->orderBy($order_field, $order);
- }else{
- $res->orderBy('time', $order);
- }
- }
- $result = $res->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'forum');
- break;
- case 'claim':
- $res = SphinxQL::create($conn)->select($select);
- $res->from('claim_users');
- if(!empty($query)){
- $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'user_state', 'str_city', 'str_state', 'str_degree_title'], $query);
- }
- if(!empty($state)){
- $res->match(['user_state', 'str_city', 'str_state'], $state);
- }
- if(!empty($query) || !empty($state)) {
- $res->option('field_weights', array('str_first_name' => 6, 'str_last_name' => 7, 'str_treatment_name' => 5, 'str_city' => 4, 'str_state' => 3, 'str_zip' => 1, 'user_state' => 2, 'str_degree_title'=>0));
- }
- if(!empty($specialty)) {
- $res->where('spec_filter', '=', 1);
- }
- if(!empty($procedure)) {
- foreach($procedure as &$pr){
- $pr = (int)$pr;
- }
- $res->where('procedure_id', 'IN', $procedure);
- }
- if(!empty($distance) && !empty($lat) && !empty($lng)){
- $res->where('dist_filter', '=', 1);
- }
- if(!empty($user_lat) && !empty($user_lng) && $search_by_name['success']==false && $search_by_location['success']==false){
- $res->where('location_flag', '=', 1);
- $res->where('distance_filter', '=', 1);
- $res->orderBy('user_city_filter', 'DESC');
- $res->orderBy('distance', 'ASC');
- $res->orderBy('str_city', 'ASC');
- }
- if(!empty($user_lat) && !empty($user_lng) && ($search_by_name['success']==false && $search_by_location['success']==false) || $search_by_loc_proc['success'] == true){
- $res->where('location_flag', '=', 1);
- $res->where('distance_filter', '=', 1);
- $res->orderBy('user_city_filter', 'DESC');
- $res->orderBy('distance', 'ASC');
- $res->orderBy('str_city', 'ASC');
- }
- if($search_by_procedure['success']==true && $search_by_name['success']==false && $search_by_procedure['success']==false){
- $res->where('location_flag', '=', 1);
- $res->where('distance_filter', '=', 1);
- $res->orderBy('distance', 'ASC');
- }
- if(!empty($score)) {
- $res->where('score_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $res->limit($offset, $limit);
- }else{
- $res->limit(1000);
- }
- // $res->compile()
- // ->getCompiled();
- $result = $res->execute()->fetchAllAssoc();
- return $result;//$this->generateSearchResult($result, 'claim_users');
- break;
- case 'questions':
- $query = SphinxQL::create($conn)->select('*')
- ->from('questions')
- ->match(['first_name', 'last_name', 'str_question', 'city', 'state', 'state_name', 'title', 'text'], $query);
- if(!empty($zip)) {
- $query->where('zip_filter', '=', 1);
- }
- if (!is_null($limit)) {
- $query->limit($offset, $limit);
- }else{
- $query->limit(1000);
- }
- if($order) {
- if($order_field) {
- $query->orderBy($order_field, $order);
- }else{
- $query->orderBy('date_create', $order);
- }
- }
- // $query->compile()
- // ->getCompiled();
- $result = $query->execute()->fetchAllAssoc();
- return $this->generateSearchResult($result, 'questions');
- break;
- default:
- return [];
- break;
- }
- } catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- }
- /**
- * generate search result
- * @param $result
- * @param $type
- * @param null $query
- * @return array
- */
- private function generateSearchResult($result, $type, $query = null, $page = null)
- {
- $results = [];
- switch ($type) {
- case 'all':
- foreach ($result as $items) {
- $results[] = [
- 'title' => $items['title'],
- 'category' => $items['category'],
- 'content' => strip_tags((strlen($items['str_content']) > 500) ? substr($items['str_content'], 0, 500) . ' ...' : $items['str_content']),
- 'link' => base_url() . $items['slug'],
- 'page' => base_url() . '',
- ];
- }
- return $results;
- break;
- case 'guides':
- foreach ($result as $items) {
- $results[] = [
- 'title' => '',
- 'category' => 'guides',
- 'content' => '',
- 'link' => '',
- 'page' => base_url() . '',
- ];
- }
- return $results;
- break;
- case 'procedure':
- foreach ($result as $items) {
- $res = [
- 'title' => $items['fact_sheet_name'],
- 'image_url' => $items['image_url'],
- 'category_slug' => $items['category_slug'],
- 'zip' => $items['zip'],
- 'category' => 'procedure',
- 'content' => strip_tags((strlen($items['content']) > 500) ? substr(trim($items['content']), 0, 500) . ' ...' : $items['content']),
- 'link' => base_url() . 'procedure/' . $items['category_slug'],
- 'page' => base_url() . 'journal',
- 'read_more' => 'VIEW ARTICLE '
- ];
- array_push($results, $res);
- }
- return $results;
- break;
- case 'articles':
- foreach($result as &$art){
- $parent_id = $this->category_model->getParentCategoryById($art['procedure_id']);
- if($parent_id) {
- $art['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
- }else {
- $proc = $this->doctorprofile->getProcedureById($art['procedure_id']);
- $art['procedure_name'] = $proc->category_slug;
- }
- }
- foreach ($result as $items) {
- if(stripos($items['content'], 'data-oembed_provider="vimeo"')){
- $items['content'] = strip_tags($items['content']);
- }
- $res = [
- 'title' => $items['page_title'],
- 'category' => 'articles',
- 'content' => strip_tags((strlen($items['content']) > 500) ? substr(trim($items['content']), 0, 500) . ' ...' : $items['content']),
- 'link' => base_url() . 'journal/' . $items['procedure_name'] . '/' . $items['article_slug'],
- 'page' => base_url() . 'journal',
- 'read_more' => 'VIEW ARTICLE '
- ];
- array_push($results, $res);
- }
- return $results;
- break;
- case 'photos':
- foreach ($result as $items) {
- $userData = $this->login_model->getnewUserData('doctor', $items['users_id']);
- $elite_badge_delete = $this->admin_model->getEliteBadgeDelete($items['users_id']);
- $category_id = $this->category_model->getCategoryByProc($items['procedure_id']);
- $category = $this->category_model->getPhotoCategoryById($category_id);
- $doctor_score = 0;
- if(!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- }
- $results[] = [
- 'id'=>$items['id'],
- 'str_first_name'=>$items['str_first_name'],
- 'str_last_name'=>$items['str_last_name'],
- 'title' => $items['title'],
- 'zip' => $items['zip'],
- 'category' => 'photos',
- 'category_id' => $items['category_id'],
- 'procedure_id' => $items['procedure_id'],
- 'category_slug' => !empty($category) ? $category->category_slug : $items['category_slug'],
- 'gallery_slug' => $items['gallery_slug'],
- 'users_id' => $items['users_id'],
- 'content' => strip_tags((strlen($items['description']) > 500) ? substr($items['description'], 0, 500) . ' ...' : $items['description']),
- 'link' => base_url() . 'photo/' . $items['gallery_slug'],
- 'page' => base_url() . 'photos',
- 'read_more' => 'VIEW GALLERY ',
- 'images' => explode(',', $items['images']),
- 'elite_badge_delete' => $elite_badge_delete,
- 'score' => $doctor_score,
- 'tags' => $items['tags']
- ];
- }
- return $results;
- break;
- case 'doctors':
- foreach ($result as $items) {
- $pos = strpos($items['profile_image'], '//lorempixel.com');
- $rankin = $doctor_score = 0;
- if(isset($items['user_id']) ) {
- $userData = $this->login_model->getnewUserData('doctor', $items['user_id']);
- if(!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score*0.25, 1);
- }
- }else if(isset($items['id']) ) {
- $userData = $this->login_model->getClaimData($items['id']);
- if(!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score*0.25, 1);
- }
- }
- if(!empty($items['str_first_name']) && !empty($items['str_last_name'])) {
- if($pos===false){
- $profile_image='/uploads/users/profilepic/'.$items['profile_image'];
- }
- else{
- $profile_image=$items['profile_image'];
- }
- if(empty($items['profile_image'])){
- $profile_image='/images/frontend/profilepic/profile.png';
- }
- $results[] = [
- 'id' => isset($items['user_id']) ? $items['user_id'] : $items['id'],
- 'title' => ucfirst($items['str_first_name']) . ' ' . ucfirst($items['str_last_name']) . ', ' . strtoupper($items['str_degree_title']),
- 'doctor_title' => isset($items['title']) ? $items['title'] : '',
- 'category' => 'doctors',
- 'user_lat' => $items['user_lat'],
- 'user_lng' => $items['user_lng'],
- 'user_lng' => $items['user_lng'],
- 'countarticles' => isset($items['countarticles']) ? $items['countarticles'] : 0,
- 'countreviews' => isset($items['countreviews']) ? $items['countreviews'] : 0,
- 'sumrating' => isset($items['sumrating']) ? $items['sumrating'] : 0,
- 'doc_rating' => isset($items['sumrating']) ? $items['sumrating'] : 0,
- 'countvideos' => isset($items['countvideos']) ? $items['countvideos'] : 0,
- 'content' => $items['str_address'],
- 'content2' => $items['str_city'] . ', ' . $items['str_state'] . ' ' . $items['str_zip'],
- 'address' => $items['str_state'].', '.$items['str_address'],
- 'link' => base_url() . 'doctor/' .$items['str_user_slug'],
- 'page' => base_url() . 'doctor/' . $items['str_user_slug'],
- 'read_more' => 'VISIT DOCTOR ',
- 'distance' => isset($items['distance']) ? $items['distance'] : '',
- 'user_city_filter' => isset($items['user_city_filter']) ? $items['user_city_filter'] : '',
- 'rating' => $rankin,
- 'profile_image' => $profile_image,
- 'board_certification' =>$items['board_certification']
- ];
- }
- }
- return $results;
- break;
- case 'videos':
- foreach ($result as $items) {
- $results[] = [
- 'title' => $items['title'],
- 'category' => 'videos',
- 'content' => strip_tags((strlen($items['descriptopn']) > 500) ? substr($items['descriptopn'], 0, 500) . ' ...' : $items['descriptopn']),
- 'link' => base_url() . 'video/' . $items['video_slug'],
- 'page' => base_url() . 'video/' . $items['video_slug'],
- 'read_more' => 'VIEW VIDEO '
- ];
- }
- return $results;
- break;
- case 'forum':
- foreach ($result as $item) {
- if($item['is_new_forum_post']){
- $post = nl2br($this->bbcodeparser->run($item['text']));
- }else {
- $post = $this->phpbbparser->run($item['text']);
- }
- $results[] = [
- 'title' => $item['title'],
- 'category' => 'forum',
- 'content' => $post,
- 'link' => base_url() . 'forum/'.$this->forum_model->prepare_string($item['name']).'/' . $this->forum_model->prepare_string($item['title']).'/'.$item['topic_id'],
- 'page' => base_url() . 'forum',
- 'read_more' => 'VIEW POST '
- ];
- }
- return $results;
- break;
- case 'claim_users':
- foreach ($result as $items) {
- $pos = strpos($items['profile_image'], 'https://lorempixel.com');
- if(!empty($items['str_first_name']) && !empty($items['str_last_name'])) {
- if($pos===false){
- $profile_image='/uploads/users/profilepic/'.$items['profile_image'];
- }
- else{
- $profile_image=$items['profile_image'];
- }
- if((!empty($items['profile_image']) && !file_exists('.'.$profile_image)) || empty($items['profile_image'])){
- $profile_image='/images/frontend/profilepic/profile.png';
- }
- $rankin = $doctor_score = 0;
- if(isset($items['id']) ) {
- $userData = $this->login_model->getClaimData($items['id']);
- if(!empty($userData)) {
- $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
- $rankin = round($doctor_score*0.25, 1);
- }
- }
- $results[] = [
- 'claim_id' =>$items['id'],
- 'title' => ucfirst($items['str_first_name']) . ' ' . ucfirst($items['str_last_name']) . ', ' . strtoupper($items['str_degree_title']),
- 'category' => 'doctors',
- 'user_lat' => $items['user_lat'],
- 'user_lng' => $items['user_lng'],
- 'content' => $items['str_address'],
- 'content2' => $items['str_city'] . ', ' . $items['str_state'] . ' ' . $items['str_zip'],
- 'link' => base_url() . 'doctor/' . $items['str_user_slug'],
- 'page' => base_url() . 'doctor/' . $items['str_user_slug'],
- 'read_more' => 'VISIT DOCTOR ',
- 'distance' => isset($items['distance']) ? $items['distance'] : '',
- 'user_city_filter' => isset($items['user_city_filter']) ? $items['user_city_filter'] : '',
- 'rating' => $rankin,
- 'profile_image' => $profile_image
- ];
- }
- }
- return $results;
- break;
- case 'questions':
- foreach ($result as $items) {
- $results[] = [
- 'title' => '',
- 'category' => 'questions',
- 'zip' => $items['zip'],
- 'content' => strip_tags((strlen($items['str_question']) > 500) ? substr($items['str_question'], 0, 500) . ' ...' : $items['str_question']),
- 'link' => base_url() . 'question/' . $items['question_id'],
- 'page' => base_url() . 'question/' . $items['question_id'],
- 'read_more' => 'VIEW QUESTION '
- ];
- }
- return $results;
- break;
- case 'news':
- foreach ($result as $items) {
- $results[] = [
- 'title' => $items['title'],
- 'category' => 'news',
- 'content' => strip_tags((strlen($items['description']) > 500) ? substr($items['description'], 0, 500) . ' ...' : $items['description']),
- 'link' => base_url() . 'news/' . $items['news_slug'],
- 'page' => base_url() . 'news/' . $items['news_slug'],
- 'read_more' => 'VIEW NEWS '
- ];
- }
- return $results;
- break;
- default:
- return [
- 'title' => '',
- 'category' => '',
- 'content' => '',
- 'link' => ''
- ];
- break;
- }
- }
- public function get_procedures_map()
- {
- $data['procedures'] = $this->user_model->get_procedure();
- if ($data['procedures']) {
- echo json_encode($data['procedures']);
- } else {
- echo json_encode(false);
- }
- }
- /**
- * get url from split variable, if split is true return url after explode
- * else just return url after read from segment
- * @param $segment
- * @param bool $split
- * @param string $delimiter
- * @return array
- */
- private function _getUrl($segment, $split = false, $delimiter = '_')
- {
- $segment = $this->uri->segment($segment);
- if ($split) {
- return explode($delimiter, $segment);
- } else {
- return $segment;
- }
- }
- /**
- * Dealing with reviews
- * @author rsingh6
- */
- public function search()
- {
- $get = $this->input->get();
- if ($get['query'] == '') {
- show_404();
- }
- $config['base_url'] = base_url() . "search/index/";
- $record_sum = array_sum($this->user_model->record_count_site());
- $config['total_rows'] = $record_sum;
- $config['per_page'] = 10;
- $config["uri_segment"] = 3;
- $config['num_links'] = 10;
- $config['reuse_query_string'] = TRUE;
- $this->pagination->initialize($config);
- $page = ($this->_getUrl(3)) ? $this->_getUrl(3) : 0;
- $data["links"] = $this->pagination->create_links();
- $data['get_var'] = '/?query=' . $get['query'];
- $data['search'] = $this->user_model->search_site($config["per_page"], $page);
- $data['featured'] = $this->doctorprofile->get_featured_doctor();
- $this->render(['search/site_search'], $data,[
- 'is_twig' => FALSE,
- ]);
- }
- /**
- * Logout for destroying all the session values
- * @author rsingh6
- */
- public function logout($check = '')
- {
- $type = $this->session->userdata('front_user');
- $this->session->unset_userdata('front_user');
- $this->session->sess_destroy();
- if ($check == 'account-disabled') {
- session_start();
- $_SESSION['logout_usr'] = 'index/login/account-disabled';
- //redirect('index/login/account-disabled');
- redirect(base_url() . 'forumlogout.php');
- } else {
- session_start();
- $_SESSION['logout_usr'] = 'index/login/';
- //redirect('index/login/', 'refresh');
- redirect(base_url() . 'forumlogout.php');
- }
- }
- public function searchbeforeafter(){
- $get = $this->input->get();
- if (isset($get['search'])) {
- $query = $get['search'] == '' ? null : trim($get['search']);
- }
- if (isset($get['activity'])) {
- $activity = $get['activity'] == '' ? null : trim($get['activity']);
- }
- $activity_id = $this->procedure_model->get_activity_by_name($activity);//var_dump($activity, $activity_id);
- /* $model = $this->procedure_model->find_one_by_attributes(array('category_slug' => $query));
- $data = array_chunk($this->gallery_model->get_by_procedure_id($model['id']),3);
- echo json_encode($data);
- die; */
- $this->load->model('procedure_model');
- $result = $this->procedure_model->searchbeforeafter($query, null, $activity_id);
- echo json_encode($result);
- exit;
- }
- public function activities()
- {
- $get = $this->input->get();
- if (isset($get['search'])) {
- $query = $get['search'] == '' ? null : trim($get['search']);
- }
- $this->load->model('procedure_model');
- $retrun_data = $this->procedure_model->get_activities($query);
- echo json_encode($retrun_data);
- die;
- }
- /*
- * get doctors by zip for rendering
- * */
- public function getDoctorsByZip()
- {
- $post = $this->input->post();
- if (!empty($post)){
- $zip = $post['zip'];
- $proc_slug = $post['proc_slug'];
- }
- $model = $this->procedure_model->find_one_by_attributes(array('category_slug' => $proc_slug));
- $proc_name = $model['name'];
- $id = $model['id'];
- $parent_proc = $this->category_model->getParentNameCategoryById($id);
- try {
- require_once __DIR__ . '/../../vendor/autoload.php';
- require __DIR__ . '/../config/database.php';
- // create a SphinxQL Connection object to use with SphinxQL
- $conn = new Connection();
- $conn->setParams(['host' => $db['default']['sphinx_hostname'],
- 'port' => $db['default']['sphinx_port'],
- 'username' => $db['default']['username'],
- 'password' => $db['default']['password'],
- ]);
- $select = array('*' );
- $res = SphinxQL::create($conn)->select($select);
- $res->from('doctors');
- if(isset($proc_name)) {
- $res->match(['str_treatment_name'], $proc_name);
- }
- if(isset($id)) {
- $res->match(['procedure_id'], $id);
- }
- if(isset($zip)) {
- $res->match(['str_zip'], $zip);
- }
- $res->orderBy('avg_rating', 'DESC');
- $res->limit(0, 6);
- $res = $res->execute()->fetchAllAssoc();
- if ((empty($res) || count($res) < 6) && !empty($parent_proc)) {
- $ids = array();
- foreach ($res as $r) {
- array_push($ids, $r['id']);
- }
- $result = SphinxQL::create($conn)->select($select);
- $result->from('doctors');
- $result->match(['str_treatment_name'], $parent_proc[0]->name);
- $result->match(['str_zip'], $zip);
- $result->orderBy('avg_rating', 'DESC');
- $result->limit(6 - count($res));
- $result = $result->execute()->fetchAllAssoc();
- foreach ($result as $rp) {
- if (!in_array($rp['id'], $ids)) {
- array_push($res, $rp);
- }
- }
- }
- }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
- } catch (Exception $ex) {
- }
- if(!empty($res)) {
- $data['top_doc_near_you'] = $res;
- $this->render(['find-near-doctors'], $data,
- [
- 'header' => ['is_visible' => false,],
- 'footer' => ['is_visible' => false,]
- ]);
- }else{
- return '';
- }
- }
- }
- /* End of file reviews.php */
- /* Location: ./application/controllers/reviews.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement