-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from ittweb/dev
Changed image handling
- Loading branch information
Showing
20 changed files
with
284 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace AccelaSearch\ProductMapper\DataMapper\Sql; | ||
use \OutOfBoundsException; | ||
use \AccelaSearch\ProductMapper\ImageLabel as Subject; | ||
|
||
class ImageLabel { | ||
private $connection; | ||
|
||
public function __construct(Connection $connection) { | ||
$this->connection = $connection; | ||
} | ||
|
||
public static function fromConnection(Connection $connection): self { | ||
return new ImageLabel($connection); | ||
} | ||
|
||
public function create(Subject $image_label): self { | ||
$query = 'INSERT INTO products_images_lbl(label, storeviewid, deleted) VALUES(:label, :shop_identifier, 0)'; | ||
$sth = $this->connection->getDbh()->prepare($query); | ||
$sth->execute([ | ||
':label' => $image_label->getLabel(), | ||
':shop_identifier' => $this->connection->getShopIdentifier(), | ||
]); | ||
$image_label->setIdentifier($this->connection->getDbh()->lastInsertId()); | ||
return $this; | ||
} | ||
|
||
public function read(int $identifier): Subject { | ||
$query = 'SELECT id, label, deleted FROM products_images_lbl WHERE id = :identifier'; | ||
$sth = $this->connection->getDbh()->prepare($query); | ||
$sth->execute([':identifier' => $identifier]); | ||
$row = $sth->fetch(); | ||
if (empty($row)) { | ||
throw new OutOfBoundsException('No image label with identifier ' . $identifier); | ||
} | ||
return $this->rowToImageLabel($row); | ||
} | ||
|
||
public function search(): array { | ||
$query = 'SELECT id, label, deleted FROM products_images_lbl WHERE storeviewid = :shop_identifier'; | ||
$sth = $this->connection->getDbh()->prepare($query); | ||
$sth->execute([':shop_identifier' => $this->connection->getShopIdentifier()]); | ||
$labels = []; | ||
while ($row = $sth->fetch()) { | ||
$labels[] = $this->rowToImageLabel($row); | ||
} | ||
return $labels; | ||
} | ||
|
||
private function rowToImageLabel(array $row): Subject { | ||
return new Subject( | ||
$row['id'], | ||
$row['label'], | ||
$row['deleted'] == 0 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace AccelaSearch\ProductMapper; | ||
|
||
class Image { | ||
private $label; | ||
private $url; | ||
private $position; | ||
|
||
public function __construct( | ||
string $label, | ||
string $url, | ||
int $position | ||
) { | ||
$this->label = $label; | ||
$this->url = $url; | ||
$this->position = $position; | ||
} | ||
|
||
public function getLabel(): ?string { | ||
return $this->label; | ||
} | ||
|
||
public function setLabel(string $label): self { | ||
$this->label = $label; | ||
return $this; | ||
} | ||
|
||
public function getUrl(): string { | ||
return $this->url; | ||
} | ||
|
||
public function setUrl(string $url): self { | ||
$this->url = $url; | ||
return $this; | ||
} | ||
|
||
public function getPosition(): int { | ||
return $this->position; | ||
} | ||
|
||
public function setPosition(int $position): self { | ||
$this->position = $position; | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.