Day.php
1 month ago
Factory.php
3 months ago
Month.php
1 month ago
PeriodValidator.php
2 years ago
Range.php
1 month ago
Week.php
1 month ago
Year.php
1 month ago
Week.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Period; |
| 10 | |
| 11 | use Piwik\Period; |
| 12 | class Week extends Period |
| 13 | { |
| 14 | public const PERIOD_ID = 2; |
| 15 | protected $label = 'week'; |
| 16 | /** |
| 17 | * Returns the current period as a localized short string |
| 18 | * |
| 19 | * @return string |
| 20 | */ |
| 21 | public function getLocalizedShortString() |
| 22 | { |
| 23 | return $this->getTranslatedRange($this->getRangeFormat(\true)); |
| 24 | } |
| 25 | /** |
| 26 | * Returns the current period as a localized long string |
| 27 | * |
| 28 | * @return string |
| 29 | */ |
| 30 | public function getLocalizedLongString() |
| 31 | { |
| 32 | $string = $this->getTranslatedRange($this->getRangeFormat()); |
| 33 | return $this->translator->translate('Intl_PeriodWeek') . " " . $string; |
| 34 | } |
| 35 | /** |
| 36 | * Returns the current period as a string |
| 37 | * |
| 38 | * @return string |
| 39 | */ |
| 40 | public function getPrettyString() |
| 41 | { |
| 42 | $dateStart = $this->getDateStart(); |
| 43 | $dateEnd = $this->getDateEnd(); |
| 44 | $out = $this->translator->translate('General_DateRangeFromTo', array($dateStart->toString(), $dateEnd->toString())); |
| 45 | return $out; |
| 46 | } |
| 47 | /** |
| 48 | * Generates the subperiods - one for each day in the week |
| 49 | */ |
| 50 | protected function generate() |
| 51 | { |
| 52 | if ($this->subperiodsProcessed) { |
| 53 | return; |
| 54 | } |
| 55 | parent::generate(); |
| 56 | $date = $this->date; |
| 57 | if ($date->toString('N') > 1) { |
| 58 | $date = $date->subDay($date->toString('N') - 1); |
| 59 | } |
| 60 | $startWeek = $date; |
| 61 | $currentDay = clone $startWeek; |
| 62 | while ($currentDay->compareWeek($startWeek) == 0) { |
| 63 | $this->addSubperiod(new \Piwik\Period\Day($currentDay)); |
| 64 | $currentDay = $currentDay->addDay(1); |
| 65 | } |
| 66 | } |
| 67 | public function getImmediateChildPeriodLabel() |
| 68 | { |
| 69 | return 'day'; |
| 70 | } |
| 71 | public function getParentPeriodLabel() |
| 72 | { |
| 73 | return 'month'; |
| 74 | } |
| 75 | } |
| 76 |