| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:45:19 2008 ] | [ Bumblebee 1.0.4 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Construct an array for exporting the data 4 * 5 * @author Stuart Prescott 6 * @copyright Copyright Stuart Prescott 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 8 * @version $Id: arrayexport.php,v 1.8 2006-01-06 10:07:21 stuart Exp $ 9 * @package Bumblebee 10 * @subpackage Export 11 */ 12 13 /** constants for defining export formatting and codes */ 14 require_once 'inc/exportcodes.php'; 15 16 /** 17 * Construct an array for exporting the data 18 * 19 * Create a monolithic array with all the data for export. The array is an 20 * intermediary form for creating PDF and HTML tables of data. 21 * 22 * @package Bumblebee 23 * @subpackage Export 24 */ 25 class ArrayExport { 26 /** @var DBList raw data list */ 27 var $dblist; 28 /** @var string field name on which the report should be broken into sections */ 29 var $breakfield; 30 /** @var unknown? unused? */ 31 var $exporter; 32 /** @var array data array of exported data */ 33 var $export; 34 /** @var string header for the report */ 35 var $header; 36 /** @var string report Author (report metadata) */ 37 var $author = 'BumbleBee'; 38 /** @var string report Creator (report metadata) */ 39 var $creator = 'BumbleBee Instrument Management System : bumblebeeman.sf.net'; 40 /** @var string report Subject (report metadata) */ 41 var $subject = 'Instrument and consumable usage report'; 42 /** @var string report Keywords (report metadata) */ 43 var $keywords = 'instruments, consumables, usage, report, billing, invoicing'; 44 /** @var array list of subtotals for each section of the report for fields that are totalled */ 45 var $_totals; 46 /** @var boolean calculate column totals */ 47 var $_doingTotalCalcs = false; 48 49 /** 50 * Create a new array export object to be used by both HTML and PDF export 51 * 52 * @param DBList &$dblist data to be exported (passed by reference for efficiency only) 53 * @param string $breakfield name of field to use to break report into sections 54 */ 55 function ArrayExport(&$dblist, $breakfield) { 56 $this->dblist =& $dblist; 57 $this->breakfield = $breakfield; 58 } 59 60 /** 61 * Parsed the exported data and create the marked-up array of data 62 */ 63 function makeExportArray() { 64 $ea = array(); //export array 65 $ea[] = array('type' => EXPORT_REPORT_START, 66 'data' => ''); 67 $ea[] = array('type' => EXPORT_REPORT_HEADER, 68 'data' => $this->header); 69 $entry = 0; 70 $numcols = count($this->dblist->formatdata[0]); 71 $breakfield = $this->breakfield; 72 $breakReport = (!empty($breakfield) && isset($this->dblist->data[$entry][$breakfield])); 73 //echo $breakReport ? 'Breaking' : 'Not breaking'; 74 while ($entry < count($this->dblist->formatdata)) { 75 //$this->log('Row: '.$entry); 76 $this->_resetTotals(); 77 $ea[] = array('type' => EXPORT_REPORT_SECTION_HEADER, 78 'data' => $this->_sectionHeader($this->dblist->data[$entry]), 79 'metadata' => $this->_getColWidths($numcols, $entry)); 80 if ($breakReport) { 81 $initial = $this->dblist->data[$entry][$breakfield]; 82 } 83 $ea[] = array('type' => EXPORT_REPORT_TABLE_START, 84 'data' => ''); 85 $ea[] = array('type' => EXPORT_REPORT_TABLE_HEADER, 86 'data' => $this->dblist->outputHeader()); 87 while ($entry < count($this->dblist->formatdata) 88 && (! $breakReport 89 || $initial == $this->dblist->data[$entry][$breakfield]) ) { 90 $ea[] = array('type' => EXPORT_REPORT_TABLE_ROW, 91 'data' => $this->_formatRowData($this->dblist->formatdata[$entry])); 92 $this->_incrementTotals($this->dblist->formatdata[$entry]); 93 $entry++; 94 } 95 if ($this->_doingTotalCalcs) { 96 $ea[] = array('type' => EXPORT_REPORT_TABLE_TOTAL, 97 'data' => $this->_getTotals()); 98 } 99 $ea[] = array('type' => EXPORT_REPORT_TABLE_END, 100 'data' => ''); 101 } 102 $ea[] = array('type' => EXPORT_REPORT_END, 103 'data' => ''); 104 $ea['metadata'] = $this->_getMetaData(); 105 //preDump($ea); 106 $this->export =& $ea; 107 } 108 109 /** 110 * create the section header 111 * 112 * @param array current data row 113 * @return string header string 114 */ 115 function _sectionHeader($row) { 116 $s = ''; 117 if (empty($this->breakfield)) { 118 //$s .= $this->header; 119 } else { 120 $s .= $row[$this->breakfield]; 121 } 122 return $s; 123 } 124 125 /** 126 * get the column widths for the columns (if defined) 127 * 128 * @param integer number of columns 129 * @param array a row from the table 130 * @return array number of columns and a picture of the column widths spec 131 */ 132 function _getColWidths($numcols, $entry) { 133 $columns = array(); 134 foreach ($this->dblist->formatdata[$entry] as $f) { 135 $columns[] = $f['width']; 136 } 137 return array( 138 'numcols' => $numcols, 139 'colwidths' => $columns 140 ); 141 } 142 143 /** 144 * create an array of metadata to include in the output 145 * 146 * @return array key => value metadata 147 */ 148 function _getMetaData() { 149 return array( 150 'author' => $this->author, 151 'creator' => $this->creator, 152 'title' => $this->header, 153 'keywords' => $this->keywords, 154 'subject' => $this->subject 155 ); 156 } 157 158 /** 159 * reset the column subtotals to 0 160 */ 161 function _resetTotals() { 162 foreach ($this->dblist->formatdata[0] as $key => $val) { 163 $this->_totals[$key] = $val; 164 if ($val['format'] & EXPORT_CALC_TOTAL) { 165 $this->_totals[$key]['value'] = 0; 166 $this->_doingTotalCalcs = true; 167 } else { 168 $this->_totals[$key]['value'] = ''; 169 } 170 } 171 } 172 173 /** 174 * increment each column subtotal 175 */ 176 function _incrementTotals($row) { 177 if (! $this->_doingTotalCalcs) return; 178 foreach ($row as $key => $val) { 179 if ($val['format'] & EXPORT_CALC_TOTAL) { 180 $this->_totals[$key]['value'] += $val['value']; 181 } 182 } 183 } 184 185 /** 186 * get the column subtotals 187 */ 188 function _getTotals() { 189 $total = $this->_totals; 190 foreach ($total as $key => $val) { 191 if ($val['format'] & EXPORT_CALC_TOTAL) { 192 $total[$key]['value'] = $this->_formatVal($val['value'],$val['format']); 193 } 194 } 195 return $total; 196 } 197 198 /** 199 * format a row of data using the formmatting information defined 200 * 201 * @param array &$row data row 202 * @return array formatted data row 203 */ 204 function _formatRowData(&$row) { 205 $newrow = array(); 206 foreach ($row as $key => $val) { 207 $newrow[$key] = $val; 208 $newrow[$key]['value'] = $this->_formatVal($val['value'], $val['format']); 209 } 210 return $newrow; 211 } 212 213 /** 214 * format a data value according to the defined rules for decimal places and currency 215 * 216 * @param string $val value to be formatted 217 * @return string formatted value 218 */ 219 function _formatVal($val, $format) { 220 global $CONFIG; 221 switch ($format & EXPORT_HTML_NUMBER_MASK) { 222 case EXPORT_HTML_MONEY: 223 $val = sprintf($CONFIG['export']['moneyFormat'], $val); 224 break; 225 case EXPORT_HTML_DECIMAL_1: 226 $val = sprintf('%.1f', $val); 227 break; 228 case EXPORT_HTML_DECIMAL_2: 229 $val = sprintf('%.2f', $val); 230 break; 231 default: 232 //echo ($format& EXPORT_HTML_NUMBER_MASK).'<br/>'; 233 } 234 return $val; 235 } 236 237 /** 238 * join another ArrayExport object into this one. 239 * 240 * @param ArrayExport &$ea ArrayExport object to be appended to this one 241 */ 242 function appendEA(&$ea) { 243 $this->export = array_merge($this->export, $ea->export); 244 } 245 246 247 } // class ArrayExport 248 249 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |