Code Duplication    Length = 21-27 lines in 3 locations

src/DataSource/NetteDatabaseTableDataSource.php 1 location

@@ 111-131 (lines=21) @@
108
	 * @param  Filter\FilterDateRange $filter
109
	 * @return void
110
	 */
111
	public function applyFilterDateRange(Filter\FilterDateRange $filter)
112
	{
113
		$conditions = $filter->getCondition();
114
115
		$value_from = $conditions[$filter->getColumn()]['from'];
116
		$value_to   = $conditions[$filter->getColumn()]['to'];
117
118
		if ($value_from) {
119
			$date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from);
120
			$date_from->setTime(0, 0, 0);
121
122
			$this->data_source->where("DATE({$filter->getColumn()}) >= ?", $date_from->format('Y-m-d'));
123
		}
124
125
		if ($value_to) {
126
			$date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to);
127
			$date_to->setTime(23, 59, 59);
128
129
			$this->data_source->where("DATE({$filter->getColumn()}) <= ?", $date_to->format('Y-m-d'));
130
		}
131
	}
132
133
134
	/**

src/DataSource/DibiFluentDataSource.php 1 location

@@ 105-125 (lines=21) @@
102
	 * @param  Filter\FilterDateRange $filter
103
	 * @return void
104
	 */
105
	public function applyFilterDateRange(Filter\FilterDateRange $filter)
106
	{
107
		$conditions = $filter->getCondition();
108
109
		$value_from = $conditions[$filter->getColumn()]['from'];
110
		$value_to   = $conditions[$filter->getColumn()]['to'];
111
112
		if ($value_from) {
113
			$date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from);
114
			$date_from->setTime(0, 0, 0);
115
116
			$this->data_source->where('DATE(%n) >= ?', $filter->getColumn(), $date_from);
117
		}
118
119
		if ($value_to) {
120
			$date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to);
121
			$date_to->setTime(23, 59, 59);
122
123
			$this->data_source->where('DATE(%n) <= ?', $filter->getColumn(), $date_to);
124
		}
125
	}
126
127
128
	/**

src/DataSource/NetteDatabaseTableMssqlDataSource.php 1 location

@@ 40-66 (lines=27) @@
37
	 * @param  Filter\FilterDateRange $filter
38
	 * @return void
39
	 */
40
	public function applyFilterDateRange(Filter\FilterDateRange $filter)
41
	{
42
		$conditions = $filter->getCondition();
43
44
		$value_from = $conditions[$filter->getColumn()]['from'];
45
		$value_to   = $conditions[$filter->getColumn()]['to'];
46
47
		if ($value_from) {
48
			$date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from);
49
			$date_from->setTime(0, 0, 0);
50
51
			$this->data_source->where(
52
				"CONVERT(varchar(10), {$filter->getColumn()}, 112) >= ?",
53
				$date_from->format('Y-m-d')
54
			);
55
		}
56
57
		if ($value_to) {
58
			$date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to);
59
			$date_to->setTime(23, 59, 59);
60
61
			$this->data_source->where(
62
				"CONVERT(varchar(10), {$filter->getColumn()}, 112) <= ?",
63
				$date_to->format('Y-m-d')
64
			);
65
		}
66
	}
67
68
69
	/**