Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| VisitorsWeek | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| render | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\visitors\Plugin\views\field; |
| 4 | |
| 5 | use Drupal\Component\Utility\Xss as UtilityXss; |
| 6 | use Drupal\views\Attribute\ViewsField; |
| 7 | use Drupal\views\Render\ViewsRenderPipelineMarkup; |
| 8 | |
| 9 | /** |
| 10 | * Field handler to display the week of the visit. |
| 11 | * |
| 12 | * @ingroup views_field_handlers |
| 13 | */ |
| 14 | #[ViewsField("visitors_week")] |
| 15 | final class VisitorsWeek extends VisitorsTimestamp { |
| 16 | |
| 17 | /** |
| 18 | * {@inheritdoc} |
| 19 | */ |
| 20 | protected $format = '%X%V'; |
| 21 | |
| 22 | /** |
| 23 | * {@inheritdoc} |
| 24 | */ |
| 25 | public function render($values) { |
| 26 | |
| 27 | $value = $this->getValue($values); |
| 28 | $year = (int) substr($value, 0, 4); |
| 29 | $week = (int) substr($value, 4, 2); |
| 30 | |
| 31 | // Converts week of year to date. |
| 32 | $date = new \DateTime(); |
| 33 | $date->setISODate($year, $week); |
| 34 | |
| 35 | return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($date->format('Y-m-d'))); |
| 36 | } |
| 37 | |
| 38 | } |