From 0b60b0ccc66cbcc26619ac762b8881f52fa85bf7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 20 Jul 2016 10:54:07 +0200 Subject: Discounts --- classes/BusinessAdmin.class.php | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'classes/BusinessAdmin.class.php') diff --git a/classes/BusinessAdmin.class.php b/classes/BusinessAdmin.class.php index d90e341..23e9c74 100644 --- a/classes/BusinessAdmin.class.php +++ b/classes/BusinessAdmin.class.php @@ -193,6 +193,48 @@ class BusinessAdmin { return $assignments; } + /** + * Get all discount ids + * + * @see BusinessAdmin::getDiscounts() This funtion returns instances of the discount class instead of just the ids + * + * @param PDO $pdo The PDO class for database connection + * @param string[] $where An array of WHERE clauses that will be AND-ed + * + * @throws PDOException Is something went wrong with the database + * + * @return int[] The ids + */ + public static function getDiscountIds($pdo, $where = array()) { + $ids = array(); + $discounts = $pdo->query("SELECT `id` FROM `".constants::db_prefix."discount`" . ((count($where) > 0) ? (" WHERE (" . implode(') AND (', $where) . ")") : ""))->fetchAll(PDO::FETCH_ASSOC); + foreach ($discounts as $discount) { + $ids[] = $discount['id']; + } + return $ids; + } + + /** + * Get all discounts + * + * @see BusinessAdmin::getDiscountIds() This function returns just the ids of the discounts, and not instances of the discount class + * + * @param PDO $pdo The PDO class for database connection + * @param string[] $where An array of WHERE clauses that will be AND-ed + * + * @throws PDOException If something went wrong with the database + * + * @return discount[] An array indexed by id of instances of the discount class + */ + public static function getDiscounts($pdo, $where = array()) { + $ids = self::getDiscountIds($pdo, $where); + $discounts = array(); + foreach ($ids as $id) { + $discounts[$id] = new discount($pdo, $id); + } + return $discounts; + } + //------------------------------------------------------------------------------ // Other functions //------------------------------------------------------------------------------ -- cgit v1.2.3