1<?php
2
3namespace FINDOLOGIC\Export\Data;
4
5use FINDOLOGIC\Export\Helpers\DataHelper;
6use FINDOLOGIC\Export\Helpers\Serializable;
7use FINDOLOGIC\Export\Helpers\XMLHelper;
8
9class BaseImageMissingException extends \RuntimeException
10{
11    public function __construct()
12    {
13        $message = 'Base image without usergroup does\'t exist, exporting a “No Image Available" image is recommended!';
14        parent::__construct($message);
15    }
16}
17
18class ImagesWithoutUsergroupMissingException extends \RuntimeException
19{
20    public function __construct()
21    {
22        parent::__construct('There exist no images without usergroup!');
23    }
24}
25
26class Image implements Serializable
27{
28    /**
29     * Main, full-size image type.
30     */
31    const TYPE_DEFAULT = '';
32
33    /**
34     * Scaled-down thumbnail image type.
35     */
36    const TYPE_THUMBNAIL = 'thumbnail';
37
38    private $url;
39    private $type;
40    private $usergroup;
41
42    /**
43     * @SuppressWarnings(PHPMD.StaticAccess)
44     */
45    public function __construct($url, $type = self::TYPE_DEFAULT, $usergroup = '')
46    {
47        $this->url = DataHelper::checkForEmptyValue($url);
48        $this->type = $type;
49        $this->usergroup = $usergroup;
50    }
51
52    /**
53     * @return string
54     */
55    public function getUrl()
56    {
57        return $this->url;
58    }
59
60    /**
61     * @return string
62     */
63    public function getType()
64    {
65        return $this->type;
66    }
67
68    /**
69     * @return string
70     */
71    public function getUsergroup()
72    {
73        return $this->usergroup;
74    }
75
76    /**
77     * @SuppressWarnings(PHPMD.StaticAccess)
78     * @inheritdoc
79     */
80    public function getDomSubtree(\DOMDocument $document)
81    {
82        $imageElem = XMLHelper::createElementWithText($document, 'image', $this->url);
83        if ($this->type) {
84            $imageElem->setAttribute('type', $this->type);
85        }
86
87        return $imageElem;
88    }
89
90    /**
91     * @inheritdoc
92     */
93    public function getCsvFragment()
94    {
95        return $this->url;
96    }
97}
98