summaryrefslogtreecommitdiff
path: root/server/src/journal_commit.cc
diff options
context:
space:
mode:
authordeva <deva>2009-05-15 11:52:52 +0000
committerdeva <deva>2009-05-15 11:52:52 +0000
commitba614b9d61f9eb7407108d7836177aa0608823e6 (patch)
treed71cfa6bcd472ed6cc41a69f015d16a4cb9326eb /server/src/journal_commit.cc
parent124384095470c9b2cfb046ff931152583c6df65a (diff)
Journal entries are now committed in the order in which they appear in the course description (the template). Misspelled 'macroes' have been corrected to 'macros' in template.h and all affected files.
Diffstat (limited to 'server/src/journal_commit.cc')
-rw-r--r--server/src/journal_commit.cc38
1 files changed, 32 insertions, 6 deletions
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc
index accf839..f74e54e 100644
--- a/server/src/journal_commit.cc
+++ b/server/src/journal_commit.cc
@@ -200,6 +200,28 @@ JournalWriter::JournalWriter(std::string host, unsigned short int port)
void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
std::string resume, std::string course)
{
+ TemplateParser tp(course);
+ tp.parse();
+ Template *templ = tp.getTemplate();
+
+ size_t index = 0;
+ std::vector< Macro >::iterator i = templ->course.macros.begin();
+ while(i != templ->course.macros.end()) {
+ Macro &m = *i;
+ if(commit.macro == m.attributes["name"]) break;
+ index++;
+ i++;
+ }
+
+ if(index >= templ->course.macros.size()) {
+ PRACRO_ERR(journal, "Could not find macro %s in course %s\n",
+ commit.macro.c_str(), course.c_str());
+ // return;
+ } else {
+ PRACRO_DEBUG(journal, "Found macro %s as index %u in course %s\n",
+ commit.macro.c_str(), index, course.c_str());
+ }
+
// First run - initialize username and cpr.
if(currentuser == "" && entrylist.size() == 0) currentuser = transaction.user;
if(currentcpr == "" && entrylist.size() == 0) currentcpr = transaction.cpr;
@@ -208,9 +230,6 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
// Add the course resume as the header (ie. first entry) of the journal entry.
if(entrylist.size() == 0 && course != "") {
- TemplateParser tp(course);
- tp.parse();
- Template *templ = tp.getTemplate();
std::string course_resume = templ->course.attributes["resume"];
PRACRO_DEBUG(journal, "CourseResume: %s\n", course_resume.c_str());
@@ -219,7 +238,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
ResumeEntry re;
re.resume = course_resume;
re.macro = "course_header";
- entrylist.push_back(re);
+ entrylist[-1] = re; // Make sure it comes first.
}
}
@@ -233,6 +252,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
std::string r = stripTrailingWhitepace(addNewlines(resume, 60));
std::string m = commit.macro;
+ /*
// If macro already exists, overwrite with this entry, otherwise, just add it
int idx = -1;
std::vector< ResumeEntry >::iterator i = entrylist.begin();
@@ -252,6 +272,12 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
re.macro = m;
entrylist.push_back(re);
}
+ */
+
+ ResumeEntry re;
+ re.resume = r;
+ re.macro = m;
+ entrylist[index] = re;
}
void JournalWriter::commit()
@@ -259,11 +285,11 @@ void JournalWriter::commit()
std::string resume;
// Iterate through all resumes, and create a string containing them all.
- std::vector< ResumeEntry >::iterator i = entrylist.begin();
+ std::map< int, ResumeEntry >::iterator i = entrylist.begin();
while(i != entrylist.end()) {
if(resume != "") resume += "\n\n";
// resume += i->macro + "\n";
- resume += i->resume;
+ resume += i->second.resume;
i++;
}