Loading Stats events from the database
Just like when loading SystemLogEvents from the database, you can use the provided StatsEvents class to retrieve and work with lists of StatsEvent objects.
For example, let's load the last fifty StatsEventHomeView objects from our earlier example, using what we learned in the Item lists section of the Items guide:
$statsEventItems = new \Cherrycake\Stats\StatsEvents([
"p" => [
"type" => "CherrycakeApp\StatsEventHomeView",
"limit" => 50
]
]);
foreach ($statsEventItems as $statsEvent) {
echo
$e->Locale->formatTimestamp($statsEvent->timestamp).
": ".$statsEvent->typeDescription.
": ".$statsEvent->count.
"\n";
}As you can see, the StatsEvents class accepts some additional keys on top of the usual Items::fillFromParameters keys:
typeRetrieves only StatsEvent objects of this class name. Must include the full namespace route to the class.fromTimestampRetrieves StatsEvent objects triggered after this timestamp.toTimestampRetrieves StatsEvent objects triggered up to this timestamp.
5/21/20: Home view: 90
5/22/20: Home view: 1See examples of loading StatsEvent object from the database in the Triggering a stats event and Events with additional dimensions examples.
Last updated
Was this helpful?