1 | <?php |
||
32 | trait FileUploadTrait |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * The directory with the Magento media files => target directory for images (relative to the root directory). |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $mediaDir; |
||
41 | |||
42 | /** |
||
43 | * The directory with the images that have to be imported (relative to the root directory). |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $imagesFileDir; |
||
48 | |||
49 | /** |
||
50 | * Contains the mappings for the image names that has been uploaded (old => new image name). |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $imageMappings = array(); |
||
55 | |||
56 | /** |
||
57 | * The flag whether to copy the images or not. |
||
58 | * |
||
59 | * @var boolean |
||
60 | */ |
||
61 | protected $copyImages = false; |
||
62 | |||
63 | /** |
||
64 | * Whether or not to override images with the same name. |
||
65 | * |
||
66 | * @var boolean |
||
67 | * @todo https://github.com/techdivision/import/issues/181 |
||
68 | */ |
||
69 | private $overrideImages = false; |
||
70 | |||
71 | /** |
||
72 | * Sets whether or not to override images with the same name. |
||
73 | * |
||
74 | * @param boolean $overrideImages Whether or not to override images |
||
75 | * |
||
76 | * @return void |
||
77 | * @todo https://github.com/techdivision/import/issues/181 |
||
78 | */ |
||
79 | private function setOverrideImages($overrideImages) |
||
83 | |||
84 | /** |
||
85 | * Returns whether or not we should override images with the same name. |
||
86 | * |
||
87 | * @return bool |
||
88 | * @todo https://github.com/techdivision/import/issues/181 |
||
89 | */ |
||
90 | 1 | private function shouldOverride() |
|
94 | |||
95 | /** |
||
96 | * Set's the flag to copy the images or not. |
||
97 | * |
||
98 | * @param boolean $copyImages The flag |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | 1 | public function setCopyImages($copyImages) |
|
106 | |||
107 | /** |
||
108 | * Return's the flag to copy images or not. |
||
109 | * |
||
110 | * @return boolean The flag |
||
111 | */ |
||
112 | 1 | public function hasCopyImages() |
|
116 | |||
117 | /** |
||
118 | * Set's directory with the Magento media files => target directory for images. |
||
119 | * |
||
120 | * @param string $mediaDir The directory with the Magento media files => target directory for images |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | 3 | public function setMediaDir($mediaDir) |
|
128 | |||
129 | /** |
||
130 | * Return's the directory with the Magento media files => target directory for images. |
||
131 | * |
||
132 | * @return string The directory with the Magento media files => target directory for images |
||
133 | */ |
||
134 | 3 | public function getMediaDir() |
|
138 | |||
139 | /** |
||
140 | * Set's directory with the images that have to be imported. |
||
141 | * |
||
142 | * @param string $imagesFileDir The directory with the images that have to be imported |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | 3 | public function setImagesFileDir($imagesFileDir) |
|
150 | |||
151 | /** |
||
152 | * Return's the directory with the images that have to be imported. |
||
153 | * |
||
154 | * @return string The directory with the images that have to be imported |
||
155 | */ |
||
156 | 3 | public function getImagesFileDir() |
|
160 | |||
161 | /** |
||
162 | * Adds the mapping from the filename => new filename. |
||
163 | * |
||
164 | * @param string $filename The filename |
||
165 | * @param string $newFilename The new filename |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | 1 | public function addImageMapping($filename, $newFilename) |
|
173 | |||
174 | /** |
||
175 | * Returns the mapped filename (which is the new filename). |
||
176 | * |
||
177 | * @param string $filename The filename to map |
||
178 | * |
||
179 | * @return string The mapped filename |
||
180 | */ |
||
181 | 1 | public function getImageMapping($filename) |
|
192 | |||
193 | /** |
||
194 | * Returns TRUE, if the passed filename has already been mapped. |
||
195 | * |
||
196 | * @param string $filename The filename to query for |
||
197 | * |
||
198 | * @return boolean TRUE if the filename has already been mapped, else FALSE |
||
199 | */ |
||
200 | public function imageHasBeenMapped($filename) |
||
204 | |||
205 | /** |
||
206 | * Returns TRUE, if the passed filename has NOT been mapped yet. |
||
207 | * |
||
208 | * @param string $filename The filename to query for |
||
209 | * |
||
210 | * @return boolean TRUE if the filename has NOT been mapped yet, else FALSE |
||
211 | */ |
||
212 | 1 | public function imageHasNotBeenMapped($filename) |
|
216 | |||
217 | /** |
||
218 | * Returns the original filename for passed one (which is the new filename). |
||
219 | * |
||
220 | * @param string $newFilename The new filename to return the original one for |
||
221 | * |
||
222 | * @return string The original filename |
||
223 | */ |
||
224 | public function getInversedImageMapping($newFilename) |
||
235 | |||
236 | /** |
||
237 | * Get new file name, if a filename with the same name already exists. |
||
238 | * |
||
239 | * @param string $targetFilename The name of target file |
||
240 | * |
||
241 | * @return string The new filename |
||
242 | */ |
||
243 | 3 | public function getNewFileName($targetFilename) |
|
271 | |||
272 | /** |
||
273 | * Upload's the file with the passed name to the Magento |
||
274 | * media directory. If the file already exists, the will |
||
275 | * be given a new name that will be returned. |
||
276 | * |
||
277 | * @param string $filename The name of the file to be uploaded |
||
278 | * |
||
279 | * @return string The name of the uploaded file |
||
280 | * @throws \Exception Is thrown, if the file with the passed name is not available |
||
281 | */ |
||
282 | 2 | public function uploadFile($filename) |
|
321 | |||
322 | /** |
||
323 | * Delete the file with the passed name. |
||
324 | * |
||
325 | * @param string $filename The name of the file to be deleted |
||
326 | * |
||
327 | * @return boolean TRUE on success, else FALSE |
||
328 | */ |
||
329 | public function deleteFile($filename) |
||
347 | } |
||
348 |