PhoenixLecture  2.0.0
Set of tools to make lectures
ptimetable_invitation.cpp File Reference
#include <iomanip>
#include <time.h>
#include "platexobj_rawtext.h"
#include "ptimetable_invitation.h"
+ Include dependency graph for ptimetable_invitation.cpp:

Go to the source code of this file.

Functions

PString ptimetable_beginInvitation (const PString &name, const PString &motif)
 Begins an invitation. More...
 
PString ptimetable_blockToEvent (size_t &counter, const PTimeTableBlock &block)
 Convert a block into a event calendar. More...
 
bool ptimetable_createFullWeekDayInvitation (size_t &counter, const PPath &outputDirectory, const TexTimetable &timetable)
 Create invitations for timetable, weeks and days. More...
 
bool ptimetable_createInvitation (const PPath &outputDirectory, const TexTimetable &timetable)
 Create an invitation. More...
 
bool ptimetable_createInvitationMergBlock (const PPath &outputDirectory, const TexTimetable &timetable)
 Create invitations but merge blocks with the same invitation. More...
 
void ptimetable_createMapInviteBlock (std::map< PString, std::vector< PTimeTableBlock > > &mapInviteVecBlock, const TexTimetable &timetable)
 Create the map of invitation blocks. More...
 
PString ptimetable_currentTimeToCalendarTime ()
 Convert the current time into the calendar time. More...
 
PString ptimetable_dateTimeToCalendarTime (const PLatexDate &date, const PLatexTime &texTime)
 Convert the given date and time into calendar time. More...
 
PString ptimetable_dayToVecEvent (size_t &counter, const TexDay &day)
 Convert a day into a event calendar. More...
 
PString ptimetable_endInvitation ()
 Ends an invitation. More...
 
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. More...
 
PString ptimetable_timetableToVecEvent (size_t &counter, const TexTimetable &texTimeTable)
 Convert a timetable into a event calendar. More...
 
PString ptimetable_weekToVecEvent (size_t &counter, const TexWeek &week)
 Convert a week into a event calendar. More...
 

Function Documentation

◆ ptimetable_beginInvitation()

PString ptimetable_beginInvitation ( const PString name,
const PString motif 
)

Begins an invitation.

Parameters
name: name of entity which create this invitation
motif: motif of the invitation
Returns
begining of the invitation

Definition at line 20 of file ptimetable_invitation.cpp.

20  {
21  PString body("");
22  body += "BEGIN:VCALENDAR\n";
23  body += "VERSION:2.0\n";
24  body += "PRODID:-//"+name+"//"+motif+"/\n";
25  return body;
26 }
Extends the std::string.
Definition: PString.h:16

Referenced by ptimetable_createFullWeekDayInvitation(), ptimetable_createInvitation(), and ptimetable_createInvitationMergBlock().

+ Here is the caller graph for this function:

◆ ptimetable_blockToEvent()

PString ptimetable_blockToEvent ( size_t &  counter,
const PTimeTableBlock block 
)

Convert a block into a event calendar.

Parameters
[out]counter: counter of block to make sure UID is unique
block: PTimeTableBlock to be converted
Returns
corresponding event calendar

Definition at line 64 of file ptimetable_invitation.cpp.

64  {
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 }
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_currentTimeToCalendarTime()
Convert the current time into the calendar time.
PString ptimetable_dateTimeToCalendarTime(const PLatexDate &date, const PLatexTime &texTime)
Convert the given date and time into calendar time.

References PTimeTableBlock::getBeginTime(), PTimeTableBlock::getDate(), PTimeTableBlock::getEndTime(), PTimeTableBlock::getInvitation(), PTimeTableBlock::getLocation(), PTimeTableBlock::getMainUrl(), PTimeTableBlock::getTitle(), PTimeTableBlock::getVecSpeaker(), platexobj_rawtext(), ptimetable_currentTimeToCalendarTime(), and ptimetable_dateTimeToCalendarTime().

Referenced by ptimetable_createInvitation(), ptimetable_dayToVecEvent(), and ptimetable_saveMapInviteBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_createFullWeekDayInvitation()

bool ptimetable_createFullWeekDayInvitation ( size_t &  counter,
const PPath outputDirectory,
const TexTimetable timetable 
)

Create invitations for timetable, weeks and days.

Parameters
[out]counter: counter of block to make sure UID is unique
outputDirectory: output directory where to put all generated invitations
timetable: TexTimetable to be used to generate invitations
Returns
true on success, false otherwise

Definition at line 178 of file ptimetable_invitation.cpp.

178  {
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 }
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
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.
PString ptimetable_beginInvitation(const PString &name, const PString &motif)
Begins an invitation.
PString ptimetable_timetableToVecEvent(size_t &counter, const TexTimetable &texTimeTable)
Convert a timetable into a event calendar.
PString invitation
Invitation of the full event.
Definition: TexTimetable.h:40
std::vector< TexWeek > vecWeek
Vector of week.
Definition: TexTimetable.h:42

References PPath::createDirectory(), TexTimetable::invitation, ptimetable_beginInvitation(), ptimetable_dayToVecEvent(), ptimetable_endInvitation(), ptimetable_timetableToVecEvent(), ptimetable_weekToVecEvent(), PPath::saveFileContent(), and TexTimetable::vecWeek.

Referenced by ptimetable_createInvitationMergBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_createInvitation()

bool ptimetable_createInvitation ( const PPath outputDirectory,
const TexTimetable timetable 
)

Create an invitation.

Parameters
outputDirectory: output directory where to put all generated invitations
timetable: TexTimetable to be used to generate invitations
Returns
true on success, false otherwise

Definition at line 139 of file ptimetable_invitation.cpp.

139  {
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 }
PString ptimetable_blockToEvent(size_t &counter, const PTimeTableBlock &block)
Convert a block into a event calendar.

References PPath::createDirectory(), TexTimetable::invitation, ptimetable_beginInvitation(), ptimetable_blockToEvent(), ptimetable_dayToVecEvent(), ptimetable_endInvitation(), ptimetable_timetableToVecEvent(), ptimetable_weekToVecEvent(), PPath::saveFileContent(), and TexTimetable::vecWeek.

+ Here is the call graph for this function:

◆ ptimetable_createInvitationMergBlock()

bool ptimetable_createInvitationMergBlock ( const PPath outputDirectory,
const TexTimetable timetable 
)

Create invitations but merge blocks with the same invitation.

Parameters
outputDirectory: output directory where to put all generated invitations
timetable: TexTimetable to be used to generate invitations
Returns
true on success, false otherwise

Definition at line 253 of file ptimetable_invitation.cpp.

253  {
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 }
void ptimetable_createMapInviteBlock(std::map< PString, std::vector< PTimeTableBlock > > &mapInviteVecBlock, const TexTimetable &timetable)
Create the map of invitation blocks.
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.
bool ptimetable_createFullWeekDayInvitation(size_t &counter, const PPath &outputDirectory, const TexTimetable &timetable)
Create invitations for timetable, weeks and days.

References PPath::createDirectory(), TexTimetable::invitation, ptimetable_beginInvitation(), ptimetable_createFullWeekDayInvitation(), ptimetable_createMapInviteBlock(), ptimetable_endInvitation(), and ptimetable_saveMapInviteBlock().

Referenced by ptimetable_tex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_createMapInviteBlock()

void ptimetable_createMapInviteBlock ( std::map< PString, std::vector< PTimeTableBlock > > &  mapInviteVecBlock,
const TexTimetable timetable 
)

Create the map of invitation blocks.

Parameters
[out]mapInviteVecBlock: map of vector of blocks sorted by invitation
timetable: TexTimetable to be used to generate invitations

Definition at line 207 of file ptimetable_invitation.cpp.

207  {
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 }

References TexTimetable::vecWeek.

Referenced by ptimetable_createInvitationMergBlock().

+ Here is the caller graph for this function:

◆ ptimetable_currentTimeToCalendarTime()

PString ptimetable_currentTimeToCalendarTime ( )

Convert the current time into the calendar time.

Returns
corresponding calendar time

Definition at line 50 of file ptimetable_invitation.cpp.

50  {
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 }

Referenced by ptimetable_blockToEvent().

+ Here is the caller graph for this function:

◆ ptimetable_dateTimeToCalendarTime()

PString ptimetable_dateTimeToCalendarTime ( const PLatexDate date,
const PLatexTime texTime 
)

Convert the given date and time into calendar time.

Parameters
date: date of the event
texTime: time of the event
Returns
corresponding calendar time

Definition at line 40 of file ptimetable_invitation.cpp.

40  {
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 }
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
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

References PLatexDate::getDay(), PLatexTime::getHour(), PLatexTime::getMinute(), PLatexDate::getMonth(), and PLatexDate::getYear().

Referenced by ptimetable_blockToEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_dayToVecEvent()

PString ptimetable_dayToVecEvent ( size_t &  counter,
const TexDay day 
)

Convert a day into a event calendar.

Parameters
[out]counter: counter of block to make sure UID is unique
day: TexDay to be converted
Returns
corresponding event calendar

Definition at line 97 of file ptimetable_invitation.cpp.

97  {
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 }
std::map< PString, PTimeTableBlock > mapBlock
Map of the block of a day (time format hour:minute)
Definition: TexTimetable.h:20

References TexDay::mapBlock, and ptimetable_blockToEvent().

Referenced by ptimetable_createFullWeekDayInvitation(), ptimetable_createInvitation(), and ptimetable_weekToVecEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_endInvitation()

PString ptimetable_endInvitation ( )

Ends an invitation.

Returns
end of the invitation

Definition at line 31 of file ptimetable_invitation.cpp.

31  {
32  return "END:VCALENDAR\n\n";
33 }

Referenced by ptimetable_createFullWeekDayInvitation(), ptimetable_createInvitation(), and ptimetable_createInvitationMergBlock().

+ Here is the caller graph for this function:

◆ ptimetable_saveMapInviteBlock()

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.

Parameters
[out]counter: counter of block to make sure UID is unique
outputDirectory: output directory where to put all generated invitations
mapInviteVecBlock: map of vector of blocks sorted by invitation to be saved
bevt: begining of invitations
eevt: anding of invitations
Returns
true on success, false otherwise

Definition at line 230 of file ptimetable_invitation.cpp.

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 }

References ptimetable_blockToEvent(), and PPath::saveFileContent().

Referenced by ptimetable_createInvitationMergBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_timetableToVecEvent()

PString ptimetable_timetableToVecEvent ( size_t &  counter,
const TexTimetable texTimeTable 
)

Convert a timetable into a event calendar.

Parameters
[out]counter: counter of block to make sure UID is unique
texTimeTable: TexTimetable to be converted
Returns
corresponding event calendar

Definition at line 125 of file ptimetable_invitation.cpp.

125  {
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 }

References ptimetable_weekToVecEvent(), and TexTimetable::vecWeek.

Referenced by ptimetable_createFullWeekDayInvitation(), and ptimetable_createInvitation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptimetable_weekToVecEvent()

PString ptimetable_weekToVecEvent ( size_t &  counter,
const TexWeek week 
)

Convert a week into a event calendar.

Parameters
[out]counter: counter of block to make sure UID is unique
week: TexWeek to be converted
Returns
corresponding event calendar

Definition at line 111 of file ptimetable_invitation.cpp.

111  {
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 }
std::map< PString, TexDay > mapDay
Map of hte day in the week (date format: year-month-day)
Definition: TexTimetable.h:32

References TexWeek::mapDay, and ptimetable_dayToVecEvent().

Referenced by ptimetable_createFullWeekDayInvitation(), ptimetable_createInvitation(), and ptimetable_timetableToVecEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: