Framework  3.9
GroupedList Class Reference
+ Inheritance diagram for GroupedList:
+ Collaboration diagram for GroupedList:

Public Member Functions

 GroupedList ($items, $id="grouped_list", $format, $cssClass="article_list", $groupClass="subheading")
 
 group ($title, $key, $expanded=false, $fixed=false)
 Adds a group to the view. More...
 
 groupBy ($groups, $format=null, $field="")
 Add groups based on the supplied list of DataItems. More...
 
 getID ()
 
 addFacetTaggingHandler ($handler)
 Adds a row tagging handler. More...
 
 format ($group, $template)
 Outputs the text for the groupedBy title bar using the given group dataitem object. More...
 
 writeScript ()
 
 drawList ()
 
 drawListToString ()
 Helpful utility function - generates the list HTML in an output buffer and returns the string representation. More...
 

Public Attributes

 $items
 
 $id
 
 $format
 
 $mode
 The display mode for the table: fixed, tree, or accordian. More...
 
 $groups
 The group definitions. More...
 
 $cssClass = null
 
 $styles = null
 
 $groupStyles = ""
 Styles for the group headings. More...
 
 $groupClass = "subheading"
 Class for the ul that links the li list. More...
 
 $groupedListClass
 The css class for the entire grouped list div. More...
 
 $group_id
 
 $tagRowCallbacks
 Array of callbacks for adding extra attributes to each row. More...
 

Detailed Description

Definition at line 83 of file grouped_list.inc.

Member Function Documentation

◆ addFacetTaggingHandler()

GroupedList::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.

Implements FacetFilterable.

Definition at line 151 of file grouped_list.inc.

152  {
153  $this->tagRowCallbacks[] = $handler;
154  }

◆ drawList()

GroupedList::drawList ( )

Definition at line 191 of file grouped_list.inc.

192  {
193  $attrs = "";
194  if ($this->cssClass) $attrs .= " class='{$this->cssClass}'";
195  if ($this->styles) $attrs .= " style='{$this->styles}'";
196 
197  echo "<div id='{$this->id}' class='{$this->groupedListClass}'>\n";
198 
199  if(count($this->groups) == 0)
200  {
201  foreach(array_keys($this->items) as $group)
202  {
203  $this->group($group, $group);
204  }
205  }
206 
207  if(count($this->groups) == 0) return;
208 
209  foreach($this->groups as $group)
210  {
211  if (array_key_exists($group->key, $this->items))
212  {
213  echo "<div id='content_{$group->key}'>\n";
214 
215  $group->draw();
216 
217  $itemsInGroup = $this->items[$group->key];
218 
219  echo "<ul id=\"subheading[{$group->key}]\" class=\"{$this->groupClass}\" $attrs>\n";
220 
221  foreach($itemsInGroup as $item)
222  {
223  $css = "";
224 
225  if ($this->onStartRow)
226  {
227  $css = call_user_func($this->onStartRow, $item);
228  if ($css === false) continue; // Skip this record if false returned
229  }
230 
231  if ($css) $css = " class='$css'";
232 
233  $dataAttrs = array();
234  foreach($this->tagRowCallbacks as $cb)
235  {
236  $dataAttrs = call_user_func($cb, $item, $dataAttrs);
237  }
238 
239  $rowAttrs = "";
240  foreach($dataAttrs as $name => $value)
241  {
242  $rowAttrs .= " ".$name."='".$value."'";
243  }
244 
245  echo "<li {$css}{$rowAttrs}>";
246 
247  if (is_callable($this->format))
248  {
249  echo call_user_func($this->format, $item);
250  }
251  else echo $item->format($this->format);
252  echo "</li>\n";
253  }
254 
255  echo "</ul>\n";
256  echo "</div>\n";
257  }
258  } // end for each groups as group
259 
260  echo "</div>\n";
261  }
group($title, $key, $expanded=false, $fixed=false)
Adds a group to the view.
format($group, $template)
Outputs the text for the groupedBy title bar using the given group dataitem object.

◆ drawListToString()

GroupedList::drawListToString ( )

Helpful utility function - generates the list HTML in an output buffer and returns the string representation.

This is useful for resolving issues in rendering order that can occur when working with facets.

Returns
string the HTML output for the list

