1: <?php
2: /**
3: * The Horde_Kolab_Cli_Module_Ledger:: provides tools to deal with ledger data
4: * stored in a Kolab backend.
5: *
6: * PHP version 5
7: *
8: * @category Horde
9: * @package Kolab_Cli
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Cli
13: */
14:
15: /**
16: * The Horde_Kolab_Cli_Module_Ledger:: provides tools to deal with ledger data
17: * stored in a Kolab backend.
18: *
19: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Horde
25: * @package Kolab_Cli
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Cli
29: */
30: class Horde_Kolab_Cli_Module_Ledger
31: implements Horde_Kolab_Cli_Module
32: {
33: /**
34: * Get the usage description for this module.
35: *
36: * @return string The description.
37: */
38: public function getUsage()
39: {
40: return Horde_Kolab_Cli_Translation::t(" ledger - Handle ledger data in a Kolab backend (the default action is \"display\").
41:
42: - display : Display all ledgers.
43: - import FOLDER FILE : Import ledger XML data stored in FILE into Kolab folder FOLDER.
44:
45: ");
46: }
47:
48: /**
49: * Get a set of base options that this module adds to the CLI argument
50: * parser.
51: *
52: * @return array The options.
53: */
54: public function getBaseOptions()
55: {
56: return array();
57: }
58:
59: /**
60: * Indicate if the module provides an option group.
61: *
62: * @return boolean True if an option group should be added.
63: */
64: public function hasOptionGroup()
65: {
66: return false;
67: }
68:
69: /**
70: * Return the title for the option group representing this module.
71: *
72: * @return string The group title.
73: */
74: public function getOptionGroupTitle()
75: {
76: return '';
77: }
78:
79: /**
80: * Return the description for the option group representing this module.
81: *
82: * @return string The group description.
83: */
84: public function getOptionGroupDescription()
85: {
86: return '';
87: }
88:
89: /**
90: * Return the options for this module.
91: *
92: * @return array The group options.
93: */
94: public function getOptionGroupOptions()
95: {
96: return array();
97: }
98:
99: /**
100: * Handle the options and arguments.
101: *
102: * @param mixed &$options An array of options.
103: * @param mixed &$arguments An array of arguments.
104: * @param array &$world A list of initialized dependencies.
105: *
106: * @return NULL
107: */
108: public function handleArguments(&$options, &$arguments, &$world)
109: {
110: }
111:
112: /**
113: * Run the module.
114: *
115: * @param Horde_Cli $cli The CLI handler.
116: * @param mixed $options An array of options.
117: * @param mixed $arguments An array of arguments.
118: * @param array &$world A list of initialized dependencies.
119: *
120: * @return NULL
121: */
122: public function run($cli, $options, $arguments, &$world)
123: {
124: if (!isset($arguments[1])) {
125: $action = 'display';
126: } else {
127: $action = $arguments[1];
128: }
129: switch ($action) {
130: case 'display':
131: $folders = $world['storage']->getList()
132: ->getQuery()
133: ->listByType('h-ledger');
134: foreach ($folders as $folder) {
135: $cli->writeln($folder);
136: }
137: break;
138: break;
139: case 'import':
140: $ledger = new Horde_Kolab_Cli_Data_Ledger();
141: $ledger->importFile($arguments[3]);
142: $data = $world['storage']->getData($arguments[2], 'h-ledger');
143: $object = array('type' => 'h-ledger');
144: foreach ($ledger->asXml() as $entry) {
145: $object['xml'] = $entry;
146: $data->create($object);
147: }
148: break;
149: default:
150: $cli->message(
151: sprintf(
152: Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
153: $action
154: ),
155: 'cli.error'
156: );
157: break;
158: }
159: }
160: }