TActivePanel   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 53
ccs 0
cts 26
cp 0
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getActiveControl() 0 3 1
A render() 0 15 5
A addAttributesToRender() 0 4 1
1
<?php
2
3
/**
4
 * TActivePanel file.
5
 *
6
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Web\UI\ActiveControls;
12
13
/**
14
 * Load active control adapter.
15
 */
16
use Prado\Prado;
17
use Prado\Web\UI\WebControls\TPanel;
18
19
/**
20
 * TActivePanel is the TPanel active control counterpart.
21
 *
22
 * TActivePanel allows the client-side panel contents to be updated during a
23
 * callback response using the {@see render} method.
24
 *
25
 * Example: Assume $param is an instance of TCallbackEventParameter attached to
26
 * the OnCallback event of a TCallback with ID "callback1", and
27
 * "panel1" is the ID of a TActivePanel.
28
 * ```php
29
 * function callback1_requested($sender, $param)
30
 * {
31
 * 	   $this->panel1->render($param->getNewWriter());
32
 * }
33
 * ```
34
 *
35
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
36
 * @since 3.1
37
 * @method TActiveControlAdapter getAdapter()
38
 */
39
class TActivePanel extends TPanel implements IActiveControl
40
{
41
	/**
42
	 * Creates a new callback control, sets the adapter to
43
	 * TActiveControlAdapter. If you override this class, be sure to set the
44
	 * adapter appropriately by, for example, by calling this constructor.
45
	 */
46
	public function __construct()
47
	{
48
		parent::__construct();
49
		$this->setAdapter(new TActiveControlAdapter($this));
50
	}
51
52
	/**
53
	 * @return TBaseActiveControl standard active control options.
54
	 */
55
	public function getActiveControl()
56
	{
57
		return $this->getAdapter()->getBaseActiveControl();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getAdapter...>getBaseActiveControl() also could return the type Prado\Web\UI\ActiveControls\TBaseActiveControl which includes types incompatible with the return type mandated by Prado\Web\UI\ActiveContr...rol::getActiveControl() of Prado\Web\UI\ActiveContr...seActiveCallbackControl. Consider adding a type-check to rule them out.
Loading history...
58
	}
59
60
	/**
61
	 * Adds attribute id to the renderer.
62
	 * @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose
63
	 */
64
	protected function addAttributesToRender($writer)
65
	{
66
		$writer->addAttribute('id', $this->getClientID());
67
		parent::addAttributesToRender($writer);
68
	}
69
70
	/**
71
	 * Renders and replaces the panel's content on the client-side.
72
	 * When render() is called before the OnPreRender event, such as when render()
73
	 * is called during a callback event handler, the rendering
74
	 * is defered until OnPreRender event is raised.
75
	 * @param \Prado\Web\UI\THtmlWriter $writer html writer
76
	 */
77
	public function render($writer)
78
	{
79
		if ($this->getHasPreRendered()) {
80
			parent::render($writer);
81
			if ($this->getActiveControl()->canUpdateClientSide()) {
82
				$this->getPage()->getCallbackClient()->replaceContent($this, $writer);
83
			}
84
		} else {
85
			$this->getPage()->getAdapter()->registerControlToRender($this, $writer);
86
			if ($this->getHasControls()) {
87
				// If we update a TActivePanel on callback,
88
				// We shouldn't update all childs, because the whole content will be replaced by
89
				// the parent
90
				foreach ($this->findControlsByType(\Prado\Web\UI\ActiveControls\IActiveControl::class, false) as $control) {
91
					$control->getActiveControl()->setEnableUpdate(false);
92
				}
93
			}
94
		}
95
	}
96
}
97