views
4 years ago
Data.php
4 years ago
Dates.php
4 years ago
Metadata.php
4 years ago
Renderer.php
4 years ago
Data.php
59 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 | use Piwik\API\Request; |
| 13 | use WpMatomo\Bootstrap; |
| 14 | use WpMatomo\Site; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; // if accessed directly |
| 18 | } |
| 19 | |
| 20 | class Data { |
| 21 | |
| 22 | /** |
| 23 | * @param $report_metadata |
| 24 | * @param $period |
| 25 | * @param $date |
| 26 | * @param $sort_by_column |
| 27 | * @param $filter_limit |
| 28 | * |
| 29 | * @return array An array containing reportData, metrics, columns, ... |
| 30 | */ |
| 31 | public function fetch_report( $report_metadata, $period, $date, $sort_by_column, $filter_limit ) { |
| 32 | $site = new Site(); |
| 33 | $idsite = $site->get_current_matomo_site_id(); |
| 34 | |
| 35 | Bootstrap::do_bootstrap(); |
| 36 | |
| 37 | if ( empty( $idsite ) ) { |
| 38 | return []; |
| 39 | } |
| 40 | |
| 41 | $params = [ |
| 42 | 'apiModule' => $report_metadata['module'], |
| 43 | 'apiAction' => $report_metadata['action'], |
| 44 | 'filter_limit' => $filter_limit, |
| 45 | 'filter_sort_column' => $sort_by_column, |
| 46 | 'period' => $period, |
| 47 | 'date' => $date, |
| 48 | 'idSite' => $idsite, |
| 49 | ]; |
| 50 | if ( ! empty( $report_metadata['parameters'] ) ) { |
| 51 | $params = array_merge( $params, $report_metadata['parameters'] ); |
| 52 | } |
| 53 | |
| 54 | $report = Request::processRequest( 'API.getProcessedReport', $params ); |
| 55 | |
| 56 | return $report; |
| 57 | } |
| 58 | } |
| 59 |