BlogPostRepository.php 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. class BlogPostRepository extends BaseRepository implements IBlogPostRepository {
  3. public function __construct() {
  4. parent::__construct();
  5. }
  6. public function GetCount() {
  7. return self::$PDO->query("SELECT COUNT(*) FROM blog_posts WHERE post_content<>'' AND post_deleted=0")->fetchColumn();
  8. }
  9. public function GetLatest($count=1,$offset=0){
  10. $prep=self::$PDO->prepare("SELECT post_id FROM blog_posts WHERE post_content<>'' AND post_deleted=0 ORDER BY post_timestamp DESC LIMIT ?,?");
  11. $prep->bindValue(1,(int)$offset,PDO::PARAM_INT); // can't just use array in execute this time as execute array is treated like strings
  12. $prep->bindValue(2,(int)$count,PDO::PARAM_INT);
  13. $prep->execute();
  14. $ids=$prep->fetchAll(PDO::FETCH_COLUMN);
  15. $posts=array();
  16. foreach ($ids as $id)
  17. $posts[]=new BlogPost($id);
  18. return $posts;
  19. }
  20. public function GetAll(){
  21. $posts=array();
  22. self::SetupPDO();
  23. $ids=self::$PDO->query("SELECT post_id FROM blog_posts WHERE post_deleted=0")->fetchAll(PDO::FETCH_COLUMN);
  24. foreach ($ids as $id)
  25. $posts[]=new BlogPost($id);
  26. return $posts;
  27. }
  28. }