]> git.mxchange.org Git - friendica.git/commitdiff
Added function to count posts
authorMichael <heluecht@pirati.ca>
Thu, 14 Jan 2021 14:51:04 +0000 (14:51 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 14 Jan 2021 14:51:04 +0000 (14:51 +0000)
src/Model/Post.php

index d29728e4901c6fa75dc4f802b32d7077bebe49ad..85f69826c43602196b5480bacf8c9c672afebcad 100644 (file)
@@ -115,17 +115,28 @@ class Post
         * @throws \Exception
         */
        public static function exists($condition) {
-               $stmt = self::select(['id'], $condition, ['limit' => 1]);
-
-               if (is_bool($stmt)) {
-                       $retval = $stmt;
-               } else {
-                       $retval = (DBA::numRows($stmt) > 0);
-               }
-
-               DBA::close($stmt);
+               return DBA::exists('post-view', $condition);
+       }
 
-               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);
        }
 
        /**