1: <?php
2:
3: /**
4: *
5: * @package Plugin
6: * @subpackage FormAssistant
7: * @version SVN Revision $Rev:$
8: * @author marcus.gnass
9: * @copyright four for business AG
10: * @link http://www.4fb.de
11: */
12:
13: // assert CONTENIDO framework
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: /**
17: * Abstract base class for all classes that are used as PIFA form module.
18: *
19: * In order for an extension class to be displayed in the CMS_PIFAFORM's editor
20: * as module class it has to extend this class and implement its abstract
21: * methods doGet() & doPost().
22: *
23: * @author marcus.gnass
24: */
25: abstract class PifaAbstractFormModule {
26:
27: /**
28: * The HTTP GET request method.
29: *
30: * @var string
31: */
32: const GET = 'GET';
33:
34: /**
35: * The HTTP POST request method.
36: *
37: * @var string
38: */
39: const POST = 'POST';
40:
41: /**
42: * Array of settings as defined for a content type CMS_PIFAFORM.
43: *
44: * @var array
45: */
46: protected $_settings = array();
47:
48: /**
49: * The unique ID of the form to be displayed and processed by this module.
50: * This ID is read from the given settings (pifaform_idform).
51: *
52: * @var int
53: */
54: private $_idform = 0;
55:
56: /**
57: * The current template name to be used when displaying the form.
58: * This name usually depends upon the request method to be used.
59: * These names are read from the given settings.
60: *
61: * @var string
62: */
63: private $_templateName = '';
64:
65: /**
66: *
67: * @var cSmartyFrontend
68: */
69: private $_tpl = NULL;
70:
71: /**
72: *
73: * @param array $settings as defined for cContentTypePifaForm
74: */
75: public function __construct(array $settings = NULL) {
76: $this->_settings = $settings;
77: $this->_idform = cSecurity::toInteger($this->_settings['pifaform_idform']);
78: $this->_tpl = cSmartyFrontend::getInstance(true);
79: }
80:
81: /**
82: *
83: * @return array
84: */
85: public function getSettings() {
86: return $this->_settings;
87: }
88:
89: /**
90: *
91: * @param string $key
92: * @return mixed
93: */
94: public function getSetting($key) {
95: return $this->_settings[$key];
96: }
97:
98: /**
99: *
100: * @param array $_settings
101: */
102: public function setSettings(array $_settings) {
103: $this->_settings = $_settings;
104: }
105:
106: /**
107: *
108: * @return int
109: */
110: public function getIdform() {
111: return $this->_idform;
112: }
113:
114: /**
115: *
116: * @param int $_idform
117: */
118: public function setIdform($_idform) {
119: $this->_idform = $_idform;
120: }
121:
122: /**
123: *
124: * @return string
125: */
126: public function getTemplateName() {
127: return $this->_templateName;
128: }
129:
130: /**
131: *
132: * @param string $_templateName
133: */
134: public function setTemplateName($_templateName) {
135: $this->_templateName = $_templateName;
136: }
137:
138: /**
139: *
140: * @return cSmartyFrontend
141: */
142: public function getTpl() {
143: return $this->_tpl;
144: }
145:
146: /**
147: *
148: * @param cSmartyFrontend $_tpl
149: */
150: public function setTpl(cSmartyFrontend $_tpl) {
151: $this->_tpl = $_tpl;
152: }
153:
154: /**
155: * Helper method to determine the current request method.
156: * The request method is returned as uppercase string.
157: *
158: * @return string
159: */
160: protected function _getRequestMethod() {
161: $requestMethod = $_SERVER['REQUEST_METHOD'];
162: $requestMethod = strtoupper($requestMethod);
163:
164: return $requestMethod;
165: }
166:
167: /**
168: *
169: * @param bool $return
170: * @throws PifaException if request method is unknown
171: */
172: public function render($return = false) {
173:
174: // determine request method
175: $requestMethod = $this->_getRequestMethod();
176:
177: // always handle POST method in backend edit mode as GET action
178: if (cRegistry::isBackendEditMode()) {
179: $requestMethod = self::GET;
180: }
181:
182: // dispatch request method
183: switch ($requestMethod) {
184: case self::GET:
185: $this->doGet();
186: break;
187: case self::POST:
188: $this->doPost();
189: break;
190: default:
191: $msg = Pifa::i18n('UNKNOWN_REQUEST_METHOD');
192: throw new PifaException($msg);
193: }
194:
195: // fetch || display template
196: $clientConfig = cRegistry::getClientConfig(cRegistry::getClientId());
197: $path = $clientConfig['template']['path'];
198: if (true === $return) {
199: return $this->_tpl->fetch($path . $this->getTemplateName());
200: } else {
201: $this->_tpl->display($path . $this->getTemplateName());
202: }
203: }
204:
205: /**
206: * Handle GET request.
207: *
208: * @param array $values
209: * @param array $errors
210: */
211: abstract protected function doGet(array $values = array(), array $errors = array());
212:
213: /**
214: * Handle POST request.
215: */
216: abstract protected function doPost();
217: }
218: