Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 135.69 KB | None | 0 0
  1. <?php
  2. include_once('base_front_end.php');
  3.  
  4. use Foolz\SphinxQL\SphinxQL;
  5. use Foolz\SphinxQL\Drivers\Pdo\Connection;
  6.  
  7. /**
  8. * Class Search
  9. */
  10. class Search extends base_front_end
  11. {
  12. public function __construct()
  13. {
  14. error_reporting(0);
  15. parent::__construct();
  16.  
  17. $this->render_options['is_twig'] = TRUE;
  18. // init configs
  19.  
  20. /*$loader = new Twig_Loader_Filesystem(TWIG_TEMPLATE_PATH);
  21. $this->twig = new Twig_Environment($loader,array(
  22. 'debug' => true,
  23. ));
  24. $this->twig->addExtension(new Twig_Extension_Debug());
  25. $this->twig->addExtension(new Twig_Extensions_Extension_Text());*/
  26. $this->load->model('admin_model');
  27. $this->load->model('category_model');
  28. $this->load->library('NewsRSS');
  29. $this->load->library('PTagCloudGenerator');
  30.  
  31. $this->load->library('phpbbparser');
  32. $this->load->library('bbcodeparser');
  33.  
  34. $this->load->library('image_lib');
  35. $this->load->model('forum_model');
  36.  
  37. $this->load->model('home_model');
  38. $this->load->model('login_model');
  39. $this->load->model('register_model');
  40. $this->load->model('doctorprofile');
  41. $this->load->model('news_model');
  42. $this->load->model('pages_model');
  43. $this->load->model('user_model');
  44. $this->load->model('video_model');
  45. $this->load->model('gallery_model');
  46. $this->load->model('review_model');
  47. $this->load->model('booking_model');
  48. $this->load->model('questions_model');
  49. $this->load->model('keyword_model');
  50. $this->load->model('procedure_model');
  51. $this->load->model('procedure_slider_model');
  52. $this->load->helper(array(
  53. 'form',
  54. 'url',
  55. 'youtube',
  56. ));
  57. $this->load->helper('vimeo');
  58. $this->load->helper('text');
  59. $this->load->helper('date');
  60. $this->load->library('pagination');
  61. //$this->load->library('MY_Pagination');
  62. $this->load->library('form_validation');
  63. $this->load->library('user_agent');
  64. $this->load->library('auth');
  65. $this->load->helper('string');
  66. $this->load->helper('cookie');
  67. $this->load->library('session');
  68. $this->load->library('email');
  69. $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
  70. $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  71. $this->output->set_header('Pragma: no-cache');
  72. $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  73.  
  74. }
  75.  
  76. public function index($query){
  77. $data['title'] = 'Search';
  78. $data['canonical'] = base_url();
  79. $cat = $query = $limit = null;
  80. $get = $this->input->get();
  81. $zip = isset($get['zipcode']) ? $get['zipcode'] : null;
  82. $order = isset($get['sort']) ? $get['sort'] : null;
  83. $limit = (isset($get['limit']) && !empty($get['limit'])) ? $get['limit'] : 25;
  84. $data['search_state'] = $get['state'];
  85. $data['city'] = $get['city'];
  86. $data['rankin_page'] = $this->review_model->get_ranking_page();
  87. $data['query'] = trim($get['query']);
  88. $data['zip'] = $zip;
  89. $data['per_page'] = $limit;
  90. $data['sort'] = isset($get['order']) && !empty($get['order']) ? $get['order'] : $order;
  91. $data['articles_hidden'] = isset($get['articles_hidden']) ? $get['articles_hidden'] : false;
  92. if(empty($get['query'])) $query=" ";
  93. $data['availableTypes'] = array('procedure', 'articles', 'photos', 'doctors', 'videos', 'questions');
  94. if($get['cat']=="news"){
  95. $data['type'] = array("articles");
  96. }
  97. else{
  98. $data['type'] = $get['type'];
  99. }
  100. if (count($data['type']) == 0) {
  101. if(isset($get['cat']) && !empty($get['cat']) && $get['cat']!='all'){
  102. $data['type'] = (array)$get['cat'];
  103. } else {
  104. $data['type'] = $data['availableTypes'];
  105. }
  106. }
  107. if(count($get['type'])==1){
  108. $get['cat'] = $get['type'][0];
  109. }
  110. $data['type_article'] = !is_null($get['type_article']) ? $get['type_article'] : array('news', 'articles'); // && !empty($get['type_article'])
  111. if(!in_array('articles', $data['type']) || $get['articles_hidden']=='true'){
  112. $data['type_article'] = array();
  113. $data['type'] = array_diff($data['type'], ['articles']);
  114. }
  115. $data['showAllTypes'] = false;
  116. if (count(array_diff($data['availableTypes'], $data['type'])) == 0) {
  117. $data['showAllTypes'] = true;
  118. }
  119. $state = null;
  120.  
  121. if (isset($get['cat']) && count($get['type']>1)) {
  122. $data['cat'] = $get['cat'] == '' ? 'all' : $get['cat'];
  123. }
  124. if (isset($get['query'])) {
  125. $pos = stripos($get['query'], '–');
  126. if($pos !== false) {
  127. $query = $get['query'] == '' ? null : preg_replace('/[^ \w]+/', '', $get['query']);
  128. } else {
  129. $query = $get['query'];
  130. }
  131. $remove[] = "'";
  132. $remove[] = '"';
  133. $query = str_replace( $remove, "", $query );
  134. }
  135.  
  136. if(!isset($limit)){
  137. $limit = 25;
  138. }
  139. $offset = $get['per_page'] == '' ? 0 : $get['per_page'];
  140. $page = 1;
  141.  
  142. $data['ajax_pagination'] = true;
  143. $data['all'] = array();
  144. if(isset($get['cat'])){
  145. if($get['cat']=='all' OR $get['cat']==''){
  146. $type = array('procedure', 'questions', 'photos');
  147. } else {
  148. $type = (array)$get['cat'];
  149. }
  150. } else {
  151. $type = array('procedure', 'questions', 'photos');
  152. }
  153. if(!in_array('photos', $type)){
  154. array_push($type, 'photos');
  155. }
  156.  
  157. foreach($type as $cat) {
  158. $data['resultCount'] = $this->getAllSearchCount($query, null, $zip);
  159. $data['result'][$cat] = $this->getSearchResult($query, $cat, null, null, null, null, null, null, null, null, null, $state, null, null, null, null, $order, $zip);
  160. if ($cat == 'photos') {
  161. $data['galleryPictures'] = array();
  162. if (is_array($data['result']['photos'])) {
  163. foreach ($data['result']['photos'] as $key=>$val) {
  164. $ids = $val['id'];
  165. $data1['galleryPicture'] = $this->gallery_model->get_gallery_pictures($ids);
  166. if (!empty($data1['galleryPicture'])) {
  167. $allPic = array();
  168. foreach ($data1['galleryPicture'] as $galleryPic) {
  169. if (is_file(ROOT_PATH . '/uploads/gallery/' . $galleryPic->image)) {
  170. array_push($allPic, $galleryPic);
  171. }
  172. }
  173. $data['doctor'][$ids] = $this->login_model->getnewUserData('doctor', $val['users_id']);
  174. if (!empty($data['doctor'][$ids])) {
  175. if (!empty($allPic)) {
  176. $val['galleryPictures'] = $allPic;
  177. array_push($data['galleryPictures'], $val);
  178. }
  179. $data['countPictures'][] = count($allPic);
  180. $data['result'][$cat][] = $val;
  181. $data['category'] = $this->gallery_model->getProcedure($val['category_id']);
  182. $data['doctor_rating'][$ids] = $this->review_model->get_avg_doctor_rating($val['users_id']);
  183. $data['count_review'][$ids] = $this->review_model->get_count_review_by_doctor($val['users_id']);
  184. }
  185. } else {
  186. unset($val[$key]);
  187. }
  188. $data['photosCount'] = count($data['galleryPictures']);
  189. }
  190. }
  191. }
  192. }
  193. if(isset($get['search_dr']) && $get['search_dr']==true){
  194. $proceduresListId = array_diff(isset($get['procedure_list_c']) && !empty($get['procedure_list_c']) ? explode(',', $get['procedure_list_c']) : $procedure,array('','undefined'));
  195. $proceduresList=array();
  196. foreach($proceduresListId as $pid){
  197. $proceduresList[] = $this->category_model->getProcedureNameById($pid);
  198. }
  199. $proceduresList = array_diff($proceduresList,array(null));
  200. }
  201. $from = array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part');
  202. if(!in_array('doctors', $data['type'])){
  203. $from = array_diff($from, array('doctors_part'));
  204. $from = array_diff($from, array('claim_part'));
  205. }
  206. if(!in_array('articles',$data['type_article']) || $get['articles_hidden']=='true'){
  207. $from = array_diff($from, ['articles_part']);
  208. }
  209. if(!in_array('videos', $data['type'])){
  210. $from = array_diff($from, ['videos_part']);
  211. }
  212. if(!in_array('news',$data['type_article']) || $get['articles_hidden']=='true'){
  213. $from = array_diff($from, ['news_part']);
  214. }
  215. if(!in_array('news', $data['type_article'])){
  216. $from = array_diff($from, ['news_part']);
  217. }
  218. if(!empty($from)) {
  219. $all_main_search = $this->getAllSearch($query, null, 0, $order, $zip, $from,null,$proceduresList);
  220. $countArt = 0;
  221. $countNews = 0;
  222. foreach ($all_main_search as &$ms) {
  223. if($ms['search_category']=='article'){
  224. $countArt++;
  225. }
  226. if($ms['search_category']=='news'){
  227. $countNews++;
  228. }
  229. $ms['category'] = $cat;
  230. array_push($data['all'], $ms);
  231. }
  232. $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, $from,null,$proceduresList);
  233. foreach ($main_search as &$ms) {
  234. $ms['category'] = $cat;
  235. array_push($data['all'], $ms);
  236. }
  237. }
  238. $url = parse_url(current_url());
  239. parse_str($url['query'], $str_url);
  240. unset($str_url['per_page']);
  241.  
  242. if(!isset($countArt) || empty($countArt)) {
  243. $countArt = $this->getAllSearchCount($query, array('articles_part'), $zip);
  244. }
  245. if(!isset($countNews) || empty($countNews)) {
  246. $countNews = $this->getAllSearchCount($query, array('news_part'), $zip);
  247. }
  248. $data['countArt'] = $countArt;
  249. $data['countNews'] = $countNews;
  250. $data['countArticles'] = $countArt + $countNews;
  251. $data['countVideos'] = $this->getAllSearchCount($query, array('videos_part'), $zip);
  252. $data['countDoctors'] = $this->getAllSearchCount($query, array('doctors_part', 'claim_part'), $zip);
  253.  
  254. $data['allResultCount'] = 0;
  255. $data['allPaginationCount'] = 0;
  256. // if(in_array('articles', $data['type'])){
  257. if(in_array('articles', $data['type_article']) or is_null($data['type_article'])) {
  258. $data['allResultCount'] += $data['countArt'];
  259. $data['allPaginationCount'] += $data['countArt'];
  260. }
  261. if(in_array('news', $data['type_article']) or is_null($data['type_article'])) {
  262. $data['allResultCount'] += $data['countNews'];
  263. $data['allPaginationCount'] += $data['countNews'];
  264. }
  265. // }
  266. if(in_array('videos', $data['type'])){
  267. $data['allResultCount'] += $data['countVideos'];
  268. $data['allPaginationCount'] += $data['countVideos'];
  269. }
  270. if(in_array('doctors', $data['type'])){
  271. $data['allResultCount'] += $data['countDoctors'];
  272. $data['allPaginationCount'] += $data['countDoctors'];
  273. }
  274. if(in_array('photos', $data['type'])){
  275. $data['allResultCount'] += $data['photosCount'];
  276. }
  277. if(in_array('procedure', $data['type'])){
  278. $data['allResultCount'] += count($data['result']['procedure']);
  279. }
  280. if(in_array('question', $data['type'])){
  281. $data['allResultCount'] += count($data['result']['questions']);
  282. }
  283.  
  284. $config['base_url'] = base_url().'search?'.http_build_query($str_url);
  285. if($get['cat']=='photos'){
  286. $config['total_rows'] = $data['photosCount'];
  287. } else {
  288. $config['total_rows'] = $data['allPaginationCount'];
  289. }
  290. $config['per_page'] = $limit;
  291. $config['enable_query_strings']= true;
  292. $config['page_query_string'] = true;
  293. $config['next_link'] = "<img class=\"img-next\" src=\"/img/select.png\">";
  294. $config['first_link'] = FALSE;
  295. $config['last_link'] = FALSE;
  296. $config['prev_link'] = "<img class=\"img-prev\" src=\"/img/select.png\">";
  297. $this->pagination->initialize($config);
  298. $data["links"] = $this->pagination->create_links();
  299. $data['currentPage'] = $page;
  300. $data['lastPage'] = round($data['resultCount']/$limit);
  301. $data['page'] = $offset!==0 ? round($config['total_rows']/$offset) : 1;
  302.  
  303.  
  304. if ($this->session->userdata('front_user')) {
  305. $data['front_user'] = $this->session->userdata('front_user');
  306. }
  307.  
  308. $procedure = $this->category_model->get_procedure_list_by_name($query);
  309. if(!empty($procedure)) {
  310. $data['top_doc_near_you'] = $this->procedure_model->get_sponsored_doctors($procedure[0]->id);
  311. foreach ($data['top_doc_near_you'] as &$td) {
  312. $pos = strpos($td->profile_image_small_thumb, 'https://lorempixel.com');
  313. if (!empty($td->profile_image_small_thumb)) {
  314. if ($pos === false) {
  315. $td->profile_image_small_thumb = base_url() . 'uploads/users/profilepic/thumbs/' . $td->profile_image_small_thumb;
  316. if (empty($td->profile_image_small_thumb)) {
  317. $td->profile_image_small_thumb = '/images/frontend/profilepic/profile.png';
  318. }
  319. } else {
  320. $td->profile_image_small_thumb = $td->profile_image_small_thumb;
  321. }
  322. } else {
  323. $td->profile_image_small_thumb = '/images/frontend/profilepic/profile.png';
  324. }
  325. if (isset($td->user_id)) {
  326. $userData = $this->login_model->getnewUserData('doctor', $td->user_id);
  327. if (!empty($userData)) {
  328. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  329. $rankin = round($doctor_score * 0.25, 1);
  330. $td->rating = $rankin;
  331. }else{
  332. $td->rating = 0;
  333. }
  334. }
  335.  
  336. }
  337. }
  338. $this->load->model('category_model');
  339. $procedure_photo = $this->category_model->get_procedure_list_by_name($query);
  340. $category_id = 0;
  341. foreach ($procedure_photo as $p) {
  342. $procedure_parent = $this->category_model->getTopParrentIdByProc($p->id);
  343. if($procedure_parent){
  344. $category_id = $this->category_model->getCategoryByProc($procedure_parent);
  345. }
  346. }
  347. $data['procedure_photo'] = $this->category_model->getPhotoCategoryById($category_id);
  348.  
  349.  
  350. if(!$this->input->is_ajax_request()){
  351. $data['hide_main_search'] = (!isset($get['cat'])) ? true : false;
  352. $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());
  353. $options = [
  354. 'header' => [
  355. 'data' => $header_data,
  356. 'is_visible' => TRUE,
  357. ],
  358. ];
  359. }else{
  360. $options = [];
  361. }
  362.  
  363. if(strtolower($this->uri->segment(2))=='map' OR ((!isset($get['cat']) && !isset($get['type'])) && !isset($get['state'])) OR isset($get['search_dr'])) {
  364. $lat = null;
  365. $lng = null;
  366. if (isset($get['state'])) {
  367. $state_code = explode(',', $get['state']);
  368. $state_name = array();
  369. foreach ($state_code as $sc) {
  370. $s_name = $this->user_model->select_state_by_code(trim($sc));
  371. if (!isset($s_name->state)) {
  372. $data['city'] = trim($sc);
  373. } else {
  374. array_push($state_name, $s_name->state);
  375. $data['state_code'] = $s_name->state_code;
  376. $data['state_name'] = $s_name->state;
  377. }
  378. }
  379. if (isset($get['city'])) {
  380. $coordinates = $this->user_model->get_coordinates_by_city($get['city']);
  381. } else {
  382. if (isset($data['state_name'])) {
  383. $coordinates = $this->user_model->get_coordinates_by_state($s_name->state);
  384. }
  385. }
  386. if (isset($coordinates) && !empty($coordinates)) {
  387. $lat = $coordinates->latitude;
  388. $lng = $coordinates->longitude;
  389. }
  390. $state_name_str = implode('||', $state_name);
  391. $state = isset($get['state']) ? str_replace(',', '||', $get['state']) : null;
  392. if (!empty($state_name_str)) {
  393. $state = $state_name_str . '||' . $state;
  394. }
  395. }
  396. $score = isset($get['score']) ? explode(',', $get['score']) : null;
  397. $rating = isset($get['rating']) ? $get['rating'] : null;
  398. $distance = isset($get['distance']) ? explode(',', $get['distance']) : array(0, 100);
  399. $specialty = isset($get['specialty']) ? $get['specialty'] : null;
  400. $procedure = isset($get['procedure']) ? $get['procedure'] : null;
  401. $procedure = isset($get['procedure_list_c']) && !empty($get['procedure_list_c']) ? explode(',', $get['procedure_list_c']) : $procedure;
  402. if(empty($procedure)){
  403. $procedure = $this->procedure_model->get_procedure_by_name($get['query']);
  404. }
  405. $data['procedure'] = $procedure;
  406. if(!empty($data['procedure'])){
  407. $procedure_name = $this->procedure_model->get_procedure($data['procedure'][0]);
  408. $data['procedure_name'] = $procedure_name->name;
  409. }
  410. $gallery_boolean = isset($get['gallery_boolean']) ? $get['gallery_boolean'] : 'all';
  411. $order_field = isset($get['order_field']) ? $get['order_field'] : null;
  412. $order = isset($get['order']) ? $get['order'] : null;
  413. $limit = isset($get['limit']) ? $get['limit'] : null;
  414. $data['ajax_pagination'] = (isset($get['ajax_pagination']) && $get['ajax_pagination'] == 'false') ? null : true;
  415. if(strtolower($this->uri->segment(2))=='map') {
  416. $query = $get['query'];
  417. $search_dr = isset($get['search_dr']) ? true : false;
  418. $data['result'] = array();
  419. $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, array('doctors_part', 'claim_part'), $state);
  420. foreach ($main_search as &$ms) {
  421. $ms['category'] = $cat;
  422. array_push($data['result'], $ms);
  423. }
  424. $url = parse_url(current_url());
  425. parse_str($url['query'], $str_url);
  426. unset($str_url['per_page']);
  427.  
  428. $data['resultCount'] = $this->getAllSearchCount($query, array('doctors_part', 'claim_part'), $zip, $state);
  429. $data['hide_main_search'] = true;
  430. $data['states'] = $this->user_model->get_state();
  431. if($this->input->is_ajax_request()){
  432. echo json_encode($data['result']);
  433. die();
  434. } else {
  435. $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);
  436. }
  437. }else if(!isset($get['cat']) && !isset($get['state']) || isset($get['search_dr'])) {
  438. $data['query']=$query = $get['query'];
  439. $search_dr = isset($get['search_dr']) ? true : false;
  440. $data['top_doc_cities'] = $this->doctorprofile->get_top_doc_cities();
  441. $data['featured'] = $this->doctorprofile->get_featured_doctor(6);
  442. foreach($data['featured'] as &$featured){
  443. $result_d = $this->login_model->getnewUserData('doctor', $featured->id);
  444. $score = $result_d[0]->niche + $result_d[0]->page_rank + $result_d[0]->review + $result_d[0]->publication;
  445. $featured->rankin = round($score*0.25, 1);
  446. }
  447. $data['featured'] = array_chunk($data['featured'], 3);
  448. $data['result'] = array();
  449. $main_search = $this->getAllSearch($query, $limit, $offset, $order, $zip, array('doctors_part','claim_part'), $state,$proceduresList);
  450. foreach ($main_search as &$ms) {
  451. $ms['category'] = $cat;
  452. array_push($data['result'], $ms);
  453. }
  454. $url = parse_url(current_url());
  455. parse_str($url['query'], $str_url);
  456. unset($str_url['per_page']);
  457.  
  458. $data['resultCount'] = $this->getAllSearchCount($query, array('doctors_part','claim_part'), $zip, $state,$proceduresList);
  459. $data['hide_main_search'] = true;
  460. $data['states'] = $this->user_model->get_state();
  461. if (isset($get['city']))
  462. $data['city'] = $get['city'];
  463. if (isset($get['search_dr'])) {
  464. if ($this->input->is_ajax_request()) {
  465. $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]),
  466. [
  467. 'header' => [
  468. 'is_visible' => FALSE,
  469. ],
  470. 'footer' => [
  471. 'is_visible' => FALSE,
  472. ]
  473. ]);
  474. } else {
  475. $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]),
  476. [
  477. 'header' => [
  478. 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
  479. ]
  480. ],
  481. $options);
  482. }
  483. } else {
  484. $data['hide_main_search'] = false;
  485. $this->render(['search-first'],
  486. 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]),
  487. [
  488. 'header' => [
  489. 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
  490. ]
  491. ],
  492. $options);
  493. }
  494. }
  495. } else {
  496. $data['hide_main_search'] = false;
  497. if ($this->input->is_ajax_request()) {
  498. $this->render(['search-all-item'], array_merge($data, ['base_url' => base_url()]),
  499. [
  500. 'header' => false,
  501. 'footer' => false
  502. ]);
  503. } else {
  504. if ($get['cat'] == 'photos') {
  505. $data['allResultCount'] = $data['photosCount'];
  506. if ($data['allResultCount'] <= $data['per_page']) {
  507. $data['countPage'] = 1;
  508. } else {
  509. $data['countPage'] = (int)round($data['photosCount'] / $data['per_page']);
  510. $data['galleryPictures'] = array_slice($data['galleryPictures'], $offset, $limit);
  511.  
  512. }
  513.  
  514. $this->render(['search-all-photos'],
  515. 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]),
  516. [
  517. 'header' => [
  518. 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
  519. ]
  520. ],
  521. $options);
  522. }else {
  523. $this->render(['search-all'],
  524. 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]),
  525. [
  526. 'header' => [
  527. 'data' => array_merge($this->header_config, $data, $this->login_model->checkHeaderLinks()),
  528. ]
  529. ],
  530. $options);
  531. }
  532. }
  533. }
  534. }
  535.  
  536. public function getAllSearch($query, $limit, $offset=0, $order=null,$zip=null, $from=null, $state=null,$procedure=null)
  537. {
  538. try {
  539. require_once __DIR__ . '/../../vendor/autoload.php';
  540. require __DIR__ . '/../config/database.php';
  541. // create a SphinxQL Connection object to use with SphinxQL
  542. $conn = new Connection();
  543. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  544. 'port' => $db['default']['sphinx_port'],
  545. 'username' => $db['default']['username'],
  546. 'password' => $db['default']['password'],
  547. ]);
  548. if (!is_array($query)) {
  549. $query = htmlentities($query);
  550. $query = str_replace('amp;', '', $query);
  551. } else {
  552. $query = implode(' ', $query);
  553. }
  554. $select = array('*');
  555. $procedure = implode("|",$procedure);
  556. $search_by_name = $this->search_by_type($query, 'name');
  557. $search_by_procedure = $this->search_by_type($query, 'procedure');
  558. $search_by_location = $this->search_by_type($query, 'location');
  559. $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
  560. $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDE‌​D_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
  561. $user_loc = $this->user_model->get_user_location_by_ip($ip);
  562. $date_diff = 0;
  563. if(!empty($user_loc)) {
  564. $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
  565. }
  566. if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
  567. $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
  568. $user_loc = new StdClass;
  569. $user_loc->lat = $user_location['lat'];
  570. $user_loc->lng = $user_location['lng'];
  571. $user_loc->city_name = $user_location['city_name'];
  572. }
  573. if(!empty($user_loc)) {
  574. $user_lat = $user_loc->lat;
  575. $user_lng = $user_loc->lng;
  576. $user_city_name = $user_loc->city_name;
  577. }
  578. if(!empty($state)){
  579. $user_city_name = $state;
  580. }
  581. $city_pos = strpos($user_city_name, '||');
  582. if($city_pos!==false){
  583. $city_array = explode('||', trim($user_city_name));
  584. }
  585. if ((isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && ($search_by_name['success']==false && $search_by_location['success']==false
  586. && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true)||
  587. (empty($state) && $search_by_location['success'] == false && isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name)))) {
  588. $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 ";
  589. array_push($select, $distance_dist);
  590. $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) ))";
  591. $distance_filter = 'IF( ';
  592. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  593. $distance_filter .= ",1,0) AS distance_filter ";
  594. array_push($select, $distance_filter);
  595. }
  596. if(((($search_by_name['success']==true || $search_by_procedure['success']==true) && !empty($state)) || !empty($user_city_name)) && !isset($city_array)){
  597. $user_city_filter = 'IF(';
  598. $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'";
  599. $user_city_filter .= ",1,0) AS user_city_filter ";
  600. array_push($select, $user_city_filter);
  601. }
  602. if(isset($city_array) && !empty($city_array)){
  603. $user_city_filter = 'IF(';
  604. $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]."'
  605. OR str_city = '".$city_array[0]."' OR str_city = '".$city_array[1]."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  606. $user_city_filter .= ",1,0) AS user_city_filter ";
  607. array_push($select, $user_city_filter);
  608. }
  609. if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
  610. $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 ";
  611. array_push($select, $distance_dist);
  612. $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) ))";
  613. $distance_filter = 'IF( ';
  614. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  615. $distance_filter .= ",1,0) AS distance_filter ";
  616. array_push($select, $distance_filter);
  617. }
  618. 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'])){
  619. $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 ";
  620. array_push($select, $distance_dist);
  621. $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) ))";
  622. $distance_filter = 'IF( ';
  623. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  624. $distance_filter .= ",1,0) AS distance_filter ";
  625. array_push($select, $distance_filter);
  626. }
  627.  
  628. if(!empty($zip)) {
  629. $zip_filter = 'IF(';
  630. $zip_filter.= " zip == ".$zip;
  631. $zip_filter.=",1,0) AS zip_filter ";
  632. array_push($select, $zip_filter);
  633. }
  634. $doctor_filter = 'IF(';
  635. $doctor_filter .= "(search_category = 'doctor' OR search_category= 'doctor_claim') AND user_id > 0 ";
  636. $doctor_filter .= ",1,0) AS doctor_filter ";
  637. array_push($select,$doctor_filter);
  638. $doctorFilter=1;
  639.  
  640. $res = SphinxQL::create($conn)->select($select);
  641. if(!empty($from)){
  642. $res->from($from);
  643. } else {
  644. $res->from(array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part'));
  645. }
  646. if(!empty($query)){
  647. $res->match(['str_first_name', 'str_last_name', 'title', 'content', 'user_state', 'str_city', 'str_state'], $query);
  648. }
  649. if(!empty($procedure)){
  650. $res->match('str_treatment_name', $procedure, true);
  651. }
  652. if(!empty($zip)){
  653. $res->where('zip_filter', '=', 1);
  654. }
  655.  
  656. if(!empty($distance) && !empty($lat) && !empty($lng)){
  657. $res->where('dist_filter', '=', 1);
  658. }
  659. if($doctorFilter==1){
  660. // $res->where('doctor_filter', '=', 1);
  661. }
  662.  
  663. if($search_by_name['success']==false && ((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_by_name['success']==false
  664. || $search_by_loc_proc['success'] == true) || (!empty($user_lat) && !empty($user_lng)))){
  665. if(!($state)){
  666. $res->where('distance_filter', '=', 1);
  667. $res->orderBy('distance', 'ASC');
  668. }
  669. $res->orderBy('user_city_filter', 'DESC');
  670. $res->orderBy('str_city', 'ASC');
  671. }
  672. if(!empty($state)){
  673. $res->orderBy('user_city_filter', 'DESC');
  674. }
  675. if(!empty($state)){
  676. $res->where('user_city_filter', '=', 1);
  677. }
  678.  
  679. if (!is_null($limit)) {
  680. $res->limit($offset, $limit);
  681. }else {
  682. $res->limit(0, 1000);
  683. }
  684. if(in_array('doctors',$from)){
  685. $res->orderBy('title', 'ASC');
  686. }
  687. else if($order){
  688. if($order=='DATE'){
  689. $res->orderBy('date_updated', 'DESC');
  690. }else {
  691. $res->orderBy('title', $order);
  692. }
  693. }else{
  694. $res->orderBy('date_updated', 'DESC');
  695. }
  696.  
  697. // $res->compile()
  698. // ->getCompiled();
  699.  
  700. $result = $res->execute()->fetchAllAssoc();
  701.  
  702. return $this->generateAllSearchResult($result);
  703. }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  704. } catch (Exception $ex) {
  705. }
  706. }
  707.  
  708. public function favorite_doc(){
  709. $data['front_user'] = $this->session->userdata('front_user');
  710. if (!empty($data['front_user'])) {
  711.  
  712. $post = $this->input->post();
  713. $data['front_user'] = $this->session->userdata('front_user');
  714. $this->load->model('doctorprofile');
  715. $result = $this->doctorprofile->favorite_doc($data['front_user']['user_id'], $post['doctor_id']);
  716. if($result===true) {
  717. echo json_encode(array('result' => $result, 'message'=>'Doctor is saved successfully.'));
  718. die;
  719. }else{
  720. echo json_encode(array('result' => 'exist', 'message'=>'The doctor has already been added.'));
  721. die;
  722. }
  723.  
  724. }else{
  725.  
  726. echo json_encode(array('result'=>false));
  727. die;
  728.  
  729. }
  730. }
  731.  
  732. public function getAllSearchCount($query, $from=null, $zip, $state=null,$procedure=null)
  733. {
  734. try {
  735. require_once __DIR__ . '/../../vendor/autoload.php';
  736. require __DIR__ . '/../config/database.php';
  737. // create a SphinxQL Connection object to use with SphinxQL
  738. $conn = new Connection();
  739. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  740. 'port' => $db['default']['sphinx_port'],
  741. 'username' => $db['default']['username'],
  742. 'password' => $db['default']['password'],
  743. ]);
  744. if (!is_array($query)) {
  745. $query = htmlentities($query);
  746. $query = str_replace('amp;', '', $query);
  747. } else {
  748. $query = implode(' ', $query);
  749. }
  750. $select = array('*');
  751. $procedure = implode("|",$procedure);
  752. $search_by_name = $this->search_by_type($query, 'name');
  753. $search_by_procedure = $this->search_by_type($query, 'procedure');
  754. $search_by_location = $this->search_by_type($query, 'location');
  755. $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
  756. $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDE‌​D_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
  757. $user_loc = $this->user_model->get_user_location_by_ip($ip);
  758. $date_diff = 0;
  759. if(!empty($user_loc)) {
  760. $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
  761. }
  762. if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
  763. $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
  764. $user_loc = new StdClass;
  765. $user_loc->lat = $user_location['lat'];
  766. $user_loc->lng = $user_location['lng'];
  767. $user_loc->city_name = $user_location['city_name'];
  768. }
  769. if(!empty($user_loc)) {
  770. $user_lat = $user_loc->lat;
  771. $user_lng = $user_loc->lng;
  772. $user_city_name = $user_loc->city_name;
  773. }
  774. if(isset($state)){
  775. $user_city_name = $state;
  776. }
  777. $city_pos = strpos($user_city_name, '||');
  778. if($city_pos!==false){
  779. $city_array = explode('||', trim($user_city_name));
  780. }
  781. 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
  782. && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true)||
  783. (empty($state) && $search_by_location['success'] == false && isset($user_lat) && !empty($user_lat) && isset($user_lng) && !empty($user_lng) && isset($user_city_name)))) {
  784. $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 ";
  785. array_push($select, $distance_dist);
  786. $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) ))";
  787. $distance_filter = 'IF( ';
  788. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  789. $distance_filter .= ",1,0) AS distance_filter ";
  790. array_push($select, $distance_filter);
  791. }
  792. if(((($search_by_name['success']==true || $search_by_procedure['success']==true) && !empty($state)) || !empty($user_city_name)) && !isset($city_array)){
  793. $user_city_filter = 'IF(';
  794. $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'";
  795. $user_city_filter .= ",1,0) AS user_city_filter ";
  796. array_push($select, $user_city_filter);
  797. }
  798. if(isset($city_array) && !empty($city_array)){
  799. $user_city_filter = 'IF(';
  800. $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]."'
  801. OR str_city = '".$city_array[0]."' OR str_city = '".$city_array[1]."' OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  802. $user_city_filter .= ",1,0) AS user_city_filter ";
  803. array_push($select, $user_city_filter);
  804. }
  805. if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
  806. $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 ";
  807. array_push($select, $distance_dist);
  808. $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) ))";
  809. $distance_filter = 'IF( ';
  810. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  811. $distance_filter .= ",1,0) AS distance_filter ";
  812. array_push($select, $distance_filter);
  813. }
  814. 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'])){
  815. $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 ";
  816. array_push($select, $distance_dist);
  817. $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) ))";
  818. $distance_filter = 'IF( ';
  819. $distance_filter .= $distance_in_miles." <= 100 OR search_category = 'video' OR search_category = 'article' OR search_category = 'news'";
  820. $distance_filter .= ",1,0) AS distance_filter ";
  821. array_push($select, $distance_filter);
  822. }
  823.  
  824. if(!empty($zip)) {
  825. $zip_filter = 'IF(';
  826. $zip_filter.= " zip == ".$zip;
  827. $zip_filter.=",1,0) AS zip_filter ";
  828. array_push($select, $zip_filter);
  829. }
  830. $doctorFilter=0;
  831. if(isset($from) && in_array("doctors_part",$from)){
  832. $doctor_filter = 'IF(';
  833. $doctor_filter .= "search_category = 'doctor' AND user_id > 0 ";
  834. $doctor_filter .= ",1,0) AS doctor_filter ";
  835. array_push($select,$doctor_filter);
  836. $doctorFilter=1;
  837. }
  838. else{
  839. $doctor_filter = 'IF(';
  840. $doctor_filter .= "search_category = 'doctor' AND user_id > 0 ";
  841. $doctor_filter .= ",1,0) AS doctor_filter ";
  842. array_push($select,$doctor_filter);
  843. $doctorFilter=1;
  844. }
  845. $res = SphinxQL::create($conn)->select($select);
  846. if(isset($from)){
  847. $res->from($from);
  848. } else {
  849. $res->from(array('doctors_part', 'claim_part', 'articles_part', 'videos_part', 'news_part'));
  850. }
  851. if(!empty($query)){
  852. $res->match(['str_first_name', 'str_last_name', 'title', 'content', 'user_state', 'str_city', 'str_state'], $query);
  853. }
  854. if(!empty($procedure)){
  855. $res->match('str_treatment_name', $procedure, true);
  856. }
  857. if(!empty($zip)){
  858. $res->where('zip_filter', '=', 1);
  859. }
  860. if($doctorFilter==1){
  861. // $res->where('doctor_filter', '=', 1);
  862. }
  863.  
  864. if(!empty($distance) && !empty($lat) && !empty($lng)){
  865. $res->where('dist_filter', '=', 1);
  866. }
  867.  
  868. if($search_by_name['success']==false && ((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_by_name['success']==false
  869. || $search_by_loc_proc['success'] == true) || (!empty($user_lat) && !empty($user_lng)))){
  870. if(!$state){
  871. $res->where('distance_filter', '=', 1);
  872. $res->orderBy('distance', 'ASC');
  873. }
  874. $res->orderBy('user_city_filter', 'DESC');
  875. $res->orderBy('str_city', 'ASC');
  876. }
  877. if($search_by_name['success']==false && !empty($state)){
  878. $res->orderBy('user_city_filter', 'DESC');
  879. }
  880. if(!empty($state)){
  881. $res->where('user_city_filter', '=', 1);
  882. }
  883.  
  884. $res->limit(0, 1000);
  885.  
  886. // $res->compile()
  887. // ->getCompiled();
  888. $result = $res->execute()->getCount();
  889.  
  890. return $result;
  891. }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  892. } catch (Exception $ex) {
  893. }
  894. }
  895.  
  896. public function generateAllSearchResult($result)
  897. {
  898. $results = [];
  899. foreach ($result as $r) {
  900. if ($r['search_category'] == 'doctor' || $r['search_category'] == 'doctor_claim') {
  901. if($r['search_category'] == 'doctor') {
  902. $user_id = $this->user_model->get_doctor_id_by_slug($r['str_slug']);
  903. $r['user_id'] = $user_id->id;
  904. } else {
  905. $claim_id = $this->user_model->get_doctor_id_by_slug($r['str_slug'], true);
  906. $r['id'] = $claim_id->id;
  907. }
  908. $pos = strpos($r['profile_image_small_thumb'], 'https://lorempixel.com');
  909. $doctor_score = 0;
  910. if (isset($r['user_id'])) {
  911. $userData = $this->login_model->getnewUserData('doctor', $r['user_id']);
  912. if (!empty($userData)) {
  913. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  914. $rankin = round($doctor_score * 0.25, 1);
  915. }
  916. $badges = $this->admin_model->getDoctorBadges($r['user_id']);
  917. } else if (isset($r['id'])){
  918. $userData = $this->login_model->getClaimData($r['id']);
  919. if (!empty($userData)) {
  920. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  921. $rankin = round($doctor_score * 0.25, 1);
  922. }
  923. $badges = $this->admin_model->getClaimBadges($r['id']);
  924. }
  925.  
  926. if (!empty($r['str_first_name']) && !empty($r['str_last_name'])) {
  927. if ($pos === false) {
  928. $profile_image = base_url().'/uploads/users/profilepic/thumbs/' . $r['profile_image_small_thumb'];
  929. if(empty($r['profile_image_small_thumb'])){
  930. $profile_image = '/images/frontend/profilepic/profile.png';
  931. }
  932. } else {
  933. $profile_image = $r['profile_image_small_thumb'];
  934. }
  935. if (!isset($r['user_id'])) {
  936. $user_id = $this->user_model->get_doctor_id_by_slug($r['str_slug'], $claim = null);
  937. $r['user_id'] = $user_id->id;
  938. }
  939. $res = [
  940. 'id' => isset($r['user_id']) ? $r['user_id'] : $r['id'],
  941. 'title' => ucfirst($r['str_first_name']) . ' ' . ucfirst($r['str_last_name']) . ', ' . strtoupper($r['title']),
  942. 'doctor_title' => isset($r['title']) ? $r['title'] : '',
  943. 'search_category' => $r['search_category'],
  944. 'user_lat' => $r['user_lat'],
  945. 'user_lng' => $r['user_lng'],
  946. 'countarticles' => isset($r['countarticles']) ? $r['countarticles'] : 0,
  947. 'countreviews' => isset($r['countreviews']) ? $r['countreviews'] : 0,
  948. 'sumrating' => isset($r['sumrating']) ? $r['sumrating'] : 0,
  949. 'doc_rating' => isset($r['sumrating']) ? $r['sumrating'] : 0,
  950. 'countvideos' => isset($r['countvideos']) ? $r['countvideos'] : 0,
  951. 'content' => $r['str_address'],
  952. 'content2' => $r['str_city'] . ', ' . $r['str_state'] . ' ' . $r['str_zip'],
  953. 'address' => $r['str_state'] . ', ' . $r['str_address'],
  954. 'zip' => $r['zip'],
  955. 'link' => base_url() . 'doctor/' . $r['str_user_slug'],
  956. 'page' => base_url() . 'doctor/' . $r['str_user_slug'],
  957. 'read_more' => 'VISIT DOCTOR ',
  958. 'distance' => isset($r['distance']) ? $r['distance'] : '',
  959. 'user_city_filter' => isset($r['user_city_filter']) ? $r['user_city_filter'] : '',
  960. 'rating' => $rankin,
  961. 'profile_image' => $profile_image,
  962. 'str_slug' => $r['str_slug'],
  963. 'board_certification' => $r['board_certification'],
  964. 'badges' => $badges,
  965. 'practice_name' => $r['str_practice_name']
  966. ];
  967. array_push($results, $res);
  968. }
  969.  
  970. } else
  971. if ($r['search_category'] == 'article') {
  972.  
  973. $parent_id = $this->category_model->getParentCategoryById($r['procedure_id']);
  974. if ($parent_id) {
  975. $r['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
  976. } else {
  977. $proc = $this->doctorprofile->getProcedureById($r['procedure_id']);
  978. $r['procedure_name'] = $proc->category_slug;
  979. }
  980.  
  981. if (stripos($r['content'], 'data-oembed_provider="vimeo"')) {
  982. $r['content'] = strip_tags($r['content']);
  983. }
  984. $res = [
  985. 'id' => $r['id'],
  986. 'title' => $r['title'],
  987. 'category_slug' => $r['category_slug'],
  988. 'search_category' => $r['search_category'],
  989. 'content' => strip_tags((strlen($r['content']) > 500) ? substr(trim($r['content']), 0, 500) . ' ...' : $r['content']),
  990. 'link' => base_url() . 'journal/' . $r['procedure_name'] . '/' . $r['article_slug'],
  991. 'page' => base_url() . 'journal',
  992. 'tags' => $r['tags'],
  993. 'zip' => $r['zip'],
  994. 'str_slug' => $r['str_slug'],
  995. ];
  996. array_push($results, $res);
  997.  
  998. } else
  999. if ($r['search_category'] == 'video') {
  1000. $video_image = 'https://img.youtube.com/vi/mqdefault.jpg';
  1001. $video_path = $r['profile_image_small_thumb'];
  1002. if(!empty($r['profile_image'])) $video_image=$r['profile_image'];
  1003. if (strpos($video_path,'youtube') !== false || strpos($video_path,'youtu.be') !== false) {
  1004. $video_image="https://img.youtube.com/vi/".getYoutubeVideoId($video_path)."/mqdefault.jpg";
  1005. $video_type="youtube";
  1006. $video_id=getYoutubeVideoId($video_path);
  1007. }
  1008. else if(strpos($video_path,'vimeo') !== false){
  1009. $vimeoInfo=getVimeoVideoInfo($video_path);
  1010. $video_image=$vimeoInfo['thumbnail'];
  1011. $video_type="vimeo";
  1012. $video_id=$vimeoInfo['videoId'];
  1013. }
  1014. else if (strpos($video_path,'cloudinary') !== false) {
  1015. $video_image=base_url()."uploads/videos/".$video_image;
  1016. $video_type="cloudinary";
  1017. $video_id="";
  1018. }
  1019. else{
  1020. $video_image=base_url()."uploads/videos/".$video_image;
  1021. $video_path=base_url()."uploads/videos/".$video_path;
  1022. $video_type="local";
  1023. $video_id="";
  1024. }
  1025. $res = [
  1026. 'title' => $r['title'],
  1027. 'category_slug' => $r['category_slug'],
  1028. 'search_category' => $r['search_category'],
  1029. 'video_image' => $video_image,
  1030. 'video_type' => $video_type,
  1031. 'video_id' => $video_id,
  1032. 'str_slug' => $r['str_slug'],
  1033. 'zip' => $r['zip'],
  1034. 'content' => strip_tags((strlen($r['content']) > 500) ? substr($r['content'], 0, 500) . ' ...' : $r['content']),
  1035. 'link' => base_url() . 'video/' . $r['video_slug'],
  1036. 'page' => base_url() . 'video/' . $r['video_slug'],
  1037. 'read_more' => 'VIEW VIDEO '
  1038. ];
  1039. array_push($results, $res);
  1040. } else {
  1041.  
  1042. $parent_id = $this->category_model->getParentCategoryById($r['procedure_id']);
  1043. if ($parent_id) {
  1044. $r['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
  1045. } else {
  1046. $proc = $this->doctorprofile->getProcedureById($r['procedure_id']);
  1047. $r['procedure_name'] = $proc->category_slug;
  1048. }
  1049.  
  1050. if (stripos($r['content'], 'data-oembed_provider="vimeo"')) {
  1051. $r['content'] = strip_tags($r['content']);
  1052. }
  1053. $res = [
  1054. 'title' => $r['title'],
  1055. 'search_category' => $r['search_category'],
  1056. 'news_image' => '/uploads/news/'.$r['profile_image'],
  1057. 'content' => strip_tags((strlen($r['content']) > 250) ? substr(trim($r['content']), 0, 250) . ' ...' : $r['content']),
  1058. 'link' => base_url() . 'news/'. $r['str_slug'],
  1059. 'page' => base_url() . 'news',
  1060. 'tags' => $r['tags'],
  1061. 'str_slug' => $r['str_slug'],
  1062. 'read_more' => 'VIEW ARTICLE '
  1063. ];
  1064. array_push($results, $res);
  1065. }
  1066. }
  1067. return $results;
  1068. }
  1069.  
  1070. public function get_video_image($video_path, $video_img, $video_type){
  1071.  
  1072. $data = array();
  1073. $this->load->model('video_model');
  1074. if($this->video_model->is_not_local_video($video_path)) {
  1075. if(empty($video_img)){
  1076. $data['video_img'] = $this->video_model->get_video_image($video_path);
  1077. }
  1078.  
  1079. if (strpos($video_path, 'youtu')){
  1080. $tmp = explode('/', $video_img);
  1081. $tmp = explode('?', end($tmp));
  1082. $image = explode('&', $tmp[0]);
  1083. $data['video_img'] = 'https://img.youtube.com/vi/' . $image[0] . '/' . $video_type . '.jpg';
  1084. } else {
  1085. if(!empty($video_img)){
  1086. $data['video_img'] = base_url().'uploads/videos/'.$video_img;
  1087. }else{
  1088. $data['video_img'] = 'https://img.youtube.com/vi/mqdefault.jpg';
  1089. }
  1090. }
  1091. } else {
  1092. $data['video_img'] = base_url().'uploads/videos/'.$video_img;
  1093. }
  1094.  
  1095. return $data;
  1096. }
  1097.  
  1098. public function searchByState()
  1099. {
  1100. $data = array();
  1101. $get = $this->input->get();
  1102. $data['title'] = 'Search';
  1103. $data['hide_main_search'] = true;
  1104. $state_name = $this->user_model->select_state_by_code($get['state']);
  1105. $data['state'] = !empty($state_name) ? $state_name->state_code : $get['state'];
  1106. $data['state_name'] = !empty($state_name) ? $state_name->state : $get['state'];
  1107. if(isset($get['state']) && !empty($state_name)){
  1108. $data['cities'] = $this->user_model->select_state_city($state_name->state_code);
  1109.  
  1110. $this->render(['search-second'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
  1111. 'header' => [
  1112. '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()),
  1113. ]
  1114. ]);
  1115. }else{
  1116. $data['procedures'] = $this->category_model->getSubCategoryListItems('name');
  1117.  
  1118. $this->render(['search-third'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
  1119. 'header' => [
  1120. '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()),
  1121. ]
  1122. ]);
  1123. }
  1124.  
  1125.  
  1126. }
  1127.  
  1128. public function searchByCity()
  1129. {
  1130. $data = array();
  1131. $get = $this->input->get();
  1132. $data['title'] = 'Search';
  1133. $data['hide_main_search'] = true;
  1134. $state_name = $this->user_model->select_state_by_code($get['state']);
  1135. $data['state'] = !empty($state_name) ? $state_name->state_code : $get['state'];
  1136. $data['state_name'] = !empty($state_name) ? $state_name->state : $get['state'];
  1137. $data['main_procedures'] = $this->category_model->getParentCategoryListItems();
  1138. foreach($data['main_procedures'] as &$proc){
  1139. $proc->sub_proc= $this->category_model->getCategorySubItems($proc->id);
  1140. }
  1141. $this->render(['search-third'], array_merge($get, $data, ['base_url' => base_url(), 'jquey_path'=>JQUERY_PATH ]), [
  1142. 'header' => [
  1143. '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()),
  1144. ]
  1145. ]);
  1146. }
  1147.  
  1148. public function keywords()
  1149. {
  1150. $get = $this->input->get();
  1151. if (isset($get['search'])) {
  1152. $query = $get['search'] == '' ? null : trim($get['search']);
  1153. }
  1154. $sString = $query;
  1155. $query = explode(' ', $query);
  1156. $search = array_pop($query);
  1157. $limit = 5;
  1158. $result = $this->keyword_model->getKeywords($query, $search, $limit, $sString);
  1159. echo json_encode($result);
  1160. die;
  1161.  
  1162. }
  1163.  
  1164. public function doctor()
  1165. {
  1166. if ($this->session->userdata('front_user')) {
  1167. redirect('/');
  1168. } else {
  1169. $data = array();
  1170. $data['method'] = $this->uri->segment(2);
  1171. $data['states'] = $this->user_model->get_state();
  1172. $data['board_certification'] = $this->register_model->get_board_certification();
  1173. if (isset($_GET['query'])) {
  1174. $queryDisplay = $_GET['query'] == '' ? null : $_GET['query'];
  1175. $query = str_replace('+', ' ', $queryDisplay);
  1176. $query = str_replace('\\', '\\\\', $query);
  1177. $limit = 10;
  1178. $page = (isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 1;
  1179. if ($page == 1) {
  1180. $start = 0;
  1181. } else {
  1182. $start = $page * $limit - ($limit);
  1183. }
  1184. $data['cat'] = 'doctors';
  1185. $data['query'] = $queryDisplay;
  1186. $limit = is_numeric($limit) ? $limit : 0;
  1187. $data['result'] = $this->getSearchResult($query, $data['cat'], $limit, $start);
  1188. $data['resultCount'] = count($this->getSearchResult($query, $data['cat'], null, null));
  1189. }
  1190. $this->render(['search-doctor'], array_merge($data, $this->header_config, ['base_url' => base_url()]));
  1191. }
  1192. }
  1193.  
  1194.  
  1195. public function page()
  1196. {
  1197. if (isset($_GET['query'])) {
  1198. $query = $_GET['query'] == '' ? null : $_GET['query'];
  1199. $query = str_replace('+', ' ', $query);
  1200. $limit = 10;
  1201. $page = (isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 1;
  1202. if($page==1){
  1203. $start = 0;
  1204. }else {
  1205. $start = $page * $limit - ($limit);
  1206. }
  1207. $data['cat'] = 'doctors';
  1208. $data['query'] = $query;
  1209. $limit = is_numeric($limit) ? $limit : 0;
  1210. $data['result'] = $this->getSearchResult($query, $data['cat'], $limit, $start);
  1211.  
  1212. echo $this->twig->render('search-doctor-item.twig', array_merge($data, $this->headerConfig, ['base_url' => base_url()]));
  1213. }
  1214. }
  1215.  
  1216. /**
  1217. * @param $query
  1218. * @param $cat
  1219. * @return array
  1220. */
  1221. private function getCount($query, $cat, $score=null, $rating=null, $lat=null, $lng=null, $distance=null)
  1222. {
  1223. try {
  1224. require_once __DIR__ . '/../../vendor/autoload.php';
  1225. require __DIR__ . '/../config/database.php';
  1226. // create a SphinxQL Connection object to use with SphinxQL
  1227. $conn = new Connection();
  1228. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  1229. 'port' => $db['default']['sphinx_port'],
  1230. 'username' => $db['default']['username'],
  1231. 'password' => $db['default']['password'],
  1232. ]);
  1233. $cat = strtolower($cat);
  1234. $query = htmlentities($query);
  1235. switch ($cat) {
  1236. case 'all':
  1237. /*$query = SphinxQL::create($conn)->select('*')
  1238. ->from('all')
  1239. ->match(array('forum_name',
  1240. 'forum_desc',
  1241. 'post_subject',
  1242. 'post_text',
  1243. 'auth_name',
  1244. 'page_title',
  1245. 'content',
  1246. 'category_slug',
  1247. 'article_slug',
  1248. 'gallery_title',
  1249. 'gallery_description',
  1250. 'gallery_slug',
  1251. 'first_name',
  1252. 'last_name',
  1253. 'video_title',
  1254. 'video_description',
  1255. 'video_slug'), $query
  1256. );
  1257.  
  1258. $result = $query->execute()->fetchAllAssoc();
  1259. return $this->generateSearchResult($result, 'all');
  1260. */
  1261. $result = [];
  1262. $items = [
  1263. 'articles',
  1264. 'photos',
  1265. 'doctors',
  1266. 'videos',
  1267. 'forum'
  1268. ];
  1269. foreach ($items as $item) {
  1270. $res = $this->getSearchResult($query, $item);
  1271. if (!empty($res))
  1272. $result = array_merge($result, $res);
  1273. }
  1274.  
  1275. return $result;
  1276. break;
  1277.  
  1278. case 'guides':
  1279. $query = SphinxQL::create($conn)->select('*')
  1280. ->from('guides')
  1281. ->match('content', $query);
  1282. $query->option('max_matches', 1000);
  1283. $result = $query->execute()->fetchAllAssoc();
  1284. return $this->generateSearchResult($result, 'guides');
  1285. break;
  1286.  
  1287. case 'articles':
  1288. $query = SphinxQL::create($conn)->select('*')
  1289. ->from('articles')
  1290. ->match('status_id', 1)
  1291. ->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug'], $query);
  1292. $query->option('max_matches', 1000);
  1293. $query->limit(1000);
  1294. $result = $query->execute()->fetchAllAssoc();
  1295. return $this->generateSearchResult($result, 'articles');
  1296. break;
  1297.  
  1298. case 'photos':
  1299. $query = SphinxQL::create($conn)->select('*')
  1300. ->from('photos')
  1301. ->match(['title', 'description', 'gallery_slug'], $query);
  1302. $query->option('max_matches', 1000);
  1303. $query->limit(1000);
  1304. $result = $query->execute()->fetchAllAssoc();
  1305. return $this->generateSearchResult($result, 'photos');
  1306. break;
  1307.  
  1308. case 'doctors':
  1309. $serchQuery = $query;
  1310. $query = SphinxQL::create($conn)->select('*')
  1311. ->from('doctors')
  1312. ->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'str_city', 'str_state', 'str_zip'], $query)
  1313. ->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));
  1314. $query->option('max_matches', 1000);
  1315. $query->limit(1000);
  1316. $result = $query->execute()->fetchAllAssoc();
  1317. $searchResult = $this->generateSearchResult($result, 'doctors');
  1318. $resClaim = $this->getSearchResult($serchQuery, 'claim');
  1319. if (!empty($resClaim)){
  1320. $searchResult = array_merge($searchResult, $resClaim);
  1321. }
  1322. return $searchResult;
  1323. break;
  1324.  
  1325. case 'videos':
  1326. $query = SphinxQL::create($conn)->select('*')
  1327. ->from('videos')
  1328. ->match(['title', 'descriptopn', 'video_slug'], $query);
  1329. $query->option('max_matches', 1000);
  1330. $result = $query->execute()->fetchAllAssoc();
  1331. return $this->generateSearchResult($result, 'videos');
  1332. break;
  1333.  
  1334. case 'forum':
  1335. $query = SphinxQL::create($conn)->select('*')
  1336. ->from('forum')
  1337. ->match(['text','title'], $query);
  1338. $query->option('max_matches', 1000);
  1339. $result = $query->execute()->fetchAllAssoc();
  1340. return $this->generateSearchResult($result, 'forum');
  1341. break;
  1342.  
  1343. case 'claim':
  1344. $query = SphinxQL::create($conn)->select('*')
  1345. ->from('claim_users')
  1346. ->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'str_city', 'str_state', 'str_zip'], $query);
  1347. $query->option('max_matches', 1000);
  1348. $result = $query->execute()->fetchAllAssoc();
  1349. return $this->generateSearchResult($result, 'claim_users');
  1350. break;
  1351.  
  1352. case 'questions':
  1353. $query = SphinxQL::create($conn)->select('*')
  1354. ->from('questions')
  1355. ->match(['first_name', 'last_name', 'str_question', 'city', 'state', 'state_name'], "$query");
  1356. $query->option('max_matches', 1000);
  1357. $result = $query->execute()->fetchAllAssoc();
  1358. return $this->generateSearchResult($result, 'questions');
  1359. break;
  1360.  
  1361. default:
  1362. return [];
  1363. break;
  1364. }
  1365. } catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  1366.  
  1367. } catch (Exception $ex) {
  1368.  
  1369. }
  1370. }
  1371.  
  1372. public function search_by($query, $type)
  1373. {
  1374. if($type =='name') {
  1375. $this_name = $this->user_model->this_name(trim($query));
  1376. if ($this_name) {
  1377. return array('success'=>true);
  1378. }
  1379. }else if($type == 'procedure') {
  1380. $this_procedure = $this->user_model->this_procedure(trim($query));
  1381. if ($this_procedure) {
  1382. return array('success'=>true);
  1383. }
  1384. }else if($type == 'location'){
  1385. $this_location = $this->user_model->this_location(trim($query));
  1386. if($this_location){
  1387. return array('success'=>true, 'lat'=>$this_location->latitude, 'lng'=>$this_location->longitude, 'name'=>isset($this_location->city) ? $this_location->city : $this_location->state_name);
  1388. }
  1389. }else if($type == 'proc_&_loc') {
  1390. $this_proc_loc = $this->user_model->this_proc_loc(trim($query));
  1391. if ($this_proc_loc) {
  1392. return array('success'=>true);
  1393. }
  1394. }
  1395. }
  1396. public function search_by_type($query, $type)
  1397. {
  1398. $str = $query;
  1399. if(!is_array($query)) {
  1400. if(!empty($query)) {
  1401. $res = $this->search_by($query, $type);
  1402. if(!empty($res)){
  1403. return $res;
  1404. }
  1405. }
  1406. $str = explode(' ', $query);
  1407. }
  1408. foreach ($str as $s)
  1409. {
  1410. if(!empty($s)) {
  1411. $res = $this->search_by($s, $type) ;
  1412. if(!empty($res)){
  1413. return $res;
  1414. }
  1415. }
  1416. }
  1417. return array('success'=>false);
  1418. }
  1419.  
  1420. 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)
  1421. {
  1422. try {
  1423. require_once __DIR__ . '/../../vendor/autoload.php';
  1424. require __DIR__ . '/../config/database.php';
  1425. // create a SphinxQL Connection object to use with SphinxQL
  1426. $conn = new Connection();
  1427. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  1428. 'port' => $db['default']['sphinx_port'],
  1429. 'username' => $db['default']['username'],
  1430. 'password' => $db['default']['password'],
  1431. ]);
  1432. $cat = strtolower($cat);
  1433. if (!is_array($query)) {
  1434. $query = htmlentities($query);
  1435. $query = str_replace('amp;', '', $query);
  1436. } else {
  1437. $query = implode(' ', $query);
  1438. }
  1439. $select = array('*');
  1440. $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) ))";
  1441. $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";
  1442. $dist_filter = " IF( ";
  1443. $dist_filter.= " $distance_miles >= ".$distance[0]." AND $distance_miles <".$distance[1]." "; //AND
  1444. $dist_filter.=",1,0) AS dist_filter ";
  1445. array_push($select, $dist_filter);
  1446. array_push($select, $dist);
  1447.  
  1448. if(!empty($score)) {
  1449. $score_filter = 'IF(';
  1450. $score_filter.= " doctor_total_score >= ".$score[0]." AND doctor_total_score <= ".$score[1]."";
  1451. $score_filter.=",1,0) AS score_filter ";
  1452. array_push($select, $score_filter);
  1453. }
  1454. if(!empty($specialty)) {
  1455. $specialty_filter = 'IF(';
  1456. foreach($specialty as $k=>$spec) {
  1457. if (count($specialty) > 1 && $k < count($specialty) - 1){
  1458. $specialty_filter .= " specialty_id = $spec OR ";
  1459. }else {
  1460. $specialty_filter.= " specialty_id = $spec";
  1461. $specialty_filter.=",1,0) AS spec_filter ";
  1462. }
  1463.  
  1464. }
  1465. array_push($select, $specialty_filter);
  1466. }
  1467.  
  1468. $res = SphinxQL::create($conn)->select($select);
  1469. $res->from('doctors');
  1470. if(!empty($query)){
  1471. $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'proc_all', 'user_state', 'str_city', 'str_state'], $query);
  1472. }
  1473. if(!empty($query) && !empty($state)) {
  1474. $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));
  1475. }
  1476. if(!empty($rating)) {
  1477. foreach($rating as &$r){
  1478. $r = (int)$r;
  1479. }
  1480. $res->where('doctor_rating', 'IN', $rating);
  1481. }
  1482. if(!empty($specialty)) {
  1483. $res->where('spec_filter', '=', 1);
  1484. }
  1485. if(!empty($gallery_boolean) && $gallery_boolean=='no') {
  1486. $res->where('gallery_true', '=', 0);
  1487. }else if(!empty($gallery_boolean) && $gallery_boolean=='yes') {
  1488. $res->where('gallery_true', '>', 0);
  1489. }
  1490. if(!empty($procedure)) {
  1491. foreach($procedure as &$pr){
  1492. $pr = (int)$pr;
  1493. }
  1494. $res->where('procedures_id', 'IN', $procedure);
  1495. $res->where('secondary_procedures_id', 'IN', $procedure);
  1496. }
  1497. if(!empty($score)) {
  1498. $res->where('score_filter', '=', 1);
  1499. }
  1500. $res->where('dist_filter', '=', 1);
  1501. if (!is_null($limit)) {
  1502. $res->limit($offset, $limit);
  1503. }else{
  1504. $res->limit(0, 1000);
  1505. }
  1506. // $res->compile()
  1507. // ->getCompiled();
  1508. $result = $res->execute()->fetchAllAssoc();
  1509.  
  1510. return $result;
  1511. }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  1512. } catch (Exception $ex) {
  1513. }
  1514. }
  1515. /**
  1516. * get search result
  1517. * @param $query
  1518. * @param $cat
  1519. * @param null $limit
  1520. * @return \Foolz\SphinxQL\Drivers\ResultSetInterface
  1521. */
  1522. 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)
  1523. {
  1524. try {
  1525. require_once __DIR__ . '/../../vendor/autoload.php';
  1526. require __DIR__ . '/../config/database.php';
  1527. // create a SphinxQL Connection object to use with SphinxQL
  1528. $conn = new Connection();
  1529. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  1530. 'port' => $db['default']['sphinx_port'],
  1531. 'username' => $db['default']['username'],
  1532. 'password' => $db['default']['password'],
  1533. ]);
  1534. $cat = strtolower($cat);
  1535. if(!is_array($query)){
  1536. $query = htmlentities($query);
  1537. $query = str_replace('amp;', '', $query);
  1538. }else{
  1539. $query = implode(' ', $query);
  1540. }
  1541.  
  1542. $select = array('*');
  1543. if(!empty($distance) && !empty($lat) && !empty($lng)){
  1544. $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) ))";
  1545. $dist_filter = 'IF(';
  1546. $dist_filter.= " $distance_miles >= ".$distance[0]." AND $distance_miles <=".$distance[1]."";
  1547. $dist_filter.=",1,0) AS dist_filter ";
  1548. array_push($select, $dist_filter);
  1549. }
  1550. if($cat == 'doctors' || $cat == 'claim' || $cat == 'doctor_name') {
  1551. $search_by_name = $this->search_by_type($query, 'name');
  1552. $search_by_procedure = $this->search_by_type($query, 'procedure');
  1553. $search_by_location = $this->search_by_type($query, 'location');
  1554. $search_by_loc_proc = $this->search_by_type($query, 'proc_&_loc');
  1555. $ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDE‌​D_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
  1556. $user_loc = $this->user_model->get_user_location_by_ip($ip);
  1557. $date_diff = 0;
  1558. if(!empty($user_loc)) {
  1559. $date_diff = $this->user_model->get_diff_date($user_loc->date_request);
  1560. }
  1561. if (empty($user_loc) && $ip != '127.0.0.1'|| $date_diff > 14) {
  1562. $user_location = $this->user_model->update_user_location_by_maxmind($ip, current_url());
  1563. $user_loc = new StdClass;
  1564. $user_loc->lat = $user_location['lat'];
  1565. $user_loc->lng = $user_location['lng'];
  1566. $user_loc->city_name = $user_location['city_name'];
  1567. }
  1568. if(isset($lat) && isset($lng)){
  1569. $user_lat = $lat;
  1570. $user_lng = $lng;
  1571. $user_city_name = $state;
  1572. }else if(!empty($user_loc)) {
  1573. $user_lat = $user_loc->lat;
  1574. $user_lng = $user_loc->lng;
  1575. $user_city_name = $user_loc->city_name;
  1576. }
  1577. 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
  1578. && $search_by_procedure['success']==true || $search_by_loc_proc['success']==true) && $search_dr != true ||
  1579. ($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)))) {
  1580. $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 ";
  1581. array_push($select, $distance_dist);
  1582. $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) ))";
  1583. $distance_filter = 'IF( ';
  1584. $distance_filter .= $distance_in_miles." <= 100";
  1585. $distance_filter .= ",1,0) AS distance_filter ";
  1586. array_push($select, $distance_filter);
  1587. $distance_filter = 'IF(';
  1588. $distance_filter .= " user_state = '".$user_city_name."' OR str_city = '".$user_city_name."'";
  1589. $distance_filter .= ",1,0) AS user_city_filter ";
  1590. array_push($select, $distance_filter);
  1591. }
  1592. if($search_by_name['success']==true && $search_dr == true && !empty($state)){
  1593. $distance_filter = 'IF(';
  1594. $distance_filter .= " user_state = '".$user_city_name."' OR str_city = '".$user_city_name."'";
  1595. $distance_filter .= ",1,0) AS user_city_filter ";
  1596. array_push($select, $distance_filter);
  1597. }
  1598. if($search_by_name['success']==true && $search_by_procedure['success']==true && $search_by_loc_proc['success']==false && isset($user_lat) && isset($user_lng)){
  1599. $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 ";
  1600. array_push($select, $distance_dist);
  1601. $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) ))";
  1602. $distance_filter = 'IF( ';
  1603. $distance_filter .= $distance_in_miles." <= 100";
  1604. $distance_filter .= ",1,0) AS distance_filter ";
  1605. array_push($select, $distance_filter);
  1606. }
  1607. 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'])){
  1608. $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 ";
  1609. array_push($select, $distance_dist);
  1610. $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) ))";
  1611. $distance_filter = 'IF( ';
  1612. $distance_filter .= $distance_in_miles." <= 100";
  1613. $distance_filter .= ",1,0) AS distance_filter ";
  1614. array_push($select, $distance_filter);
  1615. }
  1616. }
  1617.  
  1618. if(!empty($score)) {
  1619. $score_filter = 'IF(';
  1620. $score_filter.= " doctor_total_score >= ".$score[0]." AND doctor_total_score <= ".$score[1]."";
  1621. $score_filter.=",1,0) AS score_filter ";
  1622. array_push($select, $score_filter);
  1623. }
  1624. if(!empty($specialty)) {
  1625. $specialty_filter = 'IF(';
  1626. foreach($specialty as $k=>$spec) {
  1627. if (count($specialty) > 1 && $k < count($specialty) - 1){
  1628. $specialty_filter .= " specialty_id = $spec OR ";
  1629. }else {
  1630. $specialty_filter.= " specialty_id = $spec";
  1631. $specialty_filter.=",1,0) AS spec_filter ";
  1632. }
  1633.  
  1634. }
  1635. array_push($select, $specialty_filter);
  1636. }
  1637. if(!empty($zip)) {
  1638. $zip_filter = 'IF(';
  1639. $zip_filter.= " zip == ".$zip;
  1640. $zip_filter.=",1,0) AS zip_filter ";
  1641. array_push($select, $zip_filter);
  1642. }
  1643.  
  1644. switch ($cat) {
  1645. case 'all':
  1646. $result = [];
  1647. $items = [
  1648. 'procedure',
  1649. 'articles',
  1650. 'photos',
  1651. 'doctors',
  1652. 'videos',
  1653. 'news',
  1654. 'forum'
  1655. ];
  1656. foreach ($items as $item) {
  1657. $res = $this->getSearchResult($query, $item, null, null, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state);
  1658. if (!empty($res))
  1659. $result = array_merge($result, $res);
  1660. }
  1661. return $result;
  1662. break;
  1663.  
  1664. case 'guides':
  1665. $res = SphinxQL::create($conn)->select('*')
  1666. ->from('guides')
  1667. ->match('content', $query);
  1668. if (!is_null($limit)) {
  1669. $res->limit($offset, $limit);
  1670. }else{
  1671. $res->limit(1000);
  1672. }
  1673. if($order) {
  1674. if($order_field) {
  1675. $res->orderBy($order_field, $order);
  1676. }else{
  1677. $res->orderBy('date_of_publication', $order);
  1678. }
  1679. }
  1680. $result = $res->execute()->fetchAllAssoc();
  1681. return $this->generateSearchResult($result, 'guides');
  1682. break;
  1683.  
  1684. case 'procedure':
  1685. $proc_filter = 'IF(';
  1686. $proc_filter .= " procedure_name = '".$query."' OR fact_sheet_name = '".$query."'";
  1687. $proc_filter .= ",1,0) AS procedure_filter ";
  1688. array_push($select, $proc_filter);
  1689. $res = SphinxQL::create($conn)->select($select);
  1690. $res->from('procedure');
  1691. $res->match(['procedure_name', 'fact_sheet_name', 'content'], $query);
  1692.  
  1693. // $res->compile()
  1694. // ->getCompiled();
  1695.  
  1696. if(!empty($zip)) {
  1697. $res->where('zip_filter', '=', 1);
  1698. }
  1699. if (!is_null($limit)) {
  1700. $res->limit($offset, $limit);
  1701. }else{
  1702. $res->limit(1000);
  1703. }
  1704. $res->orderBy('procedure_filter', 'DESC');
  1705. if($order_field && $order) {
  1706. $res->orderBy($order_field, $order);
  1707. }else {
  1708. $res->orderBy('procedure_name', 'ASC');
  1709. }
  1710. $result = $res->execute()->fetchAllAssoc();
  1711. return $this->generateSearchResult($result, 'procedure', $query, $page);
  1712. break;
  1713.  
  1714.  
  1715. case 'articles':
  1716. $res = SphinxQL::create($conn)->select($select);
  1717. $res->from('articles');
  1718. if(!empty($state)){
  1719. $res->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug', 'status_id', 'user_state', 'user_city'], $query);
  1720. $res->match(['user_state', 'user_city'], $state);
  1721. }else {
  1722. $res->match(['auth_name', 'page_title', 'content', 'category_slug', 'article_slug', 'status_id', 'user_state', 'user_city'], $query);
  1723. }
  1724.  
  1725. if(!empty($rating)) {
  1726. $res->where('doctor_rating', '=', (int)$rating);
  1727. }
  1728. if(!empty($specialty)) {
  1729. $res->where('spec_filter', '=', 1);
  1730. }
  1731. if(!empty($procedure)) {
  1732. foreach($procedure as &$pr){
  1733. $pr = (int)$pr;
  1734. }
  1735. $res->where('procedure_id', 'IN', $procedure);
  1736. }
  1737. if(!empty($distance) && !empty($lat) && !empty($lng)){
  1738. $res->where('dist_filter', '=', 1);
  1739. }
  1740. if(!empty($score)) {
  1741. $res->where('score_filter', '=', 1);
  1742. }
  1743.  
  1744. if (!is_null($limit)) {
  1745. $res->limit($offset, $limit);
  1746. }else{
  1747. $res->limit(1000);
  1748. }
  1749. if(!is_null($order)) {
  1750. if(!is_null($order_field)) {
  1751. $res->orderBy($order_field, $order);
  1752. }else{
  1753. $res->orderBy('date_of_public', $order);
  1754. }
  1755. }
  1756. // $res->compile()
  1757. // ->getCompiled();
  1758.  
  1759. $result = $res->execute()->fetchAllAssoc();
  1760. return $this->generateSearchResult($result, 'articles', $query, $page);
  1761. break;
  1762.  
  1763. case 'news':
  1764. $res = SphinxQL::create($conn)->select($select);
  1765. $res->from('news');
  1766.  
  1767. $res->match(['title', 'description', 'tags', 'news_slug', 'category_slug', 'user_state', 'user_city'], $query);
  1768.  
  1769. if (!is_null($limit)) {
  1770. $res->limit($offset, $limit);
  1771. }else{
  1772. $res->limit(1000);
  1773. }
  1774. if($order) {
  1775. if($order_field) {
  1776. $res->orderBy($order_field, $order);
  1777. }else{
  1778. $res->orderBy('date_posted', $order);
  1779. }
  1780. }
  1781.  
  1782. // $res->compile()
  1783. // ->getCompiled();
  1784.  
  1785. $result = $res->execute()->fetchAllAssoc();
  1786. return $this->generateSearchResult($result, 'news', $query, $page);
  1787. break;
  1788.  
  1789. case 'photos':
  1790.  
  1791. $res = SphinxQL::create($conn)->select($select);
  1792. $res->from('photos');
  1793. if(!empty($state)){
  1794. $res->match(['title', 'gallery_slug', 'procedure_name'], $query);
  1795. $res->match(['user_state', 'user_city', 'user_city'], $state);
  1796. }else {
  1797. $res->match(['title', 'gallery_slug', 'procedure_name'], $query);
  1798. }
  1799.  
  1800. if(!empty($rating)) {
  1801. $res->where('doctor_rating', '=', (int)$rating);
  1802. }
  1803. if(!empty($specialty)) {
  1804. $res->where('spec_filter', '=', 1);
  1805. }
  1806. if(!empty($zip)) {
  1807. $res->where('zip_filter', '=', 1);
  1808. }
  1809. if(!empty($procedure)) {
  1810. foreach($procedure as &$pr){
  1811. $pr = (int)$pr;
  1812. }
  1813. $res->where('procedure_id', 'IN', $procedure);
  1814. }
  1815. if(!empty($distance) && !empty($lat) && !empty($lng)){
  1816. $res->where('dist_filter', '=', 1);
  1817. }
  1818. if(!empty($score)) {
  1819. $res->where('score_filter', '=', 1);
  1820. }
  1821. if (!is_null($limit)) {
  1822. $res->limit($offset, $limit);
  1823. }
  1824. else{
  1825. $res->limit(1000);
  1826. }
  1827. if($order) {
  1828. if($order_field) {
  1829. $res->orderBy($order_field, $order);
  1830. }else{
  1831. $res->orderBy('date_create', $order);
  1832. }
  1833. }
  1834. // $res->compile()
  1835. // ->getCompiled();
  1836.  
  1837. $result = $res->execute()->fetchAllAssoc();
  1838. return $this->generateSearchResult($result, 'photos');
  1839. break;
  1840.  
  1841. case 'doctors':
  1842. $serchQuery = $query;
  1843. $res = SphinxQL::create($conn)->select($select);
  1844. $res->from('doctors');
  1845. if(!empty($query) && !empty($state)) {
  1846. $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);
  1847. $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));
  1848. } else
  1849. if(!empty($query)){
  1850. $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'proc_all', 'user_state', 'str_city', 'str_state', 'str_degree_title'], $query);
  1851. } else
  1852. if(!empty($state)){ // && empty($distance)
  1853. $res->match(['user_state', 'str_city', 'str_state'], $state);
  1854. }
  1855.  
  1856. if(!empty($rating)) {
  1857. foreach($rating as &$r){
  1858. $r = (int)$r;
  1859. }
  1860. $res->where('doctor_rating', 'IN', $rating);
  1861. }
  1862. if(!empty($specialty)) {
  1863. $res->where('spec_filter', '=', 1);
  1864. }
  1865. if(!empty($gallery_boolean) && $gallery_boolean=='no') {
  1866. $res->where('gallery_true', '=', 0);
  1867. }else if(!empty($gallery_boolean) && $gallery_boolean=='yes') {
  1868. $res->where('gallery_true', '>', 0);
  1869. }
  1870. if(!empty($procedure)) {
  1871. foreach($procedure as &$pr){
  1872. $pr = (int)$pr;
  1873. }
  1874. $res->where('procedures_id', 'IN', $procedure);
  1875. }
  1876. if(!empty($distance) && !empty($lat) && !empty($lng)){
  1877. $res->where('dist_filter', '=', 1);
  1878. }
  1879.  
  1880. if((!empty($user_lat) && !empty($user_lng) && ($search_by_location['success']==false) && $search_dr != true && $search_by_name['success']==false
  1881. || $search_by_loc_proc['success'] == true) || ($search_dr == true && empty($state) && !empty($user_lat) && !empty($user_lng)) ){ // && ($search_dr==false || $search_dr==null)
  1882. $res->where('location_flag', '=', 1);
  1883. $res->where('distance_filter', '=', 1);
  1884. $res->orderBy('user_city_filter', 'DESC');
  1885. $res->orderBy('distance', 'ASC');
  1886. $res->orderBy('str_city', 'ASC');
  1887. }
  1888. if($search_by_name['success']==true && $search_dr == true && !empty($state)){
  1889. // $res->where('user_city_filter', '=', 1);
  1890. $res->orderBy('user_city_filter', 'DESC');
  1891. }
  1892. if(!empty($score)) {
  1893. $res->where('score_filter', '=', 1);
  1894. }
  1895. if (!is_null($limit)) {
  1896. $res->limit($offset, $limit);
  1897. }else{
  1898. $res->limit(0, 1000);
  1899. }
  1900. // $res->compile()
  1901. // ->getCompiled();
  1902.  
  1903. if($order) {
  1904. if($order_field) {
  1905. $res->orderBy($order_field, $order);
  1906. }else{
  1907. $res->orderBy('date_updated', $order);
  1908. }
  1909. }
  1910. $result = $res->execute()->fetchAllAssoc();
  1911.  
  1912. $ids = array();
  1913. foreach($result as $r){
  1914. array_push($ids, $r['id']);
  1915. }
  1916. $count_diff = 0;
  1917. if(!is_null($limit)) {
  1918. $count_diff = $limit - count($result);
  1919. }
  1920. if($count_diff>0 || is_null($limit)) {
  1921. if ($gallery_boolean != 'yes') {
  1922. $claim_res = $this->getSearchResult($serchQuery, 'claim', $count_diff, null, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
  1923. if (!empty($claim_res)) {
  1924. $claim_ids = array();
  1925. foreach ($claim_res as &$rc) {
  1926. array_push($claim_ids, $rc['id']);
  1927. if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
  1928. array_unshift($result, $rc);
  1929. array_push($ids, $rc->id);
  1930. } else {
  1931. array_push($result, $rc);
  1932. }
  1933. }
  1934. }
  1935. }
  1936. 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
  1937. $result_by_name = $this->getSearchResult($serchQuery, 'doctor_name', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
  1938. foreach ($result as $res) {
  1939. array_push($ids, $res['id']);
  1940. }
  1941. if (!empty($result_by_name)) {
  1942. foreach ($result_by_name as &$rbn) {
  1943. if (!in_array($rbn['id'], $ids)) {
  1944. array_push($result, $rbn);
  1945. }
  1946. }
  1947. }
  1948. }
  1949. if ($search_by_loc_proc['success'] == true) {
  1950. $result_by_loc = $this->getSearchResult($serchQuery, 'doctor_location', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr);
  1951. foreach ($result as $res) {
  1952. array_push($ids, $res['id']);
  1953. }
  1954. if (!empty($result_by_loc)) {
  1955. foreach ($result_by_loc as &$rbl) {
  1956. if (!in_array($rbl['id'], $ids)) {
  1957. array_push($result, $rbl);
  1958. }
  1959. }
  1960. }
  1961. }
  1962. if (!empty($lat) && !empty($lng) && $search_by_name['success'] == false) {
  1963. if (!isset($distance)) {
  1964. $distance = array(0, 100);
  1965. }
  1966. $result_dist = $this->get_doctors_distance($query, $cat, $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, $page, $search_dr, $gallery_boolean, true);
  1967.  
  1968. foreach ($result as $res) {
  1969. array_push($ids, $res['id']);
  1970. }
  1971. if (!empty($result_dist)) {
  1972. foreach ($result_dist as &$rd) {
  1973. if (!in_array($rd['id'], $ids)) {
  1974. array_push($result, $rd);
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. $searchResult = $this->generateSearchResult($result, 'doctors');
  1981.  
  1982. return $searchResult;
  1983. break;
  1984.  
  1985. case 'doctor_name':
  1986. $res = SphinxQL::create($conn)->select($select);
  1987. $res->from('doctors');
  1988. $res->match(['str_first_name', 'str_last_name'], $query);
  1989. if (!is_null($limit)) {
  1990. $res->limit($offset, $limit);
  1991. }else{
  1992. $res->limit(0, 1000);
  1993. }
  1994. $result = $res->execute()->fetchAllAssoc();
  1995. $claim_res = $this->getSearchResult($query, 'claim_name', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state, null, $search_dr, $gallery_boolean);
  1996.  
  1997. if (!empty($claim_res)){
  1998. foreach($claim_res as &$rc) {
  1999. if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
  2000. array_unshift($result, $rc);
  2001. } else {
  2002. array_push($result, $rc);
  2003. }
  2004. }
  2005. }
  2006.  
  2007. return $result;
  2008. break;
  2009.  
  2010. case 'claim_name':
  2011. $res = SphinxQL::create($conn)->select($select);
  2012. $res->from('claim_users');
  2013. $res->match(['str_first_name', 'str_last_name'], $query);
  2014. if (!is_null($limit)) {
  2015. $res->limit($offset, $limit);
  2016. }else{
  2017. $res->limit(0, 1000);
  2018. }
  2019. $result = $res->execute()->fetchAllAssoc();
  2020.  
  2021. return $result;
  2022. break;
  2023.  
  2024. case 'doctor_location':
  2025. $res = SphinxQL::create($conn)->select($select);
  2026. $res->from('doctors');
  2027. $res->match(['user_state', 'str_city', 'str_state'], $query);
  2028. if (!is_null($limit)) {
  2029. $res->limit($offset, $limit);
  2030. }else{
  2031. $res->limit(0, 1000);
  2032. }
  2033. $result = $res->execute()->fetchAllAssoc();
  2034. $claim_res = $this->getSearchResult($query, 'claim_location', $limit, $offset, $score, $rating, $lat, $lng, $distance, $specialty, $procedure, $state);
  2035.  
  2036. if (!empty($claim_res)){
  2037. foreach($claim_res as &$rc) {
  2038. if (isset($rc['user_city_filter']) && $rc['user_city_filter'] == 1) {
  2039. array_unshift($result, $rc);
  2040. } else {
  2041. array_push($result, $rc);
  2042. }
  2043. }
  2044. }
  2045.  
  2046. return $result;
  2047. break;
  2048.  
  2049. case 'claim_location':
  2050. $res = SphinxQL::create($conn)->select($select);
  2051. $res->from('claim_users');
  2052. $res->match(['user_state', 'str_city', 'str_state'], $query);
  2053. if (!is_null($limit)) {
  2054. $res->limit($offset, $limit);
  2055. }else{
  2056. $res->limit(0, 1000);
  2057. }
  2058. $result = $res->execute()->fetchAllAssoc();
  2059.  
  2060. return $result;
  2061. break;
  2062.  
  2063. case 'videos':
  2064.  
  2065. $res = SphinxQL::create($conn)->select($select);
  2066. $res->from('videos');
  2067. if(!empty($state)){
  2068. $res->match(['title', 'descriptopn', 'video_slug','user_state', 'user_city', 'str_state'], $query);
  2069. $res->match(['user_state', 'user_city', 'str_state'], $state);
  2070. }else {
  2071. $res->match(['title', 'descriptopn', 'video_slug','user_state', 'user_city', 'str_state'], $query);
  2072. }
  2073. if(!empty($rating)) {
  2074. $res->where('doctor_rating', '=', (int)$rating);
  2075. }
  2076. if(!empty($specialty)) {
  2077. $res->where('spec_filter', '=', 1);
  2078. }
  2079. if(!empty($procedure)) {
  2080. foreach($procedure as &$pr){
  2081. $pr = (int)$pr;
  2082. }
  2083. $res->where('procedure_id', 'IN', $procedure);
  2084. }
  2085. if(!empty($distance) && !empty($lat) && !empty($lng)){
  2086. $res->where('dist_filter', '=', 1);
  2087. }
  2088. if(!empty($score)) {
  2089. $res->where('score_filter', '=', 1);
  2090. }
  2091.  
  2092. if (!is_null($limit)) {
  2093. $res->limit($offset, $limit);
  2094. }else{
  2095. $res->limit(1000);
  2096. }
  2097. if($order) {
  2098. if($order_field) {
  2099. $res->orderBy($order_field, $order);
  2100. }else{
  2101. $res->orderBy('date_updated', $order);
  2102. }
  2103. }
  2104. $result = $res->execute()->fetchAllAssoc();
  2105. return $this->generateSearchResult($result, 'videos');
  2106. break;
  2107.  
  2108. case 'forum':
  2109. $res = SphinxQL::create($conn)->select($select);
  2110. $res->from('forum');
  2111. if(!empty($state)){
  2112. $res->match(['text', 'title', 'user_state', 'user_city', 'str_state'], $query);
  2113. $res->match(['user_state', 'user_city', 'str_state'], $state);
  2114. }else {
  2115. $res->match(['text', 'title', 'user_state', 'user_city', 'str_state'], $query);
  2116. }
  2117. if(!empty($distance) && !empty($lat) && !empty($lng)){
  2118. $res->where('dist_filter', '=', 1);
  2119. }
  2120. if (!is_null($limit)) {
  2121. $res->limit($offset, $limit);
  2122. }else{
  2123. $res->limit(1000);
  2124. }
  2125. if($order) {
  2126. if($order_field) {
  2127. $res->orderBy($order_field, $order);
  2128. }else{
  2129. $res->orderBy('time', $order);
  2130. }
  2131. }
  2132. $result = $res->execute()->fetchAllAssoc();
  2133. return $this->generateSearchResult($result, 'forum');
  2134. break;
  2135.  
  2136. case 'claim':
  2137. $res = SphinxQL::create($conn)->select($select);
  2138. $res->from('claim_users');
  2139. if(!empty($query)){
  2140. $res->match(['str_first_name', 'str_last_name', 'str_treatment_name', 'user_state', 'str_city', 'str_state', 'str_degree_title'], $query);
  2141. }
  2142. if(!empty($state)){
  2143. $res->match(['user_state', 'str_city', 'str_state'], $state);
  2144. }
  2145. if(!empty($query) || !empty($state)) {
  2146. $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));
  2147. }
  2148.  
  2149. if(!empty($specialty)) {
  2150. $res->where('spec_filter', '=', 1);
  2151. }
  2152. if(!empty($procedure)) {
  2153. foreach($procedure as &$pr){
  2154. $pr = (int)$pr;
  2155. }
  2156. $res->where('procedure_id', 'IN', $procedure);
  2157. }
  2158. if(!empty($distance) && !empty($lat) && !empty($lng)){
  2159. $res->where('dist_filter', '=', 1);
  2160. }
  2161. if(!empty($user_lat) && !empty($user_lng) && $search_by_name['success']==false && $search_by_location['success']==false){
  2162. $res->where('location_flag', '=', 1);
  2163. $res->where('distance_filter', '=', 1);
  2164. $res->orderBy('user_city_filter', 'DESC');
  2165. $res->orderBy('distance', 'ASC');
  2166. $res->orderBy('str_city', 'ASC');
  2167. }
  2168. if(!empty($user_lat) && !empty($user_lng) && ($search_by_name['success']==false && $search_by_location['success']==false) || $search_by_loc_proc['success'] == true){
  2169. $res->where('location_flag', '=', 1);
  2170. $res->where('distance_filter', '=', 1);
  2171. $res->orderBy('user_city_filter', 'DESC');
  2172. $res->orderBy('distance', 'ASC');
  2173. $res->orderBy('str_city', 'ASC');
  2174. }
  2175. if($search_by_procedure['success']==true && $search_by_name['success']==false && $search_by_procedure['success']==false){
  2176. $res->where('location_flag', '=', 1);
  2177. $res->where('distance_filter', '=', 1);
  2178. $res->orderBy('distance', 'ASC');
  2179. }
  2180. if(!empty($score)) {
  2181. $res->where('score_filter', '=', 1);
  2182. }
  2183.  
  2184. if (!is_null($limit)) {
  2185. $res->limit($offset, $limit);
  2186. }else{
  2187. $res->limit(1000);
  2188. }
  2189.  
  2190. // $res->compile()
  2191. // ->getCompiled();
  2192.  
  2193. $result = $res->execute()->fetchAllAssoc();
  2194. return $result;//$this->generateSearchResult($result, 'claim_users');
  2195. break;
  2196.  
  2197. case 'questions':
  2198. $query = SphinxQL::create($conn)->select('*')
  2199. ->from('questions')
  2200. ->match(['first_name', 'last_name', 'str_question', 'city', 'state', 'state_name', 'title', 'text'], $query);
  2201. if(!empty($zip)) {
  2202. $query->where('zip_filter', '=', 1);
  2203. }
  2204. if (!is_null($limit)) {
  2205. $query->limit($offset, $limit);
  2206. }else{
  2207. $query->limit(1000);
  2208. }
  2209. if($order) {
  2210. if($order_field) {
  2211. $query->orderBy($order_field, $order);
  2212. }else{
  2213. $query->orderBy('date_create', $order);
  2214. }
  2215. }
  2216. // $query->compile()
  2217. // ->getCompiled();
  2218.  
  2219. $result = $query->execute()->fetchAllAssoc();
  2220. return $this->generateSearchResult($result, 'questions');
  2221. break;
  2222.  
  2223. default:
  2224. return [];
  2225. break;
  2226. }
  2227. } catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  2228. } catch (Exception $ex) {
  2229. }
  2230. }
  2231.  
  2232. /**
  2233. * generate search result
  2234. * @param $result
  2235. * @param $type
  2236. * @param null $query
  2237. * @return array
  2238. */
  2239. private function generateSearchResult($result, $type, $query = null, $page = null)
  2240. {
  2241. $results = [];
  2242. switch ($type) {
  2243. case 'all':
  2244. foreach ($result as $items) {
  2245. $results[] = [
  2246. 'title' => $items['title'],
  2247. 'category' => $items['category'],
  2248. 'content' => strip_tags((strlen($items['str_content']) > 500) ? substr($items['str_content'], 0, 500) . ' ...' : $items['str_content']),
  2249. 'link' => base_url() . $items['slug'],
  2250. 'page' => base_url() . '',
  2251. ];
  2252. }
  2253. return $results;
  2254. break;
  2255.  
  2256. case 'guides':
  2257. foreach ($result as $items) {
  2258. $results[] = [
  2259. 'title' => '',
  2260. 'category' => 'guides',
  2261. 'content' => '',
  2262. 'link' => '',
  2263. 'page' => base_url() . '',
  2264. ];
  2265. }
  2266. return $results;
  2267. break;
  2268.  
  2269. case 'procedure':
  2270. foreach ($result as $items) {
  2271. $res = [
  2272. 'title' => $items['fact_sheet_name'],
  2273. 'image_url' => $items['image_url'],
  2274. 'category_slug' => $items['category_slug'],
  2275. 'zip' => $items['zip'],
  2276. 'category' => 'procedure',
  2277. 'content' => strip_tags((strlen($items['content']) > 500) ? substr(trim($items['content']), 0, 500) . ' ...' : $items['content']),
  2278. 'link' => base_url() . 'procedure/' . $items['category_slug'],
  2279. 'page' => base_url() . 'journal',
  2280. 'read_more' => 'VIEW ARTICLE '
  2281. ];
  2282. array_push($results, $res);
  2283. }
  2284. return $results;
  2285. break;
  2286.  
  2287.  
  2288. case 'articles':
  2289. foreach($result as &$art){
  2290. $parent_id = $this->category_model->getParentCategoryById($art['procedure_id']);
  2291. if($parent_id) {
  2292. $art['procedure_name'] = $this->review_model->get_procedure_list_slug_by_id($parent_id);
  2293. }else {
  2294. $proc = $this->doctorprofile->getProcedureById($art['procedure_id']);
  2295. $art['procedure_name'] = $proc->category_slug;
  2296. }
  2297. }
  2298. foreach ($result as $items) {
  2299. if(stripos($items['content'], 'data-oembed_provider="vimeo"')){
  2300. $items['content'] = strip_tags($items['content']);
  2301. }
  2302. $res = [
  2303. 'title' => $items['page_title'],
  2304. 'category' => 'articles',
  2305. 'content' => strip_tags((strlen($items['content']) > 500) ? substr(trim($items['content']), 0, 500) . ' ...' : $items['content']),
  2306. 'link' => base_url() . 'journal/' . $items['procedure_name'] . '/' . $items['article_slug'],
  2307. 'page' => base_url() . 'journal',
  2308. 'read_more' => 'VIEW ARTICLE '
  2309. ];
  2310. array_push($results, $res);
  2311. }
  2312. return $results;
  2313. break;
  2314.  
  2315. case 'photos':
  2316. foreach ($result as $items) {
  2317. $userData = $this->login_model->getnewUserData('doctor', $items['users_id']);
  2318. $elite_badge_delete = $this->admin_model->getEliteBadgeDelete($items['users_id']);
  2319. $category_id = $this->category_model->getCategoryByProc($items['procedure_id']);
  2320. $category = $this->category_model->getPhotoCategoryById($category_id);
  2321. $doctor_score = 0;
  2322. if(!empty($userData)) {
  2323. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  2324. }
  2325. $results[] = [
  2326. 'id'=>$items['id'],
  2327. 'str_first_name'=>$items['str_first_name'],
  2328. 'str_last_name'=>$items['str_last_name'],
  2329. 'title' => $items['title'],
  2330. 'zip' => $items['zip'],
  2331. 'category' => 'photos',
  2332. 'category_id' => $items['category_id'],
  2333. 'procedure_id' => $items['procedure_id'],
  2334. 'category_slug' => !empty($category) ? $category->category_slug : $items['category_slug'],
  2335. 'gallery_slug' => $items['gallery_slug'],
  2336. 'users_id' => $items['users_id'],
  2337. 'content' => strip_tags((strlen($items['description']) > 500) ? substr($items['description'], 0, 500) . ' ...' : $items['description']),
  2338. 'link' => base_url() . 'photo/' . $items['gallery_slug'],
  2339. 'page' => base_url() . 'photos',
  2340. 'read_more' => 'VIEW GALLERY ',
  2341. 'images' => explode(',', $items['images']),
  2342. 'elite_badge_delete' => $elite_badge_delete,
  2343. 'score' => $doctor_score,
  2344. 'tags' => $items['tags']
  2345. ];
  2346. }
  2347. return $results;
  2348. break;
  2349.  
  2350. case 'doctors':
  2351. foreach ($result as $items) {
  2352. $pos = strpos($items['profile_image'], '//lorempixel.com');
  2353. $rankin = $doctor_score = 0;
  2354. if(isset($items['user_id']) ) {
  2355. $userData = $this->login_model->getnewUserData('doctor', $items['user_id']);
  2356. if(!empty($userData)) {
  2357. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  2358. $rankin = round($doctor_score*0.25, 1);
  2359. }
  2360. }else if(isset($items['id']) ) {
  2361. $userData = $this->login_model->getClaimData($items['id']);
  2362. if(!empty($userData)) {
  2363. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  2364. $rankin = round($doctor_score*0.25, 1);
  2365. }
  2366. }
  2367.  
  2368. if(!empty($items['str_first_name']) && !empty($items['str_last_name'])) {
  2369. if($pos===false){
  2370. $profile_image='/uploads/users/profilepic/'.$items['profile_image'];
  2371. }
  2372. else{
  2373. $profile_image=$items['profile_image'];
  2374. }
  2375.  
  2376. if(empty($items['profile_image'])){
  2377. $profile_image='/images/frontend/profilepic/profile.png';
  2378. }
  2379.  
  2380. $results[] = [
  2381. 'id' => isset($items['user_id']) ? $items['user_id'] : $items['id'],
  2382. 'title' => ucfirst($items['str_first_name']) . ' ' . ucfirst($items['str_last_name']) . ', ' . strtoupper($items['str_degree_title']),
  2383. 'doctor_title' => isset($items['title']) ? $items['title'] : '',
  2384. 'category' => 'doctors',
  2385. 'user_lat' => $items['user_lat'],
  2386. 'user_lng' => $items['user_lng'],
  2387. 'user_lng' => $items['user_lng'],
  2388. 'countarticles' => isset($items['countarticles']) ? $items['countarticles'] : 0,
  2389. 'countreviews' => isset($items['countreviews']) ? $items['countreviews'] : 0,
  2390. 'sumrating' => isset($items['sumrating']) ? $items['sumrating'] : 0,
  2391. 'doc_rating' => isset($items['sumrating']) ? $items['sumrating'] : 0,
  2392. 'countvideos' => isset($items['countvideos']) ? $items['countvideos'] : 0,
  2393. 'content' => $items['str_address'],
  2394. 'content2' => $items['str_city'] . ', ' . $items['str_state'] . ' ' . $items['str_zip'],
  2395. 'address' => $items['str_state'].', '.$items['str_address'],
  2396. 'link' => base_url() . 'doctor/' .$items['str_user_slug'],
  2397. 'page' => base_url() . 'doctor/' . $items['str_user_slug'],
  2398. 'read_more' => 'VISIT DOCTOR ',
  2399. 'distance' => isset($items['distance']) ? $items['distance'] : '',
  2400. 'user_city_filter' => isset($items['user_city_filter']) ? $items['user_city_filter'] : '',
  2401. 'rating' => $rankin,
  2402. 'profile_image' => $profile_image,
  2403. 'board_certification' =>$items['board_certification']
  2404. ];
  2405. }
  2406. }
  2407. return $results;
  2408. break;
  2409.  
  2410. case 'videos':
  2411. foreach ($result as $items) {
  2412. $results[] = [
  2413. 'title' => $items['title'],
  2414. 'category' => 'videos',
  2415. 'content' => strip_tags((strlen($items['descriptopn']) > 500) ? substr($items['descriptopn'], 0, 500) . ' ...' : $items['descriptopn']),
  2416. 'link' => base_url() . 'video/' . $items['video_slug'],
  2417. 'page' => base_url() . 'video/' . $items['video_slug'],
  2418. 'read_more' => 'VIEW VIDEO '
  2419. ];
  2420. }
  2421. return $results;
  2422. break;
  2423.  
  2424. case 'forum':
  2425. foreach ($result as $item) {
  2426.  
  2427. if($item['is_new_forum_post']){
  2428. $post = nl2br($this->bbcodeparser->run($item['text']));
  2429. }else {
  2430. $post = $this->phpbbparser->run($item['text']);
  2431. }
  2432.  
  2433. $results[] = [
  2434. 'title' => $item['title'],
  2435. 'category' => 'forum',
  2436. 'content' => $post,
  2437. 'link' => base_url() . 'forum/'.$this->forum_model->prepare_string($item['name']).'/' . $this->forum_model->prepare_string($item['title']).'/'.$item['topic_id'],
  2438. 'page' => base_url() . 'forum',
  2439. 'read_more' => 'VIEW POST '
  2440. ];
  2441. }
  2442. return $results;
  2443. break;
  2444.  
  2445. case 'claim_users':
  2446. foreach ($result as $items) {
  2447. $pos = strpos($items['profile_image'], 'https://lorempixel.com');
  2448. if(!empty($items['str_first_name']) && !empty($items['str_last_name'])) {
  2449. if($pos===false){
  2450. $profile_image='/uploads/users/profilepic/'.$items['profile_image'];
  2451. }
  2452. else{
  2453. $profile_image=$items['profile_image'];
  2454. }
  2455. if((!empty($items['profile_image']) && !file_exists('.'.$profile_image)) || empty($items['profile_image'])){
  2456. $profile_image='/images/frontend/profilepic/profile.png';
  2457. }
  2458. $rankin = $doctor_score = 0;
  2459. if(isset($items['id']) ) {
  2460. $userData = $this->login_model->getClaimData($items['id']);
  2461. if(!empty($userData)) {
  2462. $doctor_score = $userData[0]->niche + $userData[0]->page_rank + $userData[0]->review + $userData[0]->publication;
  2463. $rankin = round($doctor_score*0.25, 1);
  2464. }
  2465. }
  2466. $results[] = [
  2467. 'claim_id' =>$items['id'],
  2468. 'title' => ucfirst($items['str_first_name']) . ' ' . ucfirst($items['str_last_name']) . ', ' . strtoupper($items['str_degree_title']),
  2469. 'category' => 'doctors',
  2470. 'user_lat' => $items['user_lat'],
  2471. 'user_lng' => $items['user_lng'],
  2472. 'content' => $items['str_address'],
  2473. 'content2' => $items['str_city'] . ', ' . $items['str_state'] . ' ' . $items['str_zip'],
  2474. 'link' => base_url() . 'doctor/' . $items['str_user_slug'],
  2475. 'page' => base_url() . 'doctor/' . $items['str_user_slug'],
  2476. 'read_more' => 'VISIT DOCTOR ',
  2477. 'distance' => isset($items['distance']) ? $items['distance'] : '',
  2478. 'user_city_filter' => isset($items['user_city_filter']) ? $items['user_city_filter'] : '',
  2479. 'rating' => $rankin,
  2480. 'profile_image' => $profile_image
  2481. ];
  2482. }
  2483. }
  2484. return $results;
  2485. break;
  2486.  
  2487. case 'questions':
  2488. foreach ($result as $items) {
  2489. $results[] = [
  2490. 'title' => '',
  2491. 'category' => 'questions',
  2492. 'zip' => $items['zip'],
  2493. 'content' => strip_tags((strlen($items['str_question']) > 500) ? substr($items['str_question'], 0, 500) . ' ...' : $items['str_question']),
  2494. 'link' => base_url() . 'question/' . $items['question_id'],
  2495. 'page' => base_url() . 'question/' . $items['question_id'],
  2496. 'read_more' => 'VIEW QUESTION '
  2497. ];
  2498. }
  2499. return $results;
  2500. break;
  2501.  
  2502. case 'news':
  2503. foreach ($result as $items) {
  2504. $results[] = [
  2505. 'title' => $items['title'],
  2506. 'category' => 'news',
  2507. 'content' => strip_tags((strlen($items['description']) > 500) ? substr($items['description'], 0, 500) . ' ...' : $items['description']),
  2508. 'link' => base_url() . 'news/' . $items['news_slug'],
  2509. 'page' => base_url() . 'news/' . $items['news_slug'],
  2510. 'read_more' => 'VIEW NEWS '
  2511. ];
  2512. }
  2513. return $results;
  2514. break;
  2515.  
  2516. default:
  2517. return [
  2518. 'title' => '',
  2519. 'category' => '',
  2520. 'content' => '',
  2521. 'link' => ''
  2522. ];
  2523. break;
  2524. }
  2525. }
  2526.  
  2527. public function get_procedures_map()
  2528. {
  2529. $data['procedures'] = $this->user_model->get_procedure();
  2530. if ($data['procedures']) {
  2531. echo json_encode($data['procedures']);
  2532. } else {
  2533. echo json_encode(false);
  2534. }
  2535. }
  2536.  
  2537. /**
  2538. * get url from split variable, if split is true return url after explode
  2539. * else just return url after read from segment
  2540. * @param $segment
  2541. * @param bool $split
  2542. * @param string $delimiter
  2543. * @return array
  2544. */
  2545. private function _getUrl($segment, $split = false, $delimiter = '_')
  2546. {
  2547. $segment = $this->uri->segment($segment);
  2548. if ($split) {
  2549. return explode($delimiter, $segment);
  2550. } else {
  2551. return $segment;
  2552. }
  2553. }
  2554.  
  2555. /**
  2556. * Dealing with reviews
  2557. * @author rsingh6
  2558. */
  2559. public function search()
  2560. {
  2561. $get = $this->input->get();
  2562. if ($get['query'] == '') {
  2563. show_404();
  2564. }
  2565. $config['base_url'] = base_url() . "search/index/";
  2566. $record_sum = array_sum($this->user_model->record_count_site());
  2567. $config['total_rows'] = $record_sum;
  2568. $config['per_page'] = 10;
  2569. $config["uri_segment"] = 3;
  2570. $config['num_links'] = 10;
  2571. $config['reuse_query_string'] = TRUE;
  2572. $this->pagination->initialize($config);
  2573. $page = ($this->_getUrl(3)) ? $this->_getUrl(3) : 0;
  2574. $data["links"] = $this->pagination->create_links();
  2575. $data['get_var'] = '/?query=' . $get['query'];
  2576. $data['search'] = $this->user_model->search_site($config["per_page"], $page);
  2577. $data['featured'] = $this->doctorprofile->get_featured_doctor();
  2578.  
  2579. $this->render(['search/site_search'], $data,[
  2580. 'is_twig' => FALSE,
  2581. ]);
  2582. }
  2583.  
  2584. /**
  2585. * Logout for destroying all the session values
  2586. * @author rsingh6
  2587. */
  2588. public function logout($check = '')
  2589. {
  2590. $type = $this->session->userdata('front_user');
  2591. $this->session->unset_userdata('front_user');
  2592. $this->session->sess_destroy();
  2593. if ($check == 'account-disabled') {
  2594.  
  2595. session_start();
  2596. $_SESSION['logout_usr'] = 'index/login/account-disabled';
  2597. //redirect('index/login/account-disabled');
  2598. redirect(base_url() . 'forumlogout.php');
  2599. } else {
  2600. session_start();
  2601. $_SESSION['logout_usr'] = 'index/login/';
  2602. //redirect('index/login/', 'refresh');
  2603. redirect(base_url() . 'forumlogout.php');
  2604. }
  2605. }
  2606.  
  2607. public function searchbeforeafter(){
  2608. $get = $this->input->get();
  2609. if (isset($get['search'])) {
  2610. $query = $get['search'] == '' ? null : trim($get['search']);
  2611. }
  2612. if (isset($get['activity'])) {
  2613. $activity = $get['activity'] == '' ? null : trim($get['activity']);
  2614. }
  2615. $activity_id = $this->procedure_model->get_activity_by_name($activity);//var_dump($activity, $activity_id);
  2616. /* $model = $this->procedure_model->find_one_by_attributes(array('category_slug' => $query));
  2617. $data = array_chunk($this->gallery_model->get_by_procedure_id($model['id']),3);
  2618.  
  2619. echo json_encode($data);
  2620. die; */
  2621. $this->load->model('procedure_model');
  2622. $result = $this->procedure_model->searchbeforeafter($query, null, $activity_id);
  2623.  
  2624.  
  2625. echo json_encode($result);
  2626. exit;
  2627. }
  2628.  
  2629. public function activities()
  2630. {
  2631. $get = $this->input->get();
  2632. if (isset($get['search'])) {
  2633. $query = $get['search'] == '' ? null : trim($get['search']);
  2634. }
  2635.  
  2636. $this->load->model('procedure_model');
  2637. $retrun_data = $this->procedure_model->get_activities($query);
  2638.  
  2639.  
  2640. echo json_encode($retrun_data);
  2641. die;
  2642.  
  2643. }
  2644.  
  2645. /*
  2646. * get doctors by zip for rendering
  2647. * */
  2648. public function getDoctorsByZip()
  2649. {
  2650. $post = $this->input->post();
  2651. if (!empty($post)){
  2652. $zip = $post['zip'];
  2653. $proc_slug = $post['proc_slug'];
  2654. }
  2655. $model = $this->procedure_model->find_one_by_attributes(array('category_slug' => $proc_slug));
  2656. $proc_name = $model['name'];
  2657. $id = $model['id'];
  2658. $parent_proc = $this->category_model->getParentNameCategoryById($id);
  2659. try {
  2660. require_once __DIR__ . '/../../vendor/autoload.php';
  2661. require __DIR__ . '/../config/database.php';
  2662. // create a SphinxQL Connection object to use with SphinxQL
  2663. $conn = new Connection();
  2664. $conn->setParams(['host' => $db['default']['sphinx_hostname'],
  2665. 'port' => $db['default']['sphinx_port'],
  2666. 'username' => $db['default']['username'],
  2667. 'password' => $db['default']['password'],
  2668. ]);
  2669. $select = array('*' );
  2670. $res = SphinxQL::create($conn)->select($select);
  2671. $res->from('doctors');
  2672. if(isset($proc_name)) {
  2673. $res->match(['str_treatment_name'], $proc_name);
  2674. }
  2675. if(isset($id)) {
  2676. $res->match(['procedure_id'], $id);
  2677. }
  2678. if(isset($zip)) {
  2679. $res->match(['str_zip'], $zip);
  2680. }
  2681. $res->orderBy('avg_rating', 'DESC');
  2682. $res->limit(0, 6);
  2683. $res = $res->execute()->fetchAllAssoc();
  2684. if ((empty($res) || count($res) < 6) && !empty($parent_proc)) {
  2685. $ids = array();
  2686. foreach ($res as $r) {
  2687. array_push($ids, $r['id']);
  2688. }
  2689. $result = SphinxQL::create($conn)->select($select);
  2690. $result->from('doctors');
  2691. $result->match(['str_treatment_name'], $parent_proc[0]->name);
  2692. $result->match(['str_zip'], $zip);
  2693. $result->orderBy('avg_rating', 'DESC');
  2694. $result->limit(6 - count($res));
  2695. $result = $result->execute()->fetchAllAssoc();
  2696. foreach ($result as $rp) {
  2697. if (!in_array($rp['id'], $ids)) {
  2698. array_push($res, $rp);
  2699. }
  2700. }
  2701. }
  2702. }catch (Foolz\SphinxQL\Exception\DatabaseException $ex) {
  2703. } catch (Exception $ex) {
  2704. }
  2705. if(!empty($res)) {
  2706. $data['top_doc_near_you'] = $res;
  2707. $this->render(['find-near-doctors'], $data,
  2708. [
  2709. 'header' => ['is_visible' => false,],
  2710. 'footer' => ['is_visible' => false,]
  2711. ]);
  2712. }else{
  2713. return '';
  2714. }
  2715. }
  2716. }
  2717. /* End of file reviews.php */
  2718. /* Location: ./application/controllers/reviews.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement