public function testTransform()
 {
     $wrapper = new EmployeeWrapper(new EmployeeMapper());
     $list = $wrapper->transformList($this->getFixtures('v1/employee_list.xml'));
     $this->assertInstanceOf('\\Justimmo\\Pager\\ListPager', $list);
     $this->assertEquals(5, $list->count());
     $this->assertEquals(5, $list->getNbResults());
     $this->assertFalse($list->haveToPaginate());
     foreach ($list as $entry) {
         $this->assertInstanceOf('\\Justimmo\\Model\\Employee', $entry);
     }
     /** @var \Justimmo\Model\Employee $entry */
     $entry = $list[1];
     $this->assertEquals(100123, $entry->getId());
     $this->assertEquals('Alexander', $entry->getFirstName());
     $this->assertEquals('Diem', $entry->getLastName());
     $this->assertEquals('Marketing & Sales', $entry->getPosition());
     $this->assertEquals('Marketing', $entry->getCategory());
     $this->assertEquals('+43 1 888 74 72', $entry->getMobile());
     $this->assertEquals('+43 676 123 45 67', $entry->getPhone());
     $this->assertEquals('+43 767 765 43 21', $entry->getFax());
     $this->assertEquals('*****@*****.**', $entry->getEmail());
     $this->assertEquals(1, count($entry->getAttachments()));
     $this->assertEquals('von der Stange', $entry->getSuffix());
     $this->assertEquals('Biografie von Alexander Diem', $entry->getBiography());
     /** @var \Justimmo\Model\Employee $entry */
     $entry = $list[2];
     $this->assertEmpty($entry->getSuffix());
 }
Esempio n. 2
0
 public function transformSingle($data)
 {
     $xml = new \SimpleXMLElement($data);
     if (isset($xml->projekt)) {
         $xml = $xml->projekt;
     }
     $project = new Project();
     $this->map($this->simpleMapping, $xml, $project);
     if (isset($xml->erstes_bild) && (string) $xml->erstes_bild != '') {
         $project->addAttachment(new Attachment((string) $xml->erstes_bild));
     }
     if (isset($xml->bilder) && isset($xml->bilder->bild)) {
         $this->mapAttachmentGroup($xml->bilder->bild, $project, 'picture');
     }
     if (isset($xml->plaene) && isset($xml->plaene->bild)) {
         $this->mapAttachmentGroup($xml->plaene->bild, $project, 'picture', 'GRUNDRISS');
     }
     if (isset($xml->dokumente) && isset($xml->dokumente->dokument)) {
         $this->mapAttachmentGroup($xml->dokumente->dokument, $project, 'document');
     }
     if (isset($xml->videos) && isset($xml->videos->video)) {
         $this->mapAttachmentGroup($xml->videos->video, $project, 'video');
     }
     if (isset($xml->bilder360) && isset($xml->bilder360->bild)) {
         $this->mapAttachmentGroup($xml->bilder360->bild, $project, 'picture', 'bilder360');
     }
     if (isset($xml->immobilien->immobilie)) {
         $wrapper = new RealtyWrapper(new RealtyMapper());
         foreach ($xml->immobilien->immobilie as $immobilie) {
             $realty = $wrapper->transformSingle($immobilie->asXML());
             $project->addRealty($realty);
         }
     }
     if (isset($xml->kontaktperson)) {
         $employeeWrapper = new EmployeeWrapper(new EmployeeMapper());
         $contact = $employeeWrapper->transformSingle($xml->kontaktperson->asXML());
         $project->setContact($contact);
     }
     return $project;
 }
