GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TbTimePicker::injectClass()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
ccs 15
cts 15
cp 1
rs 9.4285
cc 3
eloc 12
nc 2
nop 2
crap 3
1
<?php
2
/**
3
 *## TbTimePicker class file.
4
 */
5
6
/**
7
 *## TbTimePicker widget.
8
 *
9
 * @see http://jdewit.github.com/bootstrap-timepicker/
10
 * @see https://github.com/jdewit/bootstrap-timepicker
11
 *
12
 * @since 1.0.3
13
 * @package booster.widgets.forms.inputs
14
 */
15
16 1
Yii::import('booster.widgets.TbBaseInputWidget');
17
18
class TbTimePicker extends TbBaseInputWidget {
19
	
20
	/**
21
	 * @var TbActiveForm If we're called from the form, here lies the reference to it.
22
	 */
23
	public $form;
24
25
	/**
26
	 * @var array The options for the "bootstrap-timepicker" plugin.
27
	 * @see http://jdewit.github.com/bootstrap-timepicker/
28
	 *
29
	 * Available options:
30
	 * template    string
31
	 *      'dropdown' (default), Show picker in a dropdown
32
	 *      'modal', Show picker in a modal
33
	 *      false, Don't show a widget
34
	 * minuteStep    integer    15    Specify a step for the minute field.
35
	 * showSeconds    boolean    false    Show the seconds field.
36
	 * secondStep    integer    15    Specify a step for the second field.
37
	 * defaultTime    string
38
	 *      'current' (default) Set to the current time.
39
	 *      'value' Set to inputs current value
40
	 *      false    Do not set a default time
41
	 * showMeridian    boolean
42
	 *      true (default)  12hr mode
43
	 *      false24hr mode
44
	 * showInputs    boolean
45
	 *      true (default )Shows the text inputs in the widget.
46
	 *      false Hide the text inputs in the widget
47
	 * disableFocus    boolean    false    Disables the input from focusing. This is useful for touch screen devices that
48
	 *          display a keyboard on input focus.
49
	 * modalBackdrop    boolean    false    Show modal backdrop.
50
	 */
51
	public $options = array();
52
53
	/**
54
	 * @var string[] the JavaScript event handlers.
55
	 * @deprecated 2.0.0 You have the ability to set unique ID and/or class to this element.
56
	 * Define Javascript handlers inside Javascript files, not here.
57
	 * You can generate the Javascript files from PHP, too, there's no need in hand-crafted snippets of Javascript polluting view files.
58
	 */
59
	public $events = array();
60
61
	/**
62
	 * @var array HTML attributes for the wrapper "div" tag.
63
	 */
64
	public $wrapperHtmlOptions = array();
65
66
	/**
67
	 * @var boolean Whether to not append the time icon at end of input.
68
	 * NOTE that the timepicker is opening after click on this icon if it's present!
69
	 */
70
	public $noAppend = false;
71
72
	/**
73
	 * Runs the widget.
74
	 */
75 1
	public function run() {
76
		
77 1
		list($name) = $this->resolveNameID();
78
79
		// TODO: what is this?
80
		// Add a class of no-user-select to widget
81 1
		$this->htmlOptions['class'] = empty($this->htmlOptions['class'])
82 1
			? 'no-user-select'
83 1
			: 'no-user-select ' . $this->htmlOptions['class'];
84
85
		// We are overriding the result of $this->resolveNameID() here, because $id which it emits is not unique through the page.
86 1
		if (empty($this->htmlOptions['id'])) {
87 1
			$this->htmlOptions['id'] = $this->id;
88 1
		}
89
90
		// Adding essential class for timepicker to work.
91 1
		$this->wrapperHtmlOptions = $this->injectClass($this->wrapperHtmlOptions, 'bootstrap-timepicker');
92
93 1
		if (!$this->noAppend)
94 1
			$this->wrapperHtmlOptions = $this->injectClass($this->wrapperHtmlOptions, 'input-group');
95
96
97 1
		echo CHtml::openTag('div', $this->wrapperHtmlOptions);
98 1
		if ($this->hasModel()) {
99 1
			if ($this->form) {
100
				echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
101
			} else {
102 1
				echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
103
			}
104 1
		} else {
105
			echo CHtml::textField($name, $this->value, $this->htmlOptions);
106
		}
107 1
		if (!$this->noAppend)
108 1
			$this->echoAppend();
109 1
		echo CHtml::closeTag('div');
110
111 1
		$this->registerClientScript($this->id);
112 1
	}
113
114
	/**
115
	 * Registers required javascript files
116
	 *
117
	 * @param string $id
118
	 */
119 1
	public function registerClientScript($id) {
120
		
121 1
        Booster::getBooster()->cs->registerPackage('timepicker');
122
123 1
		$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
124
125 1
		ob_start();
126
127 1
		echo "jQuery('#{$id}').timepicker({$options})";
128 1
		foreach ($this->events as $event => $handler) {
0 ignored issues
show
Deprecated Code introduced by
The property TbTimePicker::$events has been deprecated with message: 2.0.0 You have the ability to set unique ID and/or class to this element.
Define Javascript handlers inside Javascript files, not here.
You can generate the Javascript files from PHP, too, there's no need in hand-crafted snippets of Javascript polluting view files.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
129
			echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
130 1
		}
131
132 1
		Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, ob_get_clean() . ';');
133 1
	}
134
135
	/**
136
	 * @param array $valueset
137
	 * @param string $className
138
	 *
139
	 * @return array
140
	 */
141 1
	private function injectClass($valueset, $className) {
142
		
143 1
		if (array_key_exists('class', $valueset) and is_string($valueset['class'])) {
144 1
			$valueset['class'] = implode(
145 1
				' ',
146 1
				array_merge(
147 1
					explode(
148 1
						' ',
149 1
						$valueset['class']
150 1
					),
151 1
					array($className)
152 1
				)
153 1
			);
154 1
		} else {
155 1
			$valueset['class'] = $className;
156
		}
157
158 1
		return $valueset;
159
	}
160
161 1
	private function echoAppend() {
162
		
163 1
		echo CHtml::tag('span', array('class' => 'input-group-addon'), CHtml::tag('i', array('class' => 'glyphicon glyphicon-time'), ''));
164 1
	}
165
}
166