Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //CLASS TO HANDLE SERIES
- class Series
- {
- // Series id from database
- public $id = null;
- //Series category from database
- public $category = null;
- //If the series is a featured series or not
- public $feature = null;
- //The name of the series
- public $title = null;
- //Description of the series
- public $description = null;
- //Poster for this series or movie
- public $poster = null;
- //If this is a seris or movie, movies=1 series=0
- public $isMovie = null;
- //What country this series/movie available from. US=1, Worldwide=0
- public $country = null;
- //How many clicks this movieORSeries received
- public $clicks = null;
- //Sets the object's properties using the values in the supplied array
- public function _construct( $data=array() ){
- if( isset ( $data['id'] ) ) $this->id = (int) $data['id'];
- if( isset ( $data['category'] ) ) $this->category = (int) $data['category'];
- if( isset ( $data['feature'] ) ) $this->featured = (int) $data['feature'];
- if( isset ( $data['title'] ) ) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title']);
- if( isset ( $data['description'] ) ) $this->description = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['description']);
- if( isset ( $data['poster'] ) ) $this->poster = preg_replace ( "/[^\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['poster']);
- if( isset ( $data['isMovie'] ) ) $this->isMovie = (int) $data['isMovie'];
- if( isset ( $data['US'] ) ) $this->country = (int) $data['US'];
- if( isset ( $data['clicks'] ) ) $this->clicks = (int) $data['clicks'];
- }
- //Sets the object's properties using the edit form post values in the supplied array
- public function storeFormValues( $params ){
- //Store all the parameters
- $this->__contruct( $params );
- }
- //Returns a Series Object matching the given series id
- public static function getById( $id ){
- $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
- $sql = "SELECT * FROM series WHERE id=:id";
- $st = $conn->prepare( $sql );
- $st->bindValue( ":id", $id, PDO::PARAM_INT );
- $st->execute();
- $row = $st->fetch();
- $conn = null;
- if( $row ) return new Series( $row );
- }
- //Return all (or range of) Series objects in the db
- public static function getList( $numRows=100000, $order="id DESC" ){
- $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
- $sql = "SELECT id, description FROM series ORDER BY :order LIMIT :numRows";
- //SQL_CALC_FOUND_ROWS *
- $st = $conn->prepare( $sql );
- $st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
- $st->bindValue( ":order", $order, PDO::PARAM_STR );
- $st->execute();
- $list = array();
- while( $row = $st->fetch() ){
- $series = new Series( $row );
- $list = $series;
- }
- //Now get the total number of series that match the criteria
- $sql = "SELECT FOUND_ROWS() AS totalRows";
- $totalRows = $conn->query( $sql )->fetch();
- $conn = null;
- return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
- }
- //Inserts current Series object into database and sets its ID properties
- public function insert(){
- //Check if the Series object already has an id
- 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 );
- //Insert the series
- $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
- $sql = "INSER INTO series (name, description, category, poster, isMovie, US ) VALUES ( :title :description, :category, :poster, :isMovie, :country )";
- $st = $conn->prepare( $sql );
- $st->bindValue( ":title", $this->title, PDO::PARAM_STR );
- $st->bindValue( ":description", $this->description, PDO::PARAM_STR );
- $st->bindValue( ":category", $this->category, PDO::PARAM_INT );
- $st->bindValue( ":poster", $this->poster, PDO::PARAM_STR );
- $st->bindValue( ":isMovie", $this->isMovie, PDO::PARAM_INT );
- $st->bindValue( ":country", $this->country, PDO::PARAM_INT );
- $st->execute();
- $this->id = $conn->lastInsertId();
- $conn = null;
- }
- //Updates current Series in Database
- public function update(){
- //Check if the Series object has an ID
- 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 );
- //Updates the Series
- $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
- $sql = "UPDATE series SET name=:title, description=:description, category=:category, poster=:poster, isMovie=:isMovie, US=:country, feature=:feature WHERE id=:id";
- $st = $conn->prepare($sql);
- $st->bindValue( ":title", $this->title, PDO::PARAM_STR );
- $st->bindValue( ":description", $this->description, PDO::PARAM_STR );
- $st->bindValue( ":category", $this->category, PDO::PARAM_INT );
- $st->bindValue( ":poster", $this->poster, PDO::PARAM_STR );
- $st->bindValue( ":isMovie", $this->isMovie, PDO::PARAM_INT );
- $st->bindValue( ":country", $this->country, PDO::PARAM_INT );
- $st->bindValue( ":feature", $this->feature, PDO::PARAM_INT );
- $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
- $st->execute();
- $conn = null;
- }
- //Delete current Series object from Database
- public function delete(){
- //Delete the seroes
- $conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
- $st = $conn->prepate( "DELETE FROM series WHERE id = :id LIMIT=1" );
- $st->bindValue( ":id", $this->id, PDO::PARAM_INT );
- $st->execute();
- $conn = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement