Advertisement
Guest User

Repository

a guest
May 26th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require 'Models/DatabaseModel.php';
  3.  
  4. class ArticleRepository extends DatabaseModel{
  5.  
  6.     public function findAll() {
  7.         return $this->db->select("*")->from("Article")->where("status = %i", 1)->fetchAll();
  8.     }
  9.    
  10.     public function findArticlesSince(DateTime $since)
  11.     {
  12.         return $this->db->select("*")->from("Article")->where("status = %i AND MONTH(published) = MONTH(%d)", 1, $since)->fetchAll();
  13.     }
  14.    
  15.     public function find($id)
  16.     {
  17.         $data = $this->db->select("*")->from("Article")->where("id = %i", intval($id))->fetch();
  18.         $article = new Article();
  19.         $article->setId($id);
  20.         $article->setStatus($data->status);
  21.         $article->setTitle($data->title);
  22.         $article->setContent($data->content);
  23.         return $article;
  24.     }
  25.    
  26.     public function save(Article $article)
  27.     {
  28.         $id = $article->getId();        
  29.         if ($id > 0) {
  30.             $this->db->update("Article", $article->toArray())->where("id = %i", intval($id))->execute();
  31.         } else {
  32.             $this->db->insert("Article", $article->toArray())->execute();
  33.         }
  34.     }
  35.    
  36.     public function delete($id)
  37.     {
  38.         return $this->db->delete("Article")->where("id = %i", intval($id))->execute();
  39.     }
  40.  
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement