Highway to PSR2
[openemr.git] / library / ESign / Abstract / Controller.php
blob4e8f16ca47a297ab890171ad61aaf1080b4ad990
1 <?php
3 namespace ESign;
5 /**
6 * Abstract implementation of the ESign controller. Implement the
7 * rest of me to create your own controller.
9 * Copyright (C) 2013 OEMR 501c3 www.oemr.org
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Ken Chapple <ken@mi-squared.com>
24 * @author Medical Information Integration, LLC
25 * @link http://www.open-emr.org
26 **/
28 require_once $GLOBALS['srcdir'].'/ESign/Viewer.php';
29 require_once $GLOBALS['srcdir'].'/ESign/ViewableIF.php';
31 abstract class Abstract_Controller implements ViewableIF
33 const STATUS_SUCCESS = 'success';
34 const STATUS_FAILURE = 'failure';
36 protected $_method = null;
37 protected $_params = null;
38 protected $_viewDir = null;
39 protected $_viewScript = null;
40 protected $_viewer = null;
41 protected $_request = null;
43 public function __construct(Request $request)
45 $this->_request = $request;
46 $this->_method = $this->_request->getParam('method');
47 $this->_viewDir = $GLOBALS['srcdir']."/ESign/views";
48 $this->_viewScript = 'esign_error.php';
49 $this->_view = new Viewer();
52 /**
53 * Triggered when the module's ESign/ButtonIF is clicked.
54 * The controller method gets all the parameters that match
55 * data-* within the button's attributes.
57 abstract public function esign_form_view();
59 /**
60 * Triggered when the module's form is saved (refresh
61 * the log.)
63 abstract public function esign_log_view();
65 /**
66 * Triggered when the ESign Sigature form is submitted
68 abstract public function esign_form_submit();
70 protected function getRequest()
72 return $this->_request;
75 protected function setViewScript($viewScript)
77 $this->_viewScript = $viewScript;
80 public function getViewScript()
82 return $this->_viewDir.DIRECTORY_SEPARATOR.$this->_viewScript;
85 public function run()
87 if (method_exists($this, $this->_method)) {
88 $this->{$this->_method}();
89 } else {
90 throw new \Exception("The method ".$this->_method." does not exist and cannot be executed");
94 public function getHtml()
96 return $this->_view->getHtml($this);
99 public function render()
101 return $this->_view->render($this);
105 class Request
107 public function __construct()
109 $this->parseParams();
112 public function getParam($key, $default = '')
114 if (isset($this->_params[$key])) {
115 return $this->_params[$key];
118 return $default;
121 protected function parseParams()
123 foreach ($_REQUEST as $key => $value) {
124 $this->_params[$key] = $value;
129 class Response
131 public $status = null;
132 public $message = null;
134 public function __construct($status, $message)
136 $this->status = $status;
137 $this->message = $message;