38 lines
865 B
PHP
38 lines
865 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace adrienpayet\analytics;
|
||
|
|
|
||
|
|
use Kirby\Cms\Page;
|
||
|
|
|
||
|
|
class AnalyticsPage extends Page
|
||
|
|
{
|
||
|
|
public function getAnalyticsData(array $filters = []): array
|
||
|
|
{
|
||
|
|
$user = kirby()->user();
|
||
|
|
|
||
|
|
if (!$user) {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($user->isAdmin()) {
|
||
|
|
return AnalyticsStore::getAggregatedData($filters);
|
||
|
|
}
|
||
|
|
|
||
|
|
$allowedProjects = $user->currentProjects();
|
||
|
|
$allowedEmails = [];
|
||
|
|
foreach ($allowedProjects as $project) {
|
||
|
|
$users = kirby()->users();
|
||
|
|
foreach ($users as $u) {
|
||
|
|
if ($u->currentProjects()->has($project)) {
|
||
|
|
$allowedEmails[] = $u->email()->value();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$filters['emails'] = array_unique($allowedEmails);
|
||
|
|
|
||
|
|
return AnalyticsStore::getAggregatedData($filters);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|