ReportDate.php in Commerce Reporting 8
File
src/Plugin/views/sort/ReportDate.php
View source
<?php
namespace Drupal\commerce_reports\Plugin\views\sort;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\sort\Date;
class ReportDate extends Date {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['granularity']['#options']['week'] = $this
->t('Week');
}
public function query() {
$this
->ensureMyTable();
switch ($this->options['granularity']) {
case 'second':
default:
$this->query
->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
return;
case 'minute':
$formula = $this
->getDateFormat('YmdHi');
break;
case 'hour':
$formula = $this
->getDateFormat('YmdH');
break;
case 'day':
$formula = $this
->getDateFormat('Ymd');
break;
case 'week':
$formula = $this
->getDateFormat('YW');
break;
case 'month':
$formula = $this
->getDateFormat('Ym');
break;
case 'year':
$formula = $this
->getDateFormat('Y');
break;
}
$this->query
->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
}
}
Classes
Name |
Description |
ReportDate |
Extends View basic sort handler for dates to add Week granularity. |