| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Plugins\ExamplePlugin; |
|
|
| use Piwik\Archive; |
| use Piwik\DataTable; |
| use Piwik\Piwik; |
| use Piwik\Plugins\ExamplePlugin\RecordBuilders\ExampleMetric; |
| use Piwik\Plugins\ExamplePlugin\RecordBuilders\ExampleMetric2; |
| use Piwik\Segment; |
|
|
| |
| |
| |
| |
| |
| class API extends \Piwik\Plugin\API |
| { |
| |
| |
| |
| |
| |
| |
| public function getAnswerToLife(bool $truth = true): int |
| { |
| if ($truth) { |
| return 42; |
| } |
|
|
| return 24; |
| } |
|
|
| |
| |
| |
| |
| public function getExampleReport(string $idSite, string $period, string $date, ?string $segment = null): DataTable |
| { |
| Piwik::checkUserHasViewAccess($idSite); |
|
|
| $table = DataTable::makeFromSimpleArray(array( |
| array('label' => 'My Label 1', 'nb_visits' => '1'), |
| array('label' => 'My Label 2', 'nb_visits' => '5'), |
| )); |
|
|
| return $table; |
| } |
|
|
| |
| |
| |
| |
| public function getExampleArchivedMetric(string $idSite, string $period, string $date, ?string $segment = null): DataTable\DataTableInterface |
| { |
| Piwik::checkUserHasViewAccess($idSite); |
|
|
| $archive = Archive::build($idSite, $period, $date, $segment); |
| return $archive->getDataTableFromNumeric([ExampleMetric::EXAMPLEPLUGIN_METRIC_NAME, ExampleMetric2::EXAMPLEPLUGIN_CONST_METRIC_NAME]); |
| } |
|
|
| public function getSegmentHash(string $idSite, string $segment) |
| { |
| Piwik::checkUserHasViewAccess($idSite); |
|
|
| $segment = new Segment($segment, [$idSite]); |
| return $segment->getHash(); |
| } |
| } |
|
|