Anyways, I am using domain objects, validators, and mappers (gateways).
So for a given table I have a domain object that represents an individual record, 0 or more validators for validating a record, and then a mapper which is what reads and writes to a database, so it might look something like this
Code: Select all
$mapper = new FCP_Item_Mapper($this->db()) ;
$validator = new FCP_Item_Validator($mapper) ;
$item = new FCP_Item() ;
$item->setSKU('somesku') ;
$item->setName('product name') ;
if ($validator->validate($item))
{
$mapper->insert($item) ;
}The problem I am having is figuring out what to do when multiple tables need to be updated for a single action. For instance, canceling an order involves the following:
-Mark the order as cancelled in the order table
-Add a orderHistory record saying the order was cancelled
-Mark any shipment records as cancelled
for each of the items in the order do this
-Add the item quantity back into inventory
-Check for items on backorder and release orders if possible
-Add a history record for the item
Here are possible solutions
1. In the controller instantiate an Order_Mapper, an Order_History_Mapper, an Order_Shipment_Mapper, an Item_Inventory_Mapper, an Order_Item_Mapper, and an Order_History_Mapper and then run the required methods. - But then I would need to redo all of that everywhere an order is cancelled, so that is not a good option.
2. Have the OrderMapper do all of this. - This would increase dependency on a lot of other classes, the mapper should only be concerned about individual order records.
3. Have another set of classes that do this. - These classes would either need to be passed a registry of all the mappers or instantiate them internally.
4. Have another specialized mapper that works with more than one table. In this case it wouldn't use mappers but instead carry out the action by directly using SQL. - If I change the table structure I would then need to go back and change this class along with the individual mappers.
5. Do #4 then try to put as much as possible into stored procedures
6. Remove all the individual mappers and have the order mapper just take care of everything.
Anyone have any other ideas on how to approach this?