/** * create a new listing in the dao. * doesn't do any of the sanitization or validation, just * does the raw heavy lifting of assigning all the values to the dao and running the query. */ public function createListing(Souk\Listing $listing) { // grab all the fields passed in that don't map to pre-defined fields. $attributes = array(); foreach (array_diff($listing->keys(), Souk\Util::fields()) as $k) { if ($k == 'id') { continue; } $attributes[$k] = $listing->{$k}; } $shard = Souk\Util::dateshard()->shard(); $table = $this->table($shard); if (\Gaia\Souk\Storage::isAutoSchemaEnabled()) { $this->create($table); } if (!Transaction::atStart()) { Transaction::add($this->db); } $sql = "INSERT INTO {$table}\n (seller, created, expires, closed, buyer, bidder, bidcount, touch, price, pricesort, item_id, bid, step, reserve, quantity) \n VALUES \n (%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"; $rs = $this->execute($sql, $listing->seller, $listing->created, $listing->expires, $listing->closed, $listing->buyer, $listing->bidder, $listing->bidcount, $listing->touch, $listing->price, Souk\Util::calcPriceSort($listing->price, $listing->quantity), $listing->item_id, $listing->bid, $listing->step, $listing->reserve, $listing->quantity); $row_id = $rs->insertid(); $listing->id = Souk\Util::composeId($shard, $row_id); if ($attributes) { $table_attr = $table . '_attr'; $sql = "INSERT INTO `{$table_attr}` (`row_id`, `attributes`) \n VALUES (%i, %s) \n ON DUPLICATE KEY UPDATE `attributes` = VALUES(`attributes`)"; $this->execute($sql, $row_id, json_encode($attributes)); } }