From 55204d26b1a2f7a9f263277aa7802604eb744546 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jan 2021 14:51:04 +0000 Subject: [PATCH] Added function to count posts --- src/Model/Post.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Model/Post.php b/src/Model/Post.php index d29728e49..85f69826c 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -115,17 +115,28 @@ class Post * @throws \Exception */ public static function exists($condition) { - $stmt = self::select(['id'], $condition, ['limit' => 1]); + return DBA::exists('post-view', $condition); + } - if (is_bool($stmt)) { - $retval = $stmt; - } else { - $retval = (DBA::numRows($stmt) > 0); - } - - DBA::close($stmt); - - return $retval; + /** + * Counts the posts satisfying the provided condition + * + * @param array $condition array of fields for condition + * @param array $params Array of several parameters + * + * @return int + * + * Example: + * $condition = ["uid" => 1, "network" => 'dspr']; + * or: + * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr']; + * + * $count = Post::count($condition); + * @throws \Exception + */ + public static function count(array $condition = [], array $params = []) + { + return DBA::count('post-view', $condition, $params); } /**