1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class Hermes_Data_Iif extends Horde_Data_Base
23: {
24: protected $_extension = 'iif';
25: protected $_contentType = 'text/plain';
26: protected $_rawData;
27: protected $_iifData;
28: protected $_mapped = false;
29:
30: public function exportData($data, $method = 'REQUEST')
31: {
32: $this->_rawData = $data;
33: $newline = $this->getNewline();
34:
35: $this->_map();
36:
37: $data = "!TIMEACT\tDATE\tJOB\tEMP\tITEM\tDURATION\tNOTE\tBILLINGSTATUS\tPITEM$newline";
38: foreach ($this->_iifData as $row) {
39: $data .= implode("\t", $row) . $newline;
40: }
41:
42: return $data;
43: }
44:
45: public function exportFile($filename, $data)
46: {
47: if (!isset($this->_browser)) {
48: throw new Horde_Data_Exception('Missing browser parameter.');
49: }
50: $export = $this->exportData($data);
51: $this->_browser->downloadHeaders($filename, $this->_contentType, false, strlen($export));
52: echo $export;
53: }
54:
55: protected function _map()
56: {
57: if ($this->_mapped) {
58: return;
59: }
60:
61: $this->_mapped = true;
62:
63: foreach ($this->_rawData as &$row) {
64: $row = $row->toArray();
65: $row['description'] = str_replace(array("\r", "\n"), array('', ' '), $row['description']);
66: $row['note'] = str_replace(array("\r", "\n"), array('', ' '), $row['note']);
67: $this->_iifData[] = array(
68: '_label' => 'TIMEACT',
69: 'DATE' => date('m/d/y', $row['date']),
70: 'JOB' => $row['client'],
71: 'EMP' => $row['employee'],
72: 'ITEM' => $row['item'],
73: 'DURATION' => date('H:i', mktime(0, $row['hours'] * 60)),
74: 'NOTE' => $row['description'] . (!empty($row['note']) ? _("; Notes: ") . $row['note'] : ''),
75: 'BILLINGSTATUS' => $row['billable'] == 2 ? '' : $row['billable'],
76: 'PITEM' => 'Not Applicable'
77: );
78: }
79: }
80:
81: }
82: