Advertisement
Guest User

Seris.php

a guest
Jun 26th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. <?php
  2.  
  3. //CLASS TO HANDLE SERIES
  4.  
  5. class Series
  6. {
  7.     // Series id from database
  8.     public $id = null;
  9.    
  10.     //Series category from database
  11.     public $category = null;
  12.    
  13.     //If the series is a featured series or not
  14.     public $feature = null;
  15.    
  16.     //The name of the series
  17.     public $title = null;
  18.    
  19.     //Description of the series
  20.     public $description = null;
  21.    
  22.     //Poster for this series or movie
  23.     public $poster = null;
  24.    
  25.     //If this is a seris or movie, movies=1 series=0
  26.     public $isMovie = null;
  27.    
  28.     //What country this series/movie available from. US=1, Worldwide=0
  29.     public $country = null;
  30.    
  31.     //How many clicks this movieORSeries received
  32.     public $clicks = null;
  33.    
  34.    
  35.    
  36.     //Sets the object's properties using the values in the supplied array
  37.     public function _construct( $data=array() ){
  38.         if( isset ( $data['id'] ) ) $this->id = (int) $data['id'];
  39.         if( isset ( $data['category'] ) ) $this->category = (int) $data['category'];
  40.         if( isset ( $data['feature'] ) ) $this->featured = (int) $data['feature'];
  41.         if( isset ( $data['title'] ) ) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title']);
  42.         if( isset ( $data['description'] ) ) $this->description = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['description']);
  43.         if( isset ( $data['poster'] ) ) $this->poster = preg_replace ( "/[^\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['poster']);
  44.         if( isset ( $data['isMovie'] ) ) $this->isMovie = (int) $data['isMovie'];
  45.         if( isset ( $data['US'] ) ) $this->country = (int) $data['US'];
  46.         if( isset ( $data['clicks'] ) ) $this->clicks = (int) $data['clicks'];
  47.     }
  48.    
  49.    
  50.    
  51.     //Sets the object's properties using the edit form post values in the supplied array
  52.     public function storeFormValues( $params ){
  53.    
  54.         //Store all the parameters
  55.         $this->__contruct( $params );
  56.    
  57.     }
  58.    
  59.    
  60.    
  61.     //Returns a Series Object matching the given series id
  62.     public static function getById( $id ){
  63.         $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  64.         $sql = "SELECT * FROM series WHERE id=:id";
  65.         $st = $conn->prepare( $sql );
  66.         $st->bindValue( ":id", $id, PDO::PARAM_INT );
  67.         $st->execute();
  68.         $row = $st->fetch();
  69.         $conn = null;
  70.         if( $row ) return new Series( $row );
  71.     }
  72.    
  73.    
  74.    
  75.     //Return all (or range of) Series objects in the db
  76.     public static function getList( $numRows=100000, $order="id DESC" ){
  77.         $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  78.         $sql = "SELECT id, description FROM series ORDER BY :order LIMIT :numRows";
  79.         //SQL_CALC_FOUND_ROWS *
  80.         $st = $conn->prepare( $sql );
  81.         $st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
  82.         $st->bindValue( ":order", $order, PDO::PARAM_STR );
  83.         $st->execute();
  84.         $list = array();
  85.        
  86.         while( $row = $st->fetch() ){
  87.             $series = new Series( $row );
  88.             $list = $series;   
  89.         }
  90.  
  91.        
  92.         //Now get the total number of series that match the criteria
  93.         $sql = "SELECT FOUND_ROWS() AS totalRows";
  94.         $totalRows = $conn->query( $sql )->fetch();
  95.         $conn =  null;
  96.         return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
  97.        
  98.     }
  99.    
  100.    
  101.    
  102.     //Inserts current Series object into database and sets its ID properties
  103.     public function insert(){
  104.    
  105.     //Check if the Series object already has an id
  106.     if( !is_null ( $this->id ) ) trigger_error ( "Series::insert() Attempt to insert a Series object that already has it ID property set ( to $this->id ).", E_USER_ERROR );
  107.    
  108.     //Insert the series
  109.     $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  110.     $sql = "INSER INTO series (name, description, category, poster, isMovie, US ) VALUES ( :title :description, :category, :poster, :isMovie, :country )";
  111.     $st = $conn->prepare( $sql );
  112.     $st->bindValue( ":title", $this->title, PDO::PARAM_STR );
  113.     $st->bindValue( ":description", $this->description, PDO::PARAM_STR );
  114.     $st->bindValue( ":category", $this->category, PDO::PARAM_INT );
  115.     $st->bindValue( ":poster", $this->poster, PDO::PARAM_STR );
  116.     $st->bindValue( ":isMovie", $this->isMovie, PDO::PARAM_INT );
  117.     $st->bindValue( ":country", $this->country, PDO::PARAM_INT );
  118.     $st->execute();
  119.     $this->id = $conn->lastInsertId();
  120.     $conn =  null;
  121.     }
  122.    
  123.    
  124.    
  125.     //Updates current Series in Database
  126.     public function update(){
  127.    
  128.     //Check if the Series object has an ID
  129.     if( !is_null ( $this->id ) ) trigger_error ( "Serries::update(): Attempt to update a Series object that does not has an ID set.", E_USSER_ERROR );
  130.    
  131.     //Updates the Series
  132.     $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  133.     $sql = "UPDATE series SET name=:title, description=:description, category=:category, poster=:poster, isMovie=:isMovie, US=:country, feature=:feature WHERE id=:id";
  134.     $st = $conn->prepare($sql);
  135.     $st->bindValue( ":title", $this->title, PDO::PARAM_STR );
  136.     $st->bindValue( ":description", $this->description, PDO::PARAM_STR );
  137.     $st->bindValue( ":category", $this->category, PDO::PARAM_INT );
  138.     $st->bindValue( ":poster", $this->poster, PDO::PARAM_STR );
  139.     $st->bindValue( ":isMovie", $this->isMovie, PDO::PARAM_INT );
  140.     $st->bindValue( ":country", $this->country, PDO::PARAM_INT );
  141.     $st->bindValue( ":feature", $this->feature, PDO::PARAM_INT );
  142.     $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
  143.     $st->execute();
  144.     $conn = null;
  145.     }
  146.  
  147.     //Delete current Series object from Database
  148.     public function delete(){
  149.    
  150.     //Delete the seroes
  151.     $conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
  152.     $st = $conn->prepate( "DELETE FROM series WHERE id = :id LIMIT=1" );
  153.     $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
  154.     $st->execute();
  155.     $conn = null;
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement