PhoenixLecture  2.0.0
Set of tools to make lectures
ptimetable_invitation.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include <iomanip>
8 #include <time.h>
9 
10 #include "platexobj_rawtext.h"
11 
12 #include "ptimetable_invitation.h"
13 
14 
16 
20 PString ptimetable_beginInvitation(const PString & name, const PString & motif){
21  PString body("");
22  body += "BEGIN:VCALENDAR\n";
23  body += "VERSION:2.0\n";
24  body += "PRODID:-//"+name+"//"+motif+"/\n";
25  return body;
26 }
27 
29 
32  return "END:VCALENDAR\n\n";
33 }
34 
36 
41  std::stringstream timeStr;
42  timeStr << date.getYear() << std::setfill('0') << std::setw(2) << date.getMonth() << std::setfill('0') << std::setw(2) << date.getDay();
43  timeStr << "T" << std::setfill('0') << std::setw(2) << texTime.getHour() << std::setfill('0') << std::setw(2) << texTime.getMinute() << "00";
44  return timeStr.str();
45 }
46 
48 
51  time_t timestamp = time(NULL);
52  struct tm * currentDate = localtime(&timestamp);
53  std::stringstream timeStr;
54  timeStr << (currentDate->tm_year + 1900) << std::setfill('0') << std::setw(2) << (currentDate->tm_mon + 1) << std::setfill('0') << std::setw(2) << currentDate->tm_mday;
55  timeStr << "T" << std::setfill('0') << std::setw(2) << (currentDate->tm_hour - currentDate->tm_gmtoff/3600) << std::setfill('0') << std::setw(2) << currentDate->tm_min << "00";
56  return timeStr.str();
57 }
58 
60 
64 PString ptimetable_blockToEvent(size_t & counter, const PTimeTableBlock & block){
65  if(block.getVecSpeaker().size() == 0lu){return "";}
66  PString body(""), currentTimeStamp(ptimetable_currentTimeToCalendarTime());
67  body += "BEGIN:VEVENT\n";
68  body += "CLASS:PUBLIC\n";
69  body += "DTSTAMP:"+currentTimeStamp+"\n";
70 
71  std::stringstream uidStr;
72  uidStr << std::setfill('0') << std::setw(4) << counter;
73  ++counter;
74  body += "UID:TH8WMR_PNR"+uidStr.str()+"_"+currentTimeStamp+"\n";
75  body += "DTSTART;TZID=Europe/Paris:"+ptimetable_dateTimeToCalendarTime(block.getDate(), block.getBeginTime())+"\n";
76  body += "DTEND;TZID=Europe/Paris:"+ptimetable_dateTimeToCalendarTime(block.getDate(), block.getEndTime())+"\n";
77  body += "SUMMARY:"+platexobj_rawtext(block.getTitle())+"\n";
78  body += "LOCATION:"+platexobj_rawtext(block.getLocation())+"\n";
79  body += "DESCRIPTION:"+platexobj_rawtext(block.getTitle())+"\\n\n";
80  if(block.getMainUrl() != ""){
81  body += " "+block.getMainUrl() + "redirect.html?label=sec_"+block.getInvitation()+"\\n\n";
82  }
83  body += "BEGIN:VALARM\n";
84  body += "TRIGGER:-PT10M\n";
85  body += "ACTION:DISPLAY\n";
86  body += "DESCRIPTION:Reminder\n";
87  body += "END:VALARM\n";
88  body += "END:VEVENT\n";
89  return body;
90 }
91 
93 
97 PString ptimetable_dayToVecEvent(size_t & counter, const TexDay & day){
98  PString body("");
99  const std::map<PString, PTimeTableBlock> & mapBlock = day.mapBlock;
100  for(std::map<PString, PTimeTableBlock>::const_iterator it(mapBlock.begin()); it != mapBlock.end(); ++it){
101  body += ptimetable_blockToEvent(counter, it->second);
102  }
103  return body;
104 }
105 
107 
111 PString ptimetable_weekToVecEvent(size_t & counter, const TexWeek & week){
112  PString body("");
113  const std::map<PString, TexDay> & mapDay = week.mapDay;
114  for(std::map<PString, TexDay>::const_iterator it(mapDay.begin()); it != mapDay.end(); ++it){
115  body += ptimetable_dayToVecEvent(counter, it->second);
116  }
117  return body;
118 }
119 
121 
125 PString ptimetable_timetableToVecEvent(size_t & counter, const TexTimetable & texTimeTable){
126  PString body("");
127  const std::vector<TexWeek> & vecWeek = texTimeTable.vecWeek;
128  for(std::vector<TexWeek>::const_iterator it(vecWeek.begin()); it != vecWeek.end(); ++it){
129  body += ptimetable_weekToVecEvent(counter, *it);
130  }
131  return body;
132 }
133 
135 
139 bool ptimetable_createInvitation(const PPath & outputDirectory, const TexTimetable & timetable){
140  bool b(true);
141  size_t counter(0lu);
142  PString bevt(ptimetable_beginInvitation("PhoenixTex2Html", timetable.invitation)), eevt(ptimetable_endInvitation());
143  b &= outputDirectory.createDirectory();
144  const std::vector<TexWeek> & vecWeek = timetable.vecWeek;
145  for(std::vector<TexWeek>::const_iterator itWeek(vecWeek.begin()); itWeek != vecWeek.end(); ++itWeek){
146  const std::map<PString, TexDay> & mapDay = itWeek->mapDay;
147  for(std::map<PString, TexDay>::const_iterator itDay(mapDay.begin()); itDay != mapDay.end(); ++itDay){
148  const std::map<PString, PTimeTableBlock> & mapBlock = itDay->second.mapBlock;
149  for(std::map<PString, PTimeTableBlock>::const_iterator it(mapBlock.begin()); it != mapBlock.end(); ++it){
150  if(it->second.getInvitation() != ""){
151  b &= PPath(outputDirectory + PPath("/") + it->second.getInvitation() + PPath(".ics")).saveFileContent(
152  bevt+ptimetable_blockToEvent(counter, it->second)+eevt);
153  }
154  }
155  if(itDay->second.invitation != ""){
156  b &= PPath(outputDirectory + PPath("/") + itDay->second.invitation + PPath(".ics")).saveFileContent(
157  bevt+ptimetable_dayToVecEvent(counter, itDay->second)+eevt);
158  }
159  }
160  if(itWeek->invitation != ""){
161  b &= PPath(outputDirectory + PPath("/") + itWeek->invitation + PPath(".ics")).saveFileContent(
162  bevt+ptimetable_weekToVecEvent(counter, *itWeek)+eevt);
163  }
164  }
165  if(timetable.invitation != ""){
166  b &= PPath(outputDirectory + PPath("/") + timetable.invitation + PPath(".ics")).saveFileContent(
167  bevt+ptimetable_timetableToVecEvent(counter, timetable)+eevt);
168  }
169  return b;
170 }
171 
173 
178 bool ptimetable_createFullWeekDayInvitation(size_t & counter, const PPath & outputDirectory, const TexTimetable & timetable){
179  bool b(true);
180  PString bevt(ptimetable_beginInvitation("PhoenixTex2Html", timetable.invitation)), eevt(ptimetable_endInvitation());
181  b &= outputDirectory.createDirectory();
182  const std::vector<TexWeek> & vecWeek = timetable.vecWeek;
183  for(std::vector<TexWeek>::const_iterator itWeek(vecWeek.begin()); itWeek != vecWeek.end(); ++itWeek){
184  const std::map<PString, TexDay> & mapDay = itWeek->mapDay;
185  for(std::map<PString, TexDay>::const_iterator itDay(mapDay.begin()); itDay != mapDay.end(); ++itDay){
186  if(itDay->second.invitation != ""){
187  b &= PPath(outputDirectory + PPath("/") + itDay->second.invitation + PPath(".ics")).saveFileContent(
188  bevt+ptimetable_dayToVecEvent(counter, itDay->second)+eevt);
189  }
190  }
191  if(itWeek->invitation != ""){
192  b &= PPath(outputDirectory + PPath("/") + itWeek->invitation + PPath(".ics")).saveFileContent(
193  bevt+ptimetable_weekToVecEvent(counter, *itWeek)+eevt);
194  }
195  }
196  if(timetable.invitation != ""){
197  b &= PPath(outputDirectory + PPath("/") + timetable.invitation + PPath(".ics")).saveFileContent(
198  bevt+ptimetable_timetableToVecEvent(counter, timetable)+eevt);
199  }
200  return b;
201 }
202 
204 
207 void ptimetable_createMapInviteBlock(std::map<PString, std::vector<PTimeTableBlock> > & mapInviteVecBlock, const TexTimetable & timetable){
208  const std::vector<TexWeek> & vecWeek = timetable.vecWeek;
209  for(std::vector<TexWeek>::const_iterator itWeek(vecWeek.begin()); itWeek != vecWeek.end(); ++itWeek){
210  const std::map<PString, TexDay> & mapDay = itWeek->mapDay;
211  for(std::map<PString, TexDay>::const_iterator itDay(mapDay.begin()); itDay != mapDay.end(); ++itDay){
212  const std::map<PString, PTimeTableBlock> & mapBlock = itDay->second.mapBlock;
213  for(std::map<PString, PTimeTableBlock>::const_iterator it(mapBlock.begin()); it != mapBlock.end(); ++it){
214  if(it->second.getInvitation() != ""){
215  mapInviteVecBlock[it->second.getInvitation()].push_back(it->second);
216  }
217  }
218  }
219  }
220 }
221 
223 
230 bool ptimetable_saveMapInviteBlock(size_t & counter, const PPath & outputDirectory,
231  const std::map<PString, std::vector<PTimeTableBlock> > & mapInviteVecBlock,
232  const PString & bevt, const PString & eevt)
233 {
234  bool b(true);
235  for(std::map<PString, std::vector<PTimeTableBlock> >::const_iterator itInvite(mapInviteVecBlock.begin()); itInvite != mapInviteVecBlock.end(); ++itInvite){
236  PString fullInvitation(bevt);
237  const std::vector<PTimeTableBlock> & vecBlock = itInvite->second;
238  for(std::vector<PTimeTableBlock>::const_iterator it(vecBlock.begin()); it != vecBlock.end(); ++it){
239  fullInvitation += ptimetable_blockToEvent(counter, *it);
240  }
241  fullInvitation += eevt;
242  PPath outputFile(outputDirectory + PPath("/") + itInvite->first + PPath(".ics"));
243  b &= outputFile.saveFileContent(fullInvitation);
244  }
245  return b;
246 }
247 
249 
253 bool ptimetable_createInvitationMergBlock(const PPath & outputDirectory, const TexTimetable & timetable){
254  std::map<PString, std::vector<PTimeTableBlock>> mapInviteVecBlock;
255  ptimetable_createMapInviteBlock(mapInviteVecBlock, timetable);
256 
257  bool b(true);
258  PString bevt(ptimetable_beginInvitation("PhoenixTex2Html", timetable.invitation)), eevt(ptimetable_endInvitation());
259  b &= outputDirectory.createDirectory();
260  size_t counter(0lu);
261  b &= ptimetable_saveMapInviteBlock(counter, outputDirectory, mapInviteVecBlock, bevt, eevt);
262  b &= ptimetable_createFullWeekDayInvitation(counter, outputDirectory, timetable);
263  return b;
264 }
265 
266 
Describes a date.
Definition: PTimeTable.h:58
size_t getMonth() const
Gets the month of the PLatexDate.
Definition: PTimeTable.cpp:245
size_t getYear() const
Gets the year of the PLatexDate.
Definition: PTimeTable.cpp:231
size_t getDay() const
Gets the day of the PLatexDate.
Definition: PTimeTable.cpp:259
Describes a date.
Definition: PTimeTable.h:86
size_t getMinute() const
Gets the minute of the PLatexTime.
Definition: PTimeTable.cpp:343
size_t getHour() const
Gets the hour of the PLatexTime.
Definition: PTimeTable.cpp:329
Path of a directory or a file.
Definition: PPath.h:17
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
bool createDirectory(mode_t mode=0755) const
Create the current directory.
Definition: PPath.cpp:331
Extends the std::string.
Definition: PString.h:16
Block of a Timetable.
Definition: PTimeTable.h:109
const PLatexObj & getTitle() const
Gets the title of the PTimeTableBlock.
Definition: PTimeTable.cpp:516
const PLatexDate & getDate() const
Gets the date of the PTimeTableBlock.
Definition: PTimeTable.cpp:586
const PLatexObj & getLocation() const
Gets the location of the PTimeTableBlock.
Definition: PTimeTable.cpp:656
const PLatexTime & getEndTime() const
Gets the endTime of the PTimeTableBlock.
Definition: PTimeTable.cpp:614
const PString & getInvitation() const
Gets the invitation of the PTimeTableBlock.
Definition: PTimeTable.cpp:558
const PLatexTime & getBeginTime() const
Gets the beginTime of the PTimeTableBlock.
Definition: PTimeTable.cpp:600
const PString & getMainUrl() const
Gets the mainUrl of the PTimeTableBlock.
Definition: PTimeTable.cpp:502
const std::vector< PString > & getVecSpeaker() const
Gets the vecSpeaker of the PTimeTableBlock.
Definition: PTimeTable.cpp:544
PString platexobj_rawtext(const std::vector< PLatexObj > &vecObj)
Convert a PLatexObj in text.
PString ptimetable_blockToEvent(size_t &counter, const PTimeTableBlock &block)
Convert a block into a event calendar.
void ptimetable_createMapInviteBlock(std::map< PString, std::vector< PTimeTableBlock > > &mapInviteVecBlock, const TexTimetable &timetable)
Create the map of invitation blocks.
PString ptimetable_endInvitation()
Ends an invitation.
PString ptimetable_dayToVecEvent(size_t &counter, const TexDay &day)
Convert a day into a event calendar.
PString ptimetable_weekToVecEvent(size_t &counter, const TexWeek &week)
Convert a week into a event calendar.
bool ptimetable_saveMapInviteBlock(size_t &counter, const PPath &outputDirectory, const std::map< PString, std::vector< PTimeTableBlock > > &mapInviteVecBlock, const PString &bevt, const PString &eevt)
Create the map of invitation blocks.
PString ptimetable_currentTimeToCalendarTime()
Convert the current time into the calendar time.
PString ptimetable_beginInvitation(const PString &name, const PString &motif)
Begins an invitation.
bool ptimetable_createInvitationMergBlock(const PPath &outputDirectory, const TexTimetable &timetable)
Create invitations but merge blocks with the same invitation.
bool ptimetable_createFullWeekDayInvitation(size_t &counter, const PPath &outputDirectory, const TexTimetable &timetable)
Create invitations for timetable, weeks and days.
PString ptimetable_dateTimeToCalendarTime(const PLatexDate &date, const PLatexTime &texTime)
Convert the given date and time into calendar time.
bool ptimetable_createInvitation(const PPath &outputDirectory, const TexTimetable &timetable)
Create an invitation.
PString ptimetable_timetableToVecEvent(size_t &counter, const TexTimetable &texTimeTable)
Convert a timetable into a event calendar.
Day of the week.
Definition: TexTimetable.h:14
std::map< PString, PTimeTableBlock > mapBlock
Map of the block of a day (time format hour:minute)
Definition: TexTimetable.h:20
Full latex timetable.
Definition: TexTimetable.h:38
PString invitation
Invitation of the full event.
Definition: TexTimetable.h:40
std::vector< TexWeek > vecWeek
Vector of week.
Definition: TexTimetable.h:42
Week of the timetable.
Definition: TexTimetable.h:24
std::map< PString, TexDay > mapDay
Map of hte day in the week (date format: year-month-day)
Definition: TexTimetable.h:32