diff options
Diffstat (limited to 'classes/BusinessAdmin.class.php')
-rw-r--r-- | classes/BusinessAdmin.class.php | 42 |
1 files changed, 42 insertions, 0 deletions
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 //------------------------------------------------------------------------------ |