views
6 years ago
Data.php
6 years ago
Dates.php
6 years ago
Metadata.php
6 years ago
Renderer.php
6 years ago
Dates.php
82 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo\Report; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // if accessed directly |
| 14 | } |
| 15 | |
| 16 | class Dates { |
| 17 | const TODAY = 'today'; |
| 18 | const YESTERDAY = 'yesterday'; |
| 19 | const THIS_WEEK = 'thisweek'; |
| 20 | const LAST_WEEK = 'lastweek'; |
| 21 | const THIS_MONTH = 'thismonth'; |
| 22 | const LAST_MONTH = 'lastmonth'; |
| 23 | const THIS_YEAR = 'thisyear'; |
| 24 | |
| 25 | public function get_supported_dates() { |
| 26 | return array( |
| 27 | self::YESTERDAY => 'Yesterday', |
| 28 | self::TODAY => 'Today', |
| 29 | self::THIS_WEEK => 'This week', |
| 30 | self::LAST_WEEK => 'Last week', |
| 31 | self::THIS_MONTH => 'This month', |
| 32 | self::LAST_MONTH => 'Last month', |
| 33 | self::THIS_YEAR => 'This year', |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | public function detect_period_and_date( $report_date ) { |
| 38 | $period = 'day'; |
| 39 | $date = 'yesterday'; |
| 40 | |
| 41 | switch ( $report_date ) { |
| 42 | case self::TODAY: |
| 43 | $period = 'day'; |
| 44 | $date = 'today'; |
| 45 | break; |
| 46 | case self::YESTERDAY: |
| 47 | $period = 'day'; |
| 48 | $date = 'yesterday'; |
| 49 | break; |
| 50 | case self::THIS_MONTH: |
| 51 | $period = 'month'; |
| 52 | $date = 'today'; |
| 53 | break; |
| 54 | case self::LAST_MONTH: |
| 55 | $period = 'month'; |
| 56 | $date = gmdate( 'Y-m-d', strtotime( '1 month ago' ) ); |
| 57 | break; |
| 58 | case self::THIS_WEEK: |
| 59 | $period = 'week'; |
| 60 | $date = 'today'; |
| 61 | break; |
| 62 | case self::LAST_WEEK: |
| 63 | $period = 'week'; |
| 64 | $date = gmdate( 'Y-m-d', strtotime( '1 week ago' ) ); |
| 65 | break; |
| 66 | case self::THIS_YEAR: |
| 67 | $period = 'year'; |
| 68 | $date = 'today'; |
| 69 | break; |
| 70 | default: |
| 71 | if ( preg_match( '/\d{4}-\d{2}-\d{2}/', $report_date ) ) { |
| 72 | $period = 'day'; |
| 73 | $date = $report_date; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return array( $period, $date ); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | } |
| 82 |