PHP code example of pavlm / yii2-stats-widget

1. Go to this page and download the library: Download pavlm/yii2-stats-widget library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pavlm / yii2-stats-widget example snippets


    public function actions()
    {
        return [
            'stats-users' => [
                'class' => StatsAction::class,
                'providerFactory' => new TimeSeriesProviderCallbackFactory(function ($rangeStart, $rangeEnd, $period, $timeZone) {
                    return new QueryStatsProvider([
                        'rangeStart' => $rangeStart,
                        'rangeEnd' => $rangeEnd,
                        'period' => $period,
                        'timeZone' => $timeZone,
                        'timeZoneConnection' => new \DateTimeZone('Europe/Moscow'),
                        'query' => (new Query())->from('user'),
                        'dateField' => 'created_at',
                        'dateFieldType' => QueryStatsProvider::DATETYPE_INT,
                    ]);
                }),
                'timeZone' => 'Europe/Moscow',
                'defaultRange' => 'P2Y',
                'defaultPeriod' => 'P1Y',
            ],
        ];
    }

echo StatsWidget::widget([
    'statsAction' => ['stats/stats-users'],
]);

    'i18n' => [
        'translations' => [
            'stats-widget' => [
                'class' => yii\i18n\PhpMessageSource::class,
                'basePath' => '@pavlm/yii/stats/messages',
            ],
        ],
    ],