Beispiel #1
0
 /**
  * Implement the R in CRUD. Calls to ``Model::find()`` arrive here.
  */
 public function read(Model $model, $queryData = array())
 {
     $objects = array();
     $url = "http://beskrivning.fasad.eu/bolag/234/objekt.xml";
     $xml = file_get_contents($url);
     $objectsList = new SimpleXMLElement($xml);
     foreach ($objectsList as $objectList) {
         if ($queryData['conditions']['objectType'] == 'all' || !(strpos(strtolower($queryData['conditions']['objectType']), strtolower($objectList['objectType'])) === FALSE)) {
             // Filter on realtor ID
             if (isset($queryData['conditions']['realtorId'])) {
                 $r_id = $queryData['conditions']['realtorId'];
                 if ($objectList['realtorId'] != $r_id) {
                     continue;
                     // Wrong realtor
                 }
             }
             // Filter on area
             if (isset($queryData['conditions']['area'])) {
                 App::import('Vendor', 'districtmapper');
                 $object_district = DistrictMapper::getInstance()->lookup($objectList['district']);
                 $area = $queryData['conditions']['area'];
                 if (!DistrictMapper::getInstance()->compare($objectList['district'], $area)) {
                     continue;
                     // Wrong area
                 }
             }
             $xmlUrl = $objectList['xml'];
             $content = file_get_contents($xmlUrl);
             $sigleObject = new SimpleXMLElement($content);
             $sigleObject->addAttribute('lastPublished', $objectList['lastPublished']);
             array_push($objects, $sigleObject);
         }
     }
     return array($model->alias => $objects);
 }
Beispiel #2
0
 /**
  * Try to find the proper name (to use in url) for an area.
  * Note that the data is inconsistent, so we can only do as much as
  * possible and see if we succeed. The strategy used is to make the data
  * as most data is (space is replaced by _ and åäö with aao). We then handle
  * the exceptions.
  * @param type $str Name of area
  * @param type $areas List of available areas
  * @return Mixed FALSE if none found, else the area is returned as a string.
  */
 function fixAreaSlug($str)
 {
     App::import('Vendor', 'districtmapper');
     return DistrictMapper::getInstance()->lookup($str);
 }