37 require_once realpath(dirname(__FILE__)).
"/data_column.inc";
38 require_once realpath(dirname(__FILE__)).
"/join.inc";
39 require_once realpath(dirname(__FILE__)).
"/excel.inc";
74 $cssClass = ($this->fixed || $this->parent->mode ==
'fixed') ?
"fixed" : ($this->expanded) ?
"expanded" :
"collapsed";
75 $select = ($this->parent->selectable && $this->parent->showSelectAll) ?
"<a href='#' class='button' style='float: right' onclick='new DOMEvent(event).stop(); GroupingTable.toggleGroup(this, \"{$this->parent->groupClass}\"); return false;'>Select All</a>" :
"";
77 <tr
class=
"<?echo $this->parent->groupClass?> <?echo $cssClass?>">
78 <td colspan=
"<?echo $this->parent->columnCount?>"><?echo $select?><?echo $this->title?></td>
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;
168 $this->tagRowCallbacks[] = $handler;
178 function group($title, $key, $expanded =
false, $fixed =
false)
180 $this->groups[] =
new DataGroup($this, $title, $key, $expanded);
192 function groupBy(
$groups, $format =
null, $field =
"", $expandedFn =
null, $fixedFn =
null)
194 if (count(
$groups) == 0)
return;
195 if (!$field) $field =
$groups[0]->primary_key;
199 $expanded = ($expandedFn) ? $expandedFn($group) :
false;
200 $fixed = ($fixedFn) ? $fixedFn($group) :
false;
202 $this->
group($this->
format($group, $format), $group->$field, $expanded, $fixed);
208 $categories = array_keys($this->items);
209 foreach($categories as $category)
211 $this->
group($category, $category);
225 if(!is_callable($template))
226 return $group->format($template);
228 return call_user_func($template, $group);
250 function column($title, $format, $sortable =
false, $style =
null, $typeHint =
null, $onExport =
null, $sortFormat =
null)
252 $this->columns[] =
new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
270 function exportColumn($title, $format, $sortable =
false, $style =
null, $typeHint =
null, $onExport =
null, $sortFormat =
null)
272 $column =
new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
273 $column->exportOnly =
true;
274 $this->columns[] = $column;
285 if(count($this->items))
287 foreach($this->items as $groupKey =>
$items)
289 $pk =
$items[0]->getPrimaryKey();
294 if (!$format && count(
$items))
295 $format =
"<input type='checkbox' class='checkbox' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
297 if($format ==
"radio" && count(
$items))
298 $format =
"<input type='radio' class='radio' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
300 $this->
column(
" ", $format,
false,
"text-align: center");
301 $this->selectable =
true;
307 if ($this->rowIdFormat)
309 return $item->format($this->rowIdFormat);
312 $pk = $item->getPrimaryKey();
313 return "id='{$pk}_" . $item->$pk .
"'";
349 function footerTotal($field, $style =
"text-align: right", $colspan = 1)
352 $this->footerColumns[] = $column;
353 $this->totalCallbacks[] = array($column, onStartRow);
367 $this->groupFooterColumns[] =
new FooterTextColumn($text, $style, $colspan);
375 $this->groupFooterColumns[] = $column;
376 $this->totalCallbacks[] = array($column, onStartRow);
388 if ($this->
id)
return;
405 if (count($this->columns) > 0)
return;
407 $fields = $item->getFieldArray();
408 foreach($fields as $field)
410 if ($item->primary_key == $field)
continue;
412 $this->
column($item->prettifyFieldName($field),
"{".$field.
"}", $true);
423 $this->menu =
new ContextMenu($this->
id .
"_menu",
"#{$this->id}_menu_button");
424 $this->menu->trigger =
"click";
425 $this->menu->position =
"element";
447 if ($this->excelFile && $_REQUEST[
"__excel"] == $this->
id)
452 if (count($this->items) == 0)
return;
454 $script =
"<script type='text/javascript' src='/fakoli/js/grouping_table.js'></script>\n";
458 $constructor =
"\n\t\tvar {$this->id} = new GroupingTable('{$this->id}', {mode: '{$this->mode}'});";
460 if ($this->selectable)
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; };";
467 $constructor .=
"\n\t\tnew ScrollingTable('{$this->id}');";
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";
477 if ($this->menu) $script .= $this->menu->writeScript();
487 if (count($this->items) > 0)
489 if (count($this->groups) == 0)
498 $attrs .=
" id='{$this->id}'";
503 $attrs .=
" class='{$this->cssClass}";
504 if ($this->sortable) $attrs .=
" sortable";
511 $attrs .=
" style='{$this->cssStyle}'";
516 $attrs .=
" summary='".htmlSafe($this->summary).
"'";
519 $this->columnCount = count($this->columns);
523 $tbodyAttrs =
" style='height: ".($this->height - 24).
"px'";
524 echo
"<div class='scrollContainer' style='height: {$this->height}px'>";
528 <table<?echo $attrs?>>
534 foreach($this->columns as $column)
536 if ($column->exportOnly)
continue;
542 if (preg_match(
"/^[\\w_]*$/", $column->style))
548 $attrs .=
" style='{$column->style}'";
554 $attrs .=
" class='$cssClass'";
561 if ($this->excelFile)
566 if ($this->excelFile && !$this->menu && !$this->hideExcelIcon)
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>
572 else if ($this->menu)
574 if ($this->excelFile)
576 $this->menu->command($this->
id.
"_excel",
"Save as Excel...", $qs,
true,
"/fakoli/images/msexcel_icon_small.png");
579 <img
id=
"<?echo $this->id?>_menu_button" src=
"<?echo $this->commandMenuIcon?>" alt=
"Table Menu" style=
"border: none; display:inline-block;vertical-align: middle"/>
586 <?echo $column->title?></th>
592 <tbody<?php echo $tbodyAttrs?>>
594 foreach($this->groups as $group)
596 if (array_key_exists($group->key, $this->items))
600 foreach($this->items[$group->key] as $item)
607 if ($this->onStartRow)
609 $retval = call_user_func($this->onStartRow, $item);
610 if ($retval ===
false)
continue;
611 if ($retval) $cl = $retval;
614 $dataAttrs = array();
615 foreach($this->tagRowCallbacks as $cb)
617 $dataAttrs = call_user_func($cb, $item, $dataAttrs);
621 foreach($dataAttrs as $name => $value)
623 $rowAttrs .=
" ".$name.
"='".$value.
"'";
626 foreach($this->totalCallbacks as $cb)
628 call_user_func($cb, $item);
631 if ($cl) $cl =
"class='$cl' ";
633 <tr<?echo $rowAttrs?> <?php echo $cl.$rowId ?>>
635 foreach($this->columns as $column)
637 if ($column->exportOnly)
continue;
642 $attrs .=
" style='{$column->style}'";
645 <td<?echo $attrs?>><?echo $column->format($item)?></td>
658 if ($this->onDrawFooter) call_user_func($this->onDrawFooter);
660 if (count($this->footerColumns) > 0)
666 foreach($this->footerColumns as $column)
670 <td<?echo $attrs?>><?echo $column->format()?></td>
682 if ($this->menu) echo $this->menu->writeMenu();
686 echo
"<p><em>{$this->emptyMessage}</em></p>";
698 $out = ob_get_contents();
710 if (preg_match(
"/^[\\w_]*$/", $column->style))
712 $attrs .=
" class='{$column->style}'";
716 $attrs .=
" style='{$column->style}'";
720 if ($column->colspan != 1)
722 $attrs .=
" colspan='{$column->colspan}'";
730 if (count($this->groupFooterColumns) == 0)
735 foreach($this->groupFooterColumns as $column)
739 <td<?echo $attrs?>><?echo $column->format()?></td>
760 if (count($this->groups) == 0)
765 $writeColumnHeadings =
true;
768 foreach($this->groups as $group)
770 if ($this->groupAsWorksheets)
773 $title = str_replace(
"/",
" ", $group->title);
777 $x->setWorksheetTitle($title);
781 $x->addWorksheet($title);
784 $writeColumnHeadings =
true;
790 if ($writeColumnHeadings)
792 foreach($this->columns as $column)
794 $x->writeHeading(0, $c, $column->title);
799 $writeColumnHeadings =
false;
802 if (array_key_exists($group->key, $this->items))
804 if (!$this->groupAsWorksheets)
806 $x->writeSubheading($r, 0,
stripHTML($group->title));
810 foreach($this->items[$group->key] as $item)
813 if ($this->onStartRow)
815 call_user_func($this->onStartRow, $item);
818 foreach($this->columns as $column)
821 if (is_callable($column->onExport))
823 $val = call_user_func($column->onExport, $item, $column);
825 else if ($column->onExport)
827 $val = $item->format($column->onExport);
831 $val = $column->format($item);
834 switch($column->typeHint)
843 $x->writeNumber($r, $c, $val);
848 $val = str_replace(array(
"$",
","), array(
"",
""), $val);
849 $x->writeCurrency($r, $c, $val);
854 $x->writePercentage($r, $c, $val);
860 if (preg_match(
"/^[\\d\\,\\.\\$]+$/", $val))
862 $val = str_replace(array(
"$",
","), array(
"",
""), $val);
863 $x->writeNumber($r, $c, $val);
881 if ($this->footerColumns)
883 foreach($this->footerColumns as $column)
885 $val = $column->format();
886 if (preg_match(
"/^[\\d\\.]+$/", $val))
888 $x->writeFooterNumber($r, $c, $val);
893 $x->writeFooter($r, $c,
stripHTML($val));
895 $c += $column->colspan;
Represents a column in a DataListView output table.
Represents a grouped collection of data within a table.
$fixed
Specifies whether this group should be fixed (i.e. exempt from expand/collapse toggling).
$key
The key value for this data group.
DataGroup($parent, $title, $key, $expanded=false, $fixed=false)
Creates a new DataGroup.
$title
The text to display in the title for this data group.
draw()
Draws the data group subheading within the table.
$expanded
Boolean indicating whether this group should initially be expanded.
$parent
The parent GroupedDataListView object.
Text footer column definition.
GroupedDataListView displays a list of DataItems (or InnerJoinResults) in tabular format grouped by a...
addFacetTaggingHandler($handler)
Adds a row tagging handler.
$onStartRow
Callback hook that gets called at the start of each row.
scrollable($height=300, $resizable=true)
$cssStyle
Optional additional inline styles to apply to the table.
$items
The items to be displayed.
$footerColumns
The footer column definitions for the table.
$onDrawFooter
Callback hook that gets called after all rows have been drawn.
$rowIdFormat
Optionally specify a custom row ID format.
$showSelectAll
Show Select All buttons for selectable tables.
groupBy($groups, $format=null, $field="", $expandedFn=null, $fixedFn=null)
Add groups based on the supplied list of DataItems.
setID($id=null)
Sets the client-side ID for this DataListView.
selector($format="")
Adds a selector column to the DataListView.
$summary
Human-readable summary of the information contained in the table (for usability/accessiblity purposes...
$hideExcelIcon
Suppress the automatic Excel icon if you want an external link.
groupFooterText($text="", $style="", $colspan=1)
Adds a text column to the table footer.
$mode
The display mode for the table: fixed or tree.
$groupClass
The CSS class to apply to the group subheading rows.
writeScript()
Write the Javascript to implement the table output.
autoPopulate($item)
Automatically build the table columns from the given DataItem.
$groups
The group definitions.
$menu
Context menu for selection-based operations.
$commandMenuIcon
Icon to use for the command menu dropdown.
drawViewToString()
Render the table view and return the generated HTML as a string.
column($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView.
$cssClass
Optional CSS class to apply to the table.
drawView()
Writes the HTML for the data table to the output buffer.
$excelFile
Name of the Excel file for automatic export to excel.
$tagRowCallbacks
Array of callbacks for adding extra attributes to each row.
footerTotal($field, $style="text-align: right", $colspan=1)
Sums the total for a column.
group($title, $key, $expanded=false, $fixed=false)
Adds a group to the view.
$groupAsWorksheets
Format groups as separate worksheets when exporting to Excel (requires PHPExcel)
$columns
The column definitions for the table.
footerValue($callback, $style="", $colspan=1)
Adds a value column to the table footer.
GroupedDataListView($items, $id, $cssClass="list", $groupClass="subheading")
Creates a new GroupedDataListView object.
getExcelLink()
Get the Excel Link.
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.
format($group, $template)
Outputs the text for the groupedBy title bar using the given group dataitem object.
footerText($text="", $style="", $colspan=1)
Adds a text column to the table footer.
$selectable
Whether the table provides a selection mechanism.
getFooterColumnFormatting($column)
commandMenu()
Adds a ContextMenu to the table that can contain a list of operations that can be performed on subsel...
groupFooterTotal($field, $style="text-align: right", $colspan=1)
writeExcelFile($file)
Writes the data table out as an Excel File.
$id
ID of the table in the output script.
$emptyMessage
Message to display when no items are present in the data set.
stripHTMLTags($text)
Removes all HTML tags from the specified string.
baseURI($uri=null)
Returns the base URI for the current script, with the query string removed.
getFullQueryString($includePOST=true)
Generates a query string containing the values passed to this page.
appendToQueryString($qs, $params)
Appends the specified parameters to the supplied query string.
makeRandomString($len)
Creates a randomized string of characters.