Completed
Push — master ( c7ab73...cc5395 )
by Fabio
19:04
created

TActiveListBox::setSelectionMode()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 8.8571
cc 5
eloc 10
nc 3
nop 1
1
<?php
2
/**
3
 * TActiveListBox class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6
 * @link https://github.com/pradosoft/prado
7
 * @copyright Copyright &copy; 2005-2015 The PRADO Group
8
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
 * @package System.Web.UI.ActiveControls
10
 */
11
12
/**
13
 * Load active list control adapter
14
 */
15
Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter');
16
17
/**
18
 * TActiveListBox class.
19
 *
20
 * List items can be added dynamically during a callback request.
21
 *
22
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
23
 * @package System.Web.UI.ActiveControls
24
 * @since 3.1
25
 */
26
class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventHandler
27
{
28
	/**
29
	 * Creates a new callback control, sets the adapter to
30
	 * TActiveListControlAdapter. If you override this class, be sure to set the
31
	 * adapter appropriately by, for example, by calling this constructor.
32
	 */
33
	public function __construct()
34
	{
35
		parent::__construct();
36
		$this->setAdapter(new TActiveListControlAdapter($this));
37
		$this->setAutoPostBack(true);
38
	}
39
40
	/**
41
	 * @return TBaseActiveCallbackControl standard callback control options.
42
	 */
43
	public function getActiveControl()
44
	{
45
		return $this->getAdapter()->getBaseActiveControl();
46
	}
47
48
	/**
49
	 * @return TCallbackClientSide client side request options.
50
	 */
51
	public function getClientSide()
52
	{
53
		return $this->getAdapter()->getBaseActiveControl()->getClientSide();
54
	}
55
56
	/**
57
	 * Creates a collection object to hold list items. A specialized
58
	 * TActiveListItemCollection is created to allow the drop down list options
59
	 * to be added.
60
	 * This method may be overriden to create a customized collection.
61
	 * @return TActiveListItemCollection the collection object
62
	 */
63
	protected function createListItemCollection()
64
	{
65
		$collection  = new TActiveListItemCollection;
66
		$collection->setControl($this);
67
		return $collection;
68
	}
69
70
	/**
71
	 * Javascript client class for this control.
72
	 * This method overrides the parent implementation.
73
	 * @return null no javascript class name.
74
	 */
75
	protected function getClientClassName()
76
	{
77
		return 'Prado.WebUI.TActiveListBox';
78
	}
79
80
	/**
81
	 * Sets the selection mode of the list control (Single, Multiple)
82
	 * on the client-side if the  {@link setEnableUpdate EnableUpdate}
83
	 * property is set to true.
84
	 * @param string the selection mode
85
	 */
86
	public function setSelectionMode($value)
87
	{
88
		if(parent::getSelectionMode() === $value)
1 ignored issue
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getSelectionMode() instead of setSelectionMode()). Are you sure this is correct? If so, you might want to change this to $this->getSelectionMode().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
89
			return;
90
91
		parent::setSelectionMode($value);
92
		$multiple = $this->getIsMultiSelect();
93
		$id = $this->getUniqueID(); $multi_id = $id.'[]';
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
94
		if($this->getActiveControl()->canUpdateClientSide())
95
		{
96
			$client = $this->getPage()->getCallbackClient();
97
			$client->setAttribute($this, 'multiple', $multiple ? 'multiple' : false);
98
			$client->setAttribute($this, 'name', $multiple ? $multi_id : $id);
99
		}
100
	}
101
102
	/**
103
	 * Raises the callback event. This method is required by {@link
104
	 * ICallbackEventHandler} interface.
105
	 * This method is mainly used by framework and control developers.
106
	 * @param TCallbackEventParameter the event parameter
107
	 */
108
 	public function raiseCallbackEvent($param)
109
	{
110
		$this->onCallback($param);
111
	}
112
113
	/**
114
	 * This method is invoked when a callback is requested. The method raises
115
	 * 'OnCallback' event to fire up the event handlers. If you override this
116
	 * method, be sure to call the parent implementation so that the event
117
	 * handler can be invoked.
118
	 * @param TCallbackEventParameter event parameter to be passed to the event handlers
119
	 */
120
	public function onCallback($param)
121
	{
122
		$this->raiseEvent('OnCallback', $this, $param);
123
	}
124
125
	/**
126
	 * Updates the client-side options if the item list has changed after the OnLoad event.
127
	 */
128
	public function onPreRender($param)
129
	{
130
		parent::onPreRender($param);
131
		$this->getAdapter()->updateListItems();
132
	}
133
134
	/**
135
	 * Override parent implementation, no javascript is rendered here instead
136
	 * the javascript required for active control is registered in {@link addAttributesToRender}.
137
	 */
138
	protected function renderClientControlScript($writer)
139
	{
140
	}
141
142
	/**
143
	 * Ensure that the ID attribute is rendered and registers the javascript code
144
	 * for initializing the active control.
145
	 */
146
	protected function addAttributesToRender($writer)
147
	{
148
		parent::addAttributesToRender($writer);
149
		$writer->addAttribute('id',$this->getClientID());
150
		if ($this->getAutoPostBack())
151
			$this->getActiveControl()->registerCallbackClientScript(
152
				$this->getClientClassName(), $this->getPostBackOptions());
153
	}
154
}
155
156