1: <?php
2: /**
3: * Kronolith_Calendar defines an API for single calendars.
4: *
5: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Jan Schneider <jan@horde.org>
11: * @package Kronolith
12: */
13: abstract class Kronolith_Calendar
14: {
15: /**
16: * Constructor.
17: *
18: * @param array $params A hash with any parameters that this calendar
19: * might need.
20: */
21: public function __construct($params = array())
22: {
23: foreach ($params as $param => $value) {
24: $this->{'_' . $param} = $value;
25: }
26: }
27:
28: /**
29: * Returns the owner of this calendar.
30: *
31: * @return string This calendar's owner.
32: */
33: public function owner()
34: {
35: return $GLOBALS['registry']->getAuth();
36: }
37:
38: /**
39: * Returns the name of this calendar.
40: *
41: * @return string This calendar's name.
42: */
43: abstract public function name();
44:
45: /**
46: * Returns the description of this calendar.
47: *
48: * @return string This calendar's description.
49: */
50: public function description()
51: {
52: return '';
53: }
54:
55: /**
56: * Returns the background color for this calendar.
57: *
58: * @return string A HTML color code.
59: */
60: public function background()
61: {
62: return '#dddddd';
63: }
64:
65: /**
66: * Returns the foreground color for this calendar.
67: *
68: * @return string A HTML color code.
69: */
70: public function foreground()
71: {
72: return Horde_Image::brightness($this->background()) < 128 ? '#fff' : '#000';
73: }
74:
75: /**
76: * Returns the CSS color definition for this calendar.
77: *
78: * @param boolean $with_attribute Whether to wrap the colors inside a
79: * "style" attribute.
80: *
81: * @return string A CSS string with color definitions.
82: */
83: public function css($with_attribute = true)
84: {
85: $css = 'background-color:' . $this->background() . ';color:' . $this->foreground();
86: if ($with_attribute) {
87: $css = ' style="' . $css . '"';
88: }
89: return $css;
90: }
91:
92: /**
93: * Encapsulates permissions checking.
94: *
95: * @param integer $permission The permission to check for.
96: * @param string $user The user to check permissions for. Defaults
97: * to the current user.
98: * @param string $creator An event creator, to check for creator
99: * permissions.
100: *
101: * @return boolean Whether the user has the permission on this calendar.
102: */
103: public function hasPermission($permission, $user = null, $creator = null)
104: {
105: switch ($permission) {
106: case Horde_Perms::SHOW:
107: case Horde_Perms::READ:
108: return true;
109:
110: default:
111: return false;
112: }
113: }
114:
115: /**
116: * Whether this calendar is supposed to be displayed in lists.
117: *
118: * @return boolean True if this calendar should be displayed.
119: */
120: abstract public function display();
121:
122: /**
123: * Returns a hash representing this calendar.
124: *
125: * @return array A simple hash.
126: */
127: public function toHash()
128: {
129: return array(
130: 'name' => $this->name(),
131: 'desc' => $this->description(),
132: 'owner' => true,
133: 'fg' => $this->foreground(),
134: 'bg' => $this->background(),
135: );
136: }
137: }
138: