]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalWeekView.m
ab520323a3b4fd3719e765e446c4e863fa733161
[scalable-opengroupware.org] / UI / Scheduler / UIxCalWeekView.m
1 /* UIxCalWeekView.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSKeyValueCoding.h>
26 #import <Foundation/NSString.h>
27
28 #import <EOControl/EOQualifier.h>
29
30 #import <NGExtensions/NSCalendarDate+misc.h>
31
32 #include "UIxCalWeekView.h"
33
34 @implementation UIxCalWeekView
35
36 - (NSCalendarDate *) startDate
37 {
38   return [[[super startDate] mondayOfWeek] beginOfDay];
39 }
40
41 - (NSCalendarDate *) endDate
42 {
43   unsigned offset;
44     
45   if([self shouldDisplayWeekend])
46     offset = 7;
47   else
48     offset = 5;
49
50   return [[[self startDate] dateByAddingYears:0 months:0 days:offset
51                             hours:0 minutes:0 seconds:0]
52                             endOfDay];
53 }
54
55 - (NSArray *) appointments
56 {
57   return [self fetchCoreAppointmentsInfos];
58 }
59
60 /* URLs */
61
62 - (NSDictionary *) weekBeforePrevWeekQueryParameters
63 {
64   return [self _dateQueryParametersWithOffset: -14];
65 }
66
67 - (NSDictionary *) prevWeekQueryParameters
68 {
69   return [self _dateQueryParametersWithOffset: -7];
70 }
71
72 - (NSDictionary *) nextWeekQueryParameters
73 {
74   return [self _dateQueryParametersWithOffset: 7];
75 }
76
77 - (NSDictionary *) weekAfterNextWeekQueryParameters
78 {
79   return [self _dateQueryParametersWithOffset: 14];
80 }
81
82 - (NSString *) _weekNumberWithOffsetFromToday: (int) offset
83 {
84   NSCalendarDate *date;
85   NSString *format;
86
87   date = [[self startDate] dateByAddingYears: 0 months: 0 days: (offset * 7)
88                            hours:0 minutes: 0 seconds: 0];
89   format = [self labelForKey: @"Week %d"];
90
91   return [NSString stringWithFormat: format, [date weekOfYear]];
92 }
93
94 - (NSString *) weekBeforeLastWeekName
95 {
96   return [self _weekNumberWithOffsetFromToday: -2];
97 }
98
99 - (NSString *) lastWeekName
100 {
101   return [self _weekNumberWithOffsetFromToday: -1];
102 }
103
104 - (NSString *) currentWeekName
105 {
106   return [self _weekNumberWithOffsetFromToday: 0];
107 }
108
109 - (NSString *) nextWeekName
110 {
111   return [self _weekNumberWithOffsetFromToday: 1];
112 }
113
114 - (NSString *) weekAfterNextWeekName
115 {
116   return [self _weekNumberWithOffsetFromToday: 2];
117 }
118
119 @end /* UIxCalWeekView */