6 * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
7 * @author Cornelius Weiss <c.weiss@metaways.de>
8 * @copyright Copyright (c) 2009-2014 Metaways Infosystems GmbH (http://www.metaways.de)
13 * backend for Calendar preferences
17 class Calendar_Preference extends Tinebase_Preference_Abstract
20 * where daysview should be scrolled to
22 const DAYSVIEW_STARTTIME = 'daysviewstarttime';
25 * where daysvoew should be scrolled maximum up to
27 const DAYSVIEW_ENDTIME = 'daysviewendtime';
30 * default calendar all newly created/invited events are placed in
32 const DEFAULTCALENDAR = 'defaultCalendar';
35 * have name of default favorite an a central palce
38 const DEFAULTPERSISTENTFILTER_NAME = "All my events";
41 * general notification level
43 const NOTIFICATION_LEVEL = 'notificationLevel';
46 * send notifications of own updates
48 const SEND_NOTIFICATION_OF_OWN_ACTIONS = 'sendnotificationsofownactions';
51 * enable default alarm
53 const DEFAULTALARM_ENABLED = 'defaultalarmenabled';
56 * default alarm time in minutes before
58 const DEFAULTALARM_MINUTESBEFORE = 'defaultalarmminutesbefore';
61 * default alarm time in minutes before
63 const DEFAULTATTENDEE_STRATEGY = 'defaultAttendeeStrategy';
66 * @var string application
68 protected $_application = 'Calendar';
71 * get all possible application prefs
73 * @return array all application prefs
75 public function getAllApplicationPreferences()
78 self::DAYSVIEW_STARTTIME,
79 self::DAYSVIEW_ENDTIME,
80 self::DEFAULTCALENDAR,
81 self::DEFAULTPERSISTENTFILTER,
82 self::NOTIFICATION_LEVEL,
83 self::SEND_NOTIFICATION_OF_OWN_ACTIONS,
84 self::DEFAULTALARM_ENABLED,
85 self::DEFAULTALARM_MINUTESBEFORE,
86 self::DEFAULTATTENDEE_STRATEGY
93 * get translated right descriptions
95 * @return array with translated descriptions for this applications preferences
97 public function getTranslatedPreferences()
99 $translate = Tinebase_Translation::getTranslation($this->_application);
101 $prefDescriptions = array(
102 self::DAYSVIEW_STARTTIME => array(
103 'label' => $translate->_('Start Time'),
104 'description' => $translate->_('Position on the left time axis, day and week view should start with'),
106 self::DAYSVIEW_ENDTIME => array(
107 'label' => $translate->_('End Time'),
108 'description' => $translate->_('Position on the left time axis, day and week view should end with'),
110 self::DEFAULTCALENDAR => array(
111 'label' => $translate->_('Default Calendar'),
112 'description' => $translate->_('The default calendar for invitations and new events'),
114 self::DEFAULTPERSISTENTFILTER => array(
115 'label' => $translate->_('Default Favorite'),
116 'description' => $translate->_('The default favorite which is loaded on calendar startup'),
118 self::NOTIFICATION_LEVEL => array(
119 'label' => $translate->_('Get Notification Emails'),
120 'description' => $translate->_('The level of actions you want to be notified about. Please note that organizers will get notifications for all updates including attendee answers unless this preference is set to "Never"'),
122 self::SEND_NOTIFICATION_OF_OWN_ACTIONS => array(
123 'label' => $translate->_('Send Notifications Emails of own Actions'),
124 'description' => $translate->_('Get notifications emails for actions you did yourself'),
126 self::DEFAULTALARM_ENABLED => array(
127 'label' => $translate->_('Enable Standard Alarm'),
128 'description' => $translate->_('New events get a standard alarm as defined below'),
130 self::DEFAULTALARM_MINUTESBEFORE => array(
131 'label' => $translate->_('Standard Alarm Time'),
132 'description' => $translate->_('Minutes before the event starts'),
134 self::DEFAULTATTENDEE_STRATEGY => array(
135 'label' => $translate->_('Default Attendee Strategy'),
136 'description' => $translate->_('Default Attendee Strategy for new events'),
140 return $prefDescriptions;
144 * Creates XML Data for a combobox
148 * @param string $default
151 protected function _createTimespanDataXML($start=0, $end=24)
153 $doc = new DomDocument('1.0');
154 $options = $doc->createElement('options');
155 $doc->appendChild($options);
157 $time = new Tinebase_DateTime('@0');
158 for ($i=$start; $i<=$end; $i++) {
160 $timeString = $time->format('H:i');
161 if ($i == $end && $timeString == '00:00') {
162 $timeString = '24:00';
164 $value = $doc->createElement('value');
165 $value->appendChild($doc->createTextNode($timeString));
166 $label = $doc->createElement('label');
167 $label->appendChild($doc->createTextNode($timeString)); // @todo l10n
169 $option = $doc->createElement('option');
170 $option->appendChild($value);
171 $option->appendChild($label);
172 $options->appendChild($option);
175 return $doc->saveXML();
179 * get preference defaults if no default is found in the database
181 * @param string $_preferenceName
182 * @param string|Tinebase_Model_User $_accountId
183 * @param string $_accountType
184 * @return Tinebase_Model_Preference
186 public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)
188 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
189 . ' Get default value for ' . $_preferenceName . ' of account id '. $_accountId);
191 $preference = $this->_getDefaultBasePreference($_preferenceName);
193 switch ($_preferenceName) {
194 case self::DAYSVIEW_STARTTIME:
195 $preference->value = '08:00';
196 $preference->options = $this->_createTimespanDataXML(0, 23);
198 case self::DAYSVIEW_ENDTIME:
199 $preference->value = '18:00';
200 $preference->options = $this->_createTimespanDataXML(1, 24);
202 case self::DEFAULTCALENDAR:
203 $this->_getDefaultContainerPreferenceDefaults($preference, $_accountId);
205 case self::DEFAULTPERSISTENTFILTER:
206 $preference->value = Tinebase_PersistentFilter::getPreferenceValues('Calendar', $_accountId, "All my events");
208 case self::NOTIFICATION_LEVEL:
209 $translate = Tinebase_Translation::getTranslation($this->_application);
210 // need to put the translations strings here because they were not found in the xml below :/
211 // _('Never') _('On invitation and cancellation only') _('On time changes') _('On all updates but attendee responses') _('On attendee responses too')
212 $preference->value = Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE;
213 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
216 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_NONE . '</value>
217 <label>'. $translate->_('Never') . '</label>
220 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_INVITE_CANCEL . '</value>
221 <label>'. $translate->_('On invitation and cancellation only') . '</label>
224 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE . '</value>
225 <label>'. $translate->_('On time changes') . '</label>
228 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_UPDATE . '</value>
229 <label>'. $translate->_('On all updates but attendee responses') . '</label>
232 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE . '</value>
233 <label>'. $translate->_('On attendee responses too') . '</label>
237 case self::SEND_NOTIFICATION_OF_OWN_ACTIONS:
238 $preference->value = 0;
239 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
241 <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
244 case self::DEFAULTALARM_ENABLED:
245 $preference->value = 0;
246 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
248 <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
251 case self::DEFAULTALARM_MINUTESBEFORE:
252 $preference->value = 15;
253 $preference->options = '';
255 case self::DEFAULTATTENDEE_STRATEGY:
256 $preference->value = 'me';
257 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
264 <label>Intelligent</label>
265 <value>intelligent</value>
268 <label>Calendar owner</label>
269 <value>calendarOwner</value>
272 <label>Filtered attendee</label>
273 <value>filteredAttendee</value>
278 throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');