Added function to count posts

This commit is contained in:
Michael 2021-01-14 14:51:04 +00:00
parent 8e12dd1658
commit 55204d26b1

View file

@ -115,17 +115,28 @@ class Post
* @throws \Exception * @throws \Exception
*/ */
public static function exists($condition) { 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); /**
* Counts the posts satisfying the provided condition
return $retval; *
* @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);
} }
/** /**