Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. include_once 'dbo.php';
  3. include_once 'oPost.php';
  4.  
  5. class postCMS {
  6.     private $db;
  7.  
  8.     public function __construct()
  9.     {
  10.         $this->db = new dbo();
  11.     }
  12.  
  13.     public function insert(oPost $p) {
  14.  
  15.         if(!$db->insert($p))
  16.             throw Exception ("Problem occured during insertion of post into databse.");
  17.  
  18.     }
  19.  
  20.     /**
  21.      * @param oPost $p
  22.      */
  23.     public function update(oPost $p) {
  24.         if(($p->postID != -1) && ($p->postID != NULL)) {
  25.             if(!$db->update($p))
  26.                 throw Exception ("Problem occured during update of post on the database.");
  27.         }
  28.  
  29.     }
  30.  
  31.     public function delete(oPost $p) {
  32.         if(!$db->delete($p))
  33.             throw Exception ("Problem occured during deletion of post from the database.");
  34.     }
  35.  
  36.     public function getByID(int $id) {
  37.         $p = null;
  38.  
  39.         if(is_int($id)) {
  40.             $row = $db->getByID($id);
  41.             $p = new oPost();
  42.  
  43.             $p->populate($row);
  44.         }
  45.         return $p;
  46.     }
  47.  
  48.     // Use to display a number of posts on a page.
  49.     public function display_public(int $pID) {
  50.         $today = getdate(time());
  51.         $list = $db->selectMonthYear($today["mon"], $today["year"]);
  52.         for($i=0; $i<= count($list); $i++) {
  53.  
  54.         $html = <<<HTML
  55.         <div class="post" id="{$list[i]->postID}">
  56.             <h1> {$list[$i]->title} </h1>
  57.             <p class="summary">
  58.                 {$list[i]->summary}
  59.             </p>
  60.                 {$list[i]->date}
  61.         </div>
  62. HTML;
  63.  
  64.         }
  65.     }
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement