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: * A tree element.
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: * @property-read IMP_Ftree_Account $account Account object for this element.
24: * @property-read boolean $base_elt True if this is the base element.
25: * @property-read boolean $children True if this element has children.
26: * @property-read array $child_list The list of the element's children.
27: * @property boolean $container True if this element is a container.
28: * @property-read boolean $inbox True if this is the INBOX.
29: * @property boolean $invisible True if this element is invisible.
30: * @property-read integer $level The tree level of the current element.
31: * @property-read IMP_Mailbox $mbox_ob The IMP_Mailbox object for this
32: * element.
33: * @property-read boolean $namespace True if this is a namespace container
34: * element.
35: * @property-read Horde_Imap_Client_Data_Namespace $namespace_info Namespace
36: * info.
37: * @property-read boolean $namespace_other True if this is an 'Other'
38: * namespace.
39: * @property-read boolean $namespace_shared True if this is a 'Shared'
40: * namespace.
41: * @property boolean $needsort True if this level needs a sort.
42: * @property-read boolean $nochildren True if this element doesn't allow
43: * children.
44: * @property-read boolean $nonimap True if this is a non-IMAP element.
45: * @property boolean $open True if this element is open (a/k/a expanded).
46: * @property-read IMP_Ftree_Element $parent The parent element (null if not
47: * found).
48: * @property boolean $polled True if this element is polled.
49: * @property-read boolean $remote True if this is a remote container.
50: * @property-read boolean $remote_auth True if this is a remote account that
51: * has been authenticated.
52: * @property-read boolean $remote_mbox True if this is a remote mailbox.
53: * @property boolean $subscribed True if the element is subscribed.
54: * @property-read boolean $vfolder True if this element is a virtual folder.
55: */
56: class IMP_Ftree_Element
57: {
58: /**
59: * The element ID.
60: *
61: * @var string
62: */
63: protected $_id;
64:
65: /**
66: * IMP folder tree object.
67: *
68: * @var IMP_Ftree
69: */
70: protected $_tree;
71:
72: /**
73: * Constructor.
74: *
75: * @param string $id Element ID.
76: * @param IMP_Ftree $tree The base tree object.
77: */
78: public function __construct($id, IMP_Ftree $tree)
79: {
80: $this->_id = $id;
81: $this->_tree = $tree;
82: }
83:
84: /**
85: */
86: public function __sleep()
87: {
88: throw new LogicException('Object can not be serialized.');
89: }
90:
91: /**
92: * @return string Element ID.
93: */
94: public function __toString()
95: {
96: return $this->_id;
97: }
98:
99: /**
100: */
101: public function __get($name)
102: {
103: switch ($name) {
104: case 'account':
105: return $this->_tree->getAccount($this->_id);
106:
107: case 'base_elt':
108: return ($this->_id == IMP_Ftree::BASE_ELT);
109:
110: case 'child_list':
111: return $this->_tree->getChildren($this->_id);
112:
113: case 'inbox':
114: return ($this->_id == 'INBOX');
115:
116: case 'level':
117: if ($this->base_elt) {
118: return 0;
119: }
120:
121: $i = substr_count($this->_id, $this->namespace_info->delimiter);
122:
123: $elt = $this;
124: while ($elt = $elt->parent) {
125: if ($elt->namespace) {
126: return $i + 1;
127: } elseif ($elt->remote) {
128: if ($this->remote_mbox) {
129: ++$i;
130: }
131: return $i + 1;
132: }
133: }
134:
135: return $i;
136:
137: case 'mbox_ob':
138: return IMP_Mailbox::get($this->_id);
139:
140: case 'namespace':
141: return ($this->namespace_other || $this->namespace_shared);
142:
143: case 'namespace_info':
144: return $this->mbox_ob->imp_imap->getNamespace($this->_id);
145:
146: case 'parent':
147: return $this->_tree->getParent($this->_id);
148:
149: default:
150: return $this->_tree->getAttribute($name, $this->_id);
151: }
152: }
153:
154: /**
155: */
156: public function __set($name, $value)
157: {
158: switch ($name) {
159: case 'container':
160: case 'invisible':
161: case 'needsort':
162: case 'open':
163: case 'polled':
164: case 'subscribed':
165: $this->_tree->setAttribute($name, $this->_id, $value);
166: break;
167: }
168: }
169:
170: }
171: