PHP Classes

File: doc/examples/website/controllers/controller.movies.php

Recommend this page to a friend!
  Classes of Kristo Vaher  >  Wave Framework  >  doc/examples/website/controllers/controller.movies.php  >  Download  
File: doc/examples/website/controllers/controller.movies.php
Role: Class source
Content type: text/plain
Description: Example Controller
Class: Wave Framework
MVC framework for building Web sites and APIs
Author: By
Last change: Release candidate for 3.2.0 version. Database cache and Memcache support has been added for caching. Custom session handling is now supported. Also expanded cache feature guide documentation with information about APC and Memcache. Added option to return cache with only specific age with getCache() method call. Fixed PHPDoc comments. Added new configuration options.
Date: 9 years ago
Size: 3,956 bytes
 

Contents

Class file image Download
<?php

/**
 * Website Tutorial <http://www.waveframework.com>
 * Tutorial Movie Controller
 *
 * It is recommended to extend View classes from WWW_Factory in order to
 * provide various useful functions and API access for the view.
 *
 * @package Factory
 * @author Kristo Vaher <kristo@waher.net>
 * @copyright Copyright (c) 2012, Kristo Vaher
 * @license Unrestricted
 * @tutorial /doc/pages/tutorial_website.htm
 * @since 1.0.0
 * @version 1.0.0
 */

class WWW_controller_movies extends WWW_Factory {

   
/**
     * Data to be returned is stored in this variable
     */
   
public $returnData=array();
   
   
/**
     * Adding movie data to database
     *
     * @param array $input input data array
     * @input [title] movie title
     * @input [year] movie year
     * @input [success-url] URL to redirect to if adding was a success
     * @input [failure-url] URL to redirect to if adding was a failure
     * @return array
     * @output [success] if adding was a success
     * @output [error] if error was encountered
     * @output [www-remporary-redirect] if client should be redirected
     */
   
public function add($input){
        if(!isset(
$input['title']) || $input['title']==''){
           
$this->returnData['error']='Title is missing';
        } else if(!isset(
$input['year']) || $input['year']==''){
           
$this->returnData['error']='Year is missing';
        } else {
           
// This loads the model object from the class we created
           
$movie=$this->getModel('movie');
           
$movie->setTitle($input['title']);
           
$movie->setYear($input['year']);
            if(
$movie->saveMovie()){
               
$this->returnData['success']='Movie saved!';
            } else {
               
$this->returnData['error']='Could not save movie!';
            }
        }
       
// If an error is detected
       
if(isset($this->returnData['error']) && isset($input['failure-url'])){
           
// This is a callback keyword that sets the redirect header
           
$this->returnData['www-temporary-redirect']=$input['failure-url'];
        } elseif(isset(
$input['success-url'])){
           
// This is a callback keyword that sets the redirect header
           
$this->returnData['www-temporary-redirect']=$input['success-url'];
        }
        return
$this->returnData;
    }
   
   
/**
     * This returns data about a movie based on ID
     *
     * @param array $input input data array
     * @input [id] movie ID
     * @return array
     * @output [title] movie title
     * @output [year] movie year
     * @output [id] movie ID
     * @output [error] if ID was incorrect or movie was not found
     */
   
public function get($input){
        if(!isset(
$input['id']) || $input['id']=='' || $input['id']==0){
           
$this->returnData['error']='ID is incorrect!';
        } else {
           
$movie=$this->getModel('movie');
           
$movie=$movie->loadMovie($input['id']);
            if(
$movie){
               
$this->returnData=$movie;
            } else {
               
$this->returnData['error']='Cannot find movie with this ID!';
            }
        }
        return
$this->returnData;
    }
   
   
/**
     * This loads all listed movies from database
     *
     * @return array
     * @output [title] movie title
     * @output [year] movie year
     * @output [id] movie ID
     * @output [error] if ID was incorrect or movies were not found
     */
   
public function all(){
       
$movies=$this->getModel('movie');
       
$movies=$movies->loadAllMovies();
        if(
$movies){
           
$this->returnData=$movies;
        } else {
           
$this->returnData['error']='Cannot find movies!';
        }
        return
$this->returnData;
    }
   
   
/**
     * This deletes a movie from database
     *
     * @param array $input input data array
     * @input [id] movie ID
     * @return array
     * @output [success] if movie was deleted
     * @output [error] if ID was incorrect or movie was not found
     */
   
public function delete($input){
        if(!isset(
$input['id']) || $input['id']=='' || $input['id']==0){
           
$this->returnData['error']='ID is incorrect!';
        } else {
           
$movie=$this->getModel('movie');
           
$movie=$movie->deleteMovie($input['id']);
            if(
$movie){
               
$this->returnData['success']='Movie deleted!';
            } else {
               
$this->returnData['error']='Cannot find movie with this ID!';
            }
        }
        return
$this->returnData;
    }

}
   
?>

For more information send a message to info at phpclasses dot org.