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    
Last Updated Ratings Unique User Downloads Download Rankings
2021-12-06 (18 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 49 This week: 4All time: 10,157 This week: 37Up
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

Picture of Uldis Nelsons
Name: Uldis Nelsons <contact>
Classes: 15 packages by
Country: Latvia Latvia
Innovation award
Innovation award
Nominee: 9x

Winner: 2x

Details

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:49
This week:4
All time:10,157
This week:37Up
For more information send a message to info at phpclasses dot org.