1: <?php
2: /**
3: * The Horde_Kolab_Cli_Data_Ledger:: class deals with ledger data.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Kolab_Cli
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Cli
12: */
13:
14: /**
15: * The Horde_Kolab_Cli_Data_Ledger:: class deals with ledger data.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Kolab_Cli
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Cli
27: */
28: class Horde_Kolab_Cli_Data_Ledger
29: implements Countable
30: {
31: /**
32: * The ledger entries.
33: *
34: * @var array
35: */
36: private $_entries = array();
37:
38: /**
39: * Import ledger data from a file.
40: *
41: * @param string $ledger_file The file to import.
42: *
43: * @return NULL
44: */
45: public function importFile($ledger_file)
46: {
47: $data = simplexml_load_file($ledger_file);
48: $this->_entries = $data->entry;
49: }
50:
51: /**
52: * Return the entries as XML strings.
53: *
54: * @return array An array of XML strings.
55: */
56: public function asXml()
57: {
58: $result = array();
59: foreach ($this->_entries as $entry) {
60: $entry->addAttribute('xmlns:en', 'http://newartisans.com/xml/ledger-en', 'http://www.w3.org/2000/xmlns/');
61: $entry->addAttribute('xmlns:tr', 'http://newartisans.com/xml/ledger-tr', 'http://www.w3.org/2000/xmlns/');
62: $result[] = strtr($entry->asXML(), array('xmlns:xmlns="http://www.w3.org/2000/xmlns/" ' => ''));
63: }
64: return $result;
65: }
66:
67: /**
68: * Returns the number of ledger entries.
69: *
70: * @return int The number of entries.
71: */
72: public function count()
73: {
74: return count($this->_entries);
75: }
76: }