Go to the documentation of this file.00001 #include <rms/appointment.hpp>
00002 #include <sstream>
00003 #include <cstdlib>
00004
00005 using namespace std;
00006 using namespace librms;
00007
00008 appointment::appointment(rms *client, unsigned int id, unsigned int user_id, unsigned int slot_id, string created, string modified)
00009 :
00010 created_(created), modified_(modified)
00011 {
00012 id_ = id;
00013 user_id_ = user_id;
00014 slot_id_ = slot_id;
00015 client_ = client;
00016 logs_fetched_ = false;
00017 }
00018
00019 unsigned int appointment::get_id() const
00020 {
00021 return id_;
00022 }
00023
00024 unsigned int appointment::get_user_id() const
00025 {
00026 return user_id_;
00027 }
00028
00029 unsigned int appointment::get_slot_id() const
00030 {
00031 return slot_id_;
00032 }
00033
00034 string appointment::get_created() const
00035 {
00036 return created_;
00037 }
00038
00039 string appointment::get_modified() const
00040 {
00041 return modified_;
00042 }
00043
00044 std::vector<log> &appointment::get_logs()
00045 {
00046 if (!logs_fetched_)
00047 {
00048 stringstream ss;
00049 ss << "SELECT * FROM `logs` WHERE `appointment_id`=" << id_ << ";";
00050 MYSQL_RES *res = client_->query(ss.str());
00051 if (res)
00052 {
00053
00054 MYSQL_ROW row;
00055 while ((row = mysql_fetch_row(res)) != NULL)
00056 {
00057
00058 string entry(row[4]);
00059 if (!entry.empty())
00060 {
00061 string from(""");
00062 string to("\"");
00063 size_t start_pos = 0;
00064 while ((start_pos = entry.find(from, start_pos)) != std::string::npos)
00065 {
00066 entry.replace(start_pos, from.length(), to);
00067 start_pos += to.length();
00068 }
00069 }
00070 log l(client_, atoi(row[0]), atoi(row[1]), atoi(row[2]), string(row[3]), entry, string(row[5]), string(row[6]));
00071 logs_.push_back(l);
00072 }
00073 mysql_free_result(res);
00074 logs_fetched_ = true;
00075 }
00076 }
00077 return logs_;
00078 }