Overview

Namespaces

  • None
  • PHP
  • picon

Classes

  • AbstractAjaxBehaviour
  • AbstractAssociatedMarkupSource
  • AbstractBehaviour
  • AbstractCallableOption
  • AbstractChoice
  • AbstractColumn
  • AbstractContextLoader
  • AbstractDatabaseDriver
  • AbstractInjectedDataProvider
  • AbstractJQueryBehaviour
  • AbstractJQueryUIBehaviour
  • AbstractLink
  • AbstractMarkupSource
  • AbstractMultipleChoice
  • AbstractOption
  • AbstractPageClassAuthorisationStrategy
  • AbstractRepeater
  • AbstractSingleChoice
  • AbstractTextComponent
  • AbstractToolbar
  • AbstractValidator
  • AjaxButton
  • AjaxEventBehaviour
  • AjaxFormComponentUpdateBehavior
  • AjaxFormSubmitBehavior
  • AjaxLink
  • AjaxRequestTarget
  • AllowAllAuthorisationStrategy
  • AnnotationRule
  • ApplicationConfigLoadListener
  • ApplicationContext
  • ApplicationContextLoadListener
  • ApplicationInitializer
  • ApplicationInitializerConfigLoadListenerCollection
  • ApplicationInitializerContextLoadListenerCollection
  • ApplicationProfile
  • Args
  • ArrayModel
  • ArrayOption
  • AttributeAppender
  • AttributeModifier
  • AutoContextLoader
  • AutoLoader
  • BasicModel
  • BooleanModel
  • BooleanOption
  • Border
  • BorderMarkupSourcingStratagy
  • BorderResolver
  • Button
  • CacheManager
  • CallbackAjaxCallDecorator
  • CallbackColumn
  • CallbackFunctionOption
  • CallbackOption
  • CallbackRowMapper
  • Check
  • CheckBox
  • CheckBoxGroup
  • CheckChoice
  • ChoiceRenderer
  • ClassNameRule
  • ClassNamespaceRule
  • ClassScanner
  • Comment
  • ComonDomainBase
  • Component
  • ComponentAfterRenderListenerCollection
  • ComponentAuthorisationListener
  • ComponentBeforeRenderListenerCollection
  • ComponentInitializationListenerCollection
  • ComponentInjector
  • ComponentInstantiationListenerCollection
  • ComponentRenderHeadListenerCollection
  • ComponentResolverHelper
  • ComponentTag
  • CompoundPropertyModel
  • Config
  • ConfigLoader
  • ContextLoaderFactory
  • DaoSupport
  • DataBaseTemplate
  • DataGridView
  • DataSource
  • DataSourceConfig
  • DataSourceFactory
  • DataSourceType
  • DataTable
  • DateField
  • DatePickerBehaviour
  • DefaultDataTable
  • DefaultJQueryUIBehaviour
  • DefaultMarkupSource
  • DefaultNotAuthorisedListener
  • DialogBehavior
  • DirectToPageComponentNotAuthorisedListener
  • DraggableBehaviour
  • DropDown
  • EmailAddressValidator
  • EmptyPanel
  • Enum
  • ExceptionPageRequestTarget
  • ExtendResolver
  • FeedbackMessage
  • FeedbackModel
  • FeedbackPanel
  • FileModel
  • FileUploadField
  • Form
  • FormComponent
  • FormComponentLabel
  • FormComponentPanel
  • FunctionOption
  • GridItem
  • GridView
  • HeaderContainer
  • HeaderPartContainer
  • HeaderResolver
  • HeaderResponse
  • HeaderToolbar
  • IdenticalValueValidator
  • Identifier
  • Injector
  • JQueryRenderHeadListener
  • JQueryUIRenderHeadListener
  • Label
  • LabeledMarkupContainer
  • Link
  • ListenerCollection
  • ListenerRequestResolver
  • ListenerRequestTarget
  • ListItem
  • ListMultiple
  • ListView
  • Localizer
  • ManualContextLoader
  • MarkupContainer
  • MarkupElement
  • MarkupLoader
  • MarkupParser
  • MarkupUtils
  • MaximumLengthValidator
  • MaximumValidator
  • MinimumLengthValidator
  • MinimumValidator
  • ModalWindow
  • MySqlDriver
  • MySqliDriver
  • NavigationLink
  • NavigationToolbar
  • Navigator
  • NumbericOption
  • NumericValidator
  • Objects
  • Options
  • PageInstanceRequestResolver
  • PageInstanceRequestTarget
  • PageMap
  • PageMapInitializationListenerCollection
  • PageNotFoundPage
  • PageNotFoundRequestTarget
  • PageRequestResolver
  • PageRequestTarget
  • PageRequestWithListenerTarget
  • PaginatingGridView
  • Panel
  • PanelMarkupSource
  • PanelResolver
  • PasswordField
  • PatternValidator
  • PiconApplication
  • PiconErrorHandler
  • PiconSerializer
  • PiconTag
  • PopupSettings
  • PropertyColumn
  • PropertyModel
  • PropertyOption
  • PropertyResolver
  • Radio
  • RadioChoice
  • RadioGroup
  • RangeLengthValidator
  • RangeValidator
  • RedirectRequestTarget
  • RepeatingView
  • RequestCycle
  • RequestResolverCollection
  • RequiredTextField
  • ResourceReference
  • ResourceRequestResolver
  • ResourceRequestTarget
  • SerializableClosure
  • SortableBehavior
  • StaticTabPanel
  • StringValidator
  • SubClassRule
  • Tab
  • TabCollection
  • TabPanel
  • TextArea
  • TextElement
  • TextField
  • TransparentMarkupContainer
  • ValidatableFormComponentWrapper
  • ValidationResponse
  • WebApplicationSecuritySettings
  • WebComponent
  • WebPage
  • WebRequest
  • WebResponse
  • WrappedCompoundModel
  • XMLDocument
  • XMLParser
  • XMLTag
  • XmlTagType

