folder = $folder; $this->id = $id; foreach (new \DirectoryIterator(sprintf('%s/%s/%s', config('app.deals_dire'), $folder, $id)) as $file) { if ($file->getExtension() === 'json') { $content = file_get_contents($file->getPathname()); $this->data = json_decode($content, true); } elseif ($file->getExtension() === 'jpg') { $data = file_get_contents($file->getPathname()); $base64 = 'data:image/jpg;base64,' . base64_encode($data); $this->images[] = $base64; } } } public function getDateCreation(): \DateTime { $date_creation = \DateTime::createFromFormat('Y-m-d H:i:s.u', $this->data['datecreation']['date']); return $date_creation; } /** * @return array */ public function getData(): array { return $this->data; } /** * @return \string[] */ public function getImages(): array { return $this->images; } /** * @return int */ public function getId(): int { return $this->id; } /** * @return string */ public function getSubject(): string { return $this->data['subject']; } /** * @return string */ public function getBody(): string { return $this->data['body']; } /** * @return float */ public function getPrice(): float { return $this->data['price']; } /** * @return int */ public function getIdCategory(): int { return (int) $this->data['category']; } /** * @return string */ public function getCategory(): string { return Categories::$categories[$this->data['category']]; } }