Order Class Reference

This class realizes the main target of the overall system: let a user to buy products by placing an order; analyzing the ER model, it’s possible to see that an order is a master-detail structure, in which the master is represented by this class and contains information about the owner of the order, the date and the overall total; the detail part is made up of the list of chosen products (relation 'madeup' of ER model). More...

#include <Order.h>

Inheritance diagram for Order:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Order ()
 Default constructor.
 Order (Row &aRow)
 Construct an instance of Order with data fetched from the database.
 ~Order ()
 Default destructor.
string primaryKey ()
 Returns the primary for entity "orders" (KEY_ORD_OID).
map< int, int > & products ()
 Returns the list of products (and requested quantity) of an order.

Static Public Member Functions

static Ordercreate (int anUid, Basket &bsk)
 Create a new order.
static vector< Order * > & ordersForUser (User &pp)
 Return the list of all orders of a given user.

Private Attributes

User_user

Friends

ostream & operator<< (ostream &, Order &)

Detailed Description

This class realizes the main target of the overall system: let a user to buy products by placing an order; analyzing the ER model, it’s possible to see that an order is a master-detail structure, in which the master is represented by this class and contains information about the owner of the order, the date and the overall total; the detail part is made up of the list of chosen products (relation 'madeup' of ER model).


Constructor & Destructor Documentation

Order::Order (  ) 

Default constructor.

References _user, and LOG_CTOR.

Referenced by create(), and ordersForUser().

Order::Order ( Row &  aRow  ) 

Construct an instance of Order with data fetched from the database.

Parameters:
[in] aRow An instance of mysqlpp::Row with data

References _user, ManagedObject::intForKey(), KEY_ORD_UID, LOG_CTOR, and User::userByID().

Order::~Order (  ) 

Default destructor.

If the user is linked to an user, dealloc the instance of class User.

References _user, and LOG_DTOR.


Member Function Documentation

Order * Order::create ( int  anUid,
Basket bsk 
) [static]

Create a new order.

Parameters:
[in] anUid ID of user that places the order
[in] bsk User basket containing products
Returns:
A pointer to an instance of Order if successful

References Database::getConnection(), ManagedObject::getLastInsertID(), Singleton< Database >::instance(), KEY_ORD_DATE, KEY_ORD_OID, KEY_ORD_TOTAL, KEY_ORD_UID, LOG, Order(), ManagedObject::setFloatForKey(), ManagedObject::setIntForKey(), ManagedObject::setValueForKey(), ManagedObject::store(), and Basket::total().

Referenced by NormalUser::placeOrder().

vector< Order * > & Order::ordersForUser ( User pp  )  [static]

Return the list of all orders of a given user.

Parameters:
[in] pp An instance of User
Returns:
A vector of Order

References Database::getConnection(), Singleton< Database >::instance(), Order(), and User::uniqueID().

Referenced by UserMenu::showUserProfile().

string Order::primaryKey (  )  [virtual]

Returns the primary for entity "orders" (KEY_ORD_OID).

Returns:
The primary key of the entity

Implements ManagedObject.

References KEY_ORD_OID.

map< int, int > & Order::products (  ) 

Returns the list of products (and requested quantity) of an order.

Returns:
A std::map where the key is product ID and the value the quantity

References Database::getConnection(), Singleton< Database >::instance(), KEY_ORD_OID, and ManagedObject::valueForKey().

Referenced by UserMenu::showUserProfile().


Friends And Related Function Documentation

ostream& operator<< ( ostream &  aStream,
Order o 
) [friend]

Member Data Documentation

User* Order::_user [private]

Referenced by operator<<(), Order(), and ~Order().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2