Interfaces

  • AjaxCallDecorator
  • ApplicationInitializerConfigLoadListener
  • ApplicationInitializerContextLoadListener
  • AuthorisationStrategy
  • Behaviour
  • BehaviourListener
  • CallDecoratorWrapper
  • ChoiceGroup
  • ClassScannerRule
  • Column
  • ComponentAfterRenderListener
  • ComponentAwareModel
  • ComponentBeforeRenderListener
  • ComponentInheritedModel
  • ComponentInitializationListener
  • ComponentInstantiationListener
  • ComponentNotAuthorisedListener
  • ComponentRenderHeadListener
  • ComponentResolver
  • CompoundModel
  • DatabaseDriver
  • DataBaseOperations
  • DataProvider
  • Detachable
  • Equalable
  • FormSubmitListener
  • FormSubmitter
  • Identifiable
  • InitializingBean
  • InjectOnWakeup
  • LinkListener
  • Listener
  • MarkupSource
  • Model
  • Pageable
  • PageMapInitializationListener
  • Request
  • RequestablePage
  • RequestResolver
  • RequestTarget
  • Response
  • RowMapper
  • Validatable
  • Validator
  • XmlElement

Exceptions

  • ConfigException
  • ConversionException
  • RestartRequestOnPageException
  • SQLException
  • UnAuthorisdeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * Picon Framework
  5:  * http://code.google.com/p/picon-framework/
  6:  *
  7:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
  8: 
  9:  * Picon Framework is free software: you can redistribute it and/or modify
 10:  * it under the terms of the GNU General Public License as published by
 11:  * the Free Software Foundation, either version 3 of the License, or
 12:  * (at your option) any later version.
 13: 
 14:  * Picon Framework is distributed in the hope that it will be useful,
 15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17:  *  General Public License for more details.
 18: 
 19:  * You should have received a copy of the GNU General Public License
 20:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
 21:  * */
 22: 
 23: namespace picon;
 24: 
 25: /**
 26:  * Superclass for all form components
 27:  * 
 28:  * @author Martin Cassidy
 29:  * @package web/markup/html/form
 30:  */
 31: abstract class FormComponent extends LabeledMarkupContainer
 32: {    
 33:     /**
 34:      * An array of Validator
 35:      * 
 36:      * @var array
 37:      */
 38:     private $validators = array();
 39:     
 40:     private $emptyInput = false;
 41:     
 42:     /**
 43:      * @var mixed The raw input from the request 
 44:      */
 45:     private $rawInput;
 46:     
 47:     /**
 48:      *
 49:      * @var mixed the processed and converted input for the form component
 50:      * @Transient
 51:      */
 52:     private $convertedInput;
 53:     
 54:     /**
 55:      * @var boolean is this form component manditory 
 56:      */
 57:     private $required = false;
 58:     
 59:     private $disabled = false;
 60:     
 61:     /**
 62:      * Add a new validator, child component or behavior to the component
 63:      * @param mixed $object
 64:      * @return void 
 65:      */
 66:     public function add(&$object)
 67:     {
 68:         if($object instanceof Validator)
 69:         {
 70:             $this->addValidator($object);
 71:             return;
 72:         }
 73:         parent::add($object);
 74:     }
 75:     
 76:     /**
 77:      * Add a new validator to the component
 78:      * @param Validator $validator 
 79:      */
 80:     public function addValidator(Validator &$validator)
 81:     {
 82:         array_push($this->validators, $validator);
 83:     }
 84:     
 85:     /**
 86:      * @todo
 87:      * @return type 
 88:      */
 89:     public function getLabel()
 90:     {
 91:         return "";
 92:     }
 93:     
 94:     protected function onComponentTag(ComponentTag $tag)
 95:     {
 96:         parent::onComponentTag($tag);
 97:         $tag->put('name', $this->getName());
 98:         
 99:         if($this->disabled)
100:         {
101:             $tag->put('disabled', 'disabled');
102:         }
103:     }
104:     
105:     /**
106:      * Find the form in which this component is located
107:      * @return Form The form to which this component belongs 
108:      */
109:     public function getForm()
110:     {
111:         $form;
112:         $callback = function($component) use (&$form)
113:         {
114:             $form = $component;
115:             return Component::VISITOR_STOP_TRAVERSAL;
116:         };
117:         $this->visitParents(Form::getIdentifier(), $callback);
118:         return $form;
119:     }
120:     
121:     /**
122:      * @return string The raw input from the request
123:      */
124:     public function getRawInput()
125:     {
126:         return $this->rawInput;
127:     }
128:     
129:     /**
130:      * 
131:      * @return array
132:      */
133:     public function getRawInputArray()
134:     {
135:         $input = $this->getRawInput();
136:         if($input==null)
137:         {
138:             return array();
139:         }
140:         if(!is_array($input))
141:         {
142:             throw new \InvalidArgumentException('CheckBoxGroup expected raw input to be an array');
143:         }
144:         return $input;
145:     }
146:     
147:     /**
148:      * {@inheritdoc}
149:      * @return boolean 
150:      */
151:     public function validate()
152:     {
153:         if($this->disabled)
154:         {
155:             return;
156:         }
157:         
158:         if($this->isValid())
159:         {
160:             $this->validateRequired();
161:         }
162: 
163:         if($this->isValid())
164:         {
165:             $this->convertInput();
166:         }
167:             
168:         if($this->isValid() && !$this->isEmptyInput())
169:         {
170:             $validatable = new ValidatableFormComponentWrapper($this);
171:             foreach($this->validators as $validator)
172:             {
173:                 $validator->validate($validatable);
174:             }
175:         }
176:         
177:         if($this->isValid())
178:         {
179:             $this->valid();
180:         }
181:     }
182:     
183:     /**
184:      * Update the model object of the form component with the new
185:      * object value.
186:      * 
187:      * This should only be called after the conponent has been validated.
188:      * Do not call this method unless you know what you are doing!
189:      */
190:     public function updateModel()
191:     {
192:         if($this->disabled)
193:         {
194:             return;
195:         }
196:         $this->setModelObject($this->convertedInput);
197:     }
198:     
199:     /**
200:      * Complete a full form component process: validate,
201:      * if valid update the model
202:      */
203:     public final function processInput()
204:     {
205:         $this->inputChanged();
206:         $valid = $this->validate();
207:         
208:         if($this->isValid())
209:         {
210:             $this->updateModel();
211:         }
212:     }
213:     
214:     /**
215:      * Convert the input from its raw format the that which is expected
216:      * Sub classes which need to handle this themselves should override this method
217:      * and have getType() throw UnsupportedOperationException
218:      */
219:     protected abstract function convertInput();
220:     
221:     public function isValid()
222:     {
223:         return !$this->hasErrorMessage();
224:     }
225:     
226:     /**
227:      *
228:      * @param boolean $required 
229:      */
230:     public function setRequired($required)
231:     {
232:         Args::isBoolean($required, 'required');
233:         $this->required = $required;
234:     }
235:     
236:     public function isRequired()
237:     {
238:         return $this->required;
239:     }
240:     
241:     public function validateRequired()
242:     {
243:         if($this->isRequired() && !$this->disabled && ($this->rawInput==null || empty($this->rawInput) || (is_array($this->rawInput) && count($this->rawInput)<1)))
244:         {
245:             $data = array('name' => $this->getId());
246:             $message = $this->getLocalizer()->getString($this->getComponentKey('Required'), new ArrayModel($data));
247:             $this->error($message);
248:             $this->invalid();
249:         }
250:     }
251:     
252:     public function getConvertedInput()
253:     {
254:         return $this->convertedInput;
255:     }
256:     
257:     protected function setConvertedInput($convertedInput)
258:     {
259:         $this->convertedInput = $convertedInput;
260:     }
261:     
262:     public function getName()
263:     {
264:         return str_replace('.', '_', $this->getComponentPath());
265:     }
266:     
267:     /**
268:      * Called by Form when the form input has changed
269:      */
270:     public function inputChanged()
271:     {
272:         if($this->disabled)
273:         {
274:             return;
275:         }
276:         $this->emptyInput = false;
277:         
278:         $raw = $this->getRequest()->getPostedParameter(str_replace('[]', '', $this->getName()));
279:         
280:         if($raw!=null && !empty($raw) || is_array($raw) && count($raw)>0)
281:         {
282:             $this->rawInput = $raw;
283:         }
284:         else
285:         {
286:             $this->emptyInput = true;
287:             $this->rawInput = null;
288:         }
289:     }
290:     
291:     public function getValue()
292:     {
293:         $input = null;
294:         if($this->disabled)
295:         {
296:             $input = $this->getModelObjectAsString();
297:         }
298:         if($this->rawInput==null)
299:         {
300:             if($this->emptyInput==true)
301:             {
302:                 return null;
303:             }
304:             else
305:             {
306:                 $input = $this->getModelObjectAsString();
307:             }
308:         }
309:         else
310:         {
311:             $input = $this->rawInput;
312:         }
313:         return htmlentities($input);
314:     }
315:     
316:     public function invalid()
317:     {
318:         
319:     }
320:     
321:     public function valid()
322:     {
323:         
324:     }
325:     
326:     public function isEmptyInput()
327:     {
328:         return $this->emptyInput;
329:     }
330:     
331:     protected abstract function validateModel();
332:     
333:     public function beforeComponentRender()
334:     {
335:         parent::beforeComponentRender();
336:         $this->validateModel();
337:     }
338:     
339:     public function setDisabled($disabled)
340:     {
341:         Args::isBoolean($disabled, 'disabled');
342:         $this->disabled = $disabled;
343:     }
344:     
345:     public function isMultiPart()
346:     {
347:         return false;
348:     }
349: }
350: 
351: ?>
352: 
Picon Framework API documentation generated by ApiGen 2.7.0