1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Generate a select form HTML input tag.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Ftree_Select
24: {
25: /**
26: * Generated tree.
27: *
28: * @var Horde_Tree
29: */
30: protected $_tree;
31:
32: /**
33: * Constructor.
34: *
35: * @param array $opts Optional parameters:
36: * - abbrev: (boolean) Abbreviate long mailbox names by replacing the
37: * middle of the name with '...'?
38: * DEFAULT: Yes
39: * - basename: (boolean) Use raw basename instead of abbreviated label?
40: * DEFAULT: false
41: * - heading: (string) The label for an empty-value option at the top of
42: * the list.
43: * DEFAULT: ''
44: * - inc_notepads: (boolean) Include user's editable notepads in list?
45: * DEFAULT: No
46: * - inc_tasklists: (boolean) Include user's editable tasklists in list?
47: * DEFAULT: No
48: * - inc_vfolder: (boolean) Include user's virtual folders in list?
49: * DEFAULT: No
50: * - iterator: (Iterator) Tree iterator to use.
51: * - new_mbox: (boolean) Display an option to create a new mailbox?
52: * DEFAULT: No
53: * - optgroup: (boolean) Whether to use <optgroup> elements to group
54: * mailbox types.
55: * DEFAULT: false
56: * - selected: (string) The mailbox to have selected by default.
57: * DEFAULT: None
58: */
59: public function __construct(array $opts = array())
60: {
61: global $injector;
62:
63: $this->_tree = $injector->getInstance('IMP_Ftree')->createTree(strval(new Horde_Support_Randomid()), array(
64: 'basename' => !empty($opts['basename']),
65: 'iterator' => empty($opts['iterator']) ? null : $opts['iterator'],
66: 'render_type' => 'IMP_Tree_Flist'
67: ));
68:
69: if (!empty($opts['selected'])) {
70: $this->_tree->addNodeParams(IMP_Mailbox::formTo($opts['selected']), array('selected' => true));
71: }
72:
73: $this->_tree->setOption($opts);
74: }
75:
76: /**
77: * The string tree representation.
78: * NOTE: The <select> and </select> tags are NOT included in
79: * the output.
80: *
81: * @return string A string containing <option> elements for each mailbox
82: * in the list.
83: */
84: public function __toString()
85: {
86: return $this->_tree->getTree();
87: }
88:
89: }
90: