Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. class StoryRepository {
  4.  
  5.     private $db;
  6.  
  7.     function __construct(database $db) {
  8.         $this->db = $db;
  9.     }
  10.  
  11.     function getStories() {
  12.         $sql = 'SELECT author.name AS authorName, author.surname AS authorSurname, category.name AS catName, article.*
  13.                 FROM article
  14.                 INNER JOIN author ON article.author_id = author.id
  15.                 INNER JOIN category ON article.category_id = category.id';
  16.         /*$sql = 'SELECT student.*, class.name AS class '
  17.                 . 'FROM student '
  18.                 . 'INNER JOIN class '
  19.                 . 'ON student.class_id = class.id';*/
  20.         return $this->db->selectAll($sql);
  21.     }
  22.    
  23.     function addStory($authorID, $categoryID, $title, $perex, $text, $createdAt) {
  24.         $sql = 'INSERT INTO article
  25.                 VALUES(default, :author_id, :category_id, :title, :perex, :text, :created_at)';
  26.         $data = [
  27.             ':author_id' => $authorID,
  28.             ':category_id' => $categoryID,
  29.             ':title' => $title,
  30.             ':perex' => $perex,
  31.             ':text' => $text,
  32.             ':created_at' => $createdAt
  33.         ];
  34.        
  35.         return $this->db->insert($sql, $data);
  36.     }
  37.    
  38.     /*function getStory($id) {
  39.         $sql = 'SELECT author.name AS authorName, author.surname AS authorSurname, category.name AS catName, article.*
  40.                 FROM article
  41.                 INNER JOIN author ON article.author_id = author.id
  42.                 INNER JOIN category ON article.category_id = category.id
  43.                 WHERE author.id = :id';
  44.         //$sql = 'SELECT * FROM student WHERE id = :id';
  45.         return $this->db->selectOne($sql, [':id' => $id]);
  46.     }*/
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement