aboutsummaryrefslogtreecommitdiff
path: root/classes/BusinessAdmin.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/BusinessAdmin.php')
-rw-r--r--classes/BusinessAdmin.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/classes/BusinessAdmin.php b/classes/BusinessAdmin.php
index dc1f3e7..ce332ee 100644
--- a/classes/BusinessAdmin.php
+++ b/classes/BusinessAdmin.php
@@ -30,6 +30,52 @@ class BusinessAdmin {
//------------------------------------------------------------------------------
/**
+ * Get all user ids
+ *
+ * @see BusinessAdmin::getUsers() This funtion returns instances of the user 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 into a prepared statement
+ * @param mixed[] $variables An array of variables that should go into the prepared statement
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public static function getUserIds($pdo, $where = [], $variables = []) {
+ $ids = [];
+ $users = $pdo->prepare("SELECT `id` FROM `".constants::db_prefix."user`" . ((count($where) > 0) ? (" WHERE (" . implode(') AND (', $where) . ")") : ""));
+ $users->execute($variables);
+ $users = $users->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($users as $user) {
+ $ids[] = $user['id'];
+ }
+ return $ids;
+ }
+
+ /**
+ * Get all users
+ *
+ * @see BusinessAdmin::getUserIds() This function returns just the ids of the users, and not instances of the user class
+ *
+ * @param PDO $pdo The PDO class for database connection
+ * @param string[] $where An array of WHERE clauses that will be AND-ed into a prepared statement
+ * @param mixed[] $variables An array of variables that should go into the prepared statement
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return user[] An array indexed by id of instances of the user class
+ */
+ public static function getUsers($pdo, $where = [], $variables = []) {
+ $ids = self::getUserIds($pdo, $where, $variables);
+ $users = [];
+ foreach ($ids as $id) {
+ $users[$id] = new user($pdo, $id);
+ }
+ return $users;
+ }
+
+ /**
* Get all client ids
*
* @see BusinessAdmin::getClients() This funtion returns instances of the client class instead of just the ids