コード例 #1
0
 /**
  * create a new auction listing in souk.
  * pass in an array or a listing object.
  * You can combine any of these parameters to create a listing:
  *    $listing = $souk->auction( array(
  *                                   'price'=>10, 
  *                                   'item_id'=>32, 
  *                                   'quantity'=>5, 
  *                                   'bid'=>100,
  *                                   'step'=>10,
  *                                   'price'=>1000,
  *                                   'expires'=>currentTime() + 86400) );
  *
  * @return   Souk\Listing
  */
 public function auction($l, array $data = NULL)
 {
     // wrap in try catch so we can handle db transactions
     try {
         // create a transaction if we don't have one already.
         Transaction::start();
         // validate the listing
         $listing = Souk\Util::validateListing($l);
         // if no seller passed in, use the current user id.
         if (!isset($listing->seller)) {
             $listing->seller = $this->user();
         }
         // make sure the seller is a positive int.
         if (!Souk\Util::validatePositiveInteger($listing->seller)) {
             throw new Exception('seller invalid', $listing->seller);
         }
         // write the listing into the db.
         $this->createListing($listing);
         // commit transaction if it was created internally.
         Transaction::commit();
         // all done.
         return $listing;
         // something bad happened.
     } catch (Exception $e) {
         // roll back the transaction.
         Transaction::rollback();
         // wrap the exception in our own exception so we can control the message.
         $e = new Exception('cannot auction: ' . $e->getMessage(), $e->__toString());
         // throw the exception up the chain.
         throw $e;
     }
 }