AdminerEditCalendar::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
<?php
2
3
/** Display jQuery UI Timepicker for each date and datetime field
4
* @link https://www.adminer.org/plugins/#use
5
* @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/
6
* @uses jQuery UI: core, widget, mouse, slider, datepicker
7
* @author Jakub Vrana, http://www.vrana.cz/
8
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
9
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
10
*/
11
class AdminerEditCalendar {
12
	/** @access protected */
13
	var $prepend, $langPath;
14
15
	/**
16
	* @param string text to append before first calendar usage
17
	* @param string path to language file, %s stands for language code
18
	*/
19
	function __construct($prepend = "<script type='text/javascript' src='jquery-ui/jquery.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui-timepicker-addon.js'></script>\n<link rel='stylesheet' type='text/css' href='jquery-ui/jquery-ui.css'>\n", $langPath = 'jquery-ui/i18n/jquery.ui.datepicker-%s.js'
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
    ) {
21
		$this->prepend = $prepend;
22
		$this->langPath = $langPath;
23
	}
24
25
	function head() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
		echo $this->prepend;
27
		if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0
28
			$lang = get_lang();
29
			$lang = ($lang == 'zh' ? 'zh-CN' : ($lang == 'zh-tw' ? 'zh-TW' : $lang));
30
			if ($lang != 'en' && file_exists(sprintf($this->langPath, $lang))) {
31
				printf("<script type='text/javascript' src='$this->langPath'></script>\n", $lang);
32
				echo "<script type='text/javascript'>jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });</script>\n";
33
			}
34
		}
35
	}
36
37
	function editInput($table, $field, $attrs, $value) {
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
		if (preg_match('~date|time~', $field['type'])) {
39
			$dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
40
			$timeFormat = "showSecond: true, timeFormat: 'hh:mm:ss'";
41
			return "<input id='fields-" . h($field['field']) . "' value='" . h($value) . "'" . (+$field['length'] ? " maxlength='" . (+$field['length']) . "'" : '') . "$attrs><script type='text/javascript'>jQuery('#fields-" . js_escape($field['field']) . "')."
42
				. ($field['type'] == 'time' ? "timepicker({ $timeFormat })"
43
				: (preg_match('~time~', $field['type']) ? "datetimepicker({ $dateFormat, $timeFormat })"
44
				: "datepicker({ $dateFormat })"
45
			)) . ';</script>';
46
		}
47
	}
48
49
}
50