Framework  3.9
PivotTableHelper Class Reference

The PivotTableHelper class provides support for configuring display tables (DataListViews and GroupedDataListViews) dynamically, based upon the structure of a pivot query. More...

Public Member Functions

 __construct ($pivot, $table)
 Creates a new PivotTableHelper. More...
 
 column ($pattern, $format, $sortable=true, $style="", $typeHint=null, $onExport=null, $sortFormat=null, $footerTotal=false)
 Adds a column specification. More...
 
 create ()
 Adds columns to the table based on the column specifications that have been provided. More...
 

Public Attributes

 $pivot
 
 $table
 
 $columnSpecs = array()
 

Detailed Description

The PivotTableHelper class provides support for configuring display tables (DataListViews and GroupedDataListViews) dynamically, based upon the structure of a pivot query.

Author
Andy Green

Definition at line 631 of file pivot.inc.

Constructor & Destructor Documentation

◆ __construct()

PivotTableHelper::__construct (   $pivot,
  $table 
)

Creates a new PivotTableHelper.

Parameters
object$pivotthe source PivotQuery or GroupedPivotQuery
object$tablethe target DataListView or GroupedDataListView

Definition at line 643 of file pivot.inc.

644  {
645  $this->pivot = $pivot;
646  $this->table = $table;
647  }

Member Function Documentation

◆ column()

PivotTableHelper::column (   $pattern,
  $format,
  $sortable = true,
  $style = "",
  $typeHint = null,
  $onExport = null,
  $sortFormat = null,
  $footerTotal = false 
)

Adds a column specification.

Column specifications match fields by regular expression and provide the output format, styles and hints for the generated columns.

Parameters
string$patternThe field matching pattern
string$formatThe output format template
boolean$sortableWhether the column is sortable (optional)
string$styleCSS styles for the column (optional)
string$typeHintType hint for the column (optional)
string$onExportData export callback for the column (optional)
string$sortFormatsorting format for the column (optional)
Returns
PivotTableHelper

Definition at line 661 of file pivot.inc.

662  {
663  $this->columnSpecs[$pattern] = array("format" => $format, "sortable" => $sortable, "style" => $style,
664  "typeHint" => $typeHint, "onExport" => $onExport, "sortFormat" => $sortFormat,
665  "footerTotal" => $footerTotal);
666  return $this;
667  }

◆ create()

PivotTableHelper::create ( )

Adds columns to the table based on the column specifications that have been provided.

Definition at line 672 of file pivot.inc.

673  {
674  $item = $this->pivot->createPivotItem();
675 
676  $fields = $item->getFields();
677 
678  foreach($fields as $field => $type)
679  {
680  foreach($this->columnSpecs as $spec => $details)
681  {
682  $matches = array();
683  if (preg_match("/{$spec}/", $field, $matches))
684  {
685  $format = str_replace("%FIELD%", $field, $details["format"]);
686 
687  if ($matches[1]) $format = str_replace("%KEY%", $matches[1], $format);
688 
689  $this->table->column($item->prettifyFieldName($field), $format, $details["sortable"], $details["style"],
690  $details["typeHint"], $details["onExport"], $details["sortFormat"]);
691  if ($details["footerTotal"])
692  {
693  $this->table->footerTotal($format);
694  }
695  break;
696  }
697  }
698  }
699  }

Member Data Documentation

◆ $columnSpecs

PivotTableHelper::$columnSpecs = array()

Definition at line 636 of file pivot.inc.

◆ $pivot

PivotTableHelper::$pivot

Definition at line 633 of file pivot.inc.

◆ $table

PivotTableHelper::$table

Definition at line 634 of file pivot.inc.


The documentation for this class was generated from the following file: