Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'Models/DatabaseModel.php';
- class ArticleRepository extends DatabaseModel{
- public function findAll() {
- return $this->db->select("*")->from("Article")->where("status = %i", 1)->fetchAll();
- }
- public function findArticlesSince(DateTime $since)
- {
- return $this->db->select("*")->from("Article")->where("status = %i AND MONTH(published) = MONTH(%d)", 1, $since)->fetchAll();
- }
- public function find($id)
- {
- $data = $this->db->select("*")->from("Article")->where("id = %i", intval($id))->fetch();
- $article = new Article();
- $article->setId($id);
- $article->setStatus($data->status);
- $article->setTitle($data->title);
- $article->setContent($data->content);
- return $article;
- }
- public function save(Article $article)
- {
- $id = $article->getId();
- if ($id > 0) {
- $this->db->update("Article", $article->toArray())->where("id = %i", intval($id))->execute();
- } else {
- $this->db->insert("Article", $article->toArray())->execute();
- }
- }
- public function delete($id)
- {
- return $this->db->delete("Article")->where("id = %i", intval($id))->execute();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement