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: * Viewport data object.
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 string $cacheid The cache ID.
24: * @property array $data The data array.
25: * @property boolean $data_reset True if viewport data should be reset.
26: * @property array $disappear The list of UIDs that have disappeared.
27: * @property string $label The view label.
28: * @property object $metadata Metadata.
29: * @property boolean $metadata_reset True if metadata should be reset.
30: * @property array $rangelist Results of a range request.
31: * @property array $rowlist The rowlist array.
32: * @property boolean $rowlist_reset True if rowlist data should be reset.
33: * @property integer $rownum The row number of the provided UID.
34: * @property integer $totalrows The total number of rows in the view.
35: * @property-read string $view The view ID.
36: */
37: class IMP_Ajax_Application_Viewport
38: {
39: /**
40: * Data.
41: *
42: * @var object
43: */
44: private $_data;
45:
46: /**
47: * View object.
48: *
49: * @var IMP_Mailbox
50: */
51: private $_mbox;
52:
53: /**
54: * Metadata.
55: *
56: * @var array
57: */
58: private $_metadata = array();
59:
60: /**
61: * Constructor.
62: *
63: * @param IMP_Mailbox $mbox Viewport view.
64: */
65: public function __construct(IMP_Mailbox $mbox)
66: {
67: $this->_data = new stdClass;
68: $this->_mbox = $mbox;
69: }
70:
71: /**
72: */
73: public function __get($name)
74: {
75: switch ($name) {
76: case 'cacheid':
77: return $this->_mbox->cacheid_date;
78:
79: case 'data':
80: case 'data_reset':
81: case 'disappear':
82: case 'label':
83: case 'metadata_reset':
84: case 'rangelist':
85: case 'rowlist':
86: case 'rowlist_reset':
87: case 'rownum':
88: case 'totalrows':
89: return isset($this->_data->$name)
90: ? $this->_data->$name
91: : false;
92:
93: case 'metadata':
94: return (object)$this->_metadata;
95:
96: case 'view':
97: return $this->_mbox->form_to;
98: }
99: }
100:
101: /**
102: */
103: public function __set($name, $value)
104: {
105: switch ($name) {
106: case 'data_reset':
107: case 'metadata_reset':
108: case 'rowlist_reset':
109: $this->_data->$name = (bool)$value;
110: break;
111:
112: case 'data':
113: case 'disappear':
114: case 'rangelist':
115: case 'rowlist':
116: $this->_data->$name = $value;
117: break;
118:
119: case 'label':
120: $this->_data->$name = strval($value);
121: break;
122:
123: case 'rownum':
124: case 'totalrows':
125: $this->_data->$name = intval($value);
126: break;
127: }
128: }
129:
130: /**
131: * Set a metadata element.
132: *
133: * @param string $name Metadata name.
134: * @param string $value Metadata value.
135: */
136: public function setMetadata($name, $value)
137: {
138: $this->_metadata[$name] = $value;
139: }
140:
141: /**
142: * Prepare the object used by the ViewPort javascript class.
143: *
144: * @return object The ViewPort object.
145: */
146: public function toObject()
147: {
148: $ob = clone $this->_data;
149: $ob->cacheid = $this->cacheid;
150: $ob->view = $this->view;
151:
152: if (!empty($this->_metadata)) {
153: $ob->metadata = $this->metadata;
154: }
155:
156: return $ob;
157: }
158:
159: /**
160: * Add flag metadata to output.
161: */
162: public function addFlagMetadata()
163: {
164: global $injector;
165:
166: $flaglist = $injector->getInstance('IMP_Flags')->getList(array(
167: 'imap' => true,
168: 'mailbox' => $this->_mbox->search ? null : $this->_mbox
169: ));
170:
171: $flags = array();
172: foreach ($flaglist as $val) {
173: $flags[] = $val->imapflag;
174: }
175:
176: $this->setMetadata('flags', $flags);
177: }
178:
179: }
180: