1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.business;
35
36 import fr.paris.lutece.plugins.calendar.service.Utils;
37
38 import java.util.ArrayList;
39 import java.util.Date;
40 import java.util.GregorianCalendar;
41 import java.util.List;
42 import java.util.Locale;
43
44
45
46
47
48 public class MultiAgenda implements Agenda
49 {
50 private static final long serialVersionUID = 564170210812312845L;
51 private String _strName;
52 private String _strKeyName;
53 private List<Agenda> _listAgendas = new ArrayList<Agenda>( );
54
55
56
57
58 public MultiAgenda( )
59 {
60 }
61
62
63
64
65
66
67 public boolean hasEvents( String strDate )
68 {
69 for ( int i = 0; i < _listAgendas.size( ); i++ )
70 {
71 Agenda agenda = _listAgendas.get( i );
72
73 if ( agenda != null && agenda.hasEvents( strDate ) )
74 {
75 return true;
76 }
77 }
78
79 return false;
80 }
81
82
83
84
85
86
87 public List<Event> getEventsByDate( String strDate )
88 {
89 List<Event> list = new ArrayList<Event>( );
90 List<Event> listEvents = getEvents( );
91
92 for ( Event event : listEvents )
93 {
94 if ( Utils.getDate( event.getDate( ) ).equals( strDate ) )
95 {
96 list.add( event );
97 }
98 }
99
100 return list;
101 }
102
103
104
105
106
107 public List<Event> getEvents( )
108 {
109 List<Event> list = new ArrayList<Event>( );
110
111 for ( int i = 0; i < _listAgendas.size( ); i++ )
112 {
113 Agenda agenda = _listAgendas.get( i );
114 List<Event> listEvents = agenda.getEvents( );
115
116 for ( Event e : listEvents )
117 {
118 MultiAgendaEvent event = new MultiAgendaEvent( e, agenda.getKeyName( ) );
119 list.add( event );
120 }
121 }
122
123 return list;
124 }
125
126
127
128
129
130 public String getName( )
131 {
132 return _strName;
133 }
134
135
136
137
138
139 public void setName( String strName )
140 {
141 _strName = strName;
142 }
143
144
145
146
147
148 public void addAgenda( Agenda agenda )
149 {
150 _listAgendas.add( agenda );
151 }
152
153
154
155
156
157
158 public String getKeyName( )
159 {
160 return _strKeyName;
161 }
162
163
164
165
166
167
168 public void setKeyName( String strKeyName )
169 {
170 _strKeyName = strKeyName;
171 }
172
173
174
175
176
177 public List<Agenda> getAgendas( )
178 {
179 return _listAgendas;
180 }
181
182
183
184
185
186
187
188
189 public List<Event> getEventsByDate( Date dateBegin, Date dateEnd, Locale localeEnv )
190 {
191 List<Event> listEvents = getEvents( );
192 List<Event> list = new ArrayList<Event>( );
193
194 java.util.Calendar calendar = new GregorianCalendar( );
195 calendar.setTime( dateBegin );
196
197 java.util.Calendar calendar1 = new GregorianCalendar( );
198 calendar1.setTime( dateEnd );
199
200 while ( dateBegin.compareTo( dateEnd ) != 0 )
201 {
202 listEvents = getEventsByDate( Utils.getDate( calendar ) );
203
204 if ( listEvents != null )
205 {
206 for ( Event event : listEvents )
207 {
208 list.add( event );
209 }
210 }
211
212 calendar.add( java.util.Calendar.DATE, 1 );
213 }
214
215 return list;
216 }
217
218
219
220
221
222 public String[] getAgendaIds( )
223 {
224 String[] arrayAgendaIds = new String[_listAgendas.size( )];
225 if ( !_listAgendas.isEmpty( ) || !( _listAgendas.size( ) == 1 && _listAgendas.get( 0 ) == null ) )
226 {
227 for ( int i = 0; i < _listAgendas.size( ); i++ )
228 {
229 Agenda agenda = _listAgendas.get( i );
230 if ( agenda != null )
231 {
232 arrayAgendaIds[i] = agenda.getKeyName( );
233 }
234 }
235 return arrayAgendaIds;
236 }
237
238 return null;
239 }
240 }