TPanel::setDirection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * TPanel class file
5
 *
6
 * @author Qiang Xue <[email protected]>
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Web\UI\WebControls;
12
13
use Prado\Prado;
14
use Prado\Exceptions\TInvalidDataValueException;
15
16
/**
17
 * TPanel class
18
 *
19
 * TPanel represents a component that acts as a container for other component.
20
 * It is especially useful when you want to generate components programmatically
21
 * or hide/show a group of components.
22
 *
23
 * By default, TPanel displays a &lt;div&gt; element on a page.
24
 * Children of TPanel are displayed as the body content of the element.
25
 * The property {@see setWrap Wrap} can be used to set whether the body content
26
 * should wrap or not. {@see setHorizontalAlign HorizontalAlign} governs how
27
 * the content is aligned horizontally, and {@see getDirection Direction} indicates
28
 * the content direction (left to right or right to left). You can set
29
 * {@see setBackImageUrl BackImageUrl} to give a background image to the panel,
30
 * and you can ste {@see setGroupingText GroupingText} so that the panel is
31
 * displayed as a field set with a legend text. Finally, you can specify
32
 * a default button to be fired when users press 'return' key within the panel
33
 * by setting the {@see setDefaultButton DefaultButton} property.
34
 *
35
 * @author Qiang Xue <[email protected]>
36
 * @since 3.0
37
 * @method TPanelStyle getStyle()
38
 */
