*/ namespace wishthis; class Wishlist { private int $id; private string $hash; public array $data; public array $products = array(); public bool $exists = false; public function __construct(int|string $id_or_hash) { global $database; $column; if (is_int($id_or_hash)) { $column = 'id'; } if (is_string($id_or_hash)) { $column = 'hash'; $id_or_hash = '"' . $id_or_hash . '"'; } /** * Get Wishlist */ $this->data = $database->query('SELECT * FROM `wishlists` WHERE `' . $column . '` = ' . $id_or_hash . ';') ->fetch(); /** Exists */ if (isset($this->data['id'])) { $this->id = $this->data['id']; $this->exists = true; } else { return; } /** * Get Products */ $this->products = $database->query('SELECT * FROM `products` WHERE `wishlist` = ' . $this->id . ';') ->fetchAll(); } public function getCards($options = array()): void { /** * Exclude */ $exclude = isset($options['exclude']) ? $options['exclude'] : array(); if ($exclude) { $products = array_filter($this->products, function ($product) use ($exclude) { return !in_array($product['status'], $exclude); }); } else { $products = $this->products; } /** * Cards */ if (!empty($products)) { ?>