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 * where daysview should be scrolled to
32 const DAYSVIEW_DEFAULT_STARTTIME = 'daysviewdefaultstarttime';
35 * default calendar all newly created/invited events are placed in
37 const DEFAULTCALENDAR = 'defaultCalendar';
40 * have name of default favorite an a central palce
43 const DEFAULTPERSISTENTFILTER_NAME = "All my events";
46 * general notification level
48 const NOTIFICATION_LEVEL = 'notificationLevel';
51 * send notifications of own updates
53 const SEND_NOTIFICATION_OF_OWN_ACTIONS = 'sendnotificationsofownactions';
56 * enable default alarm
58 const DEFAULTALARM_ENABLED = 'defaultalarmenabled';
61 * default alarm time in minutes before
63 const DEFAULTALARM_MINUTESBEFORE = 'defaultalarmminutesbefore';
66 * default alarm time in minutes before
68 const DEFAULTATTENDEE_STRATEGY = 'defaultAttendeeStrategy';
71 * @var string application
73 protected $_application = 'Calendar';
76 * get all possible application prefs
78 * @return array all application prefs
80 public function getAllApplicationPreferences()
82 $cropDays = Calendar_Config::getInstance()->get(Calendar_Config::CROP_DAYS_VIEW);
85 self::DAYSVIEW_STARTTIME,
86 self::DAYSVIEW_ENDTIME,
87 self::DEFAULTCALENDAR,
88 self::DEFAULTPERSISTENTFILTER,
89 self::NOTIFICATION_LEVEL,
90 self::SEND_NOTIFICATION_OF_OWN_ACTIONS,
91 self::DEFAULTALARM_ENABLED,
92 self::DEFAULTALARM_MINUTESBEFORE,
93 self::DEFAULTATTENDEE_STRATEGY
97 array_unshift($allPrefs, self::DAYSVIEW_DEFAULT_STARTTIME);
104 * get translated right descriptions
106 * @return array with translated descriptions for this applications preferences
108 public function getTranslatedPreferences()
110 $translate = Tinebase_Translation::getTranslation($this->_application);
112 $prefDescriptions = array(
113 self::DAYSVIEW_STARTTIME => array(
114 'label' => $translate->_('Start Time'),
115 'description' => $translate->_('Position on the left time axis, day and week view should start with'),
117 self::DAYSVIEW_ENDTIME => array(
118 'label' => $translate->_('End Time'),
119 'description' => $translate->_('Position on the left time axis, day and week view should end with'),
121 self::DAYSVIEW_DEFAULT_STARTTIME => array(
122 'label' => $translate->_('Default Start Time'),
123 'description' => $translate->_('Scroll position on the left time axis, day and week view should start with'),
125 self::DEFAULTCALENDAR => array(
126 'label' => $translate->_('Default Calendar'),
127 'description' => $translate->_('The default calendar for invitations and new events'),
129 self::DEFAULTPERSISTENTFILTER => array(
130 'label' => $translate->_('Default Favorite'),
131 'description' => $translate->_('The default favorite which is loaded on calendar startup'),
133 self::NOTIFICATION_LEVEL => array(
134 'label' => $translate->_('Get Notification Emails'),
135 '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"'),
137 self::SEND_NOTIFICATION_OF_OWN_ACTIONS => array(
138 'label' => $translate->_('Send Notifications Emails of own Actions'),
139 'description' => $translate->_('Get notifications emails for actions you did yourself'),
141 self::DEFAULTALARM_ENABLED => array(
142 'label' => $translate->_('Enable Standard Alarm'),
143 'description' => $translate->_('New events get a standard alarm as defined below'),
145 self::DEFAULTALARM_MINUTESBEFORE => array(
146 'label' => $translate->_('Standard Alarm Time'),
147 'description' => $translate->_('Minutes before the event starts'),
149 self::DEFAULTATTENDEE_STRATEGY => array(
150 'label' => $translate->_('Default Attendee Strategy'),
151 'description' => $translate->_('Default Attendee Strategy for new events'),
155 return $prefDescriptions;
159 * Creates XML Data for a combobox
163 * @param string $default
166 protected function _createTimespanDataXML($start=0, $end=24)
168 $doc = new DomDocument('1.0');
169 $options = $doc->createElement('options');
170 $doc->appendChild($options);
172 $time = new Tinebase_DateTime('@0');
173 for ($i=$start; $i<=$end; $i++) {
175 $timeString = $time->format('H:i');
176 if ($i == $end && $timeString == '00:00') {
177 $timeString = '24:00';
179 $value = $doc->createElement('value');
180 $value->appendChild($doc->createTextNode($timeString));
181 $label = $doc->createElement('label');
182 $label->appendChild($doc->createTextNode($timeString)); // @todo l10n
184 $option = $doc->createElement('option');
185 $option->appendChild($value);
186 $option->appendChild($label);
187 $options->appendChild($option);
190 return $doc->saveXML();
194 * get preference defaults if no default is found in the database
196 * @param string $_preferenceName
197 * @param string|Tinebase_Model_User $_accountId
198 * @param string $_accountType
199 * @return Tinebase_Model_Preference
201 public function getApplicationPreferenceDefaults($_preferenceName, $_accountId = NULL, $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)
203 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
204 . ' Get default value for ' . $_preferenceName . ' of account id '. $_accountId);
206 $preference = $this->_getDefaultBasePreference($_preferenceName);
208 switch ($_preferenceName) {
209 case self::DAYSVIEW_STARTTIME:
210 $preference->value = '08:00';
211 $preference->options = $this->_createTimespanDataXML(0, 23);
213 case self::DAYSVIEW_ENDTIME:
214 $preference->value = '18:00';
215 $preference->options = $this->_createTimespanDataXML(1, 24);
217 case self::DAYSVIEW_DEFAULT_STARTTIME:
218 $preference->value = '08:00';
219 $preference->options = $this->_createTimespanDataXML(0, 23);
221 case self::DEFAULTCALENDAR:
222 $this->_getDefaultContainerPreferenceDefaults($preference, $_accountId);
224 case self::DEFAULTPERSISTENTFILTER:
225 $preference->value = Tinebase_PersistentFilter::getPreferenceValues('Calendar', $_accountId, "All my events");
227 case self::NOTIFICATION_LEVEL:
228 $translate = Tinebase_Translation::getTranslation($this->_application);
229 // need to put the translations strings here because they were not found in the xml below :/
230 // _('Never') _('On invitation and cancellation only') _('On time changes') _('On all updates but attendee responses') _('On attendee responses too')
231 $preference->value = Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE;
232 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
235 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_NONE . '</value>
236 <label>'. $translate->_('Never') . '</label>
239 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_INVITE_CANCEL . '</value>
240 <label>'. $translate->_('On invitation and cancellation only') . '</label>
243 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_RESCHEDULE . '</value>
244 <label>'. $translate->_('On time changes') . '</label>
247 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_EVENT_UPDATE . '</value>
248 <label>'. $translate->_('On all updates but attendee responses') . '</label>
251 <value>'. Calendar_Controller_EventNotifications::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE . '</value>
252 <label>'. $translate->_('On attendee responses too') . '</label>
256 case self::SEND_NOTIFICATION_OF_OWN_ACTIONS:
257 $preference->value = 0;
258 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
260 <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
263 case self::DEFAULTALARM_ENABLED:
264 $preference->value = 0;
265 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
267 <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
270 case self::DEFAULTALARM_MINUTESBEFORE:
271 $preference->value = 15;
272 $preference->options = '';
274 case self::DEFAULTATTENDEE_STRATEGY:
275 $preference->value = 'me';
276 $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
283 <label>Intelligent</label>
284 <value>intelligent</value>
287 <label>Calendar owner</label>
288 <value>calendarOwner</value>
291 <label>Filtered attendee</label>
292 <value>filteredAttendee</value>
297 throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');