CFormStringElement.php 1.8 KB

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