Lines: 100.00%
| Line | Hits | Source |
|---|---|---|
| 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 | 1 | $value = $this->getValue($values); |
| 28 | 1 | $year = (int) substr($value, 0, 4); |
| 29 | 1 | $week = (int) substr($value, 4, 2); |
| 30 | ||
| 31 | // Converts week of year to date. | |
| 32 | 1 | $date = new \DateTime(); |
| 33 | 1 | $date->setISODate($year, $week); |
| 34 | ||
| 35 | 1 | return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($date->format('Y-m-d'))); |
| 36 | } | |
| 37 | ||
| 38 | } |