2 /** @package Patient Portal::Controller */
4 /** import supporting libraries */
5 require_once("verysimple/Phreeze/Controller.php");
6 require_once (dirname( __FILE__
)."/../../../lib/appsql.class.php" );
8 * AppBaseController is a base class Controller class from which
9 * the front controllers inherit. it is not necessary to use this
10 * class or any code, however you may use if for application-wide
11 * functions such as authentication
13 * From phreeze package
14 * @license http://www.gnu.org/copyleft/lesser.html LGPL
16 * @package Patient Portal::Controller
17 * @author ClassBuilder
20 class AppBaseController
extends Controller
23 static $DEFAULT_PAGE_SIZE = 20;
26 * Init is called by the base controller before the action method
27 * is called. This provided an oportunity to hook into the system
28 * for all application actions. This is a good place for authentication
31 protected function Init()
34 /* if ( !in_array($this->GetRouter()->GetUri(),array('login','loginform','logout')) )
36 require_once("App/SecureApp.php");
37 $this->RequirePermission(SecureApp::$PERMISSION_ADMIN,'SecureApp.LoginForm');
43 * Returns the number of records to return per page
44 * when pagination is used
46 protected function GetDefaultPageSize()
48 return self
::$DEFAULT_PAGE_SIZE;
52 * Returns the name of the JSONP callback function (if allowed)
54 protected function JSONPCallback()
56 // TODO: uncomment to allow JSONP
57 // return RequestUtil::Get('callback','');
63 * Return the default SimpleObject params used when rendering objects as JSON
66 protected function SimpleObjectParams()
68 return array('camelCase'=>true);
72 * Helper method to get values from stdClass without throwing errors
73 * @param stdClass $json
75 * @param string $default
77 protected function SafeGetVal($json, $prop, $default='')
79 return (property_exists($json,$prop))
85 * Helper utility that calls RenderErrorJSON
88 protected function RenderExceptionJSON(Exception
$exception)
90 $this->RenderErrorJSON($exception->getMessage(),null,$exception);
94 * Output a Json error message to the browser
95 * @param string $message
96 * @param array key/value pairs where the key is the fieldname and the value is the error
98 protected function RenderErrorJSON($message, $errors = null, $exception = null)
100 $err = new stdClass();
101 $err->success
= false;
102 $err->message
= $message;
103 $err->errors
= array();
107 foreach ($errors as $key=>$val)
109 $err->errors
[lcfirst($key)] = $val;
115 $err->stackTrace
= explode("\n#", substr($exception->getTraceAsString(),1) );
118 @header
('HTTP/1.1 401 Unauthorized');
119 $this->RenderJSON($err,RequestUtil
::Get('callback'));