コード例 #1
0
ファイル: XMLFeedItem.php プロジェクト: barricade86/raui
 public static function populate($XMLItem, $lists)
 {
     $new = new XMLFeedItem();
     $new->internal_id = (int) $XMLItem['internal-id'];
     $new->appType = array_key_exists((string) $XMLItem->type, $lists['types']) ? $lists['types'][(string) $XMLItem->type] : null;
     $country = null;
     if (isset($XMLItem->location->country)) {
         $criteria = new CDbCriteria();
         $criteria->compare('name_ru', (string) $XMLItem->location->country, true);
         $location = LocationCountry::model()->find($criteria);
         if ($location != null) {
             $country = $location->id;
         } else {
             $country = (string) $XMLItem->location->country;
         }
     }
     $region_item = isset($XMLItem->location->region) ? (string) $XMLItem->location->region : (string) $XMLItem->location->{'locality-name'};
     if (isset($XMLItem->location->region)) {
         $region_item = explode(' ', $region_item);
         $region_item = $region_item[0];
     }
     $criteria = new CDbCriteria();
     $criteria->compare('name_ru', $region_item, true);
     $region = LocationRegion::model()->find($criteria);
     if ($region != null) {
         $region = $region->id;
     } else {
         $region = $region_item;
     }
     $city = null;
     if (isset($XMLItem->location->{'locality-name'})) {
         $criteria = new CDbCriteria();
         $criteria->compare('name_ru', (string) $XMLItem->location->{'locality-name'}, true);
         $location = LocationCity::model()->find($criteria);
         if ($location != null) {
             $city = $location->id;
         } else {
             $city = (string) $XMLItem->location->{'locality-name'};
         }
     }
     $title = (string) $XMLItem->type . ' ' . (string) $XMLItem->category;
     $new->attributes = array('type' => array_key_exists((string) $XMLItem->type, $lists['types']) ? $lists['types'][(string) $XMLItem->type] : (string) $XMLItem->type, 'category' => array_key_exists((string) $XMLItem->category, $lists['category']) ? (int) $lists['category'][(string) $XMLItem->category] : (string) $XMLItem->category, 'title' => $title, 'location_country' => $country, 'location_region' => $region, 'location_city' => $city, 'price' => (isset($XMLItem->price) and isset($XMLItem->price->value)) ? (double) $XMLItem->price->value : null, 'currency' => (isset($XMLItem->price) and isset($XMLItem->price->currency)) ? (string) $XMLItem->price->currency : 'RUR', 'address' => (isset($XMLItem->location) and isset($XMLItem->location->address)) ? (string) $XMLItem->location->address : null, 'rooms' => isset($XMLItem->rooms) ? (int) $XMLItem->rooms : 0, 'floor' => isset($XMLItem->floor) ? (int) $XMLItem->floor : null, 'floor_total' => isset($XMLItem->{'floors-total'}) ? (int) $XMLItem->{'floors-total'} : null, 'area' => (isset($XMLItem->area) and isset($XMLItem->area->value)) ? (double) $XMLItem->area->value : null, 'lot_area' => (isset($XMLItem->{'lot-area'}) and isset($XMLItem->{'lot-area'}->value)) ? (double) $XMLItem->{'lot-area'}->value : null, 'kitchen_space' => (isset($XMLItem->{'kitchen-space'}) and isset($XMLItem->{'kitchen-space'}->value)) ? (double) $XMLItem->{'kitchen-space'}->value : null, 'window_view' => array_key_exists((string) $XMLItem->{'window-view'}, $lists['window_view']) ? $lists['window_view'][(string) $XMLItem->{'window-view'}] : null, 'description' => isset($XMLItem->description) ? (string) $XMLItem->description : '', 'quality' => isset($XMLItem->quality) ? (string) $XMLItem->quality : null, 'phone' => (isset($XMLItem->{'sales-agent'}) and isset($XMLItem->{'sales-agent'}->phone)) ? (string) $XMLItem->{'sales-agent'}->phone : null, 'metro' => 0, 'with_pets' => (isset($XMLItem->{'with-pets'}) and (int) $XMLItem->{'with-pets'} == 1) ? 1 : 0, 'with_children' => (isset($XMLItem->{'with-children'}) and (int) $XMLItem->{'with-children'} == 1) ? 1 : 0, 'with_phone' => isset($XMLItem->phone) ? 1 : 0, 'internet' => isset($XMLItem->internet) ? 1 : 0, 'room_furniture' => (isset($XMLItem->{'room-furniture'}) and (int) $XMLItem->{'room-furniture'} == 1) ? 1 : 0, 'kitchen_furniture' => (isset($XMLItem->{'kitchen-furniture'}) and (int) $XMLItem->{'kitchen-furniture'} == 1) ? 1 : 0, 'television' => (isset($XMLItem->television) and (int) $XMLItem->{'television'} == 1) ? 1 : 0, 'washing_machine' => (isset($XMLItem->{'washing-machine'}) and (int) $XMLItem->{'washing-machine'} == 1) ? 1 : 0, 'refrigerator' => (isset($XMLItem->refrigerator) and (int) $XMLItem->{'refrigerator'} == 1) ? 1 : 0, 'balcony' => (isset($XMLItem->balcony) and (int) $XMLItem->{'balcony'} == 1) ? 1 : 0, 'bathroom_unit' => isset($XMLItem->{'bathroom-unit'}) ? (string) $XMLItem->{'bathroom-unit'} : null, 'floor_covering' => isset($XMLItem->{'floor-covering'}) ? (string) $XMLItem->{'floor-covering'} : null, 'lift' => isset($XMLItem->lift) ? 1 : 0);
     return $new;
 }