Guest User

Untitled

a guest
Feb 3rd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.41 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Modules\Objects\Models;
  4.  
  5. use \Framework\Pagination\Pagination;
  6.  
  7. Class Objects extends \Framework\Models
  8. {
  9.  
  10. /**
  11. * Initialize language object
  12. */
  13. public function __construct()
  14. {
  15. parent::__construct();
  16.  
  17. $this->options = (object) array(
  18. 'pagination' => false,
  19. 'sold_interval' => 30
  20. );
  21.  
  22. $this->search = (object) array(
  23. 'id' => null, // null | int | array
  24. 'system' => null, // null | string
  25. 'system_reference' => null, // null | string
  26. 'bouwtype_reference' => null, // null | string
  27. 'active' => true, // null | true | false
  28. 'publiceren' => true, // null | true | false
  29. 'verborgen' => false, // null | true | false
  30. 'stilAanbod' => false, // null | true | false
  31. 'ingevoerd' => null, // null | date(Y-m-d)
  32. 'gesynchroniseerd' => null, // null | date(Y-m-d)
  33. 'gewijzigd' => null, // null | date(Y-m-d)
  34. 'status_gewijzigd' => null, // null | date(Y-m-d)
  35. 'status' => null, // null | string | array
  36. 'trefwoord' => null, // null | string
  37. 'favorite' => null, // null | string
  38. 'special' => null, // null | string
  39. 'woning' => (object) array(// null | true | false | object
  40. 'recreatie' => null, // null | true | false
  41. 'soort' => null, // null | string
  42. 'woonhuissoort' => null, // null | string
  43. 'woonhuistype' => null, // null | string
  44. 'woonhuiskenmerk' => null, // null | string
  45. 'appartementsoort' => null, // null | string
  46. 'appartementkenmerk' => null, // null | string
  47. 'min_inhoud' => null, // null | int
  48. 'max_inhoud' => null, // null | int
  49. 'min_perceeloppervlakte' => null, // null | int
  50. 'max_perceeloppervlakte' => null, // null | int
  51. 'min_woonoppervlakte' => null, // null | int
  52. 'max_woonoppervlakte' => null, // null | int
  53. 'min_slaapkamers' => null, // null | int
  54. 'max_slaapkamers' => null // null | int
  55. ),
  56. 'bedrijfspand' => (object) array(// null | true | false | object
  57. 'soort' => null, // null | string
  58. 'horecasoort' => null, // null | string
  59. 'min_oppervlakte' => null, // null | int
  60. 'max_oppervlakte' => null, // null | int
  61. 'min_terrein_oppervlakte' => null, // null | int
  62. 'max_terrein_oppervlakte' => null, // null | int
  63. 'min_vloeroppervlakte' => null, // null | int
  64. 'max_vloeroppervlakte' => null, // null | int
  65. 'unitsvanaf' => null, // null | int
  66. 'verdiepingen' => null, // null | int
  67. 'bouwvorm' => null, // null | string
  68. 'inaanbouw' => null // null | true | false
  69. ),
  70. 'agrarisch' => (object) array(// null | true | false | object
  71. 'soort' => null, // null | string
  72. 'min_oppervlakte' => null, // null | int
  73. 'max_oppervlakte' => null, // null | int
  74. 'min_plaatsen_jongvee' => null, // null | int
  75. 'max_plaatsen_jongvee' => null, // null | int
  76. 'min_plaatsen_melkvee' => null, // null | int
  77. 'max_plaatsen_melkvee' => null, // null | int
  78. 'min_glasoppervlakte' => null, // null | int
  79. 'max_glasoppervlakte' => null // null | int
  80. ),
  81. 'garage' => (object) array(// null | true | false | object
  82. 'soort' => null, // null | string
  83. 'capaciteit' => null // null | int
  84. ),
  85. 'bouwgrond' => (object) array(// null | true | false | object
  86. 'huidigebestemming' => null, // null | string
  87. 'huidiggebruik' => null, // null | string
  88. 'min_oppervlakte' => null, // null | int
  89. 'max_oppervlakte' => null, // null | int
  90. 'bouwrijp' => null // null | true | false
  91. ),
  92. 'nieuwbouw' => null, // null | true | false
  93. 'straat' => null, // null | string
  94. 'huisnummer' => null, // null | string
  95. 'toevoeging' => null, // null | string
  96. 'postcode_cf' => null, // null | int
  97. 'postcode_lt' => null, // null | string
  98. 'plaats' => null, // null | string
  99. 'provincie' => null, // null | string
  100. 'land' => null, // null | string
  101. 'koop' => null, // null | true | array('min'=>100000, 'max'=>200000)
  102. 'huur' => null, // null | true | array('min'=>1000, 'max'=>2000)
  103. 'min_koopprijs' => null, // null | int
  104. 'max_koopprijs' => null, // null | int
  105. 'min_huurprijs' => null, // null | int
  106. 'max_huurprijs' => null, // null | int
  107. 'makelaar' => null, // null | int | array
  108. 'bouwvorm' => null, // null | string
  109. 'energielabel' => null, // null | string
  110. 'bouwjaar' => null, // null | int
  111. 'bouwperiode' => null, // null | string
  112. 'customerID' => null, // null | int
  113. 'hoofdfoto' => null, // null | true | false
  114. 'openhuis' => null, // null | true | false
  115. 'min_kamers' => null, // null | int
  116. 'max_kamers' => null // null | int
  117. );
  118.  
  119. $this->order = (object) array(
  120. 'id' => false,
  121. 'system_reference' => false,
  122. 'active' => false,
  123. 'ingevoerd' => false,
  124. 'gesynchroniseerd' => false,
  125. 'gewijzigd' => false,
  126. 'adres' => false,
  127. 'plaats' => false,
  128. 'prijs' => false,
  129. 'energielabel' => false,
  130. 'updates' => false,
  131. 'random' => false,
  132. 'sequence' => array()
  133. );
  134.  
  135. $this->results = (object) array(
  136. 'total' => 0,
  137. 'data' => array(),
  138. 'order' => false,
  139. 'pagination' => false
  140. );
  141. }
  142.  
  143. /**
  144. * setOptions
  145. */
  146. protected function getOptions()
  147. {
  148.  
  149. }
  150.  
  151. /**
  152. * setSearch
  153. */
  154. protected function setSearch()
  155. {
  156.  
  157. // id
  158. if (is_array($this->search->id)) {
  159. $this->query['where'][] = '`ob`.`objectID` IN (' . implode(', ', array_map('intval', $this->search->id)) . ')';
  160. } elseif ($this->search->id != null) {
  161. $this->query['where'][] = '`ob`.`objectID` = :search_id';
  162. $this->query['params']['search_id'] = $this->search->id;
  163. }
  164.  
  165. // system
  166. if ($this->search->system != null) {
  167. $this->query['where'][] = '`ob`.`ob_system` = :search_system';
  168. $this->query['params']['search_system'] = $this->search->system;
  169. }
  170.  
  171. // system_reference
  172. if ($this->search->system_reference != null) {
  173. $this->query['where'][] = '`ob`.`ob_system_reference` = :search_system_reference';
  174. $this->query['params']['search_system_reference'] = $this->search->system_reference;
  175. }
  176.  
  177. // bouwtype_reference
  178. if ($this->search->bouwtype_reference != null) {
  179. $this->query['where'][] = '`ob`.`ob_bouwtype_reference` = :search_bouwtype_reference';
  180. $this->query['params']['search_bouwtype_reference'] = $this->search->bouwtype_reference;
  181. }
  182.  
  183. // active / status
  184. if ($this->search->active === true && (int) $this->options->sold_interval > 0 && is_array($this->search->status) && in_array('verkocht', $this->search->status) && in_array('verhuurd', $this->search->status)) {
  185. $this->query['where'][] = '(`ob`.`ob_active` = 1 OR (`ob`.`ob_status` IN ("verkocht","verhuurd") AND (`ob`.`ob_status_gewijzigd` IS NULL OR ADDDATE(`ob`.`ob_status_gewijzigd`, INTERVAL ' . (int) $this->options->sold_interval . ' DAY) >= NOW())))';
  186. } elseif ($this->search->active === true && (int) $this->options->sold_interval > 0 && is_array($this->search->status) && in_array('verkocht', $this->search->status)) {
  187. $this->query['where'][] = '(`ob`.`ob_active` = 1 OR (`ob`.`ob_status` IN ("verkocht") AND (`ob`.`ob_status_gewijzigd` IS NULL OR ADDDATE(`ob`.`ob_status_gewijzigd`, INTERVAL ' . (int) $this->options->sold_interval . ' DAY) >= NOW())))';
  188. } elseif ($this->search->active === true && (int) $this->options->sold_interval > 0 && is_array($this->search->status) && in_array('verhuurd', $this->search->status)) {
  189. $this->query['where'][] = '(`ob`.`ob_active` = 1 OR (`ob`.`ob_status` IN ("verhuurd") AND (`ob`.`ob_status_gewijzigd` IS NULL OR ADDDATE(`ob`.`ob_status_gewijzigd`, INTERVAL ' . (int) $this->options->sold_interval . ' DAY) >= NOW())))';
  190. } elseif ($this->search->active === true) {
  191. $this->query['where'][] = '`ob`.`ob_active` = 1';
  192. } elseif ($this->search->active === false) {
  193. $this->query['where'][] = '`ob`.`ob_active` = 0';
  194. } elseif ($this->search->active === null) {
  195. $this->query['where'][] = '`ob`.`ob_active` IN (0,1)';
  196. }
  197.  
  198. // status
  199. if (is_array($this->search->status)) {
  200. $this->query['where'][] = '`ob`.`ob_status` IN ("' . implode('", "', $this->search->status) . '")';
  201. } elseif ($this->search->status != null) {
  202. $this->query['where'][] = '`ob`.`ob_status` = :search_status';
  203. $this->query['params']['search_status'] = $this->search->status;
  204. }
  205.  
  206. // publiceren
  207. if ($this->search->publiceren === true) {
  208. $this->query['where'][] = '`ob`.`ob_publiceren` = 1';
  209. } elseif ($this->search->publiceren === false) {
  210. $this->query['where'][] = '`ob`.`ob_publiceren` = 0';
  211. } elseif ($this->search->publiceren === null) {
  212. $this->query['where'][] = '`ob`.`ob_publiceren` IN (0,1)';
  213. }
  214.  
  215. // verborgen
  216. if ($this->search->verborgen === true) {
  217. $this->query['where'][] = '`ob`.`ob_verborgen` = 1';
  218. } elseif ($this->search->verborgen === false) {
  219. $this->query['where'][] = '`ob`.`ob_verborgen` = 0';
  220. } elseif ($this->search->verborgen === null) {
  221. $this->query['where'][] = '`ob`.`ob_verborgen` IN (0,1)';
  222. }
  223.  
  224. // stilAanbod
  225. if ($this->search->stilAanbod === true) {
  226. $this->query['where'][] = '`ob`.`ob_stilAanbod` = 1';
  227. } elseif ($this->search->stilAanbod === false) {
  228. $this->query['where'][] = '`ob`.`ob_stilAanbod` = 0';
  229. } elseif ($this->search->stilAanbod === null) {
  230. $this->query['where'][] = '`ob`.`ob_stilAanbod` IN (0,1)';
  231. }
  232.  
  233. // customerID
  234. if ($this->search->customerID != null) {
  235. $this->query['where'][] = 'FIND_IN_SET(:search_customerID, `ob`.`ob_customerID`)';
  236. $this->query['params']['search_customerID'] = $this->search->customerID;
  237. }
  238.  
  239. // ingevoerd
  240. if ($this->search->ingevoerd != null) {
  241. $this->query['where'][] = '`ob`.`ob_ingevoerd` >= :search_ingevoerd';
  242. $this->query['params']['search_ingevoerd'] = $this->search->ingevoerd;
  243. }
  244.  
  245. // gesynchroniseerd
  246. if ($this->search->gesynchroniseerd != null) {
  247. $this->query['where'][] = '`ob`.`ob_gesynchroniseerd` >= :search_gesynchroniseerd';
  248. $this->query['params']['search_gesynchroniseerd'] = $this->search->gesynchroniseerd;
  249. }
  250.  
  251. // gewijzigd
  252. if ($this->search->gewijzigd != null) {
  253. $this->query['where'][] = 'DATE_FORMAT(`ob`.`ob_gewijzigd`, "%Y-%m-%d") >= :search_gewijzigd';
  254. $this->query['params']['search_gewijzigd'] = $this->search->gewijzigd;
  255. }
  256.  
  257.  
  258. // status_gewijzigd
  259. if ($this->search->status_gewijzigd != null) {
  260. $this->query['where'][] = 'DATE_FORMAT(`ob`.`ob_status_gewijzigd`, "%Y-%m-%d") >= :search_status_gewijzigd';
  261. $this->query['params']['search_status_gewijzigd'] = $this->search->status_gewijzigd;
  262. }
  263.  
  264.  
  265. // soorten
  266. $where = array();
  267. if (($return = $this->searchWoning()) !== false)
  268. $where[] = $return;
  269. if (($return = $this->searchBedrijfspand()) !== false)
  270. $where[] = $return;
  271. if (($return = $this->searchGarage()) !== false)
  272. $where[] = $return;
  273.  
  274. if (sizeof($where) > 0) {
  275. $this->query['where'][] = '(' . implode(' OR ', $where) . ')';
  276. }
  277.  
  278. // trefwoord
  279. if ($this->search->trefwoord != null) {
  280. $this->query['where'][] = '(`ob`.`ob_plaats` LIKE :search_keyword '
  281. . ' OR CONCAT_WS(" ",`ob`.`ob_straat`,`ob`.`ob_huisnummer`, `ob`.`ob_toevoeging`) LIKE :search_keyword'
  282. . ' OR CONCAT_WS(" ",`ob`.`ob_postcode_cf`,`ob`.`ob_postcode_lt`) LIKE :search_keyword'
  283. . ' OR CONCAT(`ob`.`ob_postcode_cf`,`ob`.`ob_postcode_lt`) LIKE :search_keyword'
  284. . ' OR `ob`.`ob_omschrijving` LIKE :search_keyword)';
  285. $this->query['params']['search_keyword'] = $this->search->trefwoord;
  286. }
  287.  
  288. // nieuwbouw
  289. if ($this->search->nieuwbouw === true) {
  290. $this->query['where'][] = '`ob`.`ob_nieuwbouw` = 1';
  291. } elseif ($this->search->nieuwbouw === false) {
  292. $this->query['where'][] = '`ob`.`ob_nieuwbouw` = 0';
  293. }
  294.  
  295. // straat
  296. if ($this->search->straat !== null) {
  297. $this->query['where'][] = '`ob`.`ob_straat` LIKE :search_straat';
  298. $this->query['params']['search_straat'] = $this->search->straat;
  299. }
  300.  
  301. // huisnummer
  302. if ($this->search->huisnummer !== null) {
  303. $this->query['where'][] = '`ob`.`ob_huisnummer` = :search_huisnummer';
  304. $this->query['params']['search_huisnummer'] = $this->search->huisnummer;
  305. }
  306.  
  307. // toevoeging
  308. if ($this->search->toevoeging !== null) {
  309. $this->query['where'][] = '`ob`.`ob_toevoeging` = :search_toevoeging';
  310. $this->query['params']['search_toevoeging'] = $this->search->toevoeging;
  311. }
  312.  
  313. // postcode_cf
  314. if ($this->search->postcode_cf !== null) {
  315. $this->query['where'][] = '`ob`.`ob_postcode_cf` = ' . (int) $this->search->postcode_cf;
  316. }
  317.  
  318. // postcode_lt
  319. if ($this->search->postcode_lt !== null) {
  320. $this->query['where'][] = '`ob`.`ob_postcode_lt` = :search_postcode_lt';
  321. $this->query['params']['search_postcode_lt'] = strtoupper($this->search->postcode_lt);
  322. }
  323.  
  324. // plaats
  325. if ($this->search->plaats !== null) {
  326. if (is_array($this->search->plaats)) {
  327. $this->query['where'][] = 'LOWER(`ob`.`ob_plaats`) IN ("' . implode('","', array_map('strtolower', $this->search->plaats)) . '")';
  328. } else {
  329. $this->query['where'][] = '`ob`.`ob_plaats` LIKE :search_plaats';
  330. $this->query['params']['search_plaats'] = $this->search->plaats;
  331. }
  332. }
  333.  
  334. // provincie
  335. if ($this->search->provincie !== null) {
  336. $this->query['where'][] = '`ob`.`ob_provincie` = :search_provincie';
  337. $this->query['params']['search_provincie'] = $this->search->provincie;
  338. }
  339.  
  340. // land
  341. if ($this->search->land !== null) {
  342. $this->query['where'][] = '`ob`.`ob_land` = :search_land';
  343. $this->query['params']['search_land'] = $this->search->land;
  344. }
  345.  
  346. // koop
  347. if (is_array($this->search->koop)) {
  348. // array('min'=>100000, 'max'=>200000)
  349. } elseif ($this->search->koop === true) {
  350. $this->query['where'][] = '`ob`.`ob_koop` = 1';
  351. }
  352.  
  353. // huur
  354. if (is_array($this->search->huur)) {
  355. // array('min'=>100000, 'max'=>200000)
  356. } elseif ($this->search->huur === true) {
  357. $this->query['where'][] = '`ob`.`ob_huur` = 1';
  358. }
  359.  
  360. // min_koopprijs
  361. if ($this->search->min_koopprijs !== null) {
  362. $this->query['where'][] = '(`ob`.`ob_koopprijs` >= :search_min_koopprijs OR `ob`.`ob_koopprijs` = 0)';
  363. $this->query['params']['search_min_koopprijs'] = $this->search->min_koopprijs;
  364. }
  365.  
  366. // max_koopprijs
  367. if ($this->search->max_koopprijs !== null) {
  368. $this->query['where'][] = '`ob`.`ob_koopprijs` <= :search_max_koopprijs';
  369. $this->query['params']['search_max_koopprijs'] = $this->search->max_koopprijs;
  370. }
  371.  
  372. // min_huurprijs
  373. if ($this->search->min_huurprijs !== null) {
  374. $this->query['where'][] = '(`ob`.`ob_huurprijs` >= :search_min_huurprijs OR `ob`.`ob_huurprijs` = 0)';
  375. $this->query['params']['search_min_huurprijs'] = $this->search->min_huurprijs;
  376. }
  377.  
  378. // max_huurprijs
  379. if ($this->search->max_huurprijs !== null) {
  380. $this->query['where'][] = '`ob`.`ob_huurprijs` <= :search_max_huurprijs';
  381. $this->query['params']['search_max_huurprijs'] = $this->search->max_huurprijs;
  382. }
  383.  
  384.  
  385. // min_kamers
  386. if ($this->search->min_kamers !== null) {
  387. $this->query['where'][] = '(`obw`.`obw_kamers` >= :search_min_kamers)';
  388. $this->query['params']['search_min_kamers'] = $this->search->min_kamers;
  389. }
  390.  
  391. // max_kamers
  392. if ($this->search->max_kamers !== null) {
  393. $this->query['where'][] = '`obw`.`obw_kamers` <= :search_max_kamers';
  394. $this->query['params']['search->max_kamers'] = $this->search->max_kamers;
  395. }
  396.  
  397. // makelaar
  398. if (is_array($this->search->makelaar)) {
  399. $this->query['where'][] = '`ob`.`ob_makelaarID` IN (' . implode(', ', array_map('intval', $this->search->makelaar)) . ')';
  400. } elseif ($this->search->makelaar !== null) {
  401. $this->query['where'][] = '`ob`.`ob_makelaarID` = :search_makelaar';
  402. $this->query['params']['search_makelaar'] = $this->search->makelaar;
  403. }
  404.  
  405. // bouwvorm
  406. if ($this->search->bouwvorm != null) {
  407. if(strstr($this->search->bouwvorm,',')){
  408. $this->query['where'][] = '`ob`.`ob_bouwvorm` IN ("' . $this->search->bouwvorm . '")';
  409. }else{
  410. $this->query['where'][] = '`ob`.`ob_bouwvorm` = :search_bouwvorm';
  411. $this->query['params']['search_bouwvorm'] = $this->search->bouwvorm;
  412. }
  413. }
  414.  
  415. // energielabel
  416. if ($this->search->energielabel != null) {
  417. $this->query['where'][] = '`ob`.`ob_energielabel` = :search_energielabel';
  418. $this->query['params']['search_energielabel'] = $this->search->energielabel;
  419. }
  420.  
  421. // bouwjaar
  422. if ($this->search->bouwjaar != null) {
  423. $this->query['where'][] = '`ob`.`ob_bouwjaar` = ' . (int) $this->search->bouwjaar;
  424. }
  425.  
  426. // favorieten
  427. if ($this->search->favorite != null) {
  428. $this->query['where'][] = '`obf`.`obf_favorite_hash` = "' . $this->search->favorite . '"';
  429. }
  430.  
  431. // bouwperiode
  432. if ($this->search->bouwperiode != null) {
  433. $this->query['where'][] = '`ob`.`ob_bouwperiode` = :search_bouwperiode';
  434. $this->query['params']['search_bouwperiode'] = $this->search->bouwperiode;
  435. }
  436.  
  437. // hoofdfoto
  438. if ($this->search->hoofdfoto === true) {
  439. $this->query['where'][] = '`ob`.`ob_hoofdfoto` IS NOT NULL';
  440. }
  441.  
  442. // special
  443. if ($this->search->special != null) {
  444. $this->query['where'][] = '`ob`.`ob_special` = :search_special';
  445. $this->query['params']['search_special'] = $this->search->special;
  446. }
  447.  
  448.  
  449. // openhuis
  450. if ($this->search->openhuis === true) {
  451. $this->query['where'][] = 'DATE_FORMAT(`ob`.`ob_openhuis_van`, "%Y-%m-%d") >= CURDATE()';
  452. } elseif ($this->search->openhuis === false) {
  453. $this->query['where'][] = '`ob`.`ob_openhuis_van` IS NULL';
  454. }
  455. }
  456.  
  457. protected function searchWoning()
  458. {
  459. $where = array();
  460.  
  461. // woning
  462. if (is_object($this->search->woning)) {
  463. foreach ($this->search->woning as $key => $value) {
  464. if ($key == 'recreatie') {
  465. if ($value === true) {
  466. $where[] = '`obw`.`obw_recreatie` = 1';
  467. } elseif ($value === false) {
  468. $where[] = '`obw`.`obw_recreatie` = 0';
  469. }
  470. } elseif (preg_match('/^min_/', $key)) {
  471. if ((int) $value > 0) {
  472. $where[] = '`obw`.`obw_' . str_replace('min_', '', $key) . '` >= :woning_' . $key;
  473. $this->query['params']['woning_' . $key] = $value;
  474. }
  475. } elseif (preg_match('/^max_/', $key)) {
  476. if ((int) $value > 0) {
  477. $where[] = '`obw`.`obw_' . str_replace('max_', '', $key) . '` <= :woning_' . $key;
  478. $this->query['params']['woning_' . $key] = $value;
  479. }
  480. } elseif ($value !== null) {
  481. $where[] = '`obw`.`obw_' . $key . '` = :woning_' . $key;
  482. $this->query['params']['woning_' . $key] = $value;
  483. }
  484. }
  485. }
  486.  
  487.  
  488. if ($this->search->woning === true || sizeof($where) > 0) {
  489. //$this->query['join'][] = 'LEFT JOIN `object_woning` `obw` ON (`obw`.`obw_objectID` = `ob`.`objectID`)';
  490. array_unshift($where, '`ob`.`ob_woning` = 1');
  491.  
  492. return '(' . implode(' AND ', $where) . ')';
  493. }
  494.  
  495. return false;
  496. }
  497.  
  498. protected function searchBedrijfspand()
  499. {
  500. $where = array();
  501.  
  502. // bedrijfspand
  503. if (is_object($this->search->bedrijfspand)) {
  504. // soort
  505. if ($this->search->bedrijfspand->soort !== null) {
  506. $where[] = '(`obb`.`obb_soort_1` = :bedrijf_soort OR `obb`.`obb_soort_2` = :bedrijf_soort)';
  507. $this->query['params']['bedrijf_soort'] = $this->search->bedrijfspand->soort;
  508.  
  509. switch ($this->search->bedrijfspand->soort) {
  510. case 'bedrijfsruimte':
  511. // min_oppervlakte
  512. if ($this->search->bedrijfspand->min_oppervlakte !== null) {
  513. $where[] = '(`obb`.`obb_bedrijfshal_oppervlakte` >= :bedrijf_min_oppervlakte '
  514. . ' OR `obb`.`obb_winkelruimte_oppervlakte` >= :bedrijf_min_oppervlakte'
  515. . ' OR `obb`.`obb_horeca_oppervlakte` >= :bedrijf_min_oppervlakte'
  516. . ' OR `obb`.`obb_kantoorruimte_oppervlakte` >= :bedrijf_min_oppervlakte'
  517. . ' OR `obb`.`obb_terrein_oppervlakte` >= :bedrijf_min_oppervlakte)';
  518. $this->query['params']['bedrijf_min_oppervlakte'] = (int) $this->search->bedrijfspand->min_oppervlakte;
  519. }
  520. // max_oppervlakte
  521. if ($this->search->bedrijfspand->max_oppervlakte !== null) {
  522. $where[] = '(`obb`.`obb_bedrijfshal_oppervlakte` <= :bedrijf_max_oppervlakte '
  523. . ' AND `obb`.`obb_winkelruimte_oppervlakte` <= :bedrijf_max_oppervlakte'
  524. . ' AND `obb`.`obb_horeca_oppervlakte` <= :bedrijf_max_oppervlakte'
  525. . ' AND `obb`.`obb_kantoorruimte_oppervlakte` <= :bedrijf_max_oppervlakte'
  526. . ' AND `obb`.`obb_terrein_oppervlakte` <= :bedrijf_max_oppervlakte)';
  527. $this->query['params']['bedrijf_max_oppervlakte'] = (int) $this->search->bedrijfspand->max_oppervlakte;
  528. }
  529. // unitsvanaf
  530. if ($this->search->bedrijfspand->unitsvanaf !== null) {
  531. $where[] = '`obb`.`obb_bedrijfshal_inunitsvanaf` = ' . (int) $this->search->bedrijfspand->unitsvanaf;
  532. }
  533. break;
  534. case 'bouwgrond':
  535. break;
  536. case 'horeca':
  537. // horecasoort
  538. if ($this->search->bedrijfspand->soort == 'horeca' && $this->search->bedrijfspand->horecasoort !== null) {
  539. $where[] = '`obb`.`obb_horeca_soort` = :bedrijf_horecasoort';
  540. $this->query['params']['bedrijf_horecasoort'] = $this->search->bedrijfspand->horecasoort;
  541. }
  542. // min_oppervlakte
  543. if ($this->search->bedrijfspand->min_oppervlakte !== null) {
  544. $where[] = '`obb`.`obb_horeca_oppervlakte` >= ' . (int) $this->search->bedrijfspand->min_oppervlakte;
  545. }
  546. // max_oppervlakte
  547. if ($this->search->bedrijfspand->max_oppervlakte !== null) {
  548. $where[] = '`obb`.`obb_horeca_oppervlakte` <= ' . (int) $this->search->bedrijfspand->max_oppervlakte;
  549. }
  550. // unitsvanaf
  551. if ($this->search->bedrijfspand->unitsvanaf !== null) {
  552. $where[] = '`obb`.`obb_horeca_inunitsvanaf` = ' . (int) $this->search->bedrijfspand->unitsvanaf;
  553. }
  554. break;
  555. case 'overig':
  556. break;
  557. case 'winkelruimte':
  558. // min_oppervlakte
  559. if ($this->search->bedrijfspand->min_oppervlakte !== null) {
  560. $where[] = '`obb`.`obb_winkelruimte_oppervlakte` >= ' . (int) $this->search->bedrijfspand->min_oppervlakte;
  561. }
  562. // max_oppervlakte
  563. if ($this->search->bedrijfspand->max_oppervlakte !== null) {
  564. $where[] = '`obb`.`obb_winkelruimte_oppervlakte` <= ' . (int) $this->search->bedrijfspand->max_oppervlakte;
  565. }
  566. // unitsvanaf
  567. if ($this->search->bedrijfspand->unitsvanaf !== null) {
  568. $where[] = '`obb`.`obb_winkelruimte_inunitsvanaf` = ' . (int) $this->search->bedrijfspand->unitsvanaf;
  569. }
  570. // verdiepingen
  571. if ($this->search->bedrijfspand->verdiepingen !== null) {
  572. $where[] = '`obb`.`obb_winkelruimte_verdiepingen` = ' . (int) $this->search->bedrijfspand->verdiepingen;
  573. }
  574. break;
  575. case 'bouwgrond':
  576. break;
  577. case 'kantoorruimte':
  578. // min_oppervlakte
  579. if ($this->search->bedrijfspand->min_oppervlakte !== null) {
  580. $where[] = '`obb`.`obb_kantoorruimte_oppervlakte` >= ' . (int) $this->search->bedrijfspand->min_oppervlakte;
  581. }
  582. // max_oppervlakte
  583. if ($this->search->bedrijfspand->max_oppervlakte !== null) {
  584. $where[] = '`obb`.`obb_kantoorruimte_oppervlakte` <= ' . (int) $this->search->bedrijfspand->max_oppervlakte;
  585. }
  586. // unitsvanaf
  587. if ($this->search->bedrijfspand->unitsvanaf !== null) {
  588. $where[] = '`obb`.`obb_kantoorruimte_inunitsvanaf` = ' . (int) $this->search->bedrijfspand->unitsvanaf;
  589. }
  590. // verdiepingen
  591. if ($this->search->bedrijfspand->verdiepingen !== null) {
  592. $where[] = '`obb`.`obb_kantoorruimte_verdiepingen` = ' . (int) $this->search->bedrijfspand->verdiepingen;
  593. }
  594. break;
  595. case 'buitenterrein':
  596. break;
  597. case 'praktijkruimte':
  598. break;
  599. case 'showroom':
  600. break;
  601. }
  602. }
  603.  
  604. // min_terrein_oppervlakte
  605. if ($this->search->bedrijfspand->min_terrein_oppervlakte !== null) {
  606. $where[] = '`obb`.`obb_terrein_oppervlakte` >= ' . (int) $this->search->bedrijfspand->min_terrein_oppervlakte;
  607. }
  608.  
  609. // max_terrein_oppervlakte
  610. if ($this->search->bedrijfspand->max_terrein_oppervlakte !== null) {
  611. $where[] = '`obb`.`obb_terrein_oppervlakte` <= ' . (int) $this->search->bedrijfspand->max_terrein_oppervlakte;
  612. }
  613.  
  614. // min_vloeroppervlakte
  615. if ($this->search->bedrijfspand->min_vloeroppervlakte !== null) {
  616. $where[] = '`obb`.`obb_vloeroppervlakte` >= ' . (int) $this->search->bedrijfspand->min_vloeroppervlakte;
  617. }
  618.  
  619. // max_vloeroppervlakte
  620. if ($this->search->bedrijfspand->max_vloeroppervlakte !== null) {
  621. $where[] = '`obb`.`obb_vloeroppervlakte` <= ' . (int) $this->search->bedrijfspand->max_vloeroppervlakte;
  622. }
  623.  
  624. // bouwvorm
  625. if ($this->search->bedrijfspand->bouwvorm !== null) {
  626. $where[] = '`obb`.`obb_bouwvorm` = :bedrijf_bouwvorm';
  627. $this->query['params']['bedrijf_bouwvorm'] = $this->search->bedrijfspand->bouwvorm;
  628. }
  629.  
  630. // inaanbouw
  631. if ($this->search->bedrijfspand->inaanbouw !== null) {
  632. $where[] = '`obb`.`obb_inaanbouw` = :bedrijf_inaanbouw';
  633. $this->query['params']['bedrijf_inaanbouw'] = $this->search->bedrijfspand->inaanbouw;
  634. }
  635. }
  636.  
  637. if ($this->search->bedrijfspand === true || sizeof($where) > 0) {
  638. //$this->query['join'][] = 'LEFT JOIN `object_bedrijfspand` `obb` ON (`obb`.`obb_objectID` = `ob`.`objectID`)';
  639. $where[] = '`ob`.`ob_bedrijfspand` = 1';
  640.  
  641. return '(' . implode(' AND ', $where) . ')';
  642. }
  643.  
  644. return false;
  645. }
  646.  
  647. /**
  648. *
  649. * @return mixed
  650. */
  651. protected function searchAgrarisch()
  652. {
  653. $where = array();
  654.  
  655. // agrarisch
  656. if (is_object($this->search->agrarisch)) {
  657. foreach ($this->search->agrarisch as $key => $value) {
  658. if ($key == 'soort') {
  659. if ($value !== null) {
  660. $where[] = '`oba`.`oba_agrarischsoort` = :agrarisch_soort';
  661. $this->query['params']['agrarisch_soort'] = $value;
  662. }
  663. } elseif (preg_match('/^min_/', $key)) {
  664. if ((int) $value > 0) {
  665. $where[] = '`oba`.`oba_' . str_replace('min_', '', $key) . '` >= :agrarisch_' . $key;
  666. $this->query['params']['agrarisch_' . $key] = $value;
  667. }
  668. } elseif (preg_match('/^max_/', $key)) {
  669. if ((int) $value > 0) {
  670. $where[] = '`oba`.`oba_' . str_replace('max_', '', $key) . '` <= :agrarisch_' . $key;
  671. $this->query['params']['agrarisch_' . $key] = $value;
  672. }
  673. }
  674. }
  675. }
  676.  
  677. if ($this->search->agrarisch === true || sizeof($where) > 0) {
  678. //$this->query['join'][] = 'LEFT JOIN `object_agrarisch` `oba` ON (`oba`.`oba_objectID` = `ob`.`objectID`)';
  679. $where[] = '`ob`.`ob_agrarisch` = 1';
  680.  
  681. return '(' . implode(' AND ', $where) . ')';
  682. }
  683.  
  684. return false;
  685. }
  686.  
  687. protected function searchGarage()
  688. {
  689. $where = array();
  690.  
  691. if (is_object($this->search->garage)) {
  692. // soort
  693. if ($this->search->garage->soort !== null) {
  694. $where[] = '(`obg`.`obg_garagesoort1` = :garage_soort OR `obg`.`obg_garagesoort2` = :garage_soort)';
  695. $this->query['params']['garage_soort'] = $this->search->garage->soort;
  696. }
  697. // capaciteit
  698. if ($this->search->garage->capaciteit !== null) {
  699. $where[] = '`obg`.`obg_capaciteit` = ' . (int) $this->search->garage->capaciteit;
  700. }
  701. }
  702.  
  703. if ($this->search->garage === true || sizeof($where) > 0) {
  704. //$this->query['join'][] = 'LEFT JOIN `object_garage` `obg` ON (`obg`.`obg_objectID` = `ob`.`objectID`)';
  705. $where[] = '`ob`.`ob_garage` = 1';
  706.  
  707. return '(' . implode(' AND ', $where) . ')';
  708. }
  709.  
  710. return false;
  711. }
  712.  
  713. protected function searchBouwgrond()
  714. {
  715. $where = array();
  716.  
  717. if (is_object($this->search->bouwgrond)) {
  718. // soort
  719. if ($this->search->bouwgrond->huidigebestemming !== null) {
  720. $where[] = '`obg`.`obd_huidigebestemming` = :bouwgrond_huidigebestemming';
  721. $this->query['params']['bouwgrond_huidigebestemming'] = $this->search->bouwgrond->huidigebestemming;
  722. }
  723. // huidiggebruik
  724. if ($this->search->bouwgrond->huidiggebruik !== null) {
  725. $where[] = '`obg`.`obd_huidiggebruik` = :bouwgrond_huidiggebruik';
  726. $this->query['params']['bouwgrond_huidiggebruik'] = $this->search->bouwgrond->huidiggebruik;
  727. }
  728. // min_oppervlakte
  729. if ($this->search->bouwgrond->min_oppervlakte !== null) {
  730. $where[] = '`obd`.`obd_oppervlakte` >= ' . (int) $this->search->bouwgrond->min_oppervlakte;
  731. }
  732. // max_oppervlakte
  733. if ($this->search->bouwgrond->max_oppervlakte !== null) {
  734. $where[] = '`obd`.`obd_oppervlakte` <= ' . (int) $this->search->bouwgrond->max_oppervlakte;
  735. }
  736. // huidiggebruik
  737. if ($this->search->bouwgrond->bouwrijp === true) {
  738. $where[] = '`obg`.`obd_bouwrijp` = 1';
  739. } elseif ($this->search->bouwgrond->bouwrijp === false) {
  740. $where[] = '`obg`.`obd_bouwrijp` = 0';
  741. }
  742. }
  743.  
  744. if ($this->search->bouwgrond === true || sizeof($where) > 0) {
  745. //$this->query['join'][] = 'LEFT JOIN `object_bouwgrond` `obd` ON (`obd`.`obd_objectID` = `ob`.`objectID`)';
  746. $where[] = '`ob`.`ob_bouwgrond` = 1';
  747.  
  748. return '(' . implode(' AND ', $where) . ')';
  749. }
  750.  
  751. return false;
  752. }
  753.  
  754. /**
  755. * getOrder
  756. */
  757. protected function getOrder()
  758. {
  759.  
  760. if (sizeof($this->order->sequence) == 0) {
  761. $this->setOrder('adres', 'asc');
  762. }
  763.  
  764. if (sizeof($this->order->sequence) > 0) {
  765. foreach ($this->order->sequence as $type) {
  766. switch ($type) {
  767. case 'id':
  768. $this->query['order'][] = sprintf('`objectID` %1$s', strtoupper($this->order->id));
  769. break;
  770. case 'system_reference':
  771. $this->query['order'][] = sprintf('`ob_system_reference` %1$s', strtoupper($this->order->system_reference));
  772. break;
  773. case 'active':
  774. $this->query['order'][] = sprintf('`ob_active` %1$s', strtoupper($this->order->active));
  775. break;
  776. case 'ingevoerd':
  777. $this->query['order'][] = sprintf('`ob_ingevoerd` %1$s', strtoupper($this->order->ingevoerd));
  778. break;
  779. case 'gesynchroniseerd':
  780. $this->query['order'][] = sprintf('`ob_gesynchroniseerd` %1$s', strtoupper($this->order->gesynchroniseerd));
  781. break;
  782. case 'gewijzigd':
  783. $this->query['order'][] = sprintf('`ob_gewijzigd` %1$s', strtoupper($this->order->gewijzigd));
  784. break;
  785. case 'adres':
  786. $this->query['order'][] = sprintf('`ob_straat` %1$s, `ob_huisnummer` %1$s, `ob_toevoeging` %1$s', strtoupper($this->order->adres));
  787. break;
  788. case 'plaats':
  789. $this->query['order'][] = sprintf('`ob_plaats` %1$s', strtoupper($this->order->plaats));
  790. break;
  791. case 'prijs':
  792. $this->query['order'][] = sprintf('`ob_koopprijs` %1$s, `ob_huurprijs` %1$s', strtoupper($this->order->prijs));
  793. break;
  794. case 'energielabel':
  795. $this->query['order'][] = sprintf('`ob_energielabel` %1$s', strtoupper($this->order->energielabel));
  796. break;
  797. case 'status':
  798. $this->query['order'][] = sprintf('`ob_status` %1$s', strtoupper($this->order->status));
  799. break;
  800. case 'updates':
  801. $this->query['order'][] = sprintf('GREATEST(`ob`.`ob_status_gewijzigd`, IFNULL(`ob`.`ob_afbeeldingen_gewijzigd`, 0), IFNULL(`ob`.`ob_prijs_gewijzigd`, 0)) %1$s', strtoupper($this->order->updates));
  802. break;
  803. case 'oppervlakte':
  804. $this->query['order'][] = sprintf('`ob_status` %1$s', strtoupper($this->order->status));
  805. break;
  806. }
  807. }
  808. }
  809.  
  810. if ($this->order->random) {
  811. $this->query['order'] = array('RAND()');
  812. } else {
  813. $this->query['order'] = array_unique($this->query['order']);
  814. }
  815. }
  816.  
  817. /**
  818. * buildQuery
  819. */
  820. public function buildQuery($nolimit = false)
  821. {
  822. $this->getOptions();
  823. $this->setSearch();
  824. $this->getOrder();
  825.  
  826. // LIMIT en offset berekenen
  827. if (!$nolimit) {
  828. $select = $this->query['select'];
  829. if (!is_null($this->query['limit'])) {
  830. $offset = 0;
  831. $limit = $this->query['limit'];
  832. } elseif ((int) $this->options->pagination > 0) {
  833. $current = (isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 1);
  834. $limit = $this->options->pagination;
  835. $offset = (($current > 0 ? ($current - 1) : 0) * $limit);
  836.  
  837. if (!is_null($this->query['limit'])) {
  838. $interval = intval($this->query['limit'] / $limit);
  839. if ($limit < $this->query['limit']) {
  840. if (($current - 1) == $interval) {
  841. $limit = ($this->query['limit'] % $limit);
  842. }
  843. } else {
  844. $limit = $this->query['limit'];
  845. }
  846. }
  847. }
  848. }else{
  849. $select = '`ob`.`objectID`';
  850. }
  851.  
  852. return sprintf('SELECT %1$s ' .
  853. 'FROM `object` `ob` ' .
  854. 'LEFT JOIN `object_woning` `obw` ON (`obw`.`obw_objectID` = `ob`.`objectID`) ' .
  855. 'LEFT JOIN `object_bedrijfspand` `obb` ON (`obb`.`obb_objectID` = `ob`.`objectID`) ' .
  856. 'LEFT JOIN `object_agrarisch` `oba` ON (`oba`.`oba_objectID` = `ob`.`objectID`) ' .
  857. 'LEFT JOIN `object_garage` `obg` ON (`obg`.`obg_objectID` = `ob`.`objectID`) ' .
  858. 'LEFT JOIN `object_bouwgrond` `obd` ON (`obd`.`obd_objectID` = `ob`.`objectID`)' .
  859. 'LEFT JOIN `object_favorite` `obf` ON (`obf`.`obf_objectID` = `ob`.`objectID`)' .
  860. '%2$s%3$s%4$s%7$s%5$s%6$s',
  861. /* 1 */ $select,
  862. /* 2 */ (sizeof($this->query['join']) > 0 ? implode(' ', $this->query['join']) : ''),
  863. /* 3 */ (sizeof($this->query['where']) > 0 ? ' WHERE ' . implode(' AND ', array_unique($this->query['where'])) : ''),
  864. /* 4 */ (!empty($this->query['group']) ? ' GROUP BY `' . $this->query['group'] . '`' : ''),
  865. /* 5 */ (sizeof($this->query['order']) > 0 ? ' ORDER BY ' . implode(', ', array_unique($this->query['order'])) : ''),
  866. /* 6 */ (isset($offset) && isset($limit) ? ' LIMIT ' . $offset . ',' . $limit : ''),
  867. /* 7 */ (!empty($this->query['having']) ? ' HAVING ' . implode(', ', array_unique($this->query['having'])) . '' : ''));
  868. }
  869.  
  870. /**
  871. * Load all the requested pages
  872. * @param array $data
  873. * @return bool
  874. */
  875. public function load($debug = false)
  876. {
  877. $query = $this->buildQuery();
  878. $query_total = $this->buildQuery(true);
  879.  
  880. if (sizeof($this->query['params']) > 0) {
  881. $results = $this->db->execute($query, $this->query['params']);
  882. if ($debug) $this->db->info();
  883. $results_total = $this->db->execute($query_total, $this->query['params']);
  884. } else {
  885. $results = $this->db->query($query);
  886. if ($debug) $this->db->info();
  887. $results_total = $this->db->query($query_total);
  888. }
  889.  
  890. if ($results->rowCount() > 0) {
  891. $rows = $results->fetchAll();
  892.  
  893. $rows_total = $results_total->fetchAll(\PDO::FETCH_COLUMN, 0);
  894.  
  895.  
  896.  
  897. $this->results->total = count($rows_total);
  898. $this->results->totaldata = $rows_total;
  899.  
  900. $this->results->data = array();
  901. foreach ($rows as $row) {
  902. $object = new Object($row);
  903. $this->results->data[] = $object;
  904. }
  905.  
  906. if ($this->options->pagination !== false) {
  907. $this->results->pagination = new Pagination($this->results->total, $this->options->pagination);
  908. }
  909.  
  910. return $this->results;
  911. }
  912.  
  913. return false;
  914. }
  915. }
Add Comment
Please, Sign In to add comment