Framework  3.9
APICSVFormatter Class Reference

Provides CSV output formatting for APIHelper. More...

+ Inheritance diagram for APICSVFormatter:
+ Collaboration diagram for APICSVFormatter:

Public Member Functions

 format ($items)
 Override this function to provide your format definition. More...
 
- Public Member Functions inherited from APIFormatter
 getClass ()
 

Additional Inherited Members

- Public Attributes inherited from APIFormatter
 $parent
 

Detailed Description

Provides CSV output formatting for APIHelper.

Author
andy

Definition at line 120 of file api_helper.inc.

Member Function Documentation

◆ format()

APICSVFormatter::format (   $items)

Override this function to provide your format definition.

The results should be sent to the output buffer, via 'echo' or equivalent.

Parameters
array$itemsthe list of DataItems to be formatted

Reimplemented from APIFormatter.

Definition at line 122 of file api_helper.inc.

123  {
124  $file = fopen('php://temp/maxmemory:'. (12*1024*1024), 'r+');
125  if (count($items))
126  {
127  $obj = $items[0];
128  $columns = array();
129  foreach($obj->getFields() as $field => $type)
130  {
131  if ($obj->filter && $obj->filter->isExcluded($field)) continue;
132  $columns[] = $field;
133  }
134 
135  fputcsv($file, $columns);
136 
137  foreach($items as $obj)
138  {
139  $values = array();
140  foreach($obj->getFields() as $field => $type)
141  {
142  if ($obj->filter && $obj->filter->isExcluded($field)) continue;
143  $values[] = $obj->get($field);
144  }
145 
146  fputcsv($file, $values);
147  }
148 
149  rewind($file);
150  $output = stream_get_contents($file);
151  fclose($file);
152 
153  header("Content-Type: text/csv");
154  echo $output;
155  }
156  }

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