Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.20 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Apps\Website\Controllers;
  4.  
  5. use Framework\Vars;
  6. use Framework\Settings;
  7. use Framework\Api\Api;
  8. use Modules\Objects\Models;
  9. use Apps\Website\Helpers;
  10.  
  11. Class ObjectOverview extends \Apps\Website\Library\Controller
  12. {
  13.  
  14. protected $objects;
  15.  
  16. /**
  17. * Initialize controller
  18. * @param int $pageID
  19. */
  20. public function __construct()
  21. {
  22. parent::__construct();
  23.  
  24. $this->objects = new Models\Objects();
  25.  
  26. $this->objects->options->pagination = (isset($_GET['c']) ? (int) $_GET['c'] : Settings::get('objects', 'pagination'));
  27. //$this->objects->options->pagination = false;
  28.  
  29. // set order
  30. if (isset($_GET['s']) && isset($_GET['d'])) {
  31. $this->objects->setOrder($_GET['s'], $_GET['d']);
  32. } else {
  33. $this->objects->setOrder('ingevoerd', 'desc');
  34. }
  35.  
  36. if (!strstr(Vars::$url->url, 'object-maps')) {
  37. $_SESSION['overzicht'] = Vars::$url->url;
  38. }
  39.  
  40. $this->initialize();
  41. }
  42.  
  43. /**
  44. * initialize the default view
  45. */
  46. public function showTemplate()
  47. {
  48. // set assets
  49. // $this->view->head->add('css', VIEW_URL . '/css/default.css');
  50. // $this->view->foot->add('js', VIEW_URL . '/js/general.js');
  51. //$this->view->foot->add('js', VIEW_URL . '/js/objects.js');
  52. //$this->view->foot->add('js', '//maps.google.com/maps/api/js');
  53. //$this->view->foot->add('js', VIEW_URL . '/js/assets/markerclusterer_compiled.js');
  54. //$this->view->foot->add('js', VIEW_URL . '/js/assets/infobubble.min.js');
  55.  
  56. // set vars
  57. Vars::$content->header = Vars::$page->header;
  58. Vars::$content->objects = $this->loadObjects();
  59.  
  60.  
  61. $this->view->showTemplate(Vars::$page->template, 'object.overview.php');
  62. }
  63.  
  64. public function pageDefault($default = true)
  65. {
  66. if ($default)
  67. $this->showTemplate();
  68. }
  69.  
  70. /**
  71. * initialize the koopwoningen view
  72. */
  73. public function pageKoopwoningen($default = true)
  74. {
  75. $this->objects->search->woning = true;
  76. $this->objects->search->koop = true;
  77. $this->objects->search->verkocht = true;
  78. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht');
  79.  
  80. if ($default)
  81. $this->showTemplate();
  82. }
  83.  
  84. public function pageExclusief($default = true)
  85. {
  86. $this->objects->search->woning = true;
  87. $this->objects->search->koop = true;
  88.  
  89. $this->objects->where = '`ob`.`ob_exclusief` = 1 OR `ob_koopprijs` >= 750000';
  90. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud');
  91.  
  92. if ($default)
  93. $this->showTemplate();
  94. }
  95.  
  96. /**
  97. * initialize the koopwoningen view
  98. */
  99. public function pageAppartementen($default = true)
  100. {
  101. $this->objects->search->woning->soort = 'appartement';
  102. $this->objects->search->koop = true;
  103. $this->objects->search->verkocht = true;
  104. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht');
  105.  
  106. if ($default)
  107. $this->showTemplate();
  108. }
  109.  
  110. /**
  111. * initialize the huurwoningen view
  112. */
  113. public function pageHuurwoningen($default = true)
  114. {
  115. $this->objects->search->woning = true;
  116. $this->objects->search->huur = true;
  117. $this->objects->search->status = array('beschikbaar', 'verhuurd onder voorbehoud', 'verhuurd');
  118.  
  119. if ($default)
  120. $this->showTemplate();
  121. }
  122.  
  123. /**
  124. * initialize the pageKantoorruimte view
  125. */
  126. public function pageKantoorruimte($default = true)
  127. {
  128. $this->objects->search->bedrijfspand->soort = 'kantoorruimte';
  129. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  130.  
  131. if ($default)
  132. $this->showTemplate();
  133. }
  134.  
  135. /**
  136. * initialize the pageBedrijfsruimte view
  137. */
  138. public function pageBedrijfsruimte($default = true)
  139. {
  140. $this->objects->search->bedrijfspand->soort = 'bedrijfsruimte';
  141. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  142.  
  143. if ($default)
  144. $this->showTemplate();
  145. }
  146.  
  147. /**
  148. * initialize the pageWinkelruimte view
  149. */
  150. public function pageWinkelruimte($default = true)
  151. {
  152. $this->objects->search->bedrijfspand->soort = 'winkelruimte';
  153. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  154.  
  155. if ($default)
  156. $this->showTemplate();
  157. }
  158.  
  159. /**
  160. * initialize the pageHoreca view
  161. */
  162. public function pageBelegging($default = true)
  163. {
  164. $this->objects->search->bedrijfspand = true;
  165. $this->objects->where = '`ob`.`ob_belegging` = 1';
  166. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  167.  
  168. if ($default)
  169. $this->showTemplate();
  170. }
  171.  
  172. /**
  173. * initialize the pageBogVerkocht view
  174. */
  175. public function pageBogVerkocht($default = true)
  176. {
  177. $this->objects->search->bedrijfspand = true;
  178. $this->objects->search->status = array('verkocht', 'verhuurd', 'verkocht onder voorbehoud', 'verhuurd onder voorbehoud');
  179. $this->objects->options->sold_interval = 90;
  180.  
  181. if ($default)
  182. $this->showTemplate();
  183. }
  184.  
  185. /**
  186. * initialize the pageBogTotaal view
  187. */
  188. public function pageBogTotaal($default = true)
  189. {
  190. $this->objects->search->bedrijfspand = true;
  191.  
  192. if ($default)
  193. $this->showTemplate();
  194. }
  195.  
  196. /**
  197. * initialize the pageHoreca view
  198. */
  199. public function pageHoreca($default = true)
  200. {
  201. $this->objects->search->bedrijfspand->soort = 'horeca';
  202. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  203.  
  204. if ($default)
  205. $this->showTemplate();
  206. }
  207.  
  208. /**
  209. * initialize the garage view
  210. */
  211. public function pageGarages($default = true)
  212. {
  213. $this->objects->search->garage = true;
  214. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  215.  
  216. if ($default)
  217. $this->showTemplate();
  218. }
  219.  
  220. /**
  221. * initialize the bouwgrond view
  222. */
  223. public function pageBouwgrond($default = true)
  224. {
  225. $this->objects->search->bouwgrond = true;
  226. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  227.  
  228. if ($default)
  229. $this->showTemplate();
  230. }
  231.  
  232. /**
  233. * initialize the bouwgrond view
  234. */
  235. public function pageNieuwbouw($default = true)
  236. {
  237. $this->objects->search->nieuwbouw = true;
  238. $this->objects->search->status = array('beschikbaar', 'verkocht onder voorbehoud', 'verkocht', 'verhuurd onder voorbehoud', 'verhuurd');
  239.  
  240. if ($default)
  241. $this->showTemplate();
  242. }
  243.  
  244. /**
  245. * initialize the bouwgrond view
  246. */
  247. public function pageOpenhuis($default = true)
  248. {
  249. $this->objects->search->openhuis = true;
  250. $this->objects->search->status = array('beschikbaar');
  251.  
  252. if ($default)
  253. $this->showTemplate();
  254. }
  255.  
  256. /**
  257. * initialize pageNieuw
  258. */
  259. public function pageNieuw($default = true)
  260. {
  261. $this->objects->search->woning = true;
  262. $this->objects->search->status = array('beschikbaar');
  263. $this->objects->search->ingevoerd = date("Y-m-d", strtotime("-3 Months"));
  264.  
  265. if ($default)
  266. $this->showTemplate();
  267. }
  268.  
  269. /**
  270. * initialize pageNieuwZakelijk
  271. */
  272. public function pageNieuwZakelijk($default = true)
  273. {
  274. $this->objects->search->bedrijfspand = true;
  275. $this->objects->search->status = array('beschikbaar');
  276. $this->objects->search->ingevoerd = date("Y-m-d", strtotime("-3 Months"));
  277.  
  278. if ($default)
  279. $this->showTemplate();
  280. }
  281.  
  282. /**
  283. * initialize pageVerkocht
  284. */
  285. public function pageVerkocht($default = true)
  286. {
  287. $this->objects->search->status = array('verkocht');
  288. $this->objects->options->sold_interval = 180;
  289.  
  290. if ($default)
  291. $this->showTemplate();
  292. }
  293.  
  294. public function pageVerhuurd($default = true)
  295. {
  296. $this->objects->search->status = array('verhuurd');
  297. $this->objects->options->sold_interval = 180;
  298.  
  299. if ($default)
  300. $this->showTemplate();
  301. }
  302.  
  303. /**
  304. * initialize the bouwgrond view
  305. */
  306. public function pageStarters($default = true)
  307. {
  308. $this->objects->search->woningen = true;
  309. $this->objects->search->status = array('beschikbaar');
  310. $this->objects->search->special = 'starter';
  311.  
  312. if ($default)
  313. $this->showTemplate();
  314. }
  315.  
  316. /**
  317. *
  318. * @return mixed bool|array
  319. * @throws \Exception
  320. */
  321. public function loadObjects()
  322. {
  323. $this->setSearch();
  324. $this->setType();
  325. $this->setMainType();
  326.  
  327. try {
  328. if (($results = $this->objects->load()) !== false) {
  329. // if ($results->total == 1) {
  330. // $url = Helpers\Object::createUrl($results->data[0]);
  331. // header('location: ' . $url);
  332. // exit();
  333. // } else {
  334. $_SESSION['objecttotal'] = $results->totaldata;
  335. return $results;
  336. // }
  337. }
  338. } catch (\PDOException $e) {
  339. //throw new Exceptions\Object('Er is een fout ontstaan bij het ophalen van de objecten', 1204);
  340. }
  341.  
  342. return false;
  343. }
  344.  
  345. /**
  346. *
  347. * @return mixed bool|array
  348. * @throws \Exception
  349. */
  350.  
  351.  
  352. public function setSearch()
  353. {
  354. if (isset($_GET['koophuur'])) {
  355.  
  356. if(is_array($_GET['koophuur'])){
  357. if (in_array('koop',$_GET['koophuur'])){
  358. $this->objects->search->koop = true;
  359. if (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])) {
  360. $this->objects->search->min_koopprijs = $_GET['min_prijs'];
  361. }
  362.  
  363. if (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])) {
  364. $this->objects->search->max_koopprijs = $_GET['max_prijs'];
  365. }
  366. }
  367. if (in_array('huur',$_GET['koophuur'])){
  368. $this->objects->search->huur = true;
  369. if (isset($_GET['min_prijs'])) {
  370. $this->objects->search->min_huurprijs = $_GET['min_prijs'];
  371. }
  372.  
  373. if (isset($_GET['max_prijs'])) {
  374. $this->objects->search->max_huurprijs = $_GET['max_prijs'];
  375. }
  376. }
  377. }else{
  378. if ($_GET['koophuur'] == 'koop') {
  379. $this->objects->search->koop = true;
  380.  
  381. if (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])) {
  382. $this->objects->search->min_koopprijs = $_GET['min_prijs'];
  383. }
  384.  
  385. if (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])) {
  386. $this->objects->search->max_koopprijs = $_GET['max_prijs'];
  387. }
  388.  
  389. } elseif ($_GET['koophuur'] == 'huur') {
  390. $this->objects->search->huur = true;
  391.  
  392. if (isset($_GET['min_prijs'])) {
  393. $this->objects->search->min_huurprijs = $_GET['min_prijs'];
  394. }
  395.  
  396. if (isset($_GET['max_prijs'])) {
  397. $this->objects->search->max_huurprijs = $_GET['max_prijs'];
  398. }
  399.  
  400. }
  401. }
  402. }
  403.  
  404. if (isset($_GET['kamers'])) {
  405. if(is_array($_GET['kamers'])):
  406. foreach($_GET['kamers'] as $kamer):
  407. if((int)$kamer<=$this->objects->search->min_kamers || (int)$this->objects->search->min_kamers==0):
  408. $this->objects->search->min_kamers = $kamer;
  409. endif;
  410. endforeach;
  411. endif;
  412. }
  413.  
  414. if (isset($_GET['query']) && !empty($_GET['query'])) {
  415. if (strstr($_GET['query'], ',')) {
  416. $query = explode(',', $_GET['query']);
  417. $this->objects->search->straat = '%' . trim($query[0]) . '%';
  418. $this->objects->search->plaats = trim($query[1]);
  419. } else if (in_array(trim($_GET['query']), $this->getPlaatsen())) {
  420. $this->objects->search->plaats = $_GET['query'];
  421. } else {
  422. $this->objects->search->trefwoord = $_GET['query'];
  423. }
  424. }
  425.  
  426. if (isset($_GET['plaats']) && !empty($_GET['plaats'])) {
  427. if (strstr($_GET['plaats'], ',')) {
  428. $query = explode(',', $_GET['plaats']);
  429. $this->objects->search->straat = '%' . trim($query[0]) . '%';
  430. $this->objects->search->plaats = trim($query[1]);
  431. } else if (in_array(trim($_GET['plaats']), $this->getPlaatsen())) {
  432. $this->objects->search->plaats = $_GET['plaats'];
  433. } else {
  434. $this->objects->search->trefwoord = $_GET['plaats'];
  435. }
  436. }
  437.  
  438. if (isset($_GET['trefwoord']) && !empty($_GET['trefwoord'])) {
  439. $this->objects->search->trefwoord = $_GET['trefwoord'];
  440. }
  441.  
  442. if (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])) {
  443. $this->objects->search->min_koopprijs = $_GET['min_prijs'];
  444. }
  445. if (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])) {
  446. $this->objects->search->max_koopprijs = $_GET['max_prijs'];
  447. }
  448. if (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])) {
  449. $this->objects->search->min_huurprijs = $_GET['min_prijs'];
  450. }
  451. if (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])) {
  452. $this->objects->search->max_huurprijs = $_GET['max_prijs'];
  453. }
  454.  
  455.  
  456.  
  457. if (isset($_GET['woonoppervlakte']) && !empty($_GET['woonoppervlakte'])) {
  458. if (is_array($_GET['woonoppervlakte'])) {
  459. foreach($_GET['woonoppervlakte'] as $opp):
  460. if((int)$opp<=$this->objects->search->woning->min_woonoppervlakte || (int)$this->objects->search->woning->min_woonoppervlakte===0):
  461. $this->objects->search->woning->min_woonoppervlakte = $opp;
  462. endif;
  463. endforeach;
  464. }else{
  465. $oppervlakte = (int)$_GET['woonoppervlakte'];
  466. if((int)$oppervlakte<=$this->objects->search->woning->min_woonoppervlakte || (int)$this->objects->search->woning->min_woonoppervlakte===0):
  467. $this->objects->search->woning->min_woonoppervlakte = $oppervlakte;
  468. endif;
  469. }
  470. }
  471.  
  472. if (isset($_GET['perceeloppervlakte']) && !empty($_GET['perceeloppervlakte'])) {
  473. if (is_array($_GET['perceeloppervlakte'])) {
  474. foreach($_GET['perceeloppervlakte'] as $opp):
  475. if((int)$opp<=$this->objects->search->woning->min_perceeloppervlakte || (int)$this->objects->search->woning->min_perceeloppervlakte===0):
  476. $this->objects->search->woning->min_perceeloppervlakte = $opp;
  477. endif;
  478. endforeach;
  479. }else{
  480. $oppervlakte = (int)$_GET['perceeloppervlakte'];
  481. if((int)$oppervlakte<=$this->objects->search->woning->min_perceeloppervlakte || (int)$this->objects->search->woning->min_perceeloppervlakte===0):
  482. $this->objects->search->woning->min_perceeloppervlakte = $oppervlakte;
  483. endif;
  484. }
  485. }
  486.  
  487. if (isset($_GET['bouwvorm']) && !empty($_GET['bouwvorm'])) {
  488. if(is_array($_GET['bouwvorm'])){
  489. $this->objects->search->bouwvorm = implode('","',$_GET['bouwvorm']);
  490. }else{
  491. $this->objects->search->bouwvorm = $_GET['bouwvorm'];
  492. }
  493. }
  494.  
  495.  
  496. if ( (isset(Vars::$content->website['link']) && Vars::$content->website['link'] == 'makelaars') ||
  497. (isset($_GET['link']) && $_GET['link'] == 'makelaars') ||
  498. (isset($_GET['link']) && $_GET['link'] == 'zoekresultaten')) {
  499.  
  500. $this->objects->where = '`ob`.`ob_woning` = 1';
  501.  
  502.  
  503. if (isset($_GET['woonoppervlakte']) && is_array($_GET['woonoppervlakte'])) {
  504. foreach($_GET['woonoppervlakte'] as $opp):
  505. if((int)$opp<=$this->objects->search->woning->min_woonoppervlakte || (int)$this->objects->search->woning->min_woonoppervlakte==0):
  506. $this->objects->search->woning->min_woonoppervlakte = $opp* 0.5;
  507. $this->objects->search->woning->max_woonoppervlakte = $opp * 1.5;
  508. endif;
  509. endforeach;
  510.  
  511. }elseif (isset($_GET['woonoppervlakte']) && !empty($_GET['woonoppervlakte'])) {
  512. $oppervlakte = (int) $_GET['woonoppervlakte'];
  513. $this->objects->search->woning->min_woonoppervlakte = $oppervlakte * 0.5;
  514. $this->objects->search->woning->max_woonoppervlakte = $oppervlakte * 1.5;
  515.  
  516. if (isset($_GET['oppervlakte']) && !empty($_GET['oppervlakte'])) {
  517. $oppervlakte = (int) $_GET['oppervlakte'];
  518. $this->objects->search->woning->min_oppervlakte = $oppervlakte * 0.5;
  519. $this->objects->search->woning->max_oppervlakte = $oppervlakte * 1.5;
  520.  
  521. }
  522.  
  523. } elseif((isset(Vars::$content->website['link']) && Vars::$content->website['link'] == 'bedrijfshuisvesting') ||
  524. (isset($_GET['link']) && $_GET['link'] == 'bedrijfshuisvesting')) {
  525.  
  526. $this->objects->where = '`ob`.`ob_bedrijfspand` = 1';
  527.  
  528. if (isset($_GET['bedrijfsruimte_opp']) && !empty($_GET['bedrijfsruimte_opp'])) {
  529. $oppervlakte = (int) $_GET['bedrijfsruimte_opp'];
  530. $this->objects->search->bedrijfspand->soort = 'bedrijfsruimte';
  531. $this->objects->search->bedrijfspand->min_oppervlakte = $oppervlakte * 0.5;
  532. $this->objects->search->bedrijfspand->max_oppervlakte = $oppervlakte * 1.5;
  533. }
  534.  
  535. if (isset($_GET['kantoorruimte_opp']) && !empty($_GET['kantoorruimte_opp'])) {
  536. $oppervlakte = (int) $_GET['kantoorruimte_opp'];
  537. $this->objects->search->bedrijfspand->soort = 'kantoorruimte';
  538. $this->objects->search->bedrijfspand->min_oppervlakte = $oppervlakte * 0.5;
  539. $this->objects->search->bedrijfspand->max_oppervlakte = $oppervlakte * 1.5;
  540. }
  541. }
  542. }
  543.  
  544. }
  545.  
  546. public function setType()
  547. {
  548. if (isset($_GET['type']) && is_array($_GET['type'])) {
  549. foreach ($_GET['type'] as $type) {
  550. switch ($type) {
  551. // Makelaars
  552. case 'Woning':
  553. case 'Woningaanbod':
  554. $this->objects->search->woning = true;
  555. break;
  556. case 'Appartement':
  557. if ($this->objects->search->woning !== true) {
  558. $this->objects->search->woning->soort = 'appartement';
  559. }
  560. break;
  561. case 'Bouwgrond':
  562. $this->objects->search->bouwgrond = true;
  563. break;
  564. case 'Nieuwbouw':
  565. $this->objects->search->nieuwbouw = true;
  566. break;
  567. case 'Garage':
  568. $this->objects->search->garage = true;
  569. break;
  570. // Bedrijfshuisvesting
  571. case 'Kantoorruimte':
  572. if ($this->objects->search->bedrijfspand !== true) {
  573. $this->objects->search->bedrijfspand->soort = 'kantoorruimte';
  574. }
  575. break;
  576. case 'Bedrijfsruimte':
  577. case 'Bedrijfsaanbod':
  578. $this->objects->search->bedrijfspand = true;
  579. break;
  580. case 'Winkelruimte':
  581. $this->objects->search->bedrijfspand->soort = 'winkelruimte';
  582. break;
  583. case 'Horeca':
  584. $this->objects->search->bedrijfspand->soort = 'horeca';
  585. break;
  586. case 'Bouwgrond':
  587. $this->objects->search->garage = true;
  588. break;
  589. }
  590. }
  591. }
  592. }
  593.  
  594. public function setMainType()
  595. {
  596. if (isset($_GET['maintype']) && is_array($_GET['maintype'])) {
  597. foreach ($_GET['maintype'] as $type) {
  598. switch ($type) {
  599. // Makelaars
  600. case 'Woningaanbod':
  601. $this->objects->search->woning = true;
  602. break;
  603. case 'Bedrijfsaanbod':
  604. $this->objects->search->bedrijfspand = true;
  605. break;
  606. }
  607. }
  608. }
  609. }
  610.  
  611. public function requestMaps()
  612. {
  613. try {
  614. $this->setNavigation();
  615.  
  616. if (isset($_GET['view']) && method_exists($this, $_GET['view'])) {
  617. $this->{$_GET['view']}(false);
  618.  
  619. try {
  620. $this->objects->options->pagination = false;
  621.  
  622. $results = $this->loadObjects();
  623. if ($results->total > 0) {
  624. $objects = array();
  625. foreach ($results->data as $object) {
  626. $object->labels = Settings::get('objects', 'labels');
  627.  
  628. if ($object->latitude != false || $object->longitude != false) {
  629. $objects[] = array(
  630. 'adres' => $object->adres,
  631. 'plaats' => $object->plaats,
  632. 'url' => Helpers\Object::createUrl($object),
  633. 'image' => ($object->hoofdfoto !== false ? $object->hoofdfoto->createUrl(600, 400, 'crop') : false),
  634. 'label' => implode(Helpers\Object::getBullets($object)),
  635. 'prijs' => Helpers\Object::getPrijs($object),
  636. 'latitude' => $object->latitude,
  637. 'longitude' => $object->longitude
  638. );
  639. }
  640. }
  641.  
  642. $response = array(
  643. 'error' => false,
  644. 'message' => false,
  645. 'data' => $objects
  646. );
  647. } else {
  648. throw new \Exception('No objects found');
  649. }
  650. } catch (Exceptions\Object $e) {
  651. throw new \Exception($e);
  652. }
  653. } else {
  654. throw new \Exception('View "' . $_GET['view'] . '" not found');
  655. }
  656. } catch (\Exception $e) {
  657. $response = array(
  658. 'error' => false,
  659. 'message' => $e->getMessage()
  660. );
  661. }
  662.  
  663. echo json_encode($response);
  664. }
  665.  
  666. private function formatPlaats($plaats)
  667. {
  668. return ucfirst(strtolower(trim($plaats)));
  669. }
  670.  
  671. public function requestAutocomplete()
  672. {
  673. try {
  674. set_time_limit(0);
  675. $templateWhere = '';
  676. $templateJoin = '';
  677. switch ((isset($_GET['website']) ? $_GET['website'] : '')) {
  678. case 'bedrijfshuisvesting':
  679. $templateWhere = ' AND `ob_bedrijfspand` = 1';
  680. break;
  681. case 'makelaars':
  682. $templateWhere = ' AND `ob_woning` = 1';
  683. break;
  684. }
  685.  
  686. if (isset($_GET['q']) && !empty($_GET['q'])) {
  687. $searchString = $_GET['q'];
  688.  
  689. if (strtolower($searchString) == 'den bosch') {
  690. $searchString = 'hertogenbosch';
  691. }
  692.  
  693. try {
  694. $objects = array();
  695.  
  696. if (preg_match('/[0-9]/', $searchString) === 1) {
  697. $results = $this->db->execute('
  698. SELECT ob_postcode_cf as postcode, count(ob_postcode_cf) as aantal
  699. FROM object
  700. ' . $templateJoin . '
  701. WHERE ob_postcode_cf LIKE :search_string
  702. ' . $templateWhere . '
  703. AND ob_active = 1 and ob_publiceren = 1 and ob_stilAanbod = 0
  704. GROUP BY ob_postcode_cf ORDER BY aantal DESC;', array('search_string' => '%' . $searchString . '%'));
  705. if ($results->rowCount() > 0) {
  706. foreach ($results as $result) {
  707. $objects[] = array(
  708. 'item' => $this->formatPlaats($result['postcode']),
  709. 'numberOf' => $result['aantal'],
  710. );
  711. }
  712. }
  713. } else {
  714. $results = $this->db->execute('
  715. SELECT ob_plaats as plaats, count(ob_plaats) as aantal
  716. FROM object
  717. ' . $templateJoin . '
  718. WHERE ob_plaats LIKE :search_string
  719. ' . $templateWhere . '
  720. AND ob_active = 1 and ob_publiceren = 1 and ob_stilAanbod = 0
  721. GROUP BY ob_plaats ORDER BY aantal DESC;', array('search_string' => '%' . $searchString . '%'));
  722. if ($results->rowCount() > 0) {
  723. foreach ($results as $result) {
  724. $objects[] = array(
  725. 'item' => $this->formatPlaats($result['plaats']),
  726. 'numberOf' => $result['aantal'],
  727. );
  728. }
  729. }
  730.  
  731. $results = $this->db->execute('
  732. SELECT ob_straat as straat , ob_plaats as plaats, count(ob_straat) as aantal
  733. FROM object
  734. ' . $templateJoin . '
  735. WHERE ob_straat LIKE :search_string
  736. ' . $templateWhere . '
  737. AND ob_active = 1 and ob_publiceren = 1 and ob_stilAanbod = 0
  738. GROUP BY ob_plaats ORDER BY aantal DESC;', array('search_string' => '%' . $searchString . '%'));
  739. if ($results->rowCount() > 0) {
  740. foreach ($results as $result) {
  741. $objects[] = array(
  742. 'item' => $this->formatPlaats($result['straat']) . ', ' . $this->formatPlaats($result['plaats']),
  743. 'numberOf' => $result['aantal'],
  744. );
  745. }
  746. }
  747. }
  748.  
  749. if (sizeof($objects) > 0) {
  750. $response = array(
  751. 'error' => false,
  752. 'message' => false,
  753. 'data' => $objects
  754. );
  755. } else {
  756. throw new \Exception('<li>Geen resultaten gevonden</li>');
  757. }
  758.  
  759. } catch (Exceptions\Object $e) {
  760. throw new \Exception($e);
  761. }
  762. } else {
  763. throw new \Exception('Queryparam "' . $_GET['q'] . '" not found');
  764. }
  765. } catch (\Exception $e) {
  766. $response = array(
  767. 'error' => false,
  768. 'message' => $e->getMessage()
  769. );
  770. }
  771.  
  772. echo json_encode($response);
  773. }
  774.  
  775. private function getPlaatsen()
  776. {
  777. $resultArray = array();
  778. $result = $this->db->execute('SELECT DISTINCT(ob_plaats) FROM object WHERE ob_plaats IS NOT NULL ORDER BY ob_plaats ASC;');
  779.  
  780. foreach ($result->fetchAll() as $row) {
  781. $resultArray[] = $row['ob_plaats'];
  782. }
  783.  
  784. return $resultArray;
  785. }
  786. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement