Overview

Packages

  • Kolab
    • Cli

Classes

  • Horde_Kolab_Cli
  • Horde_Kolab_Cli_Data_Ledger
  • Horde_Kolab_Cli_Exception
  • Horde_Kolab_Cli_Module_Account
  • Horde_Kolab_Cli_Module_Base
  • Horde_Kolab_Cli_Module_Data
  • Horde_Kolab_Cli_Module_Folder
  • Horde_Kolab_Cli_Module_Format
  • Horde_Kolab_Cli_Module_Ledger
  • Horde_Kolab_Cli_Module_List
  • Horde_Kolab_Cli_Translation

Interfaces

  • Horde_Kolab_Cli_Module
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Kolab_Cli_Module_Folder:: class handles single folders.
  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_Module_Folder:: class handles single folders.
 16:  *
 17:  * Copyright 2010-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_Module_Folder
 29: implements Horde_Kolab_Cli_Module
 30: {
 31:     /**
 32:      * Get the usage description for this module.
 33:      *
 34:      * @return string The description.
 35:      */
 36:     public function getUsage()
 37:     {
 38:         return Horde_Kolab_Cli_Translation::t("  folder - Handle a single folder (the default action is \"show\")
 39: 
 40:   - show      PATH         : Display information about the folder at PATH.
 41:   - create    PATH [TYPE]  : Create the folder PATH (with the optional type TYPE).
 42:   - delete    PATH         : Delete the folder PATH.
 43:   - rename    OLD NEW      : Rename the folder from OLD to NEW.
 44:   - getacl    PATH         : Get all ACL on the specified folder.
 45:   - getmyacl  PATH         : Get your ACL on the specified folder.
 46:   - setacl    PATH USER ACL: Set the ACL for the specified user on the folder.
 47:   - deleteacl PATH USER ACL: Delete the ACL for the specified user on the folder.
 48:   - getdesc   PATH         : Return the share description of the specified folder.
 49:   - setdesc   PATH DESC    : Set the share description of the specified folder to DESC.
 50:   - getshare  PATH         : Return the share parameters of the specified folder.
 51: 
 52: 
 53: ");
 54:     }
 55: 
 56:     /**
 57:      * Get a set of base options that this module adds to the CLI argument
 58:      * parser.
 59:      *
 60:      * @return array The options.
 61:      */
 62:     public function getBaseOptions()
 63:     {
 64:         return array();
 65:     }
 66: 
 67:     /**
 68:      * Indicate if the module provides an option group.
 69:      *
 70:      * @return boolean True if an option group should be added.
 71:      */
 72:     public function hasOptionGroup()
 73:     {
 74:         return false;
 75:     }
 76: 
 77:     /**
 78:      * Return the title for the option group representing this module.
 79:      *
 80:      * @return string The group title.
 81:      */
 82:     public function getOptionGroupTitle()
 83:     {
 84:         return '';
 85:     }
 86: 
 87:     /**
 88:      * Return the description for the option group representing this module.
 89:      *
 90:      * @return string The group description.
 91:      */
 92:     public function getOptionGroupDescription()
 93:     {
 94:         return '';
 95:     }
 96: 
 97:     /**
 98:      * Return the options for this module.
 99:      *
100:      * @return array The group options.
101:      */
102:     public function getOptionGroupOptions()
103:     {
104:         return array();
105:     }
106: 
107:     /**
108:      * Handle the options and arguments.
109:      *
110:      * @param mixed &$options   An array of options.
111:      * @param mixed &$arguments An array of arguments.
112:      * @param array &$world     A list of initialized dependencies.
113:      *
114:      * @return NULL
115:      */
116:     public function handleArguments(&$options, &$arguments, &$world)
117:     {
118:     }
119: 
120:     /**
121:      * Run the module.
122:      *
123:      * @param Horde_Cli $cli       The CLI handler.
124:      * @param mixed     $options   An array of options.
125:      * @param mixed     $arguments An array of arguments.
126:      * @param array     &$world    A list of initialized dependencies.
127:      *
128:      * @return NULL
129:      */
130:     public function run($cli, $options, $arguments, &$world)
131:     {
132:         if (!isset($arguments[1])) {
133:             $action = 'show';
134:         } else {
135:             $action = $arguments[1];
136:         }
137:         if (!isset($arguments[2])) {
138:             $folder_name = 'INBOX';
139:         } else {
140:             $folder_name = $arguments[2];
141:         }
142:         switch ($action) {
143:         case 'create':
144:             if (!isset($arguments[3])) {
145:                 $folder = $world['storage']->getList()
146:                     ->createFolder($folder_name);
147:             } else {
148:                 $folder = $world['storage']->getList()
149:                     ->createFolder($folder_name, $arguments[3]);
150:             }
151:             $this->_showFolder($folder_name, $world, $cli);
152:             break;
153:         case 'rename':
154:             $folder = $world['storage']->getList()
155:                 ->renameFolder($folder_name, $arguments[3]);
156:             $this->_showFolder($arguments[3], $world, $cli);
157:             break;
158:         case 'delete':
159:             $folder = $world['storage']->getList()
160:                 ->deleteFolder($folder_name);
161:             break;
162:         case 'getacl':
163:             $acl = $world['storage']->getList()
164:                 ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
165:                 ->getAcl($folder_name);
166:             $cli->writeln($folder_name);
167:             $cli->writeln(str_repeat('=', strlen($folder_name)));
168:             $pad = max(array_map('strlen', array_keys($acl))) + 2;
169:             foreach ($acl as $user => $rights) {
170:                 $cli->writeln(Horde_String::pad($user . ':', $pad) . $rights);
171:             }
172:             break;
173:         case 'getmyacl':
174:             $acl = $world['storage']->getList()
175:                 ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
176:                 ->getMyAcl($folder_name);
177:             $cli->writeln('Your rights on ' . $folder_name . ': ' . $acl);
178:             break;
179:         case 'setacl':
180:             $acl = $world['storage']->getList()
181:                 ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
182:                 ->setAcl($folder_name, $arguments[3], $arguments[4]);
183:             break;
184:         case 'deleteacl':
185:             $acl = $world['storage']->getList()
186:                 ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
187:                 ->deleteAcl($folder_name, $arguments[3]);
188:             break;
189:         case 'getdesc':
190:             $list = $world['storage']->getList();
191:             $world['storage']->addListQuery(
192:                 $list,
193:                 Horde_Kolab_Storage_List::QUERY_SHARE
194:             );
195:             $cli->writeln(
196:                 $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
197:                     ->getDescription($folder_name)
198:             );
199:             break;
200:         case 'setdesc':
201:             $list = $world['storage']->getList();
202:             $world['storage']->addListQuery(
203:                 $list,
204:                 Horde_Kolab_Storage_List::QUERY_SHARE
205:             );
206:             $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
207:                 ->setDescription($folder_name, $arguments[3]);
208:             break;
209:         case 'getshare':
210:             $list = $world['storage']->getList();
211:             $world['storage']->addListQuery(
212:                 $list,
213:                 Horde_Kolab_Storage_List::QUERY_SHARE
214:             );
215:             $parameters = $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
216:                 ->getParameters($folder_name);
217:             $pad = max(array_map('strlen', array_keys($parameters))) + 2;
218:             foreach ($parameters as $key => $value) {
219:                 $cli->writeln(Horde_String::pad($key . ':', $pad) . $value);
220:             }
221:             break;
222:         case 'show':
223:             $this->_showFolder($folder_name, $world, $cli);
224:             break;
225:         default:
226:             $cli->message(
227:                 sprintf(
228:                     Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
229:                     $action
230:                 ),
231:                 'cli.error'
232:             );
233:             break;
234:         }
235:     }
236: 
237:     private function _showFolder($folder_name, $world, $cli)
238:     {
239:         $folder = $world['storage']->getList()->getFolder($folder_name);
240:         $cli->writeln('Path:      ' . $folder->getPath());
241:         $cli->writeln('Title:     ' . $folder->getTitle());
242:         $cli->writeln('Owner:     ' . $folder->getOwner());
243:         $cli->writeln('Type:      ' . $folder->getType());
244:         $cli->writeln('Parent:    ' . $folder->getParent());
245:         $cli->writeln('Namespace: ' . $folder->getNamespace());
246:     }
247: }
API documentation generated by ApiGen