1: <?php
2: /**
3: * This file contains the cHTMLOptionElement class.
4: *
5: * @package Core
6: * @subpackage GUI_HTML
7: * @version SVN Revision $Rev:$
8: *
9: * @author Simon Sprankel
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * cHTMLOptionElement class represents a select option element.
20: *
21: * @package Core
22: * @subpackage GUI_HTML
23: */
24: class cHTMLOptionElement extends cHTMLFormElement {
25:
26: /**
27: * Title to display
28: *
29: * @var string
30: */
31: protected $_title;
32:
33: /**
34: * Constructor.
35: * Creates an HTML option element.
36: *
37: * @param string $title Displayed title of the element
38: * @param string $value Value of the option
39: * @param bool $selected If true, element is selected
40: * @param bool $disabled If true, element is disabled
41: * @param string $class the class of this element
42: */
43: public function __construct($title, $value, $selected = false, $disabled = false, $class = '') {
44: cHTML::__construct();
45: $this->_tag = 'option';
46: $this->_title = $title;
47:
48: $this->updateAttribute('value', $value);
49: $this->_contentlessTag = false;
50:
51: $this->setSelected($selected);
52: $this->setDisabled($disabled);
53: $this->setClass($class);
54: }
55:
56: /**
57: * Sets the selected flag
58: *
59: * @param bool $selected If true, adds the "selected" attribute
60: * @return cHTMLOptionElement $this
61: */
62: public function setSelected($selected) {
63: if ($selected == true) {
64: return $this->updateAttribute('selected', 'selected');
65: } else {
66: return $this->removeAttribute('selected');
67: }
68: }
69:
70: /**
71: * Checks whether this option element is selected.
72: *
73: * @return bool whether this option element is selected
74: */
75: public function isSelected() {
76: return $this->getAttribute('selected') === 'selected';
77: }
78:
79: /**
80: * Sets the disabled flag
81: *
82: * @param bool $disabled If true, adds the "disabled" attribute
83: * @return cHTMLOptionElement $this
84: */
85: public function setDisabled($disabled) {
86: if ($disabled == true) {
87: return $this->updateAttribute('disabled', 'disabled');
88: } else {
89: return $this->removeAttribute('disabled');
90: }
91: }
92:
93: /**
94: * Renders the option element.
95: * Note:
96: * the cHTMLSelectElement renders the options by itself.
97: *
98: * @return string Rendered HTML
99: */
100: public function toHtml() {
101: $this->_setContent($this->_title);
102:
103: return parent::toHTML();
104: }
105:
106: }
107: