1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php
namespace hji\construction\models;
class Images extends \hji\membership\models\data\Images
{
protected $baseUrl;
function __construct($imagesObject)
{
if (!is_object($imagesObject))
{
trigger_error('Images must be an object.', E_USER_ERROR);
}
if (!empty($imagesObject->baseUrl))
{
$this->baseUrl = $imagesObject->baseUrl;
}
else
{
trigger_error('Base URL is required in subdivision and subdivision listing images object.', E_USER_ERROR);
}
if ($imagesObject->primary)
{
$this->addImage($imagesObject->primary, true);
}
foreach ($imagesObject as $property => $value)
{
if (is_array($value))
{
if (!isset($this->$property))
{
$this->$property = array();
}
foreach ($value as $imageObj)
{
$this->addImage($imageObj);
$this->{$property}[] = end($this->collection);
}
}
}
}
function __get($imageType)
{
if (isset($this->$imageType) && !empty($this->$imageType))
{
return $this->$imageType;
}
return null;
}
function addImage($image, $primary = false)
{
if (!filter_var($image->url, FILTER_VALIDATE_URL) !== false)
{
$image->url = $this->baseUrl . '/' . $image->url;
}
parent::addImage($image, $primary);
}
}