Esempio n. 3
0
 /**
  * @param $data
  *
  * @return Objekt
  */
 public function transformSingle($data)
 {
     $xml = new \SimpleXMLElement($data);
     if (isset($xml->immobilie)) {
         $xml = $xml->immobilie;
     }
     $objekt = new Realty();
     //basic attributes from list view
     $this->map($this->simpleMapping, $xml, $objekt);
     //list object attachment mapping
     if (isset($xml->erstes_bild)) {
         $objekt->addAttachment(new Attachment((string) $xml->erstes_bild));
     }
     if (isset($xml->zweites_bild)) {
         $objekt->addAttachment(new Attachment((string) $xml->zweites_bild));
     }
     //detailed attributes from detail view, OpenImmo
     if (isset($xml->verwaltung_techn)) {
         $objekt->setId((int) $xml->verwaltung_techn->objektnr_intern);
         $objekt->setPropertyNumber((string) $xml->verwaltung_techn->objektnr_extern);
         $objekt->setProjectId((int) $xml->verwaltung_techn->projekt_id);
     }
     if (isset($xml->verwaltung_objekt)) {
         $objekt->setStatus($this->cast($xml->verwaltung_objekt->status));
         $objekt->setStatusId($this->cast($xml->verwaltung_objekt->status_id));
         $objekt->setAvailableFrom($this->cast($xml->verwaltung_objekt->verfuegbar_ab));
         if (isset($xml->verwaltung_objekt->max_mietdauer)) {
             $objekt->setRentDuration($this->cast($xml->verwaltung_objekt->max_mietdauer, 'int'));
             if ($xml->verwaltung_objekt->max_mietdauer->attributes()->max_dauer == 'JAHR') {
                 $objekt->setRentDurationType('year');
             } elseif ($xml->verwaltung_objekt->max_mietdauer->attributes()->max_dauer == 'MONAT') {
                 $objekt->setRentDurationType('month');
             }
         }
         if (isset($xml->verwaltung_objekt->user_defined_anyfield) && isset($xml->verwaltung_objekt->user_defined_anyfield->justimmo_kategorie)) {
             foreach ($xml->verwaltung_objekt->user_defined_anyfield->justimmo_kategorie as $category) {
                 $objekt->addCategory((int) $category['id'], (string) $category);
             }
         }
         foreach ($xml->verwaltung_objekt->user_defined_simplefield as $simpleField) {
             $this->mapSimpleField($simpleField, $objekt);
         }
     }
     if (isset($xml->objektkategorie)) {
         if (isset($xml->objektkategorie->objektart)) {
             $objekt->setRealtyType((string) $xml->objektkategorie->objektart->children()->getName());
             $objekt->setSubRealtyType((string) $xml->objektkategorie->objektart->children()->attributes());
         }
         if (isset($xml->objektkategorie->nutzungsart)) {
             $objekt->setOccupancy(filter_var_array($this->attributesToArray($xml->objektkategorie->nutzungsart->attributes()), FILTER_VALIDATE_BOOLEAN));
         }
         if (isset($xml->objektkategorie->vermarktungsart)) {
             $objekt->setMarketingType(filter_var_array($this->attributesToArray($xml->objektkategorie->vermarktungsart->attributes()), FILTER_VALIDATE_BOOLEAN));
         }
         foreach ($xml->objektkategorie->user_defined_simplefield as $simpleField) {
             $this->mapSimpleField($simpleField, $objekt);
         }
         foreach ($xml->objektkategorie->user_defined_anyfield as $anyField) {
             foreach ($anyField->ji_kategorie as $kategorie) {
                 $attributes = $this->attributesToArray($kategorie);
                 if (array_key_exists('id', $attributes)) {
                     $objekt->addCategory($attributes['id'], (string) $kategorie);
                 }
             }
         }
     }
     if (isset($xml->freitexte)) {
         $objekt->setTitle((string) $xml->freitexte->objekttitel);
         $objekt->setEquipmentDescription((string) $xml->freitexte->ausstatt_beschr);
         $objekt->setDescription((string) $xml->freitexte->objektbeschreibung);
         if (isset($xml->freitexte->lage)) {
             $objekt->setLocality((string) $xml->freitexte->lage);
         }
         if (isset($xml->freitexte->user_defined_anyfield)) {
             if (isset($xml->freitexte->user_defined_anyfield->justimmo_freitext1)) {
                 $objekt->setFreetext1((string) $xml->freitexte->user_defined_anyfield->justimmo_freitext1);
             }
             if (isset($xml->freitexte->user_defined_anyfield->justimmo_freitext2)) {
                 $objekt->setFreetext2((string) $xml->freitexte->user_defined_anyfield->justimmo_freitext2);
             }
             if (isset($xml->freitexte->user_defined_anyfield->justimmo_freitext3)) {
                 $objekt->setFreetext3((string) $xml->freitexte->user_defined_anyfield->justimmo_freitext3);
             }
         }
     }
     if (isset($xml->geo)) {
         $this->map($this->geoMapping, $xml->geo, $objekt);
         if (isset($xml->geo->geokoordinaten)) {
             $coord = $this->attributesToArray($xml->geo->geokoordinaten->attributes());
             $objekt->setLatitude((double) $coord['breitengrad']);
             $objekt->setLongitude((double) $coord['laengengrad']);
         }
         if (isset($xml->geo->land)) {
             $iso = $this->attributesToArray($xml->geo->land->attributes());
             if (array_key_exists('iso_land', $iso)) {
                 $objekt->setCountry((string) $iso['iso_land']);
             }
         }
         foreach ($xml->geo->user_defined_simplefield as $simpleField) {
             $this->mapSimpleField($simpleField, $objekt);
         }
     }
     if (isset($xml->preise)) {
         $this->map($this->preisMapping, $xml->preise, $objekt);
         $objekt->setTotalRent($this->cast($xml->preise->warmmiete, 'double'));
         if (isset($xml->preise->waehrung)) {
             $iso = $this->attributesToArray($xml->preise->waehrung->attributes());
             if (array_key_exists('iso_waehrung', $iso)) {
                 $objekt->setCurrency((string) $iso['iso_waehrung']);
             }
         }
         foreach ($xml->preise->user_defined_simplefield as $simpleField) {
             $this->mapSimpleField($simpleField, $objekt);
         }
         if (isset($xml->preise->zusatzkosten)) {
             foreach ($xml->preise->zusatzkosten[0] as $key => $zusatzkosten) {
                 $name = isset($zusatzkosten->name) ? $zusatzkosten->name : $key;
                 $costs = new AdditionalCosts((string) $name, (double) $zusatzkosten->brutto, (double) $zusatzkosten->netto, (double) $zusatzkosten->ust, (string) $zusatzkosten->ust_typ, (double) $zusatzkosten->ust_berechneter_wert, (double) $zusatzkosten->ust_wert);
                 if (isset($zusatzkosten->optional)) {
                     $costs->setOptional(filter_var((string) $zusatzkosten->optional, FILTER_VALIDATE_BOOLEAN));
                 }
                 $objekt->addAdditionalCosts($key, $costs);
             }
         }
     }
     if (isset($xml->anhaenge) && isset($xml->anhaenge->anhang)) {
         $this->mapAttachmentGroup($xml->anhaenge->anhang, $objekt);
     }
     if (isset($xml->dokumente) && isset($xml->dokumente->dokument)) {
         $this->mapAttachmentGroup($xml->dokumente->dokument, $objekt, 'document');
     }
     if (isset($xml->videos) && isset($xml->videos->video)) {
         $this->mapAttachmentGroup($xml->videos->video, $objekt, 'video');
     }
     if (isset($xml->bilder360) && isset($xml->bilder360->pfad)) {
         foreach ($xml->bilder360->pfad as $anhang) {
             $attachment = new Attachment($this->cast($anhang), 'picture', 'bilder360');
             $objekt->addAttachment($attachment);
         }
     }
     if (isset($xml->links) && isset($xml->links->link)) {
         $this->mapAttachmentGroup($xml->links->link, $objekt, 'link');
     }
     if (isset($xml->flaechen)) {
         $this->map($this->flaechenMapping, $xml->flaechen, $objekt);
         $objekt->setSurfaceArea($this->cast($xml->flaechen->grundstuecksflaeche));
     }
     if (isset($xml->zustand_angaben)) {
         $objekt->setYearBuilt($this->cast($xml->zustand_angaben->baujahr, 'int'));
         $data = $this->attributesToArray($xml->zustand_angaben->zustand);
         if (array_key_exists('zustand_art', $data)) {
             $objekt->setCondition($data['zustand_art']);
         }
         $data = $this->attributesToArray($xml->zustand_angaben->alter);
         if (array_key_exists('alter_attr', $data)) {
             $objekt->setAge($data['alter_attr']);
         }
         $data = $this->attributesToArray($xml->zustand_angaben->erschliessung);
         if (array_key_exists('erschl_attr', $data)) {
             $objekt->setInfrastructureProvision($data['erschl_attr']);
         }
         if (isset($xml->zustand_angaben->energiepass)) {
             $energiepass = new EnergyPass();
             $energiepass->setEpart($this->cast($xml->zustand_angaben->energiepass->epart))->setValidUntil($this->cast($xml->zustand_angaben->energiepass->gueltig_bis, 'datetime'));
             foreach ($xml->zustand_angaben->user_defined_simplefield as $simpleField) {
                 $this->mapSimpleField($simpleField, $energiepass);
             }
             $objekt->setEnergyPass($energiepass);
         }
         if (isset($xml->ausstattung[0])) {
             /** @var \SimpleXMLElement $element */
             foreach ($xml->ausstattung[0] as $key => $element) {
                 if ((string) $element === "true" || (int) $element === 1) {
                     $objekt->addEquipment($key, $key);
                 } elseif ($element->attributes()->count()) {
                     $attributes = $this->attributesToArray($element);
                     $value = array();
                     foreach ($attributes as $k => $v) {
                         if ($v === "true" || $v == 1) {
                             $value[] = $k;
                         } else {
                             $value[$k] = $v;
                         }
                     }
                     $objekt->addEquipment($key, count($value) > 1 || array_keys($value) !== range(0, count($value) - 1) ? $value : $value[0]);
                 } else {
                     $objekt->addEquipment($key, (string) $element);
                 }
             }
         }
     }
     if (isset($xml->kontaktperson)) {
         $employeeWrapper = new EmployeeWrapper(new EmployeeMapper());
         $contact = $employeeWrapper->transformSingle($xml->kontaktperson->asXML());
         $objekt->setContact($contact);
     }
     return $objekt;
 }