39
class TPanel extends \Prado\Web\UI\WebControls\TWebControl
40
{
41
	/**
42
	 * @var string ID path to the default button
43
	 */
44
	private $_defaultButton = '';
45
46
	/**
47
	 * @return string tag name of the panel
48
	 */
49
	protected function getTagName()
50
	{
51
		return 'div';
52
	}
53
54
	/**
55
	 * Creates a style object to be used by the control.
56
	 * This method overrides the parent impementation by creating a TPanelStyle object.
57
	 * @return TPanelStyle the style used by TPanel.
58
	 */
59
	protected function createStyle()
60
	{
61
		return new TPanelStyle();
62
	}
63
64
	/**
65
	 * Adds attributes to renderer.
66
	 * @param \Prado\Web\UI\THtmlWriter $writer the renderer
67
	 * @throws TInvalidDataValueException if default button is not right.
68
	 */
69
	protected function addAttributesToRender($writer)
70
	{
71
		parent::addAttributesToRender($writer);
72
		if (($butt = $this->getDefaultButton()) !== '') {
0 ignored issues
show
Unused Code introduced by
The assignment to $butt is dead and can be removed.
Loading history...
73
			$writer->addAttribute('id', $this->getClientID());
74
		}
75
	}
76
77
	/**
78
	 * @return bool whether the content wraps within the panel. Defaults to true.
79
	 */
80
	public function getWrap()
81
	{
82
		return $this->getStyle()->getWrap();
83
	}
84
85
	/**
86
	 * Sets the value indicating whether the content wraps within the panel.
87
	 * @param bool $value whether the content wraps within the panel.
88
	 */
89
	public function setWrap($value)
90
	{
91
		$this->getStyle()->setWrap($value);
92
	}
93
94
	/**
95
	 * @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
96
	 */
97
	public function getHorizontalAlign()
98
	{
99
		return $this->getStyle()->getHorizontalAlign();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getStyle()->getHorizontalAlign() returns the type Prado\Web\UI\WebControls\THorizontalAlign which is incompatible with the documented return type string.
Loading history...
100
	}
101
102
	/**
103
	 * Sets the horizontal alignment of the contents within the panel.
104
	 * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
105
	 * @param string $value the horizontal alignment
106
	 */
107
	public function setHorizontalAlign($value)
108
	{
109
		$this->getStyle()->setHorizontalAlign($value);
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type Prado\Web\UI\WebControls\THorizontalAlign expected by parameter $value of Prado\Web\UI\WebControls...e::setHorizontalAlign(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
		$this->getStyle()->setHorizontalAlign(/** @scrutinizer ignore-type */ $value);
Loading history...
110
	}
111
112
	/**
113
	 * @return string the URL of the background image for the panel component.
114
	 */
115
	public function getBackImageUrl()
116
	{
117
		return $this->getStyle()->getBackImageUrl();
118
	}
119
120
	/**
121
	 * Sets the URL of the background image for the panel component.
122
	 * @param string $value the URL
123
	 */
124
	public function setBackImageUrl($value)
125
	{
126
		$this->getStyle()->setBackImageUrl($value);
127
	}
128
129
	/**
130
	 * @return string alignment of the content in the panel. Defaults to 'NotSet'.
131
	 */
132
	public function getDirection()
133
	{
134
		return $this->getStyle()->getDirection();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getStyle()->getDirection() returns the type Prado\Web\UI\WebControls\TContentDirection which is incompatible with the documented return type string.
Loading history...
135
	}
136
137
	/**
138
	 * @param string $value alignment of the content in the panel.
139
	 * Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
140
	 */
141
	public function setDirection($value)
142
	{
143
		$this->getStyle()->setDirection($value);
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type Prado\Web\UI\WebControls\TContentDirection expected by parameter $value of Prado\Web\UI\WebControls...elStyle::setDirection(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

143
		$this->getStyle()->setDirection(/** @scrutinizer ignore-type */ $value);
Loading history...
144
	}
145
146
	/**
147
	 * @return string the ID path to the default button. Defaults to empty.
148
	 */
149
	public function getDefaultButton()
150
	{
151
		return $this->_defaultButton;
152
	}
153
154
	/**
155
	 * Specifies the default button for the panel.
156
	 * The default button will be fired (clicked) whenever a user enters 'return'
157
	 * key within the panel.
158
	 * The button must be locatable via the function call {@see \Prado\Web\UI\TControl::findControl findControl}.
159
	 * @param string $value the ID path to the default button.
160
	 */
161
	public function setDefaultButton($value)
162
	{
163
		$this->_defaultButton = $value;
164
	}
165
166
	/**
167
	 * @return string the legend text when the panel is used as a fieldset. Defaults to empty.
168
	 */
169
	public function getGroupingText()
170
	{
171
		return $this->getViewState('GroupingText', '');
172
	}
173
174
	/**
175
	 * @param string $value the legend text. If this value is not empty, the panel will be rendered as a fieldset.
176
	 */
177
	public function setGroupingText($value)
178
	{
179
		$this->setViewState('GroupingText', $value, '');
180
	}
181
182
	/**
183
	 * @return string the visibility and position of scroll bars in a panel control, defaults to None.
184
	 */
185
	public function getScrollBars()
186
	{
187
		return $this->getStyle()->getScrollBars();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getStyle()->getScrollBars() returns the type Prado\Web\UI\WebControls\TScrollBars which is incompatible with the documented return type string.
Loading history...
188
	}
189
190
	/**
191
	 * @param string $value the visibility and position of scroll bars in a panel control.
192
	 * Valid values include None, Auto, Both, Horizontal and Vertical.
193
	 */
194
	public function setScrollBars($value)
195
	{
196
		$this->getStyle()->setScrollBars($value);
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type Prado\Web\UI\WebControls\TScrollBars expected by parameter $value of Prado\Web\UI\WebControls...lStyle::setScrollBars(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

196
		$this->getStyle()->setScrollBars(/** @scrutinizer ignore-type */ $value);
Loading history...
197
	}
198
199
	/**
200
	 * Renders the openning tag for the control (including attributes)
201
	 * @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose
202
	 */
203
	public function renderBeginTag($writer)
204
	{
205
		parent::renderBeginTag($writer);
206
		if (($text = $this->getGroupingText()) !== '') {
207
			$writer->renderBeginTag('fieldset');
208
			$writer->renderBeginTag('legend');
209
			$writer->write($text);
210
			$writer->renderEndTag();
211
		}
212
	}
213
214
	/**
215
	 * Renders the closing tag for the control
216
	 * @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose
217
	 */
218
	public function renderEndTag($writer)
219
	{
220
		if ($this->getGroupingText() !== '') {
221
			$writer->renderEndTag();
222
		}
223
		parent::renderEndTag($writer);
224
	}
225
226
	public function render($writer)
227
	{
228
		parent::render($writer);
229
230
		if (($butt = $this->getDefaultButton()) !== '') {
231
			if (($button = $this->findControl($butt)) === null) {
232
				throw new TInvalidDataValueException('panel_defaultbutton_invalid', $butt);
233
			} else {
234
				$this->getPage()->getClientScript()->registerDefaultButton($this, $button);
235
			}
236
		}
237
	}
238
}
239