/** * @covers Imbo\Model\Images::getImages * @covers Imbo\Model\Images::setImages */ public function testCanSetAndGetImages() { $images = array($this->getMock('Imbo\\Model\\Image'), $this->getMock('Imbo\\Model\\Image'), $this->getMock('Imbo\\Model\\Image')); $this->assertSame(array(), $this->model->getImages()); $this->assertSame($this->model, $this->model->setImages($images)); $this->assertSame($images, $this->model->getImages()); }
/** * {@inheritdoc} */ public function formatImages(Model\Images $model) { $images = $model->getImages(); $data = array(); // Fields to display if ($fields = $model->getFields()) { $fields = array_fill_keys($fields, 1); } foreach ($images as $image) { $entry = array('added' => $this->dateFormatter->formatDate($image->getAddedDate()), 'updated' => $this->dateFormatter->formatDate($image->getUpdatedDate()), 'checksum' => $image->getChecksum(), 'originalChecksum' => $image->getOriginalChecksum(), 'extension' => $image->getExtension(), 'size' => $image->getFilesize(), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'mime' => $image->getMimeType(), 'imageIdentifier' => $image->getImageIdentifier(), 'publicKey' => $image->getPublicKey()); // Add metadata if the field is to be displayed if (empty($fields) || isset($fields['metadata'])) { $metadata = $image->getMetadata(); if (is_array($metadata)) { if (empty($metadata)) { $metadata = new stdClass(); } $entry['metadata'] = $metadata; } } // Remove elements that should not be displayed if (!empty($fields)) { foreach (array_keys($entry) as $key) { if (!isset($fields[$key])) { unset($entry[$key]); } } } $data[] = $entry; } return $this->encode(array('search' => array('hits' => $model->getHits(), 'page' => $model->getPage(), 'limit' => $model->getLimit(), 'count' => $model->getCount()), 'images' => $data)); }
/** * {@inheritdoc} */ public function formatImages(Model\Images $model) { $images = ''; if ($fields = $model->getFields()) { $fields = array_fill_keys($fields, 1); } foreach ($model->getImages() as $image) { $images .= '<image>'; if (empty($fields) || isset($fields['publicKey'])) { $images .= '<publicKey>' . $image->getPublicKey() . '</publicKey>'; } if (empty($fields) || isset($fields['imageIdentifier'])) { $images .= '<imageIdentifier>' . $image->getImageIdentifier() . '</imageIdentifier>'; } if (empty($fields) || isset($fields['checksum'])) { $images .= '<checksum>' . $image->getChecksum() . '</checksum>'; } if (empty($fields) || isset($fields['originalChecksum'])) { $images .= '<originalChecksum>' . $image->getOriginalChecksum() . '</originalChecksum>'; } if (empty($fields) || isset($fields['mime'])) { $images .= '<mime>' . $image->getMimeType() . '</mime>'; } if (empty($fields) || isset($fields['extension'])) { $images .= '<extension>' . $image->getExtension() . '</extension>'; } if (empty($fields) || isset($fields['added'])) { $images .= '<added>' . $this->dateFormatter->formatDate($image->getAddedDate()) . '</added>'; } if (empty($fields) || isset($fields['updated'])) { $images .= '<updated>' . $this->dateFormatter->formatDate($image->getUpdatedDate()) . '</updated>'; } if (empty($fields) || isset($fields['size'])) { $images .= '<size>' . $image->getFilesize() . '</size>'; } if (empty($fields) || isset($fields['width'])) { $images .= '<width>' . $image->getWidth() . '</width>'; } if (empty($fields) || isset($fields['height'])) { $images .= '<height>' . $image->getHeight() . '</height>'; } $metadata = $image->getMetadata(); if (is_array($metadata) && (empty($fields) || isset($fields['metadata']))) { $images .= '<metadata>'; foreach ($metadata as $key => $value) { $images .= '<tag key="' . $key . '">' . $value . '</tag>'; } $images .= '</metadata>'; } $images .= '</image>'; } return <<<IMAGES <?xml version="1.0" encoding="UTF-8"?> <imbo> <search> <hits>{$model->getHits()}</hits> <page>{$model->getPage()}</page> <limit>{$model->getLimit()}</limit> <count>{$model->getCount()}</count> </search> <images>{$images}</images> </imbo> IMAGES; }