PHP code example of kakaprodo / system-analytic

1. Go to this page and download the library: Download kakaprodo/system-analytic 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/ */

    

kakaprodo / system-analytic example snippets


use Kakaprodo\SystemAnalytic\AnalyticGate;

AnalyticGate::process([
    'analytic_type' => 'new-user-bar-chart',
    'scope_type' => 'this_week',// last_week, last_year,last_month,range_date, range_year ...
]);


class NewUserBarChart extends BlockChart
{
    protected function boot()
    {
    }

    protected function query()
    {
        return DB::table('example')
    }

    protected function result(LazyCollection $groupedResult): AnalyticResponse
    {
        return $this->response($groupedResult->all());
    }
}

class NewUserBarChart extends BlockChart
{
    protected $scopeColumn = "users.created_at";

    protected $groupBy = "created_at";

    protected function boot()
    {
    }

    protected function query()
    {
        return DB::table('users')->orderBy('id');
    }

    protected function result(LazyCollection $groupedUsersByCreatedAt): AnalyticResponse
    {
        $result = $groupedUsersByCreatedAt->map(function ($users) {
            return $users->count();
        });

        return $this->response($result->all());
    }
}

class AnalyticHandlerRegister extends AnalyticHandlerRegisterBase
{
    /**
     * register a key value array of your handlers,
     * where the key is the analytic_type and the value
     * is the actual handler
     */
    public static function handlers(): array
    {
        return [
            NewUserBarChart::type() => NewUserBarChart::class,
        ];
    }
}

use Kakaprodo\SystemAnalytic\AnalyticGate;

AnalyticGate::process([
    'analytic_type' => 'new-user-bar-chart',// NewUserBarChart::type()
    'scope_type' => 'this_week',// last_week, last_year,last_month ...
]);


 $options = [
    'scope_value' => date based on the scope_type,
    'scope_from_date' => date or dateTime based on your need,
    'scope_to_date' => date or dateTime based on your need,
    'search_value' => string or Array,
    'should_export' => Bool,
    'file_type' => string between [csv,xlsx],
    'selected_option' => string,
    'should_clear_cache' => Bool
 ];
sh
    php artisan system-analytic:config
    
sh
    php artisan system-analytic:install
    
sh
php artisan system-analytic:handler NewUserBarChart --bar-chart