1: <?php
2: /**
3: * Extension of the Horde_DataTreeObject class for storing Share information in the
4: * Horde_DataTree driver. If you want to store specialized Share information, you
5: * should extend this class instead of extending Horde_DataTreeObject directly.
6: *
7: * @author Mike Cochrane <mike@graftonhall.co.nz>
8: * @author Jan Schneider <jan@horde.org>
9: * @package Share
10: */
11: class Horde_Share_Object_DataTree_Share extends Horde_DataTreeObject
12: {
13: /**
14: * Returns the properties that need to be serialized.
15: *
16: * @return array List of serializable properties.
17: */
18: public function __sleep()
19: {
20: $properties = get_object_vars($this);
21: unset($properties['datatree']);
22: $properties = array_keys($properties);
23: return $properties;
24: }
25:
26: /**
27: * Maps this object's attributes from the data array into a format that we
28: * can store in the attributes storage backend.
29: *
30: * @access protected
31: *
32: * @param boolean $permsonly Only process permissions? Lets subclasses
33: * override part of this method while handling
34: * their additional attributes seperately.
35: *
36: * @return array The attributes array.
37: */
38: protected function _toAttributes($permsonly = false)
39: {
40: // Default to no attributes.
41: $attributes = array();
42:
43: foreach ($this->data as $key => $value) {
44: if ($key == 'perm') {
45: foreach ($value as $type => $perms) {
46: if (is_array($perms)) {
47: foreach ($perms as $member => $perm) {
48: $attributes[] = array('name' => 'perm_' . $type,
49: 'key' => $member,
50: 'value' => $perm);
51: }
52: } else {
53: $attributes[] = array('name' => 'perm_' . $type,
54: 'key' => '',
55: 'value' => $perms);
56: }
57: }
58: } elseif (!$permsonly) {
59: $attributes[] = array('name' => $key,
60: 'key' => '',
61: 'value' => $value);
62: }
63: }
64:
65: return $attributes;
66: }
67:
68: /**
69: * Takes in a list of attributes from the backend and maps it to our
70: * internal data array.
71: *
72: * @access protected
73: *
74: * @param array $attributes The list of attributes from the backend
75: * (attribute name, key, and value).
76: * @param boolean $permsonly Only process permissions? Lets subclasses
77: * override part of this method while handling
78: * their additional attributes seperately.
79: */
80: protected function _fromAttributes($attributes, $permsonly = false)
81: {
82: // Initialize data array.
83: $this->data['perm'] = array();
84:
85: foreach ($attributes as $attr) {
86: if (substr($attr['name'], 0, 4) == 'perm') {
87: if (!empty($attr['key'])) {
88: $this->data['perm'][substr($attr['name'], 5)][$attr['key']] = $attr['value'];
89: } else {
90: $this->data['perm'][substr($attr['name'], 5)] = $attr['value'];
91: }
92: } elseif (!$permsonly) {
93: $this->data[$attr['name']] = $attr['value'];
94: }
95: }
96: }
97: }
98: