Joywork/import/builder/ApartmentBuilder.php
2026-05-22 21:21:54 +03:00

62 lines
2.0 KiB
PHP

<?php
class ApartmentBuilder implements ModelBuilder
{
public function getModelClassName()
{
return Apartment::className();
}
/**
* @param array $data
* @return ImportRecord
*/
public function getModel(array $data)
{
assert('!empty($data)');
assert('!empty($data["id"])');
$id = (int)$data['id'];
$model = Apartment::findOne($id) ?: new Apartment;
$model->id = $id;
$model->block_id = (int)$data['blockid'];
$model->building_id = (int)$data['buildingid'];
$model->room_type_id = (int)$data['rooms']+1;
$model->space_total = Convertor::strToFloat($data['stotal']);
$model->height = Convertor::strToFloat($data['height']);
$model->number = $data['number'];
$model->section = $data['section'];
$model->base_price = (int)$data['flatcostbase'];
$model->meter_price = (int)$data['metrecostbase'];
$model->price = (int)$data['flatcostwithdiscounts'];
$model->discount_price = (int)$data['flatcostwithdiscounts'];
$model->discount_meter_price = (int)$data['metrecostwithdiscounts'];
$model->space_kitchen = $data['skitchen'];
$model->space_corridor = $data['scorridor'];
$model->space_room = $data['sroom'];
$model->space_balcony = $data['sbalcony'];
$model->space_watercloset = $data['swatercloset'];
$model->flat_type_id = (int)$data['flattypeid']+1;
$model->decoration_id = DecorationType::getIdByName($data['decoration']);
$model->subsidy = (int)$data['subsidy'];
$model->creditend = (int)$data['creditend'];
$model->flat_floor = (int)$data['flatfloor'];
if (!empty($data['flatplan'])) {
$model->image = ImageHelper::getFullUrl($data['flatplan']);
}
if (!empty($data['floorplan'])) {
$model->image2 = ImageHelper::getFullUrl($data['floorplan']);
}
return $model;
}
}