for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Models;
use Core\Model;
use Core\Container;
class PaginationModel extends Model{
private $postsTbl;
public function __construct(Container $container)
{
parent::__construct($container);
$this->postsTbl = $this->getTablePrefix('posts');
}
/**
* get the total number of posts
* @return int
* @throws \Exception
*/
public function totalNumberPosts(): int
$sql = "SELECT COUNT(*) FROM $this->postsTbl WHERE published = 1";
$this->query($sql);
$this->execute();
return $this->stmt->fetchColumn();
* get the total number of posts in a category
* @param int $categoryId
public function totalNumberPostsInCategory(int $categoryId): int
$sql = "SELECT COUNT(*) FROM $this->postsTbl WHERE published = 1 AND categories_idcategories = :categoryId ";
$this->bind(":categoryId", $categoryId, \PDO::PARAM_INT);
* @param int $authorid
public function totalNumberPostsByAuthor(int $authorid):int
$sql = "SELECT COUNT(*) FROM $this->postsTbl WHERE published = 1 AND author_iduser = :authorId ";
$this->bind(":authorId", $authorid, \PDO::PARAM_INT);