3 /** @package Patient Portal::Controller */
5 /** import supporting libraries */
6 require_once("verysimple/Phreeze/PortalController.php");
7 require_once(dirname(__FILE__
) . "/../../../lib/appsql.class.php");
9 * AppBaseController is a base class Controller class from which
10 * the front controllers inherit. it is not necessary to use this
11 * class or any code, however you may use if for application-wide
12 * functions such as authentication
14 * From phreeze package
15 * @license http://www.gnu.org/copyleft/lesser.html LGPL
17 * @package Patient Portal::Controller
18 * @author ClassBuilder
21 class AppBasePortalController
extends PortalController
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');
42 * Returns the number of records to return per page
43 * when pagination is used
45 protected function GetDefaultPageSize()
47 return self
::$DEFAULT_PAGE_SIZE;
51 * Returns the name of the JSONP callback function (if allowed)
53 protected function JSONPCallback()
55 // TODO: uncomment to allow JSONP
56 // return RequestUtil::Get('callback','');
62 * Return the default SimpleObject params used when rendering objects as JSON
65 protected function SimpleObjectParams()
67 return array('camelCase' => true);
71 * Helper method to get values from stdClass without throwing errors
72 * @param stdClass $json
74 * @param string $default
76 protected function SafeGetVal($json, $prop, $default = '')
78 return (property_exists($json, $prop))
84 * Helper utility that calls RenderErrorJSON
87 protected function RenderExceptionJSON(Exception
$exception)
89 $this->RenderErrorJSON($exception->getMessage(), null, $exception);
93 * Output a Json error message to the browser
94 * @param string $message
95 * @param array key/value pairs where the key is the fieldname and the value is the error
97 protected function RenderErrorJSON($message, $errors = null, $exception = null)
99 $err = new stdClass();
100 $err->success
= false;
101 $err->message
= $message;
102 $err->errors
= array();
104 if ($errors != null) {
105 foreach ($errors as $key => $val) {
106 $err->errors
[lcfirst($key)] = $val;
111 $err->stackTrace
= explode("\n#", substr($exception->getTraceAsString(), 1));
114 @header
('HTTP/1.1 401 Unauthorized');
115 $this->RenderJSON($err, RequestUtil
::Get('callback'));