Skip to content

Commit

Permalink
Merge pull request #17 from BBrunekreeft/patch-2
Browse files Browse the repository at this point in the history
Retrieve 360 images
  • Loading branch information
haringsrob authored May 28, 2019
2 parents 70ec53f + 38d4594 commit f679968
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 20 deletions.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ $icecat->getImages(5);

// Returns key => value array with specifications. e.g: ['cpu' => 'Core I5', 'screensize' => '15.6']
$icecat->getSpecs();

// Returns array with videos of the product.
$icecat->getVideos();

// Returns array with manuals.
$icecat->getManuals();

// Returns array with 360 images.
$icecat->get360imageArray();


```

Demo is soon available.
Expand Down
87 changes: 67 additions & 20 deletions src/Model/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class Result implements ResultInterface
* @var array
*/
private $images = [];

/**
* The multimedia objects as an array.
*
* @var array
*/
private $multimediaObjects = [];


/**
* Icecat Constructor.
*
Expand Down Expand Up @@ -180,13 +181,15 @@ private function productHasMainImage()
{
return !empty($this->getProductData()->{'@attributes'}->HighPic);
}

/**
* Gets an array of images.
* Gets an array of multimedia Objects.
*
* @param string $objectType MultimediaObjectType (video/mp4|manual|360|leaflet)
*
* @return array
*/
public function getMultimediaObjects()
public function getMultimediaObjects($objectType = '')
{
if (empty($this->multimediaObjects)) {
if ($this->productHasMultimediaObject()) {
Expand All @@ -195,24 +198,68 @@ public function getMultimediaObjects()
if (!is_array($productMultimediaObjects)){
$productMultimediaObjects = [$productMultimediaObjects];
}

foreach ($productMultimediaObjects as $multimediaObject) {
$attr = $multimediaObject->{'@attributes'};
$this->multimediaObjects[] = [
foreach ($productMultimediaObjects as $productMultimediaObject) {
$attr = $productMultimediaObject->{'@attributes'};
$multimediaObject = [
'contentType' => $attr->ContentType,
'description' => $attr->Description,
'size' => $attr->Size,
'type' => $attr->Type,
'url' => $attr->URL,
'langId' => $attr->langid,
];
'size' => (!empty($attr->Size) ? $attr->Size : 0),
'url' => (!empty($attr->URL) ? $attr->URL : ''),
];

// retrieve 360 images?
if ($attr->Type == '360') {
$images360 = [];

foreach ($productMultimediaObject->ImagesList360->Image as $image) {
$attr = $image->{'@attributes'};
$images360[(int) $attr->No] = $attr->Link;
}
$multimediaObject['image360'] = $images360;
}

$this->multimediaObjects[$attr->Type][] = $multimediaObject;
}
}
}

return $this->multimediaObjects;

if (empty($objectType)) {
return $this->multimediaObjects;
}

return (isset($this->multimediaObjects[$objectType]) ? $this->multimediaObjects[$objectType] : []);
}

/**
* Gets an array of 360 images.
*
* @return array
*/
public function get360imageArray()
{
return $this->getMultimediaObjects('360');
}

/**
* Gets an array of manuals.
*
* @return array
*/
public function getManuals()
{
return $this->getMultimediaObjects('manual');
}

/**
* Gets an array of videos.
*
* @return array
*/
public function getVideos()
{
return $this->getMultimediaObjects('video/mp4');
}

/**
* Checks if the product has multimedia objects.
*
Expand All @@ -222,7 +269,7 @@ private function productHasMultimediaObject()
{
return !empty($this->getProductData()->ProductMultimediaObject->MultimediaObject);
}

/**
* Checks if the product has Product Features.
*
Expand All @@ -246,7 +293,7 @@ public function getSpecByIdentifier($identifier)
{
if ($this->productHasProductFeature()) {
$productFeature = $this->getProductData()->ProductFeature;

// Make sure $productFeature is an array.
if (!is_array($productFeature)) {
$productFeature = [$productFeature];
Expand All @@ -272,7 +319,7 @@ public function getSpecByName($specificationName)
{
if ($this->productHasProductFeature()) {
$productFeature = $this->getProductData()->ProductFeature;

// Make sure $productFeature is an array.
if (!is_array($productFeature)) {
$productFeature = [$productFeature];
Expand All @@ -294,10 +341,10 @@ public function getSpecByName($specificationName)
public function getSpecs()
{
$specifications = [];

if ($this->productHasProductFeature()) {
$productFeature = $this->getProductData()->ProductFeature;

// Make sure $productFeature is an array.
if (!is_array($productFeature)) {
$productFeature = [$productFeature];
Expand Down

0 comments on commit f679968

Please sign in to comment.