public function CalendarDayDate::query in Calendar 8.2
Build the query based upon the formula.
Overrides Formula::query
File
- src/
Plugin/ views/ argument/ CalendarDayDate.php, line 104
Class
- CalendarDayDate
- Argument handler for a day.
Namespace
Drupal\calendar\Plugin\views\argumentCode
public function query($group_by = FALSE) {
$this
->ensureMyTable();
// Extend query logic only if field is of type daterange.
if ($this
->getFieldDefinition()
->getType() === 'daterange') {
if (!isset($this->argument)) {
return;
}
else {
$validated_argument = $this->calendarHelper
->getCalendarArguments($this->view);
}
$this->argument = $validated_argument[0]['argument'];
$date = new DrupalDateTime($this->argument);
$date
->format('Y-m-d H:i:s');
// We need dates that begin before this day or end after this day too.
// To build the expression get day before and after.
$date_after = new DrupalDateTime($this->argument);
$date_after
->add(new \DateInterval('P1D'));
$after = $date_after
->format('Y-m-d H:i:s');
$start_field_name = "{$this->tableAlias}.{$this->realField}";
$end_field_name = substr($start_field_name, 0, -6) . '_end_value';
$date_start = $this->query
->getDateFormat($this->query
->getDateField($start_field_name, TRUE), 'Y-m-d H:i:s', FALSE);
$date_end = $this->query
->getDateFormat($this->query
->getDateField($end_field_name, TRUE), 'Y-m-d H:i:s', FALSE);
$this->query
->setWhereGroup('AND', 'StartDate');
$expression1 = "{$date_start} < '{$after}'";
$expression2 = "{$date_end} > '{$date}'";
$this->query
->addWhereExpression('StartDate', $expression1);
$this->query
->addWhereExpression('StartDate', $expression2);
}
}