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_List:: handles folder lists.
  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_List:: handles folder lists.
 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_List
 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("  list - Handle folder lists (the default action is \"folders\")
 39: 
 40:   - folders          : List the folders in the backend
 41:   - types            : Display all folders that have a folder type.
 42:   - type TYPE        : Display the folders of type TYPE.
 43:   - owners           : List all folders and their owners.
 44:   - defaults         : List the default folders for all users.
 45:   - aclsupport       : Display if the server supports ACL.
 46:   - namespace        : Display the server namespace information.
 47:   - sync             : Synchronize the cache.
 48: 
 49: 
 50: ");
 51:     }
 52: 
 53:     /**
 54:      * Get a set of base options that this module adds to the CLI argument
 55:      * parser.
 56:      *
 57:      * @return array The options.
 58:      */
 59:     public function getBaseOptions()
 60:     {
 61:         return array();
 62:     }
 63: 
 64:     /**
 65:      * Indicate if the module provides an option group.
 66:      *
 67:      * @return boolean True if an option group should be added.
 68:      */
 69:     public function hasOptionGroup()
 70:     {
 71:         return false;
 72:     }
 73: 
 74:     /**
 75:      * Return the title for the option group representing this module.
 76:      *
 77:      * @return string The group title.
 78:      */
 79:     public function getOptionGroupTitle()
 80:     {
 81:         return '';
 82:     }
 83: 
 84:     /**
 85:      * Return the description for the option group representing this module.
 86:      *
 87:      * @return string The group description.
 88:      */
 89:     public function getOptionGroupDescription()
 90:     {
 91:         return '';
 92:     }
 93: 
 94:     /**
 95:      * Return the options for this module.
 96:      *
 97:      * @return array The group options.
 98:      */
 99:     public function getOptionGroupOptions()
100:     {
101:         return array();
102:     }
103: 
104:     /**
105:      * Handle the options and arguments.
106:      *
107:      * @param mixed &$options   An array of options.
108:      * @param mixed &$arguments An array of arguments.
109:      * @param array &$world     A list of initialized dependencies.
110:      *
111:      * @return NULL
112:      */
113:     public function handleArguments(&$options, &$arguments, &$world)
114:     {
115:     }
116: 
117:     /**
118:      * Run the module.
119:      *
120:      * @param Horde_Cli $cli       The CLI handler.
121:      * @param mixed     $options   An array of options.
122:      * @param mixed     $arguments An array of arguments.
123:      * @param array     &$world    A list of initialized dependencies.
124:      *
125:      * @return NULL
126:      */
127:     public function run($cli, $options, $arguments, &$world)
128:     {
129:         if (!isset($arguments[1])) {
130:             $action = 'folders';
131:         } else {
132:             $action = $arguments[1];
133:         }
134:         switch ($action) {
135:         case 'folders':
136:             $folders = $world['storage']->getList()->listFolders();
137:             foreach ($folders as $folder) {
138:                 $cli->writeln($folder);
139:             }
140:             break;
141:         case 'types':
142:             $types = $world['storage']->getList()
143:                 ->getQuery()
144:                 ->listTypes();
145:             if (!empty($types)) {
146:                 $pad = max(array_map('strlen', array_keys($types))) + 2;
147:                 foreach ($types as $folder => $type) {
148:                     $cli->writeln(Horde_String::pad($folder . ':', $pad) . $type);
149:                 }
150:             }
151:             break;
152:         case 'type':
153:             if (!isset($arguments[2])) {
154:                 throw new Horde_Kolab_Cli_Exception('You must provide a TYPE argument!');
155:             }
156:             $type = $arguments[2];
157:             $folders = $world['storage']->getList()
158:                 ->getQuery()
159:                 ->listByType($type);
160:             foreach ($folders as $folder) {
161:                 $cli->writeln($folder);
162:             }
163:             break;
164:         case 'owners':
165:             $owners = $world['storage']->getList()
166:                 ->getQuery()
167:                 ->listOwners();
168:             if (!empty($owners)) {
169:                 $pad = max(array_map('strlen', array_keys($owners))) + 2;
170:                 foreach ($owners as $folder => $owner) {
171:                     $cli->writeln(Horde_String::pad($folder . ':', $pad) . $owner);
172:                 }
173:             }
174:             break;
175:         case 'defaults':
176:             $defaults = $world['storage']->getList()
177:                 ->getQuery()
178:                 ->listDefaults();
179:             if (!empty($defaults)) {
180:                 foreach ($defaults as $owner => $folders) {
181:                     $cli->writeln('User "' . $owner . '":');
182:                     $cli->writeln();
183:                     foreach ($folders as $type => $folder) {
184:                         $cli->writeln('  ' . Horde_String::pad($type . ':', 14) . $folder);
185:                     }
186:                     $cli->writeln();
187:                 }
188:             }
189:             break;
190:         case 'aclsupport':
191:             if ($world['storage']->getList()
192:                 ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
193:                 ->hasAclSupport()) {
194:                 echo "The remote server supports ACL.\n";
195:             } else {
196:                 echo "The remote server does not support ACL.\n";
197:             }
198:             break;
199:         case 'namespaces':
200:             $cli->writeln((string)$world['storage']->getList()->getNamespace());
201:             break;
202:         case 'sync':
203:             $folders = $world['storage']->getList()->synchronize();
204:             break;
205:         default:
206:             $cli->message(
207:                 sprintf(
208:                     Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
209:                     $action
210:                 ),
211:                 'cli.error'
212:             );
213:             break;
214:         }
215:     }
216: }
API documentation generated by ApiGen