Packages

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • NButton
  • NCheckbox
  • NConventionalRenderer
  • NFileUpload
  • NForm
  • NFormContainer
  • NFormGroup
  • NHiddenField
  • NImageButton
  • NInstantClientScript
  • NMultiSelectBox
  • NRadioList
  • NRule
  • NRules
  • NSelectBox
  • NSubmitButton
  • NTextArea
  • NTextBase
  • NTextInput

Interfaces

  • IFormControl
  • IFormRenderer
  • INamingContainer
  • ISubmitterControl
  • Overview
  • Package
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Forms
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * A user group of form controls.
 17:  *
 18:  * @author     David Grudl
 19:  *
 20:  * @property-read array $controls
 21:  * @property-read array $options
 22:  * @package Nette\Forms
 23:  */
 24: class NFormGroup extends NObject
 25: {
 26:     /** @var SplObjectStorage */
 27:     protected $controls;
 28: 
 29:     /** @var array user options */
 30:     private $options = array();
 31: 
 32: 
 33: 
 34:     public function __construct()
 35:     {
 36:         $this->controls = new SplObjectStorage;
 37:     }
 38: 
 39: 
 40: 
 41:     /**
 42:      * @return NFormGroup  provides a fluent interface
 43:      */
 44:     public function add()
 45:     {
 46:         foreach (func_get_args() as $num => $item) {
 47:             if ($item instanceof IFormControl) {
 48:                 $this->controls->attach($item);
 49: 
 50:             } elseif ($item instanceof Traversable || is_array($item)) {
 51:                 foreach ($item as $control) {
 52:                     $this->controls->attach($control);
 53:                 }
 54: 
 55:             } else {
 56:                 throw new InvalidArgumentException("Only IFormControl items are allowed, the #$num parameter is invalid.");
 57:             }
 58:         }
 59:         return $this;
 60:     }
 61: 
 62: 
 63: 
 64:     /**
 65:      * @return array IFormControl
 66:      */
 67:     public function getControls()
 68:     {
 69:         return iterator_to_array($this->controls);
 70:     }
 71: 
 72: 
 73: 
 74:     /**
 75:      * Sets user-specific option.
 76:      * Options recognized by ConventionalRenderer
 77:      * - 'label' - textual or Html object label
 78:      * - 'visual' - indicates visual group
 79:      * - 'container' - container as Html object
 80:      * - 'description' - textual or Html object description
 81:      * - 'embedNext' - describes how render next group
 82:      * @param  string key
 83:      * @param  mixed  value
 84:      * @return NFormGroup  provides a fluent interface
 85:      */
 86:     public function setOption($key, $value)
 87:     {
 88:         if ($value === NULL) {
 89:             unset($this->options[$key]);
 90: 
 91:         } else {
 92:             $this->options[$key] = $value;
 93:         }
 94:         return $this;
 95:     }
 96: 
 97: 
 98: 
 99:     /**
100:      * Returns user-specific option.
101:      * @param  string key
102:      * @param  mixed  default value
103:      * @return mixed
104:      */
105:     final public function getOption($key, $default = NULL)
106:     {
107:         return isset($this->options[$key]) ? $this->options[$key] : $default;
108:     }
109: 
110: 
111: 
112:     /**
113:      * Returns user-specific options.
114:      * @return array
115:      */
116:     final public function getOptions()
117:     {
118:         return $this->options;
119:     }
120: 
121: }
122: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0