diff options
author | Camil Staps | 2016-07-28 10:09:30 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-28 10:12:10 +0200 |
commit | 127d8394eda517cbe9f1a0b94e6f5ac303786c1a (patch) | |
tree | a83f62e8ce880d7440f1939293ba963715f6bd29 /classes/BusinessAdmin.php | |
parent | Braintree integration: first version (diff) |
v0.5.1 secret files
Diffstat (limited to 'classes/BusinessAdmin.php')
-rw-r--r-- | classes/BusinessAdmin.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/classes/BusinessAdmin.php b/classes/BusinessAdmin.php index 3e654a2..be6f1a4 100644 --- a/classes/BusinessAdmin.php +++ b/classes/BusinessAdmin.php @@ -76,6 +76,52 @@ class BusinessAdmin { } /** + * Get all file ids + * + * @see BusinessAdmin::getFiles() This funtion returns instances of the file 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 getFileIds($pdo, $where = [], $variables = []) { + $ids = []; + $files = $pdo->prepare("SELECT `id` FROM `".Constants::db_prefix."file`" . ((count($where) > 0) ? (" WHERE (" . implode(') AND (', $where) . ")") : "")); + $files->execute($variables); + $files = $files->fetchAll(PDO::FETCH_ASSOC); + foreach ($files as $file) { + $ids[] = $file['id']; + } + return $ids; + } + + /** + * Get all files + * + * @see BusinessAdmin::getFileIds() This function returns just the ids of the files, and not instances of the file 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 file[] An array indexed by id of instances of the file class + */ + public static function getFiles($pdo, $where = [], $variables = []) { + $ids = self::getFileIds($pdo, $where, $variables); + $files = []; + foreach ($ids as $id) { + $files[$id] = new File($pdo, $id); + } + return $files; + } + + /** * Get all client ids * * @see BusinessAdmin::getClients() This funtion returns instances of the client class instead of just the ids |