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:  * A form component which contains a pre-defined list of
 27:  * posible choices
 28:  * 
 29:  * @todo implement disabled for all abstract choice components
 30:  * 
 31:  * @author Martin Cassidy
 32:  * @package web/markup/html/form
 33:  */
 34: abstract class AbstractChoice extends FormComponent
 35: {
 36:     private $choiceRenderer;
 37:     
 38:     private $choices;
 39:     
 40:     private $isDisabled;
 41:     
 42:     /**
 43:      *
 44:      * @param string $id
 45:      * @param array $choices
 46:      * @param Model $model 
 47:      */
 48:     public function __construct($id, $choices, ChoiceRenderer $choiceRenderer = null, Model $model = null, $isDisabled = null)
 49:     {
 50:         parent::__construct($id, $model);
 51:         Args::isArray($choices, 'choices');
 52:         
 53:         $this->choices = $choices;
 54:         
 55:         if($choiceRenderer==null)
 56:         {
 57:             $choiceRenderer = new ChoiceRenderer();
 58:         }
 59:         $this->choiceRenderer = $choiceRenderer;
 60:         
 61:         if($isDisabled!=null)
 62:         {
 63:             Args::callBackArgs($isDisabled, 2, 'isDisabled');
 64:             $this->isDisabled = $isDisabled;
 65:         }
 66:     }
 67:     
 68:     protected function getChoiceRenderer()
 69:     {
 70:         return $this->choiceRenderer;
 71:     }
 72:     
 73:     protected function getChoices()
 74:     {
 75:         return $this->choices;
 76:     }
 77:     
 78:     public abstract function isSelected($choice, $index);   
 79:     
 80:     
 81:     /**
 82:      * Render an <option> element
 83:      * @param type $choice 
 84:      */
 85:     protected function renderOption($name, $value, $selected, $disabled)
 86:     {
 87:         $this->getResponse()->write('<option');
 88:         if($selected)
 89:         {
 90:              $this->getResponse()->write(' selected="selected"');
 91:         }
 92:         if($disabled)
 93:         {
 94:              $this->getResponse()->write(' disabled="disabled"');
 95:         }
 96:         $this->getResponse()->write(' value="'.htmlentities($value).'"');
 97:         
 98:         $this->getResponse()->write('>');
 99:         $this->getResponse()->write(htmlentities($name));
100:         $this->getResponse()->write('</option>');
101:     }
102:     
103:     protected function renderOptGroup($name, $options, $index)
104:     {
105:         $this->getResponse()->write('<optgroup');
106:         $this->getResponse()->write(' label="'.htmlentities($name).'"');
107:         $this->getResponse()->write('>');
108:         $this->renderOptions($options, $index);
109:         $this->getResponse()->write('</optgroup>');
110:     }
111:     
112:     protected function renderOptions($choices = null, $outerIndex = 1)
113:     {
114:         if($choices==null)
115:         {
116:             $choices = $this->choices;
117:         }
118:         $i = 1;
119:         foreach($choices as $index => $choice)
120:         {
121:             $actualIndex = $i * $outerIndex;
122:             if(is_array($choice))
123:             {
124:                 $this->renderOptGroup($index, $choice, $i);
125:             }
126:             else
127:             {
128:                 $selected = $this->isSelected($choice, $actualIndex);
129:                 $disabled = $this->isDisabled($choice, $actualIndex);
130:                 $this->renderOption($this->choiceRenderer->getDisplay($choice, $actualIndex), $this->choiceRenderer->getValue($choice, $actualIndex), $selected, $disabled);
131:             }
132:             $i++;
133:         }
134:     }
135:     
136:     protected function isDisabled($choice, $index)
137:     {
138:         if($this->isDisabled!=null)
139:         {
140:             $callable = $this->isDisabled;
141:             return $callable($choice, $index);
142:         }
143:         return false;
144:     }
145:     
146:     protected final function valueForChoice($choice, $value, $index)
147:     {
148:         return $this->choiceRenderer->getValue($choice, $index)==$value;
149:     }
150:     
151:     protected function validateModel()
152:     {
153:         if(count($this->choices)>0)
154:         {
155:             //$firstType = null;
156:             //if(is_object($this->choices[0]))
157:             //{
158:                 //$firstType = get_class($this->choices[0]);
159:             //}
160:             //else
161:             //{
162:                 $firstType = gettype($this->choices[0]);
163:             //}
164:                 
165:             //@todo validate model against the type
166: 
167:             foreach($this->choices as $choice)
168:             {
169:                 if(is_array($choice) && !$this->supportNestedArray())
170:                 {
171:                     throw new \InvalidArgumentException('Choices array may not contain nested arrays');
172:                 }
173:                 else if(is_array($choice) && $this->supportNestedArray())
174:                 {
175:                     foreach($choice as $option)
176:                     {
177:                         if(is_array($option))
178:                         {
179:                             throw new \InvalidArgumentException('Nested choice arrays may contain nested arrays');
180:                         }
181:                     }
182:                 }
183:                 //@todo this doesn't actually work as it assumes that classes will be identical but the full hierarchy should be checked
184:                 /*else if((is_object($choice) && get_class($choice)!=$firstType) || (!is_object($choice) && gettype($choice)!=$firstType))
185:                 {
186:                     throw new \InvalidArgumentException('Choice array does not contain the same values');
187:                 }*/
188:             }
189:         }
190:     }
191:     
192:     public function getValue()
193:     {
194:         $input = null;
195:         if($this->disabled)
196:         {
197:             $input = $this->getModelObject();
198:         }
199:         if($this->rawInput==null)
200:         {
201:             if($this->emptyInput==true)
202:             {
203:                 return null;
204:             }
205:             else
206:             {
207:                 $input = $this->getModelObject();
208:             }
209:         }
210:         else
211:         {
212:             $input = $this->rawInput;
213:         }
214:         return $input;
215:     }
216:     
217:     protected function supportNestedArray()
218:     {
219:         return false;
220:     }
221: }
222: 
223: ?>
224: 
Picon Framework API documentation generated by ApiGen 2.7.0