DateTimeWidget   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 77
rs 10
c 1
b 0
f 0
wmc 9
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEditHtml() 0 4 1
B generateRow() 0 22 4
A showFilterHtml() 0 7 1
A processEditAction() 0 13 3
1
<?php
2
3
namespace DigitalWand\AdminHelper\Widget;
4
5
class DateTimeWidget extends HelperWidget
6
{
7
	static protected $defaults = array(
8
		'FILTER' => 'BETWEEN',
9
	);
10
	
11
	/**
12
	 * Генерирует HTML для редактирования поля
13
	 * @see AdminEditHelper::showField();
14
	 * @return mixed
15
	 */
16
	protected function getEditHtml()
17
	{
18
		return \CAdminCalendar::CalendarDate($this->getEditInputName(), ConvertTimeStamp(strtotime($this->getValue()), "FULL"), 10, true);
19
	}
20
21
	/**
22
	 * Генерирует HTML для поля в списке
23
	 * @see AdminListHelper::addRowCell();
24
	 * @param CAdminListRow $row
25
	 * @param array $data - данные текущей строки
26
	 * @return mixed
27
	 */
28
	public function generateRow(&$row, $data)
29
	{
30
		if (isset($this->settings['EDIT_IN_LIST']) AND $this->settings['EDIT_IN_LIST'])
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
31
		{
32
			$row->AddCalendarField($this->getCode());
33
		}
34
		else
35
		{
36
			$arDate = ParseDateTime($this->getValue());
37
38
			if ($arDate['YYYY'] < 10)
39
			{
40
				$stDate = '-';
41
			}
42
			else
43
			{
44
				$stDate = ConvertDateTime($this->getValue(), "DD.MM.YYYY HH:MI:SS", "ru");
45
			}
46
47
			$row->AddViewField($this->getCode(), $stDate);
48
		}
49
	}
50
51
	/**
52
	 * Генерирует HTML для поля фильтрации
53
	 * @see AdminListHelper::createFilterForm();
54
	 * @return mixed
55
	 */
56
	public function showFilterHtml()
57
	{
58
		list($inputNameFrom, $inputNameTo) = $this->getFilterInputName();
59
		print '<tr>';
60
		print '<td>' . $this->settings['TITLE'] . '</td>';
61
		print '<td width="0%" nowrap>' . CalendarPeriod($inputNameFrom, $$inputNameFrom, $inputNameTo, $$inputNameTo, "find_form") . '</td>';
62
	}
63
64
	/**
65
	 * Сконвертируем дату в формат Mysql
66
	 * @return boolean
67
	 */
68
	public function processEditAction()
69
	{
70
		try
71
		{
72
			$this->setValue(new \Bitrix\Main\Type\Datetime($this->getValue()));
73
		} catch (\Exception $e)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
74
		{
75
		}
76
		if (!$this->checkRequired())
77
		{
78
			$this->addError('REQUIRED_FIELD_ERROR');
79
		}
80
	}
81
}
82