Created
June 3, 2019 07:08
-
-
Save qwertik17/3f387f597f84f9c0563bce920e41bbee to your computer and use it in GitHub Desktop.
Domclick feed for modx revo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once MODX_ASSETS_PATH . 'ArrayToXML.php'; | |
$feeds = $developer = $complexes = $sales_info = array(); | |
$site_url = $modx->getOption('site_url'); | |
//Информация о застройщике | |
$developer['id'] = $developer_id; | |
$developer['name'] = $developer_name; | |
$developer['phone'] = $developer_phone; | |
$developer['site'] = $developer_site; | |
$developer['logo'] = $developer_logo; | |
//Информация об офисе продаж | |
$sales_info['sales_phone'] = $sales_info_sales_phone; | |
$sales_info['address'] = $sales_info_address; | |
$sales_info['sales_latitude'] = $sales_info_sales_latitude; | |
$sales_info['sales_longitude'] = $sales_info_sales_longitude; | |
$sales_info['timezone'] = $sales_info_timezone; | |
$sales_info['work_days']['work_day1']['day'] = $sales_info_work_days_work_day1_day; | |
$sales_info['work_days']['work_day1']['open_at'] = $sales_info_work_days_work_day1_open_at; | |
$sales_info['work_days']['work_day1']['close_at'] = $sales_info_work_days_work_day1_close_at; | |
$sales_info['work_days']['work_day2']['day'] = $sales_info_work_days_work_day2_day; | |
$sales_info['work_days']['work_day2']['open_at'] = $sales_info_work_days_work_day2_open_at; | |
$sales_info['work_days']['work_day2']['close_at'] = $sales_info_work_days_work_day2_close_at; | |
$sales_info['work_days']['work_day3']['day'] = $sales_info_work_days_work_day3_day; | |
$sales_info['work_days']['work_day3']['open_at'] = $sales_info_work_days_work_day3_open_at; | |
$sales_info['work_days']['work_day3']['close_at'] = $sales_info_work_days_work_day3_close_at; | |
$sales_info['work_days']['work_day4']['day'] = $sales_info_work_days_work_day4_day; | |
$sales_info['work_days']['work_day4']['open_at'] = $sales_info_work_days_work_day4_open_at; | |
$sales_info['work_days']['work_day4']['close_at'] = $sales_info_work_days_work_day4_close_at; | |
$sales_info['work_days']['work_day5']['day'] = $sales_info_work_days_work_day5_day; | |
$sales_info['work_days']['work_day5']['open_at'] = $sales_info_work_days_work_day5_open_at; | |
$sales_info['work_days']['work_day5']['close_at'] = $sales_info_work_days_work_day5_close_at; | |
$sales_info['responsible_officer_phone'] = $developer_phone; | |
//Получаем список ID корпусов | |
$complex_ids = $modx->runSnippet('pdoResources', array('parents' => 0,'returnIds' => 1,'limit' => 0,'includeTVs' => 'domclick_use','tvPrefix' => '','where' => json_encode(array ('template:IN' => array(9,13),'domclick_use' => 1), true))); | |
$query = $modx->newQuery('modResource'); | |
$query->where(array('id:IN' => explode(',',$complex_ids))); | |
$complexes = $modx->getCollection('modResource', $query); | |
$i = 0; | |
foreach($complexes as $complex) { | |
//Добавляем ID ЖК | |
$feeds['complex'.$i]['id'] = $complex->getTVvalue('domclick_id'); | |
//Добавляем название ЖК | |
$feeds['complex'.$i]['name'] = rep($complex->getTVvalue('domclick_name')); | |
//Добавляем координаты на карте | |
$coords = explode(',', $complex->getTVvalue('coords')); | |
$feeds['complex'.$i]['latitude'] = $coords[0]; | |
$feeds['complex'.$i]['longitude'] = $coords[1]; | |
//Добавляем адрес ЖК | |
$feeds['complex'.$i]['address'] = rep($complex->getTVvalue('domclick_address')); | |
//Добавляем изображения | |
$images = $modx->runSnippet('ms2Gallery', array('resources' => $complex->get('id'),'tplRow' => 'tpl.ms2Gallery.row3','tplOuter' => 'tpl.ms2Gallery.outer','tplEmpty' => 'tpl.ms2Gallery.empty3', 'limit' => 10)); | |
$images = explode('||', str_replace("\n", '', strip_tags($images))); | |
$images_arr = array(); | |
$ii = 0; | |
foreach($images as $image) { | |
$images_arr['image'.$ii] = $image; | |
$ii++; | |
} | |
$feeds['complex'.$i]['images'] = $images_arr; | |
//Добавляем основное описание ЖК | |
$feeds['complex'.$i]['description_main']['text'] = rep($complex->getTVvalue('domclick_description_main')); | |
//Добавляем корпуса | |
$buildings = json_decode($complex->getTVvalue('domclick_buildings')); | |
$iii = 0; | |
foreach($buildings as $building) { | |
//Добавляем информаци о корпусе | |
$feeds['complex'.$i]['buildings']['building'.$iii]['id'] = $building->id; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['fz_214'] = $building->fz_214; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['name'] = $building->name; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['floors'] = $building->floors; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['building_state'] = $building->building_state; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['built_year'] = $building->built_year; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['ready_quarter'] = $building->ready_quarter; | |
$feeds['complex'.$i]['buildings']['building'.$iii]['building_type'] = $building->building_type; | |
//Добавляем квартиры корпуса | |
$flats_ids = $modx->runSnippet('pdoResources', array('parents' => $complex->get('id'),'returnIds' => 1,'limit' => 0,'includeTVs' => 'domclick_use,domclick_select_building','tvPrefix' => '','where' => json_encode(array ('template:IN' => array(10),'domclick_use' => 1,'domclick_select_building' => $building->id), true))); | |
$query = $modx->newQuery('modResource'); | |
$query->where(array('id:IN' => explode(',',$flats_ids))); | |
$flats = $modx->getCollection('modResource', $query); | |
$flats_arr = array(); | |
$iiii = 0; | |
foreach($flats as $flat) { | |
$flats_arr['flat'.$iiii]['apartment'] = 'teh'.$flat->get('id'); | |
$flats_arr['flat'.$iiii]['renovation'] = 'нет'; | |
$flats_arr['flat'.$iiii]['rooms_area']['area'] = '10'; | |
$flats_arr['flat'.$iiii]['decoration'] = '-'; | |
$flats_arr['flat'.$iiii]['ready_housing'] = 1; | |
$flats_arr['flat'.$iiii]['housing_type'] = 1; | |
$flats_arr['flat'.$iiii]['layout_type'] = ' '; | |
$flats_arr['flat'.$iiii]['flat_id'] = $flat->get('id'); | |
if ($floor = $flat->getTVvalue('domclick_floor')) $flats_arr['flat'.$iiii]['floor'] = $floor; | |
if ($room = $flat->getTVvalue('count_room')) $flats_arr['flat'.$iiii]['room'] = $room; | |
if ($plan = $flat->getTVvalue('img_cvar')) { | |
$flats_arr['flat'.$iiii]['plan'] = $site_url . $plan; | |
} else { | |
$flats_arr['flat'.$iiii]['plan'] = 'http://sknvek.ru/uploads/zaglushka.jpg'; | |
} | |
if ($balcony = $flat->getTVvalue('domclick_balcony')) { | |
$flats_arr['flat'.$iiii]['balcony'] = $balcony; | |
} else { | |
$flats_arr['flat'.$iiii]['balcony'] = 'Балкон'; | |
} | |
if ($renovation = $flat->getTVvalue('domclick_renovation')) $flats_arr['flat'.$iiii]['renovation'] = $renovation; | |
if ($flat->getTVvalue('sale_price')) { | |
if ($price = $flat->getTVvalue('sale_price')) $flats_arr['flat'.$iiii]['price'] = $price; | |
} else { | |
if ($price = $flat->getTVvalue('min_price')) $flats_arr['flat'.$iiii]['price'] = $price; | |
} | |
if ($area = $flat->getTVvalue('domclick_area')) { | |
$flats_arr['flat'.$iiii]['area'] = $area; | |
} else { | |
if ($area = $flat->getTVvalue('sum_size')) { | |
$area = str_replace(',', '.', $area); | |
$area = str_replace(' ', '', $area); | |
$flats_arr['flat'.$iiii]['area'] = $area; | |
} else { | |
$flats_arr['flat'.$iiii]['area'] = ''; | |
} | |
} | |
if ($kitchen_area = $flat->getTVvalue('domclick_kitchen_area')) { | |
$flats_arr['flat'.$iiii]['kitchen_area'] = $kitchen_area; | |
} else { | |
$flats_arr['flat'.$iiii]['kitchen_area'] = " "; | |
} | |
if ($living_area = $flat->getTVvalue('domclick_living_area')) { | |
$flats_arr['flat'.$iiii]['living_area'] = $living_area; | |
} else { | |
$flats_arr['flat'.$iiii]['living_area'] = ' '; | |
} | |
if ($window_view = $flat->getTVvalue('domclick_window_view')) { | |
$flats_arr['flat'.$iiii]['window_view'] = $window_view; | |
} else { | |
$flats_arr['flat'.$iiii]['window_view'] = 'Во двор'; | |
} | |
if ($bathroom = $flat->getTVvalue('domclick_bathroom')) { | |
$flats_arr['flat'.$iiii]['bathroom'] = $bathroom; | |
} else { | |
$flats_arr['flat'.$iiii]['bathroom'] = 'Раздельный'; | |
} | |
$iiii++; | |
} | |
$feeds['complex'.$i]['buildings']['building'.$iii]['flats'] = $flats_arr; | |
$iii++; | |
} | |
//Добавляем УТП ЖК | |
$feeds['complex'.$i]['profits_main']['profit_main']['title'] = rep($complex->getTVvalue('domclick_profits_main_title')); | |
$feeds['complex'.$i]['profits_main']['profit_main']['text'] = rep($complex->getTVvalue('domclick_profits_main_text')); | |
$feeds['complex'.$i]['profits_main']['profit_main']['image'] = $site_url . $complex->getTVvalue('domclick_profits_main_image'); | |
//Добавляем информацию об офисе продаж | |
$feeds['complex'.$i]['sales_info'] = $sales_info; | |
//Добавляем застройщика | |
$feeds['complex'.$i]['developer'] = $developer; | |
$i++; | |
} | |
return ArrayToXML::toXML($feeds, 'complexes'); | |
//функции | |
function rep($data) { | |
$data = str_replace(array('«', '»'), '', $data); | |
$data = str_replace('—', '-', $data); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment