ODE STYLE Formating gulliver/system/class.controller.php

Change format files in gulliver/system/class.controller.php
This commit is contained in:
norahmollo
2012-10-17 15:38:04 +00:00
parent 1d7954bcc6
commit 5c6d1230bc

View File

@@ -1,268 +1,296 @@
<?php <?php
/**
* Controller Class /**
* Implementing MVC Pattern * Controller Class
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com> * Implementing MVC Pattern
* @package gulliver.system *
* @access private * @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
*/ * @package gulliver.system
class Controller * @access private
{ */
/** class Controller
* @var boolean debug switch for general purpose {
*/ /**
public $debug = null; *
/** * @var boolean debug switch for general purpose
* @var array - private array to store proxy data */
*/ public $debug = null;
private $__data__ = array(); /**
*
/** * @var array - private array to store proxy data
* @var object - private object to store the http request data */
*/ private $__data__ = array ();
private $__request__;
/**
/** *
* @var object - headPublisher object to handle the output * @var object - private object to store the http request data
*/ */
private $headPublisher = null; private $__request__;
/** /**
* @var string - response type var. possibles values: json|plain *
*/ * @var object - headPublisher object to handle the output
private $responseType = ''; */
private $headPublisher = null;
/**
* @var string - layout to pass skinEngine /**
*/ *
private $layout = ''; * @var string - response type var. possibles values: json|plain
*/
/** private $responseType = '';
* Magic setter method
* /**
* @param string $name *
* @param string $value * @var string - layout to pass skinEngine
*/ */
public function __set($name, $value) private $layout = '';
{
$this->__data__[$name] = $value; /**
} * Magic setter method
*
/** * @param string $name
* Magic getter method * @param string $value
* */
* @param string $name public function __set ($name, $value)
* @return string or NULL if the internal var doesn't exist {
*/ $this->__data__[$name] = $value;
public function __get($name) }
{
if (array_key_exists($name, $this->__data__)) { /**
return $this->__data__[$name]; * Magic getter method
} *
* @param string $name
$trace = debug_backtrace(); * @return string or NULL if the internal var doesn't exist
trigger_error( */
'Undefined property via __get(): ' . $name . public function __get ($name)
' in ' . $trace[0]['file'] . {
' on line ' . $trace[0]['line'], if (array_key_exists( $name, $this->__data__ )) {
E_USER_NOTICE); return $this->__data__[$name];
return null; }
}
$trace = debug_backtrace();
/** trigger_error( 'Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE );
* Magic isset method return null;
* @param string $name }
*/
public function __isset($name) /**
{ * Magic isset method
return isset($this->__data__[$name]); *
} * @param string $name
*/
public function __isset ($name)
/** {
* Magic unset method return isset( $this->__data__[$name] );
* @param string $name }
*/
public function __unset($name) /**
{ * Magic unset method
unset($this->__data__[$name]); *
} * @param string $name
*/
/** public function __unset ($name)
* Set Response type method {
* @param string $type contains : json|plain unset( $this->__data__[$name] );
*/ }
public function setResponseType($type)
{ /**
$this->responseType = $type; * Set Response type method
} *
* @param string $type contains : json|plain
/** */
* call to execute a internal proxy method and handle its exceptions public function setResponseType ($type)
* @param string $name {
*/ $this->responseType = $type;
public function call($name) }
{
try { /**
$result = $this->$name($this->__request__); * call to execute a internal proxy method and handle its exceptions
if ($this->responseType == 'json') { *
print G::json_encode($result); * @param string $name
} */
} catch (Exception $e) { public function call ($name)
if ($this->responseType != 'json') { {
$result->exception->class = get_class($e); try {
$result->exception->code = $e->getCode(); $result = $this->$name( $this->__request__ );
if ($this->responseType == 'json') {
$template = new TemplatePower(PATH_TEMPLATE . 'controller.exception.tpl'); print G::json_encode( $result );
$template->prepare(); }
$template->assign('controller', (function_exists('get_called_class') ? get_called_class() : 'Controller')); } catch (Exception $e) {
$template->assign('message', $e->getMessage()); if ($this->responseType != 'json') {
$template->assign('file', $e->getFile()); $result->exception->class = get_class( $e );
$template->assign('line', $e->getLine()); $result->exception->code = $e->getCode();
$template->assign('trace', $e->getTraceAsString());
$template = new TemplatePower( PATH_TEMPLATE . 'controller.exception.tpl' );
echo $template->getOutputContent(); $template->prepare();
$template->assign( 'controller', (function_exists( 'get_called_class' ) ? get_called_class() : 'Controller') );
} else { $template->assign( 'message', $e->getMessage() );
$result->success = false; $template->assign( 'file', $e->getFile() );
$result->msg = $e->getMessage(); $template->assign( 'line', $e->getLine() );
switch(get_class($e)) { $template->assign( 'trace', $e->getTraceAsString() );
case 'Exception': $error = "SYSTEM ERROR"; break;
case 'PMException': $error = "PROCESSMAKER ERROR"; break; echo $template->getOutputContent();
case 'PropelException': $error = "DATABASE ERROR"; break;
case 'UserException': $error = "USER ERROR"; break; } else {
} $result->success = false;
$result->error = $error; $result->msg = $e->getMessage();
switch (get_class( $e )) {
$result->exception->class = get_class($e); case 'Exception':
$result->exception->code = $e->getCode(); $error = "SYSTEM ERROR";
print G::json_encode($result); break;
} case 'PMException':
} $error = "PROCESSMAKER ERROR";
} break;
case 'PropelException':
/** $error = "DATABASE ERROR";
* Set the http request data break;
* @param array $data case 'UserException':
*/ $error = "USER ERROR";
public function setHttpRequestData($data) break;
{ }
if (!is_object($this->__request__)) { $result->error = $error;
$this->__request__ = new stdclass();
} $result->exception->class = get_class( $e );
if( is_array($data) ) { $result->exception->code = $e->getCode();
while( $var = each($data) ) print G::json_encode( $result );
$this->__request__->$var['key'] = $var['value']; }
} else }
$this->__request__ = $data; }
}
/**
/** * Set the http request data
* Get debug var. method *
* @param boolan $val boolean value for debug var. * @param array $data
*/ */
public function setDebug($val) public function setHttpRequestData ($data)
{ {
$this->debug = $val; if (! is_object( $this->__request__ )) {
} $this->__request__ = new stdclass();
}
/** if (is_array( $data )) {
* Get debug var. method while ($var = each( $data )) {
*/ $this->__request__->$var['key'] = $var['value'];
public function getDebug() }
{ } else {
if ($this->debug === null) { $this->__request__ = $data;
$this->debug = defined('DEBUG') && DEBUG ? true : false; }
} }
return $this->debug; /**
} * Get debug var.
* method
*
/*** HeadPublisher Functions Binding ***/ * @param boolan $val boolean value for debug var.
*/
/** public function setDebug ($val)
* Include a particular extjs library or extension to the main output {
* @param string $srcFile path of a extjs library or extension $this->debug = $val;
* @param boolean $debug debug flag to indicate if the js output will be minifield or not }
* $debug: true -> the js content will be not minified (readable)
* false -> the js content will be minified /**
*/ * Get debug var.
public function includeExtJSLib($srcFile, $debug=false) * method
{ */
$this->getHeadPublisher()->usingExtJs($srcFile, ($debug ? $debug : $this->getDebug())); public function getDebug ()
} {
if ($this->debug === null) {
/** $this->debug = defined( 'DEBUG' ) && DEBUG ? true : false;
* Include a javascript file that is using extjs framework to the main output }
* @param string $srcFile path of javascrit file to include
* @param boolean $debug debug flag to indicate if the js output will be minifield or not return $this->debug;
* $debug: true -> the js content will be not minified (readable) }
* false -> the js content will be minified
*/ /**
public function includeExtJS($srcFile, $debug=false) * * HeadPublisher Functions Binding **
{ */
$this->getHeadPublisher()->addExtJsScript($srcFile, ($debug ? $debug : $this->getDebug()));
} /**
* Include a particular extjs library or extension to the main output
/** *
* Include a Html file to the main output * @param string $srcFile path of a extjs library or extension
* @param string $file path of html file to include to the main output * @param boolean $debug debug flag to indicate if the js output will be minifield or not
*/ * $debug: true -> the js content will be not minified (readable)
public function setView($file) * false -> the js content will be minified
{ */
$this->getHeadPublisher()->addContent($file); public function includeExtJSLib ($srcFile, $debug = false)
} {
$this->getHeadPublisher()->usingExtJs( $srcFile, ($debug ? $debug : $this->getDebug()) );
/** }
* Set variables to be accesible by javascripts
* @param string $name contains var. name /**
* @param string $value conatins var. value * Include a javascript file that is using extjs framework to the main output
*/ *
public function setJSVar($name, $value) * @param string $srcFile path of javascrit file to include
{ * @param boolean $debug debug flag to indicate if the js output will be minifield or not
$this->getHeadPublisher()->assign($name, $value); * $debug: true -> the js content will be not minified (readable)
} * false -> the js content will be minified
*/
/** public function includeExtJS ($srcFile, $debug = false)
* Set variables to be accesible by the extjs layout template {
* @param string $name contains var. name $this->getHeadPublisher()->addExtJsScript( $srcFile, ($debug ? $debug : $this->getDebug()) );
* @param string $value conatins var. value }
*/
public function setVar($name, $value) /**
{ * Include a Html file to the main output
$this->getHeadPublisher()->assignVar($name, $value); *
} * @param string $file path of html file to include to the main output
*/
/** public function setView ($file)
* method to get the local getHeadPublisher object {
*/ $this->getHeadPublisher()->addContent( $file );
public function getHeadPublisher() }
{
if (!is_object($this->headPublisher)) { /**
$this->headPublisher = headPublisher::getSingleton(); * Set variables to be accesible by javascripts
} *
* @param string $name contains var. name
return $this->headPublisher; * @param string $value conatins var. value
} */
public function setJSVar ($name, $value)
public function setLayout($layout) {
{ $this->getHeadPublisher()->assign( $name, $value );
$this->layout = $layout; }
}
/**
public function render($type='mvc') * Set variables to be accesible by the extjs layout template
{ *
G::RenderPage('publish', $type, null, $this->layout); * @param string $name contains var. name
} * @param string $value conatins var. value
*/
public function header($header) public function setVar ($name, $value)
{ {
G::header($header); $this->getHeadPublisher()->assignVar( $name, $value );
} }
public function redirect($url) /**
{ * method to get the local getHeadPublisher object
G::header("Location: $url"); */
} public function getHeadPublisher ()
} {
if (! is_object( $this->headPublisher )) {
$this->headPublisher = headPublisher::getSingleton();
}
return $this->headPublisher;
}
public function setLayout ($layout)
{
$this->layout = $layout;
}
public function render ($type = 'mvc')
{
G::RenderPage( 'publish', $type, null, $this->layout );
}
public function header ($header)
{
G::header( $header );
}
public function redirect ($url)
{
G::header( "Location: $url" );
}
}