slot.cpp
Go to the documentation of this file.
00001 #include <rms/slot.hpp>
00002 #include <sstream>
00003 #include <cstdlib>
00004 #include <iostream>
00005 
00006 using namespace std;
00007 using namespace librms;
00008 
00009 slot::slot(rms *client, unsigned int id, unsigned int condition_id, string start, string end, string created, string modified)
00010     :
00011     start_(start), end_(end), created_(created), modified_(modified)
00012 {
00013   id_ = id;
00014   condition_id_ = condition_id;
00015   client_ = client;
00016   appointment_checked_ = false;
00017   appointment_fetched_ = false;
00018 }
00019 
00020 slot::~slot()
00021 {
00022   if (appointment_fetched_)
00023   {
00024     delete appointment_;
00025   }
00026 }
00027 
00028 unsigned int slot::get_id() const
00029 {
00030   return id_;
00031 }
00032 
00033 unsigned int slot::get_condition_id() const
00034 {
00035   return condition_id_;
00036 }
00037 
00038 string slot::get_start() const
00039 {
00040   return start_;
00041 }
00042 
00043 string slot::get_end() const
00044 {
00045   return end_;
00046 }
00047 
00048 string slot::get_created() const
00049 {
00050   return created_;
00051 }
00052 
00053 string slot::get_modified() const
00054 {
00055   return modified_;
00056 }
00057 
00058 bool slot::has_appointment()
00059 {
00060   if (!appointment_checked_)
00061   {
00062     stringstream ss;
00063     ss << "SELECT COUNT(`id`) FROM `appointments` WHERE `slot_id`=" << id_ << ";";
00064     MYSQL_RES *res = client_->query(ss.str());
00065     if (res)
00066     {
00067       // parse and get it
00068       MYSQL_ROW row = mysql_fetch_row(res);
00069       has_appointment_ = (atoi(row[0]) == 1);
00070       mysql_free_result(res);
00071     }
00072   }
00073   return has_appointment_;
00074 }
00075 
00076 appointment &slot::get_appointment()
00077 {
00078   if (!appointment_fetched_)
00079   {
00080     stringstream ss;
00081     ss << "SELECT * FROM `appointments` WHERE `slot_id`=" << id_ << ";";
00082     MYSQL_RES *res = client_->query(ss.str());
00083     if (res)
00084     {
00085       // parse and get it
00086       MYSQL_ROW row = mysql_fetch_row(res);
00087       // check for a null user
00088       uint user_id = 0;
00089       if (row[1] != NULL)
00090       {
00091         user_id = atoi(row[1]);
00092       }
00093       appointment_ = new appointment(client_, atoi(row[0]), user_id, atoi(row[2]), string(row[3]), string(row[4]));
00094       mysql_free_result(res);
00095       appointment_fetched_ = true;
00096     }
00097   }
00098   return *appointment_;
00099 }


librms
Author(s): Russell Toris
autogenerated on Thu Feb 25 2016 11:42:49