Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

No commit message

  • Loading branch information...
commit 27cc745f2ccf245e3095b0594ffcd781bd1818bf 1 parent 840e016
qiang.xue authored
View
62 framework/web/form/CBaseFormElement.php
@@ -1,62 +0,0 @@
-<?php
-
-abstract class CBaseFormElement extends CComponent
-{
- public $attributes=array();
- private $_visible;
-
- abstract function render();
-
- public function __toString()
- {
- return $this->render();
- }
-
- public function __get($name)
- {
- $getter='get'.$name;
- if(method_exists($this,$getter))
- return $this->$getter();
- else if(isset($this->attributes[$name]))
- return $this->attributes[$name];
- else
- throw new CException('');
- }
-
- public function __set($name,$value)
- {
- $setter='set'.$name;
- if(method_exists($this,$setter))
- $this->$setter($value);
- else
- $this->attributes[$name]=$value;
- }
-
- public function configure($config)
- {
- if(is_string($config))
- $config=require($config);
- if(is_array($config))
- {
- foreach($config as $name=>$value)
- $this->$name=$value;
- }
- }
-
- public function getVisible()
- {
- if($this->_visible===null)
- $this->_visible=$this->evaluateVisible();
- return $this->_visible;
- }
-
- public function setVisible($value)
- {
- $this->_visible=$value;
- }
-
- protected function evaluateVisible()
- {
- return true;
- }
-}
View
59 framework/web/form/CForm.php
@@ -1,6 +1,24 @@
<?php
+/**
+ * CForm class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
-class CForm extends CBaseFormElement implements ArrayAccess
+/**
+ * CForm is the base class providing the common features needed by data model objects.
+ *
+ * CForm defines the basic framework for data models that need to be validated.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
+class CForm extends CFormElement implements ArrayAccess
{
public $legend;
public $description; // TODO!!!
@@ -12,7 +30,6 @@ class CForm extends CBaseFormElement implements ArrayAccess
public $buttonElementClass='CFormButtonElement';
public $formElementClass='CForm';
- private $_parent;
private $_model;
private $_elements;
@@ -20,7 +37,7 @@ class CForm extends CBaseFormElement implements ArrayAccess
public function __construct($parent,$model=null)
{
- $this->_parent=$parent;
+ $this->parent=$parent;
$this->_model=$model;
}
@@ -42,7 +59,7 @@ protected function getUniqueId()
public function getSubmitMethod()
{
- return strcasecmp($this->getRootForm()->method,'get') ? 'post' : 'get';
+ return strcasecmp($this->getRoot()->method,'get') ? 'post' : 'get';
}
public function loadData()
@@ -81,33 +98,28 @@ protected function evaluateVisible()
return false;
}
- public function getParentForm()
- {
- return $this->_parent instanceof self ? $this->_parent : null;
- }
-
- public function getRootForm()
+ public function getRoot()
{
$root=$this;
- while($root->_parent instanceof self)
- $root=$root->_parent;
+ while($root->parent instanceof self)
+ $root=$root->parent;
return $root;
}
public function getOwner()
{
- $owner=$this->_parent;
+ $owner=$this->parent;
while($owner instanceof self)
- $owner=$owner->_parent;
+ $owner=$owner->parent;
return $owner;
}
public function getModel()
{
- if($this->_model!==null)
- return $this->_model;
- else if($this->_parent instanceof self)
- return $this->_parent->getModel();
+ $form=$this;
+ while($form->_model===null && $form->parent instanceof self)
+ $form=$form->parent;
+ return $form->_model;
}
public function setModel($model)
@@ -118,7 +130,7 @@ public function setModel($model)
public function getElements()
{
if($this->_elements===null)
- $this->_elements=new CFormInputCollection($this);
+ $this->_elements=new CFormElementCollection($this,false);
return $this->_elements;
}
@@ -132,7 +144,7 @@ public function setElements($elements)
public function getButtons()
{
if($this->_buttons===null)
- $this->_buttons=new CFormButtonCollection($this);
+ $this->_buttons=new CFormElementCollection($this,true);
return $this->_buttons;
}
@@ -146,10 +158,10 @@ public function setButtons($buttons)
public function render()
{
$output='';
- if(!$this->_parent instanceof self)
+ if(!$this->parent instanceof self)
$output.=$this->begin();
$output.=$this->body();
- if(!$this->_parent instanceof self)
+ if(!$this->parent instanceof self)
$output.=$this->end();
return $output;
}
@@ -225,8 +237,7 @@ public function offsetExists($offset)
*/
public function offsetGet($offset)
{
- if($this->getElements()->contains($offset))
- return $this->getElements()->itemAt($offset);
+ return $this->getElements()->itemAt($offset);
}
/**
View
27 framework/web/form/CFormButtonCollection.php
@@ -1,27 +0,0 @@
-<?php
-
-class CFormButtonCollection extends CMap
-{
- private $_form;
-
- public function __construct($form)
- {
- parent::__construct();
- $this->_form=$form;
- }
-
- public function add($key,$value)
- {
- if(is_array($value))
- {
- $class=$this->_form->buttonElementClass;
- $value['name']=$key;
- $button=new $class($this->_form,$value);
- parent::add($key, $button);
- }
- else if($value instanceof CFormButtonElement)
- parent::add($key,$value);
- else
- throw new CException('');
- }
-}
View
73 framework/web/form/CFormButtonElement.php
@@ -1,7 +1,42 @@
<?php
+/**
+ * CFormButtonElement class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+/**
+ * CFormButtonElement represents a form button element.
+ *
+ * CFormButtonElement can represent the following types of button based on {@link type} property:
+ * <ul>
+ * <li>submit: a submit button generated using {@link CHtml::submitButton}</li>
+ * <li>button: a normal button generated using {@link CHtml::button}</li>
+ * <li>image: an image button generated using {@link CHtml::imageButton}</li>
+ * <li>reset: a reset button generated using {@link CHtml::resetButton}</li>
+ * <li>link: a link button generated using {@link CHtml::linkButton}</li>
+ * </ul>
+ * The {@link type} property can also be a class name or a path alias to the class. In this case,
+ * the button is generated using a widget of the specified class. Note, the widget must
+ * have a property called "name".
+ *
+ * Because CFormElement is an ancestor class of CFormButtonElement, a value assigned to a non-existing property will be
+ * stored in {@link attributes} which will be passed as HTML attribute values to the {@link CHtml} method
+ * generating the button or initial values of the widget properties.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
class CFormButtonElement extends CFormElement
{
+ /**
+ * @var array Core button types (alias=>CHtml method name)
+ */
public static $coreTypes=array(
'submit'=>'submitButton',
'button'=>'button',
@@ -9,27 +44,59 @@ class CFormButtonElement extends CFormElement
'reset'=>'resetButton',
'link'=>'linkButton',
);
- public $name;
+
+ /**
+ * @var string the type of this button. This can be a class name, a path alias of a class name,
+ * or a button type alias (submit, button, image, reset, or link).
+ */
public $type;
+ /**
+ * @var string name of this button
+ */
+ public $name;
+ /**
+ * @var string the label of this button. This property is ignored when a widget is used to generate the button.
+ */
public $label;
private $_on;
+ /**
+ * Evaluates the visibility of this element.
+ * This method will check the {@link on} property to see if
+ * the model is in a scenario that should have this string displayed.
+ * @return boolean whether this element is visible.
+ */
protected function evaluateVisible()
{
- return empty($this->on) || in_array($this->getForm()->getModel()->getScenario(),$this->on);
+ return empty($this->_on) || in_array($this->getParent()->getModel()->getScenario(),$this->_on);
}
+ /**
+ * Returns a value indicating under which scenarios this button is visible.
+ * If the value is empty, it means the button is visible under all scenarios.
+ * Otherwise, only when the model is in the scenario whose name can be found in
+ * this value, will the button be visible. See {@link CModel::scenario} for more
+ * information about model scenarios.
+ * @return string scenario names separated by commas. Defaults to null.
+ */
public function getOn()
{
return $this->_on;
}
+ /**
+ * @param string scenario names separated by commas.
+ */
public function setOn($value)
{
$this->_on=preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
}
+ /**
+ * Returns this button.
+ * @return string the rendering result
+ */
public function render()
{
$attributes=$this->attributes;
@@ -52,7 +119,7 @@ public function render()
{
$attributes['name']=$this->name;
ob_start();
- $this->getForm()->getOwner()->widget($this->type, $attributes);
+ $this->getParent()->getOwner()->widget($this->type, $attributes);
return ob_get_clean();
}
}
View
154 framework/web/form/CFormElement.php
@@ -1,17 +1,159 @@
<?php
+/**
+ * CFormElement class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
-abstract class CFormElement extends CBaseFormElement
+/**
+ * CFormElement is the base class for presenting all kinds of form element.
+ *
+ * CFormElement implements the way to get and set arbitrary attributes.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
+abstract class CFormElement extends CComponent
{
- private $_form;
+ /**
+ * @var array list of attributes (name=>value) for the HTML element represented by this object.
+ */
+ public $attributes=array();
+ /**
+ * @var mixed the direct parent of this element. This could be either a {@link CForm} object or a {@link CBaseController} object
+ * (a controller or a widget).
+ */
+ public $parent;
- public function __construct($form,$config=null)
+ private $_visible;
+
+ /**
+ * Renders this element.
+ * @return string the rendering result
+ */
+ abstract function render();
+
+ /**
+ * Constructor.
+ * @param mixed the direct parent of this element.
+ * @param mixed the configuration for this element.
+ * @see configure
+ */
+ public function __construct($parent,$config=null)
{
- $this->_form=$form;
+ $this->parent=$parent;
$this->configure($config);
}
- public function getForm()
+ /**
+ * Converts the object to a string.
+ * This is a PHP magic method.
+ * The default implementation simply calls {@link render} and return
+ * the rendering result.
+ * @return string the string representation of this object.
+ */
+ public function __toString()
+ {
+ return $this->render();
+ }
+
+ /**
+ * Returns a property value or an attribute value.
+ * Do not call this method. This is a PHP magic method that we override
+ * to allow using the following syntax to read a property or attribute:
+ * <pre>
+ * $value=$element->propertyName;
+ * $value=$element->attributeName;
+ * </pre>
+ * @param string the property or attribute name
+ * @return mixed the property or attribute value
+ * @throws CException if the property or attribute is not defined
+ * @see __set
+ */
+ public function __get($name)
+ {
+ $getter='get'.$name;
+ if(method_exists($this,$getter))
+ return $this->$getter();
+ else if(isset($this->attributes[$name]))
+ return $this->attributes[$name];
+ else
+ throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
+ array('{class}'=>get_class($this), '{property}'=>$name)));
+ }
+
+ /**
+ * Sets value of a property or attribute.
+ * Do not call this method. This is a PHP magic method that we override
+ * to allow using the following syntax to set a property or attribute.
+ * <pre>
+ * $this->propertyName=$value;
+ * $this->attributeName=$value;
+ * </pre>
+ * @param string the property or attribute name
+ * @param mixed the property or attribute value
+ * @see __get
+ */
+ public function __set($name,$value)
+ {
+ $setter='set'.$name;
+ if(method_exists($this,$setter))
+ $this->$setter($value);
+ else
+ $this->attributes[$name]=$value;
+ }
+
+ /**
+ * Configures this object with property initial values.
+ * @param mixed the configuration for this object. This can be an array
+ * representing the property names and their initial values.
+ * It can also be a string representing the file name of the PHP script
+ * that returns a configuration array.
+ */
+ public function configure($config)
+ {
+ if(is_string($config))
+ $config=require($config);
+ if(is_array($config))
+ {
+ foreach($config as $name=>$value)
+ $this->$name=$value;
+ }
+ }
+
+ /**
+ * Returns a value indicating whether this element is visible and should be rendered.
+ * This method will call {@link evaluateVisible} to determine the visibility of this element.
+ * @return boolean whether this element is visible and should be rendered.
+ */
+ public function getVisible()
+ {
+ if($this->_visible===null)
+ $this->_visible=$this->evaluateVisible();
+ return $this->_visible;
+ }
+
+ /**
+ * @param boolean whether this element is visible and should be rendered.
+ */
+ public function setVisible($value)
+ {
+ $this->_visible=$value;
+ }
+
+ /**
+ * Evaluates the visibility of this element.
+ * Child classes should override this method to implement the actual algorithm
+ * for determining the visibility.
+ * @return boolean whether this element is visible. Defaults to true.
+ */
+ protected function evaluateVisible()
{
- return $this->_form;
+ return true;
}
}
View
100 framework/web/form/CFormElementCollection.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * CFormElementCollection class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+/**
+ * CFormElementCollection implements the collection for storing form elements.
+ *
+ * Because CFormElementCollection extends from {@link CMap}, it can be used like an associative array.
+ * For example,
+ * <pre>
+ * $element=$collection['username'];
+ * $collection['username']=array('type'=>'text', 'maxlength'=>128);
+ * $collection['password']=new CFormInputElement($form, array('type'=>'password'));
+ * $collection[]='some string';
+ * </pre>
+ *
+ * CFormElementCollection can store three types of value: a configuration array, a {@link CFormElement}
+ * object, or a string, as shown in the above example. Internally, these values will be converted
+ * to {@link CFormElement} objects.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
+class CFormElementCollection extends CMap
+{
+ private $_form;
+ private $_forButtons;
+
+ /**
+ * Constructor.
+ * @param CForm the form object that owns this collection
+ * @param boolean whether this collection is used to store buttons.
+ */
+ public function __construct($form,$forButtons=false)
+ {
+ parent::__construct();
+ $this->_form=$form;
+ $this->_forButtons=$buttonOnly;
+ }
+
+ /**
+ * Adds an item to the collection.
+ * This method overrides the parent implementation to ensure
+ * only configuration arrays, strings, or {@link CFormElement} objects
+ * can be stored in this collection.
+ * @param mixed key
+ * @param mixed value
+ * @throws CException if the value is invalid.
+ */
+ public function add($key,$value)
+ {
+ if(is_array($value))
+ {
+ $value['name']=$key;
+
+ if($this->_forButtons)
+ {
+ $class=$this->_form->buttonElementClass;
+ $button=new $class($this->_form,$value);
+ parent::add($key, $button);
+ }
+ else
+ {
+ if(!isset($value['type']))
+ $value['type']='text';
+ if($value['type']==='string')
+ {
+ unset($value['type'],$value['name']);
+ $class='CFormStringElement';
+ }
+ else if($value['type']==='form')
+ {
+ unset($value['type']);
+ $class=$this->_form->formElementClass;
+ }
+ else
+ $class=$this->_form->inputElementClass;
+ parent::add($key,new $class($this->_form,$value));
+ }
+ }
+ else if($value instanceof CFormElement)
+ {
+ if(property_exists($value,'name'))
+ $value->name=$key;
+ parent::add($key,$value);
+ }
+ else if(is_string($value))
+ parent::add($key,new CFormStringElement($this->_form,array('content'=>$value)));
+ else
+ throw new CException(Yii::t('yii','The element "{name}" must be a configuration array, a string or a CFormElement object.',array('{name}'=>$key)));
+ }
+}
View
41 framework/web/form/CFormInputCollection.php
@@ -1,41 +0,0 @@
-<?php
-
-class CFormInputCollection extends CMap
-{
- private $_form;
-
- public function __construct($form)
- {
- parent::__construct();
- $this->_form=$form;
- }
-
- public function add($key,$value)
- {
- if(is_array($value))
- {
- $value['name']=$key;
- if(!isset($value['type']))
- $value['type']='text';
- if($value['type']==='string')
- {
- unset($value['type'],$value['name']);
- $class='CFormStringElement';
- }
- else if($value['type']==='form')
- {
- unset($value['type']);
- $class=$this->_form->formElementClass;
- }
- else
- $class=$this->_form->inputElementClass;
- parent::add($key,new $class($this->_form,$value));
- }
- else if($value instanceof CBaseFormElement)
- parent::add($key,$value);
- else if(is_string($value))
- parent::add($key,new CFormStringElement($this->_form,array('content'=>$value)));
- else
- throw new CException('');
- }
-}
View
121 framework/web/form/CFormInputElement.php
@@ -1,7 +1,49 @@
<?php
+/**
+ * CFormInputElement class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+/**
+ * CFormInputElement represents form input element.
+ *
+ * CFormInputElement can represent the following types of form input based on {@link type} property:
+ * <ul>
+ * <li>text: a normal text input generated using {@link CHtml::activeTextField}</li>
+ * <li>hidden: a hidden input generated using {@link CHtml::activeHiddenField}</li>
+ * <li>password: a password input generated using {@link CHtml::activePasswordField}</li>
+ * <li>textarea: a text area generated using {@link CHtml::activeTextArea}</li>
+ * <li>file: a file input generated using {@link CHtml::activeFileField}</li>
+ * <li>radio: a radio button generated using {@link CHtml::activeRadioButton}</li>
+ * <li>checkbox: a check box generated using {@link CHtml::activeCheckBox}</li>
+ * <li>listbox: a list box generated using {@link CHtml::activeListBox}</li>
+ * <li>dropdownlist: a drop-down list generated using {@link CHtml::activeDropDownList}</li>
+ * <li>checkboxlist: a list of check boxes generated using {@link CHtml::activeCheckBoxList}</li>
+ * <li>radiolist: a list of radio buttons generated using {@link CHtml::activeRadioButtonList}</li>
+ * </ul>
+ * The {@link type} property can also be a class name or a path alias to the class. In this case,
+ * the input is generated using a widget of the specified class. Note, the widget must
+ * have a property called "model" which expects a model object, and a property called "attribute"
+ * which expects the name of a model attribute.
+ *
+ * Because CFormElement is an ancestor class of CFormInputElement, a value assigned to a non-existing property will be
+ * stored in {@link attributes} which will be passed as HTML attribute values to the {@link CHtml} method
+ * generating the input or initial values of the widget properties.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
class CFormInputElement extends CFormElement
{
+ /**
+ * @var array Core input types (alias=>CHtml method name)
+ */
public static $coreTypes=array(
'text'=>'activeTextField',
'hidden'=>'activeHiddenField',
@@ -15,50 +57,97 @@ class CFormInputElement extends CFormElement
'checkboxlist'=>'activeCheckBoxList',
'radiolist'=>'activeRadioButtonList',
);
+
+ /**
+ * @var string the type of this input. This can be a class name, a path alias of a class name,
+ * or a input type alias (text, hidden, password, textarea, file, radio, checkbox, listbox, dropdownlist, checkboxlist, or radiolist).
+ */
public $type;
+ /**
+ * @var string name of this input
+ */
public $name;
+ /**
+ * @var string hint text of this input
+ */
public $hint;
+ /**
+ * @var array the options for this input when it is a list box, drop-down list, check box list, or radio button list.
+ * Please see {@link CHtml::listData} for details of generating this property value.
+ */
public $items=array();
+
private $_label;
+ /**
+ * Evaluates the visibility of this element.
+ * This method will check the {@link on} property to see if
+ * the model is in a scenario that should have this string displayed.
+ * @return boolean whether this element is visible.
+ */
protected function evaluateVisible()
{
- return $this->getForm()->getModel()->isAttributeSafe($this->name);
+ return $this->getParent()->getModel()->isAttributeSafe($this->name);
}
+ /**
+ * @return boolean whether this input is required. The value is determined by calling
+ * {@link CModel::isAttributeRequired} for the associated model and attribute of this input.
+ */
public function getRequired()
{
- return $this->getForm()->getModel()->isAttributeRequired($this->name);
+ return $this->getParent()->getModel()->isAttributeRequired($this->name);
}
+ /**
+ * @return string the label for this input. If the label is not manually set,
+ * this method will call {@link CModel::getAttributeLabel} to determine the label.
+ */
public function getLabel()
{
if($this->_label!==null)
return $this->_label;
- else if(($model=$this->getForm()->getModel())!==null)
- return $model->getAttributeLabel($this->name);
else
- return '';
+ return $this->getParent()->getModel()->getAttributeLabel($this->name);
}
+ /**
+ * @param string the label for this input
+ */
public function setLabel($value)
{
$this->_label=$value;
}
+ /**
+ * Renders everything for this input.
+ * The default implementation simply returns the result of {@link renderLabel}, {@link renderInput},
+ * {@link renderHint} and {@link renderError}.
+ * @return string the complete rendering result for this input, including label, input field, hint, and error.
+ */
public function render()
{
- return $this->renderLabel()
- . $this->renderInput()
- . $this->renderHint()
- . $this->renderError();
+ return $this->renderLabel() . "\n"
+ . $this->renderInput() . "\n"
+ . $this->renderHint() . "\n"
+ . $this->renderError();
}
+ /**
+ * Renders the label for this input.
+ * The default implementation returns the result of {@link CHtml activeLabelEx}.
+ * @return string the rendering result
+ */
public function renderLabel()
{
return CHtml::activeLabelEx($this->getForm()->getModel(), $this->name, array('label'=>$this->getLabel()));
}
+ /**
+ * Renders the input field.
+ * The default implementation returns the result of the appropriate CHtml method or the widget.
+ * @return string the rendering result
+ */
public function renderInput()
{
if(isset(self::$coreTypes[$this->type]))
@@ -75,18 +164,28 @@ public function renderInput()
$attributes['model']=$this->getForm()->getModel();
$attributes['attribute']=$this->name;
ob_start();
- $this->getForm()->getOwner()->widget($this->type, $attributes);
+ $this->getParent()->getOwner()->widget($this->type, $attributes);
return ob_get_clean();
}
}
+ /**
+ * Renders the error display of this input.
+ * The default implementation returns the result of {@link CHtml::error}.
+ * @return string the rendering result
+ */
public function renderError()
{
return CHtml::error($this->getForm()->getModel(), $this->name);
}
+ /**
+ * Renders the hint text for this input.
+ * The default implementation returns the {@link hint} property enclosed in a paragraph HTML tag.
+ * @return string the rendering result.
+ */
public function renderHint()
{
- return $this->hint===null ? '' : '<p class="hint">'.CHtml::encode($this->hint).'</p>';
+ return $this->hint===null ? '' : '<p class="hint">'.$this->hint.'</p>';
}
}
View
52 framework/web/form/CFormStringElement.php
@@ -1,27 +1,69 @@
<?php
+/**
+ * CFormStringElement class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2009 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+/**
+ * CFormStringElement represents a string in a form.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.web.form
+ * @since 1.1
+ */
class CFormStringElement extends CFormElement
{
+ /**
+ * @var string the string content
+ */
public $content;
- private $_on;
- public function getVisible()
- {
- return empty($this->on) || in_array($this->getForm()->getModel()->getScenario(),$this->on);
- }
+ private $_on;
+ /**
+ * Returns a value indicating under which scenarios this string is visible.
+ * If the value is empty, it means the string is visible under all scenarios.
+ * Otherwise, only when the model is in the scenario whose name can be found in
+ * this value, will the string be visible. See {@link CModel::scenario} for more
+ * information about model scenarios.
+ * @return string scenario names separated by commas. Defaults to null.
+ */
public function getOn()
{
return $this->_on;
}
+ /**
+ * @param string scenario names separated by commas.
+ */
public function setOn($value)
{
$this->_on=preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
}
+ /**
+ * Renders this element.
+ * The default implementation simply returns {@link content}.
+ * @return string the string content
+ */
public function render()
{
return $this->content;
}
+
+ /**
+ * Evaluates the visibility of this element.
+ * This method will check the {@link on} property to see if
+ * the model is in a scenario that should have this string displayed.
+ * @return boolean whether this element is visible.
+ */
+ protected function evaluateVisible()
+ {
+ return empty($this->_on) || in_array($this->getForm()->getModel()->getScenario(),$this->_on);
+ }
}

0 comments on commit 27cc745

Please sign in to comment.
Something went wrong with that request. Please try again.