Definition at line 269 of file grouped_list.inc.

270  {
271  ob_start();
272  $this->drawList();
273  $out = ob_get_contents();
274  ob_end_clean();
275  return $out;
276  }

◆ format()

GroupedList::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 164 of file grouped_list.inc.

165  {
166  if(!is_callable($template))
167  return $group->format($template);
168  else
169  return call_user_func($template, $group);
170  }

◆ getID()

GroupedList::getID ( )

Implements FacetFilterable.

Definition at line 142 of file grouped_list.inc.

143  {
144  return $this->id;
145  }

◆ group()

GroupedList::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 117 of file grouped_list.inc.

118  {
119  $this->groups[] = new GroupedListGroup($this, $title, $key, $expanded);
120  return $this;
121  }
Represents a grouped collection of data within a table.

◆ groupBy()

GroupedList::groupBy (   $groups,
  $format = null,
  $field = "" 
)

Add groups based on the supplied list of DataItems.

Parameters
$groupslist of DataItems
$formatformat template for the group titles
$fieldthe field to use for the key (defaults to the primary key of the group items if not specified)

Definition at line 129 of file grouped_list.inc.

130  {
131  if (count($groups) == 0) return;
132  if (!$field) $field = $groups[0]->getPrimaryKey();
133 
134  $this->group_id = $field;
135 
136  foreach($groups as $group)
137  {
138  $this->group($this->format($group, $format), $group->$field);
139  }
140  }
$groups
The group definitions.

◆ GroupedList()

GroupedList::GroupedList (   $items,
  $id = "grouped_list",
  $format,
  $cssClass = "article_list",
  $groupClass = "subheading" 
)

Definition at line 98 of file grouped_list.inc.

99  {
100  $this->items = $items;
101  $this->id = $id;
102  $this->format = $format;
103  $this->cssClass = $cssClass;
104  $this->groupClass = $groupClass;
105  $this->cssStyle = null;
106  $this->mode = "accordian";
107  $this->tagRowCallbacks = array();
108  }
$groupClass
Class for the ul that links the li list.

◆ writeScript()

GroupedList::writeScript ( )

Definition at line 173 of file grouped_list.inc.

174  {
175  if(count($this->items) == 0) return;
176 
177  $script = "<script type='text/javascript' src='/fakoli/js/grouping_list.js'></script>\n";
178 
179  $constructor .= "\n\t\tvar {$this->id} = new GroupingList('{$this->id}', {mode: '{$this->mode}'});";
180 
181  if ($constructor)
182  {
183  $script .= "\t<script type='text/javascript'>\n\twindow.addEvent('domready', function()\n\t{";
184  $script .= $constructor;
185  $script .= "\n\t});\n\t</script>\n";
186  }
187 
188  return $script;
189  }

Member Data Documentation

◆ $cssClass

GroupedList::$cssClass = null

Definition at line 90 of file grouped_list.inc.

◆ $format

GroupedList::$format

Definition at line 87 of file grouped_list.inc.

◆ $group_id

GroupedList::$group_id

Definition at line 95 of file grouped_list.inc.

◆ $groupClass

GroupedList::$groupClass = "subheading"

Class for the ul that links the li list.

Definition at line 93 of file grouped_list.inc.

◆ $groupedListClass

GroupedList::$groupedListClass

The css class for the entire grouped list div.

Definition at line 94 of file grouped_list.inc.

◆ $groups

GroupedList::$groups

The group definitions.

Definition at line 89 of file grouped_list.inc.

◆ $groupStyles

GroupedList::$groupStyles = ""

Styles for the group headings.

Definition at line 92 of file grouped_list.inc.

◆ $id

GroupedList::$id

Definition at line 86 of file grouped_list.inc.

◆ $items

GroupedList::$items

Definition at line 85 of file grouped_list.inc.

◆ $mode

GroupedList::$mode

The display mode for the table: fixed, tree, or accordian.

Definition at line 88 of file grouped_list.inc.

◆ $styles

GroupedList::$styles = null

Definition at line 91 of file grouped_list.inc.

◆ $tagRowCallbacks

GroupedList::$tagRowCallbacks

Array of callbacks for adding extra attributes to each row.

Definition at line 96 of file grouped_list.inc.


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