1: <?php
2: /**
3: * CJuiInputWidget class file.
4: *
5: * @author Sebastian Thierer <sebathi@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: Yii::import('zii.widgets.jui.CJuiWidget');
12:
13: /**
14: * CJuiInputWidget is the base class for JUI widgets that can collect user input.
15: *
16: * @author Sebastian Thierer <sebathi@gmail.com>
17: * @package zii.widgets.jui
18: * @since 1.1
19: */
20: abstract class CJuiInputWidget extends CJuiWidget
21: {
22: /**
23: * @var CModel the data model associated with this widget.
24: */
25: public $model;
26: /**
27: * @var string the attribute associated with this widget.
28: * The name can contain square brackets (e.g. 'name[1]') which is used to collect tabular data input.
29: */
30: public $attribute;
31: /**
32: * @var string the input name. This must be set if {@link model} is not set.
33: */
34: public $name;
35: /**
36: * @var string the input value.
37: */
38: public $value;
39:
40: /**
41: * Resolves name and ID of the input. Source property of the name and/or source property of the attribute
42: * could be customized by specifying first and/or second parameter accordingly.
43: * @param string $nameProperty class property name which holds element name to be used. This parameter
44: * is available since 1.1.14.
45: * @param string $attributeProperty class property name which holds model attribute name to be used. This
46: * parameter is available since 1.1.14.
47: * @return array name and ID of the input: array('name','id').
48: * @throws CException in case model and attribute property or name property cannot be resolved.
49: */
50: protected function resolveNameID($nameProperty='name',$attributeProperty='attribute')
51: {
52: if($this->$nameProperty!==null)
53: $name=$this->$nameProperty;
54: elseif(isset($this->htmlOptions[$nameProperty]))
55: $name=$this->htmlOptions[$nameProperty];
56: elseif($this->hasModel())
57: $name=CHtml::activeName($this->model,$this->$attributeProperty);
58: else
59: throw new CException(Yii::t('zii','{class} must specify "model" and "{attribute}" or "{name}" property values.',
60: array('{class}'=>get_class($this),'{attribute}'=>$attributeProperty,'{name}'=>$nameProperty)));
61:
62: if(($id=$this->getId(false))===null)
63: {
64: if(isset($this->htmlOptions['id']))
65: $id=$this->htmlOptions['id'];
66: else
67: $id=CHtml::getIdByName($name);
68: }
69:
70: return array($name,$id);
71: }
72:
73: /**
74: * @return boolean whether this widget is associated with a data model.
75: */
76: protected function hasModel()
77: {
78: return $this->model instanceof CModel && $this->attribute!==null;
79: }
80: }