Overview

Packages

  • Hermes
  • Horde
    • Data
  • Kronolith
  • None

Classes

  • Hermes_Data_Hermescsv
  • Hermes_Data_Hermestsv
  • Hermes_Data_Hermesxls
  • Hermes_Data_Iif
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * The Horde_Data_iif class implements the Horde_Data:: framework for
 4:  * QuickBooks .iif files.
 5:  *
 6:  * Here's a sample header and row from a .iif file (it's
 7:  * tab-delimited):
 8:  *
 9:  * !TIMEACT        DATE        JOB        EMP        ITEM        DURATION        NOTE        BILLINGSTATUS        PITEM
10:  * TIMEACT        07/30/02        A Company:Their Projec        Sylvester Employee        Programming        10:00                1        Not Applicable
11:  *
12:  * $Horde: hermes/lib/Data/iif.php,v 1.21 2009/01/06 17:50:09 jan Exp $
13:  *
14:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
15:  *
16:  * See the enclosed file LICENSE for license information (BSD). If you
17:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
18:  *
19:  * @author Chuck Hagenbuch <chuck@horde.org>
20:  * @package Horde_Data
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: 
API documentation generated by ApiGen