1 <?php
2
3 /* --------------------------------------------------------------
4 ProductImage.inc.php 2015-12-07
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13
14 /**
15 * Class ProductImage
16 *
17 * @category System
18 * @package Product
19 * @subpackage Entities
20 */
21 class ProductImage implements ProductImageInterface
22 {
23 /**
24 * Filename of the product image
25 *
26 * @var string
27 */
28 protected $filename;
29
30 /**
31 * Alt texts of the image.
32 *
33 * @var array
34 */
35 protected $altTexts = array();
36
37 /**
38 * Is the product visible?
39 *
40 * @var bool
41 */
42 protected $productVisibility;
43
44
45 /**
46 * ProductImage constructor.
47 *
48 * @param FilenameStringType $filename Filename of the image.
49 */
50 public function __construct(FilenameStringType $filename)
51 {
52 $this->filename = $filename->asString();
53 }
54
55
56 /**
57 * Get Filename
58 *
59 * Returns the filename of the product.
60 *
61 * @return string The filename of the product.
62 */
63 public function getFilename()
64 {
65 return $this->filename;
66 }
67
68
69 /**
70 * Get Alt Text
71 *
72 * Returns the alternative text of a product image.
73 *
74 * @param LanguageCode $language The language code of the alt text to return.
75 *
76 * @throws InvalidArgumentException if the language code is not valid.
77 *
78 * @return string The alternative text of the product image.
79 */
80 public function getAltText(LanguageCode $language)
81 {
82 if(!array_key_exists($language->asString(), $this->altTexts))
83 {
84 throw new InvalidArgumentException($language->asString() . ' is not a valid key.');
85 }
86
87 return $this->altTexts[$language->asString()];
88 }
89
90
91 /**
92 * Is Visible
93 *
94 * Checks if the product is set to visible or not.
95 *
96 * @return bool Is the product visible?
97 */
98 public function isVisible()
99 {
100 return $this->productVisibility;
101 }
102
103
104 /**
105 * Set Alt Text
106 *
107 * Sets the alternative text of the product image.
108 *
109 * @param StringType $text The alternative text for the product image.
110 * @param LanguageCode $language The language code of the alternative text.
111 *
112 * @return string The alternative text of the product image.
113 */
114 public function setAltText(StringType $text, LanguageCode $language)
115 {
116 $this->altTexts[$language->asString()] = $text->asString();
117 }
118
119
120 /**
121 * Set Visible
122 *
123 * Activates or deactivates the products visibility.
124 *
125 * @param BoolType $visible Should the product be visible?
126 *
127 * @return ProductImageInterface Same instance for chained method calls.
128 */
129 public function setVisible(BoolType $visible)
130 {
131 $this->productVisibility = $visible->asBool();
132 }
133
134 }