| 1 | <?php |
||
| 7 | class Auction |
||
| 8 | { |
||
| 9 | const MAX_PHOTOS = 8; |
||
| 10 | |||
| 11 | protected $fields = []; |
||
| 12 | |||
| 13 | protected $photos = []; |
||
| 14 | |||
| 15 | 2 | public function __construct(array $fields = []) |
|
| 16 | { |
||
| 17 | 2 | $this->fields = $fields; |
|
| 18 | 2 | } |
|
| 19 | |||
| 20 | |||
| 21 | 1 | public function setPhotos(array $photos) |
|
| 22 | { |
||
| 23 | 1 | $photosCount = count($photos); |
|
| 24 | |||
| 25 | 1 | if ($photosCount > self::MAX_PHOTOS) { |
|
| 26 | 1 | throw new Exception("Photo files limit exceeded, " . self::MAX_PHOTOS . " allowed, " . $photosCount . " given"); |
|
| 27 | } |
||
| 28 | |||
| 29 | $this->photos = $photos; |
||
| 30 | } |
||
| 31 | |||
| 32 | |||
| 33 | 1 | public function toApiRepresentation() |
|
| 34 | { |
||
| 35 | 1 | $fields = []; |
|
| 36 | |||
| 37 | 1 | foreach ($this->fields as $fid => $value) { |
|
| 38 | 1 | $fields[] = (new Field($fid, $value))->toArray(); |
|
| 39 | 1 | } |
|
| 40 | |||
| 41 | 1 | $this->addPhotoFields($fields); |
|
| 42 | |||
| 43 | return [ |
||
| 44 | 1 | 'fields' => $fields, |
|
| 45 | 1 | ]; |
|
| 46 | } |
||
| 47 | |||
| 48 | |||
| 49 | public function fromApiRepresentation(array $fields) |
||
| 60 | |||
| 61 | |||
| 62 | 1 | protected function addPhotoFields(array& $fields) |
|
| 63 | { |
||
| 79 | |||
| 80 | } |
||
| 81 |