Advertisement
Sdelkadrom

Untitled

Apr 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public static function getObjTypesArray($with_all = false, $apartmentType = null, $apartmentPriceType = null) {
  2. $objTypes = $objTypesJsonData = array();
  3. $objTypeModel = ApartmentObjType::model()->findAll(array(
  4. 'order' => 'sorter'
  5. ));
  6. foreach ($objTypeModel as $type) {
  7. $objTypes[$type->id] = $type->name;
  8. $objTypesJsonData[$type->id] = $type->json_data;
  9. }
  10.  
  11. if (!empty($apartmentType) || !empty($apartmentPriceType)) {
  12. // в функцию передаётся только $apartmentType нужно type конвертнуть в price_type
  13. # Т.е аренда - это вся аренда: посуточно, помесячно и т.д
  14. # продажа - продажа
  15. # Рё С‚.Рї
  16. if (empty($apartmentPriceType)) {
  17. $apartmentPriceType = HApartment::getPriceArray($apartmentType, false, false);
  18.  
  19. $apartmentPriceType = array_keys($apartmentPriceType);
  20.  
  21. if (count($apartmentPriceType) == 1) {
  22. $apartmentPriceType = $apartmentPriceType[0];
  23. }
  24. }
  25.  
  26. foreach($objTypesJsonData as $key => $value) {
  27. $enable = false;
  28.  
  29. if (!empty($value)) {
  30. $valueArr = CJSON::decode($value);
  31.  
  32. if (!empty($valueArr) && isset($valueArr['price_types']) && !empty($valueArr['price_types'])) {
  33. if (!empty($apartmentPriceType)) {
  34. if (!is_array($apartmentPriceType)) {
  35. if (is_numeric(array_search($apartmentPriceType, $valueArr['price_types']))) {
  36. $enable = true;
  37. }
  38. }
  39. else {
  40. if (!empty(array_intersect($valueArr['price_types'], $apartmentPriceType))) {
  41. $enable = true;
  42. }
  43. }
  44. }
  45. }
  46. }
  47.  
  48. if (!$enable) {
  49. if (isset($objTypes[$key])) {
  50. unset($objTypes[$key]);
  51. }
  52. }
  53. }
  54. }
  55.  
  56. if ($with_all) {
  57. $objTypes[0] = tt('All object', 'apartments');
  58. }
  59.  
  60. return $objTypes;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement