Added function to count posts
This commit is contained in:
parent
8e12dd1658
commit
55204d26b1
1 changed files with 21 additions and 10 deletions
|
@ -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;
|
* Counts the posts satisfying the provided condition
|
||||||
} else {
|
*
|
||||||
$retval = (DBA::numRows($stmt) > 0);
|
* @param array $condition array of fields for condition
|
||||||
}
|
* @param array $params Array of several parameters
|
||||||
|
*
|
||||||
DBA::close($stmt);
|
* @return int
|
||||||
|
*
|
||||||
return $retval;
|
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue