PHP Classes

D3 Data PHP Pivot Table: Show reports using pivot tables on Web pages

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 112 All time: 9,576 This week: 75Up
Version License PHP version Categories
d3data 1.0.0Freeware5HTML, PHP 5, Business
Description 

Author

This package can show reports using pivot tables on Web pages.

It provides classes that can provide data to render a pivot table displayed using an HTML table.

Applications can configure the pivot table by specifying details like:

- The table column fields

- The key columns

- The columns that will be aggregated

- The query that will define the data that will be retrieved to display in the table

- Query filter parameters

- Details of formatting of the table columns like the column name, CSS class and a PHP class that format the column value

Innovation Award
PHP Programming Innovation award nominee
December 2021
Number 7
Pivot tables show helpful information to make decisions on how to improve businesses.

This package can show pivot tables on Web pages from a specification of how to retrieve the information from a database to display on the pivot table.

Manuel Lemos
Picture of Uldis Nelsons
Name: Uldis Nelsons <contact>
Classes: 18 packages by
Country: Latvia Latvia
Age: 54
All time rank: 19746 in Latvia Latvia
Week rank: 91 Up1 in Latvia Latvia Up
Innovation award
Innovation award
Nominee: 12x

Winner: 2x

Documentation

D3 Data"

Yii2 module for pivot reporting.

Features

- get data from db by query - define columns - from records create pivot table. - output pivot field unique values list for filters - filter data

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require d3yii2/d3data "*"

or add

"d3yii2/d3data": "*"

to the require section of your composer.json file.

Usage

<?php



class ReportGrid
{

    public const F_STORE = 'store';
    public const F_MANUFACTURED = 'manufactured';
    public const F_PRODUCT = 'product';
    public const F_PACKS_COUNT = 'packsCount';
    / @var D3DataProvider */
    public $dataProvider;

    public function __construct(int $productId, string $manufacturedDate )
    {

        $storeList = StoreDictionary::getList($this->sysCompanyId);
        $this->dataProvider = new D3DataProvider([
            'rowKeyColumns' => [self::F_PRODUCT,self::F_MANUFACTURED],
            'tableColumnFields' => [self::F_STORE],
            'tableAggregateColumns' => [self::F_PACKS_COUNT],
            'query' => $this->query(),
            'filter' => [
                self::F_PRODUCT => (string)$productId,
                self::F_MANUFACTURED => $manufacturedDate,
            ],
            'columns' => [
                self::F_STORE => [
                    'class' => D3DataListColumn::class,
                    'name' => self::F_STORE,
                    'label' => 'Noliktava',
                    'list' => StoreDictionary::getList($this->sysCompanyId)
                ],
                self::F_MANUFACTURED => [
                    'class' => D3DataDateColumn::class,
                    'name' => self::F_MANUFACTURED,
                    'label' => 'Ra?ots',
                ],
                self::F_PRODUCT => [
                    'class' => D3DataListColumn::class,
                    'name' => self::F_PRODUCT,
                    'label' => 'Produkts',
                    'list' => CwclProductsDictionary::getListAll()
                ],
                self::F_PACKS_COUNT => [
                    'name' => self::F_PACKS_COUNT,
                    'label' => static function(string $value) use ($storeList){
                        return $storeList[$value] ?? $value;
                    }
                ],
            ]
        ]);
    }


    public function getTable(): array
    {
        return $this->dataProvider->getTable();
    }

    public function getProductFilterItems(int $selectedId, string $manufacturedDate): array
    {
        $items = [];
        $filterList = [ 0 => 'Visi']
            + $this
                ->dataProvider
                ->columns[self::F_PRODUCT]
                ->getFilterList();
        foreach($filterList as $id => $label
        ){

                $items[] = [
                    'label' => $label,
                    'url' => [
                        '',
                        'productId' => $id,
                        'manufacturedDate' => $manufacturedDate
                    ],
                    'selected' => $id === $selectedId
                ];

        }
        return $items;
    }

    public function getManufacturedFilterItems(string $selected, int $productId): array
    {
        $items = [];
        $filterList = [ '' => 'Visi']
            + $this
                ->dataProvider
                ->columns[self::F_MANUFACTURED]
                ->getFilterList();
        foreach($filterList as $id => $label
        ){

            $items[] = [
                'label' => $label,
                'url' => [
                    '',
                    'manufacturedDate' => $id,
                    'productId' => $productId
                ],
                'selected' => $id === $selected
            ];

        }
        return $items;

    }

    public function getColumns(): array
    {
        return $this->dataProvider->getGeneratedColumns();
    }
    public function query(): StoreTransactionsQuery
    {
        return StoreTransactions::find()
            ->select([
                self::F_STORE => 'stack.store_id',
                self::F_PRODUCT => 'product.product_id',
                self::F_MANUFACTURED => 'product.manufacture_date',
                self::F_PACKS_COUNT => 'COUNT(*)'
            ])
            ;
    }
}

controller

    /
     * @param int $productId
     * @param string $manufacturedDate
     * @return string|Response
     * @throws Exception
     */
    public function actionStackGrid(int $productId = 0, string $manufacturedDate = '')
    {
        $logic = new ReportGrid( $productId, $manufacturedDate);

        return $this->render('stack_grid', [
            'data' => $logic->getTable(),
            'columns' => $logic->getColumns(),
            'productFilterItems' => $logic->getProductFilterItems($productId, $manufacturedDate),
            'manufacturedFilterItems' => $logic->getManufacturedFilterItems($manufacturedDate, $productId),
        ]);
    }


  Files folder image Files  
File Role Description
Files folder imagegii (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file D3DataColumn.php Class Class source
Plain text file D3DataDateColumn.php Class Class source
Plain text file D3DataListColumn.php Class Class source
Plain text file D3DataProvider.php Class Class source
Plain text file Module.php Class Class source
Accessible without login Plain text file README.md Doc. Class source

  Files folder image Files  /  gii  
File Role Description
  Accessible without login Plain text file d3dataGiiantNModule.json Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:112
This week:0
All time:9,576
This week:75Up