1: <?php
2:
3: /**
4: * Abstract base class for all classes that are used as PIFA form module.
5: *
6: * In order for an extension class to be displayed in the CMS_PIFAFORM's editor
7: * as module class it has to extend this class and implement its abstract
8: * methods doGet() & doPost().
9: *
10: * @package Plugin
11: * @subpackage FormAssistant
12: * @version SVN Revision $Rev:$
13: * @author marcus.gnass
14: * @copyright four for business AG
15: * @link http://www.4fb.de
16: */
17:
18: // assert CONTENIDO framework
19: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
20:
21: /**
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 Smarty
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 = Contenido_SmartyWrapper::getInstance(true);
79: }
80:
81: /**
82: *
83: * @return the $_settings
84: */
85: public function getSettings() {
86: return $this->_settings;
87: }
88:
89: /**
90: *
91: * @return the $_settings
92: */
93: public function getSetting($key) {
94: return $this->_settings[$key];
95: }
96:
97: /**
98: *
99: * @param multitype: $_settings
100: */
101: public function setSettings($_settings) {
102: $this->_settings = $_settings;
103: }
104:
105: /**
106: *
107: * @return the $_idform
108: */
109: public function getIdform() {
110: return $this->_idform;
111: }
112:
113: /**
114: *
115: * @param number $_idform
116: */
117: public function setIdform($_idform) {
118: $this->_idform = $_idform;
119: }
120:
121: /**
122: *
123: * @return the $_templateName
124: */
125: public function getTemplateName() {
126: return $this->_templateName;
127: }
128:
129: /**
130: *
131: * @param string $_templateName
132: */
133: public function setTemplateName($_templateName) {
134: $this->_templateName = $_templateName;
135: }
136:
137: /**
138: *
139: * @return the $_tpl
140: */
141: public function getTpl() {
142: return $this->_tpl;
143: }
144:
145: /**
146: *
147: * @param Smarty $_tpl
148: */
149: public function setTpl($_tpl) {
150: $this->_tpl = $_tpl;
151: }
152:
153: /**
154: * Helper method to determine the current request method.
155: * The request method is returned as uppercase string.
156: *
157: * @return string
158: */
159: protected function _getRequestMethod() {
160: $requestMethod = $_SERVER['REQUEST_METHOD'];
161: $requestMethod = strtoupper($requestMethod);
162:
163: return $requestMethod;
164: }
165:
166: /**
167: */
168: public function render($return = false) {
169:
170: // determine request method
171: $requestMethod = $this->_getRequestMethod();
172:
173: // always handle POST method in backend edit mode as GET action
174: if (cRegistry::isBackendEditMode()) {
175: $requestMethod = self::GET;
176: }
177:
178: // dispatch request method
179: switch ($requestMethod) {
180: case self::GET:
181: $this->doGet();
182: break;
183: case self::POST:
184: $this->doPost();
185: break;
186: default:
187: $msg = Pifa::i18n('UNKNOWN_REQUEST_METHOD');
188: throw new PifaException($msg);
189: }
190:
191: // fetch || display template
192: $clientConfig = cRegistry::getClientConfig(cRegistry::getClientId());
193: $path = $clientConfig['template']['path'];
194: if (true === $return) {
195: return $this->_tpl->fetch($path . $this->getTemplateName());
196: } else {
197: $this->_tpl->display($path . $this->getTemplateName());
198: }
199: }
200:
201: /**
202: *
203: * @param array $values
204: * @param array $errors
205: */
206: abstract protected function doGet(array $values = array(), array $errors = array());
207:
208: /**
209: */
210: abstract protected function doPost();
211: }
212: