1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Kronolith_Calendar_Internal extends Kronolith_Calendar
15: {
16: 17: 18: 19: 20:
21: protected $_share;
22:
23: 24: 25: 26: 27: 28: 29: 30:
31: public function __construct($params = array())
32: {
33: if (!isset($params['share'])) {
34: throw new BadMethodCallException('share parameter is missing');
35: }
36: if (!($params['share'] instanceof Horde_Share_Object)) {
37: throw new InvalidArgumentException('share parameter is not a Horde_Share_Object');
38: }
39: parent::__construct($params);
40: }
41:
42: 43: 44: 45: 46:
47: public function owner()
48: {
49: return $this->_share->get('owner');
50: }
51:
52: 53: 54: 55: 56:
57: public function name()
58: {
59: return $this->_share->get('name');
60: }
61:
62: 63: 64: 65: 66:
67: public function description()
68: {
69: return $this->_share->get('desc');
70: }
71:
72: 73: 74: 75: 76:
77: public function background()
78: {
79: $color = $this->_share->get('color');
80: return empty($color) ? parent::background() : $color;
81: }
82:
83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93:
94: public function hasPermission($permission, $user = null, $creator = null)
95: {
96: if ($user === null) {
97: $user = $GLOBALS['registry']->getAuth();
98: }
99: return $this->_share->hasPermission($user, $permission, $creator);
100: }
101:
102: 103: 104: 105: 106:
107: public function display()
108: {
109: return $this->owner() == $GLOBALS['registry']->getAuth() ||
110: empty($GLOBALS['conf']['share']['hidden']) ||
111: in_array($this->_share->getName(), $GLOBALS['display_calendars']);
112: }
113:
114: 115: 116: 117: 118:
119: public function share()
120: {
121: return $this->_share;
122: }
123:
124: 125: 126: 127: 128:
129: public function toHash()
130: {
131: $id = $this->_share->getName();
132: $owner = $GLOBALS['registry']->getAuth() &&
133: $this->owner() == $GLOBALS['registry']->getAuth();
134:
135: $hash = parent::toHash();
136: $hash['name'] = $this->name()
137: . ($owner || !$this->owner() ? '' : ' [' . $GLOBALS['registry']->convertUsername($this->owner(), false) . ']');
138: $hash['owner'] = $owner;
139: $hash['show'] = in_array($id, $GLOBALS['display_calendars']);
140: $hash['edit'] = $this->hasPermission(Horde_Perms::EDIT);
141: $hash['sub'] = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . ($GLOBALS['conf']['urls']['pretty'] == 'rewrite' ? '/rpc/kronolith/' : '/rpc.php/kronolith/'), true, -1)
142: . ($this->owner() ? $this->owner() : '-system-') . '/'
143: . $id . '.ics';
144: $hash['feed'] = (string)Kronolith::feedUrl($id);
145: $hash['embed'] = Kronolith::embedCode($id);
146: $hash['tg'] = array_values(Kronolith::getTagger()->getTags($id, 'calendar'));
147: if ($owner) {
148: $hash['perms'] = Kronolith::permissionToJson($this->_share->getPermission());
149: }
150:
151: return $hash;
152: }
153: }
154: