Framework  3.9
GroupedDataListView Class Reference

GroupedDataListView displays a list of DataItems (or InnerJoinResults) in tabular format grouped by a specific field. More...

Public Member Functions

 GroupedDataListView ($items, $id, $cssClass="list", $groupClass="subheading")
 Creates a new GroupedDataListView object. More...
 
 getID ()
 
 addFacetTaggingHandler ($handler)
 Adds a row tagging handler. More...
 
 group ($title, $key, $expanded=false, $fixed=false)
 Adds a group to the view. More...
 
 groupBy ($groups, $format=null, $field="", $expandedFn=null, $fixedFn=null)
 Add groups based on the supplied list of DataItems. More...
 
 autoGroup ()
 
 format ($group, $template)
 Outputs the text for the groupedBy title bar using the given group dataitem object. More...
 
 scrollable ($height=300, $resizable=true)
 
 column ($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
 Adds a column definition to the DataListView. More...
 
 exportColumn ($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
 Adds a column definition to the DataListView that is only output when exporting the table to Excel. More...
 
 selector ($format="")
 Adds a selector column to the DataListView. More...
 
 formatRowId ($item)
 
 footerText ($text="", $style="", $colspan=1)
 Adds a text column to the table footer. More...
 
 footerValue ($callback, $style="", $colspan=1)
 Adds a value column to the table footer. More...
 
 footerTotal ($field, $style="text-align: right", $colspan=1)
 Sums the total for a column. More...
 
 groupFooterText ($text="", $style="", $colspan=1)
 Adds a text column to the table footer. More...
 
 groupFooterTotal ($field, $style="text-align: right", $colspan=1)
 
 setID ($id=null)
 Sets the client-side ID for this DataListView. More...
 
 autoPopulate ($item)
 Automatically build the table columns from the given DataItem. More...
 
 commandMenu ()
 Adds a ContextMenu to the table that can contain a list of operations that can be performed on subselections of the table's contents. More...
 
 getExcelLink ()
 Get the Excel Link. More...
 
 writeScript ()
 Write the Javascript to implement the table output. More...
 
 drawView ()
 Writes the HTML for the data table to the output buffer. More...
 
 drawViewToString ()
 Render the table view and return the generated HTML as a string. More...
 
 getFooterColumnFormatting ($column)
 
 drawSubFooterColumns ()
 
 writeExcelFile ($file)
 Writes the data table out as an Excel File. More...
 

Public Attributes

 $columns
 The column definitions for the table. More...
 
 $footerColumns
 The footer column definitions for the table. More...
 
 $cssClass
 Optional CSS class to apply to the table. More...
 
 $groupClass
 The CSS class to apply to the group subheading rows. More...
 
 $id
 ID of the table in the output script. More...
 
 $cssStyle
 Optional additional inline styles to apply to the table. More...
 
 $emptyMessage
 Message to display when no items are present in the data set. More...
 
 $onStartRow
 Callback hook that gets called at the start of each row. More...
 
 $onDrawFooter
 Callback hook that gets called after all rows have been drawn. More...
 
 $mode
 The display mode for the table: fixed or tree. More...
 
 $groups
 The group definitions. More...
 
 $items
 The items to be displayed. More...
 
 $excelFile
 Name of the Excel file for automatic export to excel. More...
 
 $summary
 Human-readable summary of the information contained in the table (for usability/accessiblity purposes) More...
 
 $selectable = false
 Whether the table provides a selection mechanism. More...
 
 $showSelectAll = true
 Show Select All buttons for selectable tables. More...
 
 $rowId = false
 
 $rowIdFormat = null
 Optionally specify a custom row ID format. More...
 
 $groupFooterColumns = array()
 
 $totalCallbacks = array()
 
 $groupAsWorksheets = false
 Format groups as separate worksheets when exporting to Excel (requires PHPExcel) More...
 
 $menu = null
 Context menu for selection-based operations. More...
 
 $commandMenuIcon = "/fakoli/images/data_view_menu.png"
 Icon to use for the command menu dropdown. More...
 
 $hideExcelIcon = false
 Suppress the automatic Excel icon if you want an external link. More...
 
 $tagRowCallbacks = array()
 Array of callbacks for adding extra attributes to each row. More...
 
 $height
 
 $scrollable = false
 
 $resizable = true
 

Detailed Description

GroupedDataListView displays a list of DataItems (or InnerJoinResults) in tabular format grouped by a specific field.

Grouped tables cannot be sortable or filterable by column or paginated. However, the groups can optionally be expandable by clicking, in either a "tree" or "accordion" style. With "tree" mode, each group can be expanded or hidden independently of the others. With "accordion" mode, only one group can be expanded at a time. With "fixed" mode, all the groups are displayed and cannot be hidden.

GroupedDataListViews can also be rendered directly into binary Microsoft Excel format via the writeExcelFile() method.

Author
andy

Definition at line 100 of file grouped_data_view.inc.

Member Function Documentation

◆ addFacetTaggingHandler()

GroupedDataListView::addFacetTaggingHandler (   $handler)

Adds a row tagging handler.

This function will receive the data item for each row and can add custom attributes to the row tag.

Definition at line 166 of file grouped_data_view.inc.

167  {
168  $this->tagRowCallbacks[] = $handler;
169  }

◆ autoGroup()

GroupedDataListView::autoGroup ( )

Definition at line 206 of file grouped_data_view.inc.

207  {
208  $categories = array_keys($this->items);
209  foreach($categories as $category)
210  {
211  $this->group($category, $category);
212  }
213  }
group($title, $key, $expanded=false, $fixed=false)
Adds a group to the view.

◆ autoPopulate()

GroupedDataListView::autoPopulate (   $item)

Automatically build the table columns from the given DataItem.

Not recommended except for quick and dirty pages. This method is called automatically if no columns have been defined before drawing the view.

Parameters
$itemthe item to use as a template for the columns.

Definition at line 403 of file grouped_data_view.inc.

404  {
405  if (count($this->columns) > 0) return;
406 
407  $fields = $item->getFieldArray();
408  foreach($fields as $field)
409  {
410  if ($item->primary_key == $field) continue;
411 
412  $this->column($item->prettifyFieldName($field), "{".$field."}", $true);
413  }
414  }
column($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView.

◆ column()

GroupedDataListView::column (   $title,
  $format,
  $sortable = false,
  $style = null,
  $typeHint = null,
  $onExport = null,
  $sortFormat = null 
)

Adds a column definition to the DataListView.

Parameters
$titlethe title of the column
$formatthe formatter for the column, either as a formatting string or callback function. (For details on format template specifications, see comments above class DataItem function format.)
$sortablewhether this column is sortable
$styleany inline styles specific to this column
$typeHinthint for cell type to use when exporting to Excel
$onExportoptional callback function to format value for Excel
string$sortFormatOptional explicit format to use as the basis for sorting
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 250 of file grouped_data_view.inc.

251  {
252  $this->columns[] = new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
253  return $this;
254  }
Represents a column in a DataListView output table.
Definition: data_column.inc:39

◆ commandMenu()

GroupedDataListView::commandMenu ( )

Adds a ContextMenu to the table that can contain a list of operations that can be performed on subselections of the table's contents.

Returns
ContextMenu

Definition at line 421 of file grouped_data_view.inc.

422  {
423  $this->menu = new ContextMenu($this->id . "_menu", "#{$this->id}_menu_button");
424  $this->menu->trigger = "click";
425  $this->menu->position = "element";
426 
427  return $this->menu;
428  }
$menu
Context menu for selection-based operations.

◆ drawSubFooterColumns()

GroupedDataListView::drawSubFooterColumns ( )

Definition at line 728 of file grouped_data_view.inc.

729  {
730  if (count($this->groupFooterColumns) == 0)
731  return;
732 ?>
733  <tr>
734 <?
735  foreach($this->groupFooterColumns as $column)
736  {
737  $attrs = $this->getFooterColumnFormatting($column);
738 ?>
739  <td<?echo $attrs?>><?echo $column->format()?></td>
740 <?
741  // reset to 0 before start of next group
742  $column->total = 0;
743  }
744 ?>
745  </tr>
746 <?
747  }

◆ drawView()

GroupedDataListView::drawView ( )

Writes the HTML for the data table to the output buffer.

Definition at line 485 of file grouped_data_view.inc.

486  {
487  if (count($this->items) > 0)
488  {
489  if (count($this->groups) == 0)
490  {
491  $this->autoGroup();
492  }
493 
494  $this->autoPopulate($this->items[0]); // Autopopulate the column list from the first object, if not specified
495  $attrs = "";
496  if ($this->id)
497  {
498  $attrs .= " id='{$this->id}'";
499  }
500 
501  if ($this->cssClass)
502  {
503  $attrs .= " class='{$this->cssClass}";
504  if ($this->sortable) $attrs .=" sortable";
505  if ($this->scrollable) $attrs.= " scroll";
506  $attrs .= "'";
507  }
508 
509  if ($this->cssStyle)
510  {
511  $attrs .= " style='{$this->cssStyle}'";
512  }
513 
514  if ($this->summary)
515  {
516  $attrs .= " summary='".htmlSafe($this->summary)."'";
517  }
518 
519  $this->columnCount = count($this->columns);
520 
521  if ($this->scrollable)
522  {
523  $tbodyAttrs = " style='height: ".($this->height - 24)."px'";
524  echo "<div class='scrollContainer' style='height: {$this->height}px'>";
525  }
526 
527 ?>
528  <table<?echo $attrs?>>
529  <thead>
530  <tr>
531 <?
532  $first = true;
533 
534  foreach($this->columns as $column)
535  {
536  if ($column->exportOnly) continue;
537 
538  $attrs = "";
539  $cssClass = "nosort";
540  if ($column->style)
541  {
542  if (preg_match("/^[\\w_]*$/", $column->style))
543  {
544  $cssClass = $column->style;
545  }
546  else
547  {
548  $attrs .= " style='{$column->style}'";
549  }
550  }
551 
552  if ($cssClass)
553  {
554  $attrs .= " class='$cssClass'";
555  }
556 ?>
557  <th<?echo $attrs?>>
558 <?
559  if ($first)
560  {
561  if ($this->excelFile)
562  {
563  $qs = $this->getExcelLink();
564  }
565 
566  if ($this->excelFile && !$this->menu && !$this->hideExcelIcon)
567  {
568 ?>
569  <a href='<?echo $qs?>' style="float: left"><img src="/fakoli/images/msexcel_icon_small.png" alt="Excel" style="border: none; display:inline-block;vertical-align: middle"/></a>
570 <?
571  }
572  else if ($this->menu)
573  {
574  if ($this->excelFile)
575  {
576  $this->menu->command($this->id."_excel", "Save as Excel...", $qs, true, "/fakoli/images/msexcel_icon_small.png");
577  }
578 ?>
579  <img id="<?echo $this->id?>_menu_button" src="<?echo $this->commandMenuIcon?>" alt="Table Menu" style="border: none; display:inline-block;vertical-align: middle"/>
580 <?
581  }
582 
583  $first = false;
584  }
585 ?>
586 <?echo $column->title?></th>
587 <?
588  }
589 ?>
590  </tr>
591  </thead>
592  <tbody<?php echo $tbodyAttrs?>>
593 <?
594  foreach($this->groups as $group)
595  {
596  if (array_key_exists($group->key, $this->items))
597  {
598  $group->draw();
599 
600  foreach($this->items[$group->key] as $item)
601  {
602  $cl = "";
603 
604  if($this->rowId)
605  $rowId = $this->formatRowId($item);
606 
607  if ($this->onStartRow)
608  {
609  $retval = call_user_func($this->onStartRow, $item);
610  if ($retval === false) continue; // return false to indicate row should be skipped
611  if ($retval) $cl = $retval; // return a string to indicate a css class for the row
612  }
613 
614  $dataAttrs = array();
615  foreach($this->tagRowCallbacks as $cb)
616  {
617  $dataAttrs = call_user_func($cb, $item, $dataAttrs);
618  }
619 
620  $rowAttrs = "";
621  foreach($dataAttrs as $name => $value)
622  {
623  $rowAttrs .= " ".$name."='".$value."'";
624  }
625 
626  foreach($this->totalCallbacks as $cb)
627  {
628  call_user_func($cb, $item);
629  }
630 
631  if ($cl) $cl = "class='$cl' ";
632 ?>
633  <tr<?echo $rowAttrs?> <?php echo $cl.$rowId ?>>
634 <?
635  foreach($this->columns as $column)
636  {
637  if ($column->exportOnly) continue;
638 
639  $attrs = "";
640  if ($column->style)
641  {
642  $attrs .= " style='{$column->style}'";
643  }
644 ?>
645  <td<?echo $attrs?>><?echo $column->format($item)?></td>
646 <?
647  }
648 ?>
649  </tr>
650 <?
651  } // end foreach group items as items
652  $this->drawSubFooterColumns();
653  } // end if group key is in items array
654  } // end for each groups as group
655 ?>
656  </tbody>
657 <?
658  if ($this->onDrawFooter) call_user_func($this->onDrawFooter);
659 
660  if (count($this->footerColumns) > 0)
661  {
662 ?>
663  <tfoot>
664  <tr>
665 <?
666  foreach($this->footerColumns as $column)
667  {
668  $attrs = $this->getFooterColumnFormatting($column);
669  ?>
670  <td<?echo $attrs?>><?echo $column->format()?></td>
671 <?
672  }
673 ?>
674  </tr>
675  </tfoot>
676 <?
677  }
678 ?>
679  </table>
680 <?
681  if ($this->scrollable) echo "</div>\n";
682  if ($this->menu) echo $this->menu->writeMenu();
683  }
684  else
685  {
686  echo "<p><em>{$this->emptyMessage}</em></p>";
687  }
688  }
scrollable($height=300, $resizable=true)
autoPopulate($item)
Automatically build the table columns from the given DataItem.
$cssClass
Optional CSS class to apply to the table.
getExcelLink()
Get the Excel Link.

◆ drawViewToString()

GroupedDataListView::drawViewToString ( )

Render the table view and return the generated HTML as a string.

Returns
string the generated HTML for the table

Definition at line 694 of file grouped_data_view.inc.

695  {
696  ob_start();
697  $this->drawView();
698  $out = ob_get_contents();
699  ob_end_clean();
700  return $out;
701  }
drawView()
Writes the HTML for the data table to the output buffer.

◆ exportColumn()

GroupedDataListView::exportColumn (   $title,
  $format,
  $sortable = false,
  $style = null,
  $typeHint = null,
  $onExport = null,
  $sortFormat = null 
)

Adds a column definition to the DataListView that is only output when exporting the table to Excel.

Use this method for extended detail columns when space is constrained on the page but more details might be useful in an exported spreadsheet

Parameters
$titlethe title of the column
$formatthe formatter for the column, either as a formatting string or callback function. (For details on format template specifications, see comments above class DataItem function format.)
$sortablewhether this column is sortable
$styleany inline styles specific to this column
$typeHinthint for cell type to use when exporting to Excel
$onExportoptional callback function to format value for Excel
string$sortFormatOptional explicit format to use as the basis for sorting
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 270 of file grouped_data_view.inc.

271  {
272  $column = new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
273  $column->exportOnly = true;
274  $this->columns[] = $column;
275  return $this;
276  }

◆ footerText()

GroupedDataListView::footerText (   $text = "",
  $style = "",
  $colspan = 1 
)

Adds a text column to the table footer.

Parameters
$textstring the text to display
$stylestring any CSS classes or inline styles to apply
$colspanint the colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 323 of file grouped_data_view.inc.

324  {
325  $this->footerColumns[] = new FooterTextColumn($text, $style, $colspan);
326  return $this;
327  }

◆ footerTotal()

GroupedDataListView::footerTotal (   $field,
  $style = "text-align: right",
  $colspan = 1 
)

Sums the total for a column.

Parameters
$fieldstring the field to total in the format "{field}"
$stylestring any CSS classes or inline styles to apply
$colspanint the colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 349 of file grouped_data_view.inc.

349  : right", $colspan = 1)
350  {
351  $column = new FooterTotalColumn($field, $template = "", $style, $colspan);
352  $this->footerColumns[] = $column;
353  $this->totalCallbacks[] = array($column, onStartRow);
354 
355  return $this;
356  }

◆ footerValue()

GroupedDataListView::footerValue (   $callback,
  $style = "",
  $colspan = 1 
)

Adds a value column to the table footer.

Parameters
$callbackcallable Callback function or object method used to calculate the value for this column.
$stylestring any CSS classes or inline styles to apply
$colspanint the colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 336 of file grouped_data_view.inc.

337  {
338  $this->footerColumns[] = new FooterValueColumn($callback, $style, $colspan);
339  return $this;
340  }

◆ format()

GroupedDataListView::format (   $group,
  $template 
)

Outputs the text for the groupedBy title bar using the given group dataitem object.

This function should not be invoked directly, but is invoked as part of the GroupedDataListView's rendering operations.

Parameters
$groupthe dataitem object for the title bar being rendered
Returns
title for the titel bar.

Definition at line 223 of file grouped_data_view.inc.

224  {
225  if(!is_callable($template))
226  return $group->format($template);
227  else
228  return call_user_func($template, $group);
229  }

◆ formatRowId()

GroupedDataListView::formatRowId (   $item)

Definition at line 305 of file grouped_data_view.inc.

306  {
307  if ($this->rowIdFormat)
308  {
309  return $item->format($this->rowIdFormat);
310  }
311 
312  $pk = $item->getPrimaryKey();
313  return "id='{$pk}_" . $item->$pk . "'";
314  }

◆ getExcelLink()

GroupedDataListView::getExcelLink ( )

Get the Excel Link.

Definition at line 433 of file grouped_data_view.inc.

434  {
435  $qs = appendToQueryString(getFullQueryString(), "__excel={$this->id}");
436  return baseURI().$qs;
437  }
baseURI($uri=null)
Returns the base URI for the current script, with the query string removed.
Definition: functions.inc:1582
getFullQueryString($includePOST=true)
Generates a query string containing the values passed to this page.
Definition: functions.inc:1634
appendToQueryString($qs, $params)
Appends the specified parameters to the supplied query string.
Definition: functions.inc:1594

◆ getFooterColumnFormatting()

GroupedDataListView::getFooterColumnFormatting (   $column)

Definition at line 704 of file grouped_data_view.inc.

705  {
706  $attrs = "";
707  $cssClass = "";
708  if ($column->style)
709  {
710  if (preg_match("/^[\\w_]*$/", $column->style))
711  {
712  $attrs .= " class='{$column->style}'";
713  }
714  else
715  {
716  $attrs .= " style='{$column->style}'";
717  }
718  }
719 
720  if ($column->colspan != 1)
721  {
722  $attrs .= " colspan='{$column->colspan}'";
723  }
724 
725  return $attrs;
726  }

◆ getID()

GroupedDataListView::getID ( )

Definition at line 157 of file grouped_data_view.inc.

158  {
159  return $this->id;
160  }
$id
ID of the table in the output script.

◆ group()

GroupedDataListView::group (   $title,
  $key,
  $expanded = false,
  $fixed = false 
)

Adds a group to the view.

Parameters
unknown_type$titlethe title text for the group.
unknown_type$keythe key value for the group.
unknown_type$expandedtrue for expanded by default, false for collapsed by default
Returns
GroupDataListView returns the current instance, allowing function call chaining for the group definitions.

Definition at line 178 of file grouped_data_view.inc.

179  {
180  $this->groups[] = new DataGroup($this, $title, $key, $expanded);
181  return $this;
182  }
Represents a grouped collection of data within a table.

◆ groupBy()

GroupedDataListView::groupBy (   $groups,
  $format = null,
  $field = "",
  $expandedFn = null,
  $fixedFn = null 
)

Add groups based on the supplied list of DataItems.

Parameters
$groupsarray list of DataItems
$formatstring format template for the group titles
$fieldstring the field to use for the key (defaults to the primary key of the group items if not specified)
$expandedFncallable optional function that can be used to determine if each group should be expanded or collapsed
$fixedFncallable optional function that can be used to determine if each group should be fixed

Definition at line 192 of file grouped_data_view.inc.

193  {
194  if (count($groups) == 0) return;
195  if (!$field) $field = $groups[0]->primary_key;
196 
197  foreach($groups as $group)
198  {
199  $expanded = ($expandedFn) ? $expandedFn($group) : false;
200  $fixed = ($fixedFn) ? $fixedFn($group) : false;
201 
202  $this->group($this->format($group, $format), $group->$field, $expanded, $fixed);
203  }
204  }
$groups
The group definitions.
format($group, $template)
Outputs the text for the groupedBy title bar using the given group dataitem object.

◆ GroupedDataListView()

GroupedDataListView::GroupedDataListView (   $items,
  $id,
  $cssClass = "list",
  $groupClass = "subheading" 
)

Creates a new GroupedDataListView object.

Parameters
array$itemsthe array of DataItems or InnerJoinResults to be displayed
string$idthe client-side ID for this table
string$cssClassOptional CSS class to apply to the table
string$sortableSpecifies whether to enable client-side sorting for this table
integer$pageSizeSpecifies the number of items per page - set to zero for unpaginated
boolean$filterSpecifies whether to enable client-side filtering for this table.

Definition at line 143 of file grouped_data_view.inc.

144  {
145  $this->items = $items;
146  $this->id = $id;
147  $this->cssClass = $cssClass;
148  $this->groupClass = $groupClass;
149  $this->cssStyle = null;
150  $this->emptyMessage = "No matching items.";
151  $this->onStartRow = null;
152  $this->onDrawFooter = false;
153  $this->mode = "fixed";
154  $this->excelFile = null;
155  }
$items
The items to be displayed.
$groupClass
The CSS class to apply to the group subheading rows.

◆ groupFooterText()

GroupedDataListView::groupFooterText (   $text = "",
  $style = "",
  $colspan = 1 
)

Adds a text column to the table footer.

Parameters
$textthe text to display
$styleany CSS classes or inline styles to apply
$colspanthe colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 365 of file grouped_data_view.inc.

366  {
367  $this->groupFooterColumns[] = new FooterTextColumn($text, $style, $colspan);
368  return $this;
369  }

◆ groupFooterTotal()

GroupedDataListView::groupFooterTotal (   $field,
  $style = "text-align: right",
  $colspan = 1 
)

Definition at line 372 of file grouped_data_view.inc.

372  : right", $colspan = 1)
373  {
374  $column = new FooterTotalColumn($field, $template = "", $style, $colspan);
375  $this->groupFooterColumns[] = $column;
376  $this->totalCallbacks[] = array($column, onStartRow);
377 
378  return $this;
379  }

◆ scrollable()

GroupedDataListView::scrollable (   $height = 300,
  $resizable = true 
)

Definition at line 231 of file grouped_data_view.inc.

232  {
233  $this->scrollable = true;
234  $this->height = $height;
235  $this->resizable = $resizable;
236  }

◆ selector()

GroupedDataListView::selector (   $format = "")

Adds a selector column to the DataListView.

If no format is specified then selection is handled via a checklist box for the list objects' primary keys.

Parameters
$format(optional) format to use for the selector

Definition at line 283 of file grouped_data_view.inc.

284  {
285  if(count($this->items))
286  {
287  foreach($this->items as $groupKey => $items)
288  {
289  $pk = $items[0]->getPrimaryKey();
290  break;
291  }
292  }
293 
294  if (!$format && count($items))
295  $format = "<input type='checkbox' class='checkbox' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
296 
297  if($format == "radio" && count($items))
298  $format = "<input type='radio' class='radio' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
299 
300  $this->column("&nbsp;", $format, false, "text-align: center");
301  $this->selectable = true;
302  return $this;
303  }

◆ setID()

GroupedDataListView::setID (   $id = null)

Sets the client-side ID for this DataListView.

Parameters
$idthe ID to use. Passing in null will generate a random ID string.

Definition at line 386 of file grouped_data_view.inc.

387  {
388  if ($this->id) return;
389  if ($id)
390  {
391  $this->id = $id;
392  return;
393  }
394 
395  $this->id = makeRandomString(6);
396  }
makeRandomString($len)
Creates a randomized string of characters.
Definition: functions.inc:1735

◆ writeExcelFile()

GroupedDataListView::writeExcelFile (   $file)

Writes the data table out as an Excel File.

The file is output with an 'attachment' disposition, which will prompt a save dialog in the client browser.

Parameters
$filethe name of the file to be output.
Returns
Does not return - exits script on completion to prevent corruption of the output file.

Definition at line 756 of file grouped_data_view.inc.

757  {
758  $x = ExcelFileWriter::create($file);
759 
760  if (count($this->groups) == 0)
761  {
762  $this->autoGroup();
763  }
764 
765  $writeColumnHeadings = true;
766  $firstGroup = true;
767 
768  foreach($this->groups as $group)
769  {
770  if ($this->groupAsWorksheets)
771  {
772  //AJG: Excel can't cope with slashes in worksheet names
773  $title = str_replace("/", " ", $group->title);
774 
775  if ($firstGroup)
776  {
777  $x->setWorksheetTitle($title);
778  }
779  else
780  {
781  $x->addWorksheet($title);
782  }
783 
784  $writeColumnHeadings = true;
785  $firstGroup = false;
786  }
787 
788  $c = 0;
789 
790  if ($writeColumnHeadings)
791  {
792  foreach($this->columns as $column)
793  {
794  $x->writeHeading(0, $c, $column->title);
795  ++$c;
796  }
797 
798  $r = 1;
799  $writeColumnHeadings = false;
800  }
801 
802  if (array_key_exists($group->key, $this->items))
803  {
804  if (!$this->groupAsWorksheets)
805  {
806  $x->writeSubheading($r, 0, stripHTML($group->title));
807  $r++;
808  }
809 
810  foreach($this->items[$group->key] as $item)
811  {
812  $c = 0;
813  if ($this->onStartRow)
814  {
815  call_user_func($this->onStartRow, $item);
816  }
817 
818  foreach($this->columns as $column)
819  {
820 
821  if (is_callable($column->onExport))
822  {
823  $val = call_user_func($column->onExport, $item, $column);
824  }
825  else if ($column->onExport)
826  {
827  $val = $item->format($column->onExport);
828  }
829  else
830  {
831  $val = $column->format($item);
832  }
833 
834  switch($column->typeHint)
835  {
836  case String:
837 
838  $x->writeText($r, $c, stripHTMLTags(stripHTML($val)));
839  break;
840 
841  case Number:
842 
843  $x->writeNumber($r, $c, $val);
844  break;
845 
846  case Currency:
847 
848  $val = str_replace(array("$", ","), array("", ""), $val);
849  $x->writeCurrency($r, $c, $val);
850  break;
851 
852  case Percentage:
853 
854  $x->writePercentage($r, $c, $val);
855  break;
856 
857  default:
858 
859  /* JDG 5/11/10 currency export fix */
860  if (preg_match("/^[\\d\\,\\.\\$]+$/", $val))
861  {
862  $val = str_replace(array("$", ","), array("", ""), $val);
863  $x->writeNumber($r, $c, $val);
864  }
865  else
866  {
867  // No HTML required in Excel output
868  $x->writeText($r, $c, stripHTML($val));
869  }
870  }
871 
872  ++$c;
873  }
874  ++$r;
875  }
876  }
877  }
878 
879  $c = 0;
880 
881  if ($this->footerColumns)
882  {
883  foreach($this->footerColumns as $column)
884  {
885  $val = $column->format();
886  if (preg_match("/^[\\d\\.]+$/", $val))
887  {
888  $x->writeFooterNumber($r, $c, $val);
889  }
890  else
891  {
892  // No HTML required in Excel output
893  $x->writeFooter($r, $c, stripHTML($val));
894  }
895  $c += $column->colspan;
896  }
897  }
898 
899  $x->send();
900  die();
901  }
static create($filename)
Definition: excel.inc:48
stripHTMLTags($text)
Removes all HTML tags from the specified string.
Definition: functions.inc:1491
stripHTML($text)
Definition: functions.inc:847

◆ writeScript()

GroupedDataListView::writeScript ( )

Write the Javascript to implement the table output.

Returns
string containing the required Javascript.

Definition at line 443 of file grouped_data_view.inc.

444  {
445  $this->setID(); // Set to a default ID if none was specified.
446 
447  if ($this->excelFile && $_REQUEST["__excel"] == $this->id)
448  {
449  $this->writeExcelFile($this->excelFile);
450  }
451 
452  if (count($this->items) == 0) return;
453 
454  $script = "<script type='text/javascript' src='/fakoli/js/grouping_table.js'></script>\n";
455 
456  $constructor = "";
457 
458  $constructor = "\n\t\tvar {$this->id} = new GroupingTable('{$this->id}', {mode: '{$this->mode}'});";
459 
460  if ($this->selectable)
461  {
462  $constructor .= "\n\t\tdocument.id('{$this->id}').getSelectedValues = function() { var values = []; this.getElements(\"input[type='checkbox']\").each(function(e) { if (e.checked) values.push(e.value); }); return values; };";
463  }
464 
465  if ($this->scrollable)
466  {
467  $constructor .= "\n\t\tnew ScrollingTable('{$this->id}');";
468  }
469 
470  if ($constructor)
471  {
472  $script .= "\t<script type='text/javascript'>\n\twindow.addEvent('domready', function()\n\t{";
473  $script .= $constructor;
474  $script .= "\n\t});\n\t</script>\n";
475  }
476 
477  if ($this->menu) $script .= $this->menu->writeScript();
478 
479  return $script;
480  }
setID($id=null)
Sets the client-side ID for this DataListView.
writeExcelFile($file)
Writes the data table out as an Excel File.

Member Data Documentation

◆ $columns

GroupedDataListView::$columns

The column definitions for the table.

Definition at line 102 of file grouped_data_view.inc.

◆ $commandMenuIcon

GroupedDataListView::$commandMenuIcon = "/fakoli/images/data_view_menu.png"

Icon to use for the command menu dropdown.

Definition at line 124 of file grouped_data_view.inc.

◆ $cssClass

GroupedDataListView::$cssClass

Optional CSS class to apply to the table.

Definition at line 104 of file grouped_data_view.inc.

◆ $cssStyle

GroupedDataListView::$cssStyle

Optional additional inline styles to apply to the table.

Definition at line 107 of file grouped_data_view.inc.

◆ $emptyMessage

GroupedDataListView::$emptyMessage

Message to display when no items are present in the data set.

Definition at line 108 of file grouped_data_view.inc.

◆ $excelFile

GroupedDataListView::$excelFile

Name of the Excel file for automatic export to excel.

Definition at line 114 of file grouped_data_view.inc.

◆ $footerColumns

GroupedDataListView::$footerColumns

The footer column definitions for the table.

Definition at line 103 of file grouped_data_view.inc.

◆ $groupAsWorksheets

GroupedDataListView::$groupAsWorksheets = false

Format groups as separate worksheets when exporting to Excel (requires PHPExcel)

Definition at line 122 of file grouped_data_view.inc.

◆ $groupClass

GroupedDataListView::$groupClass

The CSS class to apply to the group subheading rows.

Definition at line 105 of file grouped_data_view.inc.

◆ $groupFooterColumns

GroupedDataListView::$groupFooterColumns = array()

Definition at line 120 of file grouped_data_view.inc.

◆ $groups

GroupedDataListView::$groups

The group definitions.

Definition at line 112 of file grouped_data_view.inc.

◆ $height

GroupedDataListView::$height

Definition at line 129 of file grouped_data_view.inc.

◆ $hideExcelIcon

GroupedDataListView::$hideExcelIcon = false

Suppress the automatic Excel icon if you want an external link.

Definition at line 125 of file grouped_data_view.inc.

◆ $id

GroupedDataListView::$id

ID of the table in the output script.

Definition at line 106 of file grouped_data_view.inc.

◆ $items

GroupedDataListView::$items

The items to be displayed.

Definition at line 113 of file grouped_data_view.inc.

◆ $menu

GroupedDataListView::$menu = null

Context menu for selection-based operations.

Definition at line 123 of file grouped_data_view.inc.

◆ $mode

GroupedDataListView::$mode

The display mode for the table: fixed or tree.

Definition at line 111 of file grouped_data_view.inc.

◆ $onDrawFooter

GroupedDataListView::$onDrawFooter

Callback hook that gets called after all rows have been drawn.

Definition at line 110 of file grouped_data_view.inc.

◆ $onStartRow

GroupedDataListView::$onStartRow

Callback hook that gets called at the start of each row.

Definition at line 109 of file grouped_data_view.inc.

◆ $resizable

GroupedDataListView::$resizable = true

Definition at line 131 of file grouped_data_view.inc.

◆ $rowId

GroupedDataListView::$rowId = false

Definition at line 118 of file grouped_data_view.inc.

◆ $rowIdFormat

GroupedDataListView::$rowIdFormat = null

Optionally specify a custom row ID format.

Definition at line 119 of file grouped_data_view.inc.

◆ $scrollable

GroupedDataListView::$scrollable = false

Definition at line 130 of file grouped_data_view.inc.

◆ $selectable

GroupedDataListView::$selectable = false

Whether the table provides a selection mechanism.

Definition at line 116 of file grouped_data_view.inc.

◆ $showSelectAll

GroupedDataListView::$showSelectAll = true

Show Select All buttons for selectable tables.

Definition at line 117 of file grouped_data_view.inc.

◆ $summary

GroupedDataListView::$summary

Human-readable summary of the information contained in the table (for usability/accessiblity purposes)

Definition at line 115 of file grouped_data_view.inc.

◆ $tagRowCallbacks

GroupedDataListView::$tagRowCallbacks = array()

Array of callbacks for adding extra attributes to each row.

Definition at line 126 of file grouped_data_view.inc.

◆ $totalCallbacks

GroupedDataListView::$totalCallbacks = array()

Definition at line 121 of file grouped_data_view.inc.


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