summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-07-21 00:45:13 +0200
committerBart Visscher <bartv@thisnet.nl>2012-07-21 00:45:30 +0200
commit060b8865a4701cfe400e424765031c219330fa1a (patch)
tree3a0ac9c0e2f370f1fbcb0d584733b280651413ee /apps
parent1c30a97833235e585528da288d20663f65ac25b3 (diff)
downloadnextcloud-server-060b8865a4701cfe400e424765031c219330fa1a.tar.gz
nextcloud-server-060b8865a4701cfe400e424765031c219330fa1a.zip
DRY for getting calendar timezone setting
Diffstat (limited to 'apps')
-rw-r--r--apps/calendar/ajax/event/new.form.php2
-rw-r--r--apps/calendar/lib/app.php14
-rw-r--r--apps/calendar/lib/object.php2
-rw-r--r--apps/calendar/lib/search.php2
-rw-r--r--apps/tasks/ajax/addtask.php2
-rw-r--r--apps/tasks/ajax/edittask.php2
-rw-r--r--apps/tasks/ajax/gettasks.php2
-rw-r--r--apps/tasks/ajax/update_property.php4
-rw-r--r--apps/tasks/lib/app.php8
9 files changed, 24 insertions, 14 deletions
diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php
index 0b19e7e92f9..db04cdf2d49 100644
--- a/apps/calendar/ajax/event/new.form.php
+++ b/apps/calendar/ajax/event/new.form.php
@@ -27,7 +27,7 @@ if (!$end){
}
$start = new DateTime('@'.$start);
$end = new DateTime('@'.$end);
-$timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$timezone = OC_Calendar_App::getTimezone();
$start->setTimezone(new DateTimeZone($timezone));
$end->setTimezone(new DateTimeZone($timezone));
diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php
index 1a13f2958c0..29e5ab5b0c8 100644
--- a/apps/calendar/lib/app.php
+++ b/apps/calendar/lib/app.php
@@ -9,7 +9,7 @@
* This class manages our app actions
*/
OC_Calendar_App::$l10n = new OC_L10N('calendar');
-OC_Calendar_App::$tz = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+OC_Calendar_App::$tz = OC_Calendar_App::getTimezone();
class OC_Calendar_App{
const CALENDAR = 'calendar';
const EVENT = 'event';
@@ -282,7 +282,17 @@ class OC_Calendar_App{
public static function getWeekofMonth(){
return OC_Calendar_Object::getWeekofMonth(self::$l10n);
}
-
+
+ /**
+ * @return (string) $timezone as set by user or the default timezone
+ */
+ public static function getTimezone() {
+ return OCP\Config::getUserValue(OCP\User::getUser(),
+ 'calendar',
+ 'timezone',
+ date_default_timezone_get());
+ }
+
/**
* @brief checks the access for a calendar / an event
* @param (int) $id - id of the calendar / event
diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php
index 140542bf4fb..34676830205 100644
--- a/apps/calendar/lib/object.php
+++ b/apps/calendar/lib/object.php
@@ -856,7 +856,7 @@ class OC_Calendar_Object{
$vevent->setDateTime('DTSTART', $start, Sabre_VObject_Property_DateTime::DATE);
$vevent->setDateTime('DTEND', $end, Sabre_VObject_Property_DateTime::DATE);
}else{
- $timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$start = new DateTime($from.' '.$fromtime, $timezone);
$end = new DateTime($to.' '.$totime, $timezone);
diff --git a/apps/calendar/lib/search.php b/apps/calendar/lib/search.php
index 560330f65e9..551489672b9 100644
--- a/apps/calendar/lib/search.php
+++ b/apps/calendar/lib/search.php
@@ -12,7 +12,7 @@ class OC_Search_Provider_Calendar extends OC_Search_Provider{
}else{
$searchquery[] = $query;
}
- $user_timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+ $user_timezone = OC_Calendar_App::getTimezone();
$l = new OC_l10n('calendar');
foreach($calendars as $calendar){
$objects = OC_Calendar_Object::all($calendar['id']);
diff --git a/apps/tasks/ajax/addtask.php b/apps/tasks/ajax/addtask.php
index 188e179236a..d98fdbf3888 100644
--- a/apps/tasks/ajax/addtask.php
+++ b/apps/tasks/ajax/addtask.php
@@ -22,7 +22,7 @@ $request['description'] = null;
$vcalendar = OC_Task_App::createVCalendarFromRequest($request);
$id = OC_Calendar_Object::add($cid, $vcalendar->serialize());
-$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$user_timezone = OC_Calendar_App::getTimezone();
$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone);
OCP\JSON::success(array('task' => $task));
diff --git a/apps/tasks/ajax/edittask.php b/apps/tasks/ajax/edittask.php
index 77ecff13e66..e1475c7d45a 100644
--- a/apps/tasks/ajax/edittask.php
+++ b/apps/tasks/ajax/edittask.php
@@ -26,7 +26,7 @@ $tmpl->assign('details', $vcalendar->VTODO);
$tmpl->assign('id', $id);
$page = $tmpl->fetchPage();
-$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$user_timezone = OC_Calendar_App::getTimezone();
$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone);
OCP\JSON::success(array('data' => array( 'id' => $id, 'page' => $page, 'task' => $task )));
diff --git a/apps/tasks/ajax/gettasks.php b/apps/tasks/ajax/gettasks.php
index 011730d0a13..b6183d9cb65 100644
--- a/apps/tasks/ajax/gettasks.php
+++ b/apps/tasks/ajax/gettasks.php
@@ -11,7 +11,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('tasks');
$calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser(), true);
-$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$user_timezone = OC_Calendar_App::getTimezone();
$tasks = array();
foreach( $calendars as $calendar ){
diff --git a/apps/tasks/ajax/update_property.php b/apps/tasks/ajax/update_property.php
index f47040a77d4..679cfdefe48 100644
--- a/apps/tasks/ajax/update_property.php
+++ b/apps/tasks/ajax/update_property.php
@@ -39,7 +39,7 @@ switch($property) {
$type = null;
if ($due != 'false') {
try {
- $timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$due = new DateTime('@'.$due);
$due->setTimezone($timezone);
@@ -64,6 +64,6 @@ switch($property) {
}
OC_Calendar_Object::edit($id, $vcalendar->serialize());
-$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$user_timezone = OC_Calendar_App::getTimezone();
$task_info = OC_Task_App::arrayForJSON($id, $vtodo, $user_timezone);
OCP\JSON::success(array('data' => $task_info));
diff --git a/apps/tasks/lib/app.php b/apps/tasks/lib/app.php
index 7c23bbc1f49..a97c6b95d1d 100644
--- a/apps/tasks/lib/app.php
+++ b/apps/tasks/lib/app.php
@@ -82,7 +82,7 @@ class OC_Task_App {
}
try {
- $timezone = OCP\Config::getUserValue(OCP\User::getUser(), "calendar", "timezone", "Europe/London");
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
new DateTime($request['due'], $timezone);
} catch (Exception $e) {
@@ -94,7 +94,7 @@ class OC_Task_App {
}
if ($request['percent_complete'] == 100 && !empty($request['completed'])) {
try {
- $timezone = OCP\Config::getUserValue(OCP\User::getUser(), "calendar", "timezone", "Europe/London");
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
new DateTime($request['completed'], $timezone);
} catch (Exception $e) {
@@ -147,7 +147,7 @@ class OC_Task_App {
$vtodo->setString('PRIORITY', $priority);
if ($due) {
- $timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$due = new DateTime($due, $timezone);
$vtodo->setDateTime('DUE', $due);
@@ -176,7 +176,7 @@ class OC_Task_App {
$completed = null;
}
if ($completed) {
- $timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+ $timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$completed = new DateTime($completed, $timezone);
$vtodo->setDateTime('COMPLETED', $completed);