diff --git a/public/lib/item.php b/public/lib/item.php index 511868d..5260d0b 100644 --- a/public/lib/item.php +++ b/public/lib/item.php @@ -12,11 +12,13 @@ class Item { private $itemid = null; private $itemdata = []; + private $itemimages = []; function __construct($itemid) { global $binstack; $this->itemdata = $binstack->get('items', ['itemid', 'catid', 'name', 'text1', 'qty', 'want', 'cost', 'price'], ['itemid' => $itemid]); $this->itemid = $itemid; + $this->itemimages = $binstack->select('images', ['imagename', 'primary', 'imageid'], ['itemid' => $itemid, 'ORDER' => ['primary' => 'DESC']]); } function getId() { @@ -59,6 +61,68 @@ class Item { return $this->itemdata['catid']; } + function getImageCount() { + return count($this->itemimages); + } + + function getPrimaryImage(): ItemImage { + if (count($this->itemimages) > 0) { + foreach ($this->itemimages as $i) { + if ($i['primary'] == true) { + return new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); + } + } + $i = $this->itemimages[0]; + return new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); + } + return null; + } + + function getImages(): array { + $images = []; + + foreach ($this->itemimages as $i) { + $images[] = new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); + } + return $images; + } + +} + +class ItemImage { + + private $url = ""; + private $primary = false; + private $imageid = 0; + private $itemid = 0; + + function __construct(string $url, int $imageid, bool $primary, int $itemid) { + $this->url = $url; + $this->imageid = $imageid; + $this->primary = $primary; + $this->itemid = $itemid; + } + + function getName(): string { + return $this->url; + } + + function getAbsoluteUrl(): string { + return BINSTACK_URL_IMAGEPHP . "?i=" . $this->url; + } + + function isPrimary(): bool { + return $this->primary == true; + } + + function getID(): int { + return $this->imageid; + } + + function getItemID(): int { + return $this->itemid; + } + } class RenderItem { @@ -69,13 +133,29 @@ class RenderItem { $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); + $image = ""; + if ($item->getImageCount() > 0) { + $image = '' . $name . ''; + } + /* $html = << +
+ $image +
+ $name
+ $$price +
+
+ + END; */ $html = << -
- $name
- $$price +
+ $image +
+ $name
+ $$price +
-
END; return $html; } @@ -86,8 +166,13 @@ END; $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); + $image = ""; + if ($item->getImageCount() > 0) { + $image = '' . $name . ''; + } $html = << + $image

$name

$$price @@ -116,8 +201,13 @@ END; $catname = $item->getCategoryName(); $price = $item->getPrice(); $linetotal = number_format($price * $qty, 2); + $image = ""; + if ($item->getImageCount() > 0) { + $image = '' . $name . ''; + } $html = << + $image

$name

$$price diff --git a/public/parts/footer.php b/public/parts/footer.php index 2b47ec7..81110c5 100644 --- a/public/parts/footer.php +++ b/public/parts/footer.php @@ -11,4 +11,5 @@ if (!defined('NICKELBOX')) { } ?> - \ No newline at end of file + + \ No newline at end of file diff --git a/public/parts/head.php b/public/parts/head.php index f4fb915..6b75d6a 100644 --- a/public/parts/head.php +++ b/public/parts/head.php @@ -15,6 +15,7 @@ if (!defined('NICKELBOX')) { <?php echo $settings['sitename']; ?> + diff --git a/public/parts/home.php b/public/parts/home.php index e20fbf4..a27ed8b 100644 --- a/public/parts/home.php +++ b/public/parts/home.php @@ -7,7 +7,7 @@ if (!defined('NICKELBOX')) { die("Direct access denied."); -} +} $dbitems = $binstack->select('items', 'itemid', ['AND' => ['price[>]' => 0], 'LIMIT' => 20]); @@ -41,11 +41,13 @@ foreach ($dbitems as $i) {
- +
+ +
\ No newline at end of file diff --git a/public/parts/item.php b/public/parts/item.php index 7cb5c13..2f5cf18 100644 --- a/public/parts/item.php +++ b/public/parts/item.php @@ -14,7 +14,31 @@ $item = new Item($_GET['id']);
- + getImageCount() > 0) { + $primary = $item->getPrimaryImage(); + $image = '
'; + echo $image; + ?> +
+ getImages() as $img) { + ?> +
" data-imgid="getID(); ?>" data-imgurl="getAbsoluteUrl(); ?>"> + +
+ +
+
@@ -37,7 +61,7 @@ $item = new Item($_GET['id']);
-
+
Description
diff --git a/public/parts/nav.php b/public/parts/nav.php index a4311a6..10cf1b4 100644 --- a/public/parts/nav.php +++ b/public/parts/nav.php @@ -53,7 +53,11 @@ foreach ($cats as $c) {