1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Hermes_Slice implements ArrayAccess, IteratorAggregate
13: {
14: 15: 16: 17: 18:
19: protected $_properties;
20:
21: public function __construct(array $properties = array())
22: {
23: $this->_properties = $properties;
24: }
25:
26: public function toArray()
27: {
28: return $this->_properties;
29: }
30:
31: 32: 33: 34: 35:
36: public function fromJson(stdClass $json)
37: {
38: $this->_properties = array (
39: 'client' => $json->c,
40: 'costobject' => $json->co,
41: 'c_costobject_name' => $json->con,
42: 'date' => $json->d,
43: 'description' => $json->desc,
44: 'employee' => $json->e,
45: 'hours' => $json->h,
46: 'id' => $json->i,
47: 'note' => $json->n,
48: 'rate' => $json->r,
49: 'submitted' => $json->s,
50: 'type' => $json->t,
51: '_type_name' => $json->tn,
52: );
53: }
54:
55: 56: 57: 58:
59: public function readForm()
60: {
61:
62: $this->_properties['date'] = new Horde_Date(Horde_Util::getPost('start_date'));
63: $this->_properties['hours'] = Horde_Util::getPost('hours');
64: $this->_properties['description'] = Horde_Util::getPost('description');
65: $this->_properties['id'] = Horde_Util::getPost('id', 0);
66: $this->_properties['billable'] = Horde_Util::getPost('billable') ? 1 : 0;
67:
68:
69: $client = Horde_Util::getPost('client');
70: $this->_properties['client'] = empty($client) ? '' : $client;
71: $this->_properties['type'] = Horde_Util::getPost('type');
72: $this->_properties['costobject'] = Horde_Util::getPost('costobject');
73: $this->_properties['note'] = Horde_Util::getPost('notes');
74: }
75:
76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98:
99: public function toJson()
100: {
101:
102: $cn = $GLOBALS['registry']->clients->getClients(array($this->_properties['client']));
103: $json = array (
104: 'c' => $this->_properties['client'],
105: 'cn' => current($cn),
106: 'co' => $this->_properties['costobject'],
107: 'con' => $this->_properties['_costobject_name'],
108: 'd' => $this->_properties['date']->dateString(),
109: 'desc' => $this->_properties['description'],
110: 'e' => $this->_properties['employee'],
111: 'h' => $this->_properties['hours'],
112: 'i' => $this->_properties['id'],
113: 'n' => $this->_properties['note'],
114: 'r' => $this->_properties['rate'],
115: 's' => $this->_properties['submitted'],
116: 't' => $this->_properties['type'],
117: 'tn' => $this->_properties['_type_name'],
118: 'b' => $this->_properties['billable']
119: );
120:
121: return $json;
122: }
123:
124: 125: 126: 127: 128: 129: 130:
131: public function offsetExists($offset)
132: {
133: return isset($this->_properties[$offset]);
134: }
135:
136: 137: 138: 139: 140: 141: 142:
143: public function offsetGet($offset)
144: {
145: return array_key_exists($offset, $this->_properties) ? $this->_properties[$offset] : null;
146: }
147:
148: 149: 150: 151: 152: 153: 154: 155:
156: public function offsetSet($offset, $value)
157: {
158: $this->_properties[$offset] = $value;
159: }
160:
161: 162: 163: 164: 165: 166: 167:
168: public function offsetUnset($offset)
169: {
170: unset($this->_properties[$offset]);
171: }
172:
173: 174: 175: 176:
177: public function getIterator()
178: {
179: return new ArrayIterator($this->_properties);
180: }
181:
182: }