public function transformSingle($data) { $xml = new \SimpleXMLElement($data); if (isset($xml->mitarbeiter)) { $xml = $xml->mitarbeiter; } $mitarbeiter = new Employee(); $this->map($this->simpleMapping, $xml, $mitarbeiter); if (isset($xml->bild) && isset($xml->bild->pfad) && (string) $xml->bild->pfad != '') { $attachment = new Attachment((string) $xml->bild->pfad); if (isset($xml->bild->pfad_medium)) { $attachment->addData('medium', (string) $xml->bild->pfad_medium); } $mitarbeiter->addAttachment($attachment); } if (isset($xml->bild) && isset($xml->bild->medium) && (string) $xml->bild->medium != '') { $attachment = new Attachment((string) $xml->bild->medium); if (isset($xml->bild->small)) { $attachment->addData('small', (string) $xml->bild->small); } if (isset($xml->bild->big)) { $attachment->addData('big', (string) $xml->bild->big); } $mitarbeiter->addAttachment($attachment); } return $mitarbeiter; }
protected function mapAttachmentGroup(\SimpleXMLElement $xml, Project $project, $type = null, $group = null) { foreach ($xml as $anhang) { $data = (array) $anhang; if (array_key_exists('pfad', $data)) { $attachment = new Attachment($data['pfad'], $type, $group); $attachment->setTitle($this->cast($anhang->titel)); $project->addAttachment($attachment); } } }
public function testCalculateUrl() { $attachment = new Attachment('http://files.justimmo.at/public/pic/medium/test.jpg'); $this->assertEquals('http://files.justimmo.at/public/pic/medium/test.jpg', $attachment->calculateUrl('medium')); $this->assertEquals('http://files.justimmo.at/public/pic/big/test.jpg', $attachment->calculateUrl('big')); $attachment = new Attachment('http://files.justimmo.at/public/video/lq/test.mp4'); $this->assertEquals('http://files.justimmo.at/public/video/hq/test.mp4', $attachment->calculateUrl('hq')); $this->assertEquals('http://files.justimmo.at/public/video/default/test.mp4', $attachment->calculateUrl('default')); $attachment = new Attachment('http://files.justimmo.at/public/doc/test.pdf'); $this->assertEquals('http://files.justimmo.at/public/doc/test.pdf', $attachment->calculateUrl('hq')); $this->assertEquals('http://files.justimmo.at/public/doc/test.pdf', $attachment->calculateUrl('default')); $this->assertEquals('http://files.justimmo.at/public/doc/test.pdf', $attachment->calculateUrl()); }
/** * @param \SimpleXMLElement $xml * @param null $type * * @param \Justimmo\Model\Realty $objekt * * @internal param array $data * @return \Justimmo\Model\Attachment|null */ protected function mapAttachmentGroup(\SimpleXMLElement $xml, Realty $objekt, $type = null) { foreach ($xml as $anhang) { $data = (array) $anhang->daten; $attributes = $this->attributesToArray($anhang); $group = array_key_exists('gruppe', $attributes) ? $attributes['gruppe'] : null; if (array_key_exists('pfad', $data)) { $attachment = new Attachment($data['pfad'], $type, $group); $attachment->mergeData($data); $attachment->setTitle($this->cast($anhang->anhangtitel)); $objekt->addAttachment($attachment); } elseif (isset($anhang->pfad)) { $attachment = new Attachment($this->cast($anhang->pfad), $type, $group); $attachment->setTitle($this->cast($anhang->titel)); $objekt->addAttachment($attachment); } } }