Advertisement
Guest User

ArticlesModel.php (includes/models)

a guest
Aug 6th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2.    
  3. // it should work with DB in direct way no filter etc...   
  4. //this is var but must type it inside the class inside functions   
  5. class ArticlesModel
  6. {
  7.     public function Get($extra='')
  8.     {
  9.         $articles = array();
  10.         System::Get('db')->Execute("SELETE * FROM `articles` {$extra}");
  11.         if(System::Get('db')->AffectedRows()>0)
  12.         {
  13.             $articles = System::Get('db')->GetRows();
  14.         }
  15.         return $articles;
  16.    
  17.     }
  18.    
  19.     // return one article
  20.    
  21.     public function Get_By_Id($id)
  22.     {
  23.        
  24.        
  25.         $id = (int)$id;
  26.         $article = $this->Get("WHERE `id`= $id") ;
  27.         return $article;
  28.    
  29.  
  30.     }
  31.    
  32.     //get catogery by id
  33.     //return array
  34.     public function Get_By_Cat($cid)
  35.     {
  36.        
  37.         $cid = (int)$cid;
  38.         return $this->Get("WHERE `cid` = $cid");
  39.        
  40.     }
  41.    
  42.     //Get last Articles
  43.    
  44.     public function Get_Last($num)
  45.     {
  46.        
  47.         $num = (int)$num;
  48.         return $this->Get("ORDER BY `id` DESC LIMIT $num");
  49.        
  50.     }
  51.    
  52.        
  53.    
  54.     public function Add($data)
  55.     {
  56.        
  57.         if(System::Get('db')->Insert('aticles',$data)){
  58.             return TRUE;
  59.         }
  60.         return FALSE;
  61.        
  62.     }
  63.    
  64.    
  65.     public function Update($id,$data)
  66.    
  67.     {
  68.         $id=(int)$id;
  69.         if(System::Get('db')->Update('aticles',$data,"WHERE `id` = $id")){
  70.             return TRUE;
  71.         }
  72.         return FALSE;      
  73.        
  74.     }
  75.    
  76.     public function Delete($id)
  77.    
  78.     {
  79.        
  80.         $id =(int)$id;
  81.         if(System::Get('db')->Delete('aticles',"WHERE `id` = $id")){
  82.             return TRUE;
  83.         }
  84.         return FALSE;
  85.        
  86.     }
  87.    
  88.    
  89.    
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement