1: <?php
2: /**
3: * CFormStringElement class file.
4: *
5: * @author Qiang Xue <qiang.xue@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: /**
12: * CFormStringElement represents a string in a form.
13: *
14: * @property string $on Scenario names separated by commas. Defaults to null.
15: *
16: * @author Qiang Xue <qiang.xue@gmail.com>
17: * @package system.web.form
18: * @since 1.1
19: */
20: class CFormStringElement extends CFormElement
21: {
22: /**
23: * @var string the string content
24: */
25: public $content;
26:
27: private $_on;
28:
29: /**
30: * Returns a value indicating under which scenarios this string is visible.
31: * If the value is empty, it means the string is visible under all scenarios.
32: * Otherwise, only when the model is in the scenario whose name can be found in
33: * this value, will the string be visible. See {@link CModel::scenario} for more
34: * information about model scenarios.
35: * @return string scenario names separated by commas. Defaults to null.
36: */
37: public function getOn()
38: {
39: return $this->_on;
40: }
41:
42: /**
43: * @param string $value scenario names separated by commas.
44: */
45: public function setOn($value)
46: {
47: $this->_on=preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
48: }
49:
50: /**
51: * Renders this element.
52: * The default implementation simply returns {@link content}.
53: * @return string the string content
54: */
55: public function render()
56: {
57: return $this->content;
58: }
59:
60: /**
61: * Evaluates the visibility of this element.
62: * This method will check the {@link on} property to see if
63: * the model is in a scenario that should have this string displayed.
64: * @return boolean whether this element is visible.
65: */
66: protected function evaluateVisible()
67: {
68: return empty($this->_on) || in_array($this->getParent()->getModel()->getScenario(),$this->_on);
69: }
70: }
71: