Exemplo n.º 1
0
 /**
  * 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));
     }
 }
Exemplo n.º 2
0
 /**
  * translate the simple array of data we store in the db in souk back into a Stockpile\Quantity object.
  */
 protected function prepListing(Listing $listing)
 {
     $prior = $listing->priorstate();
     if ($prior) {
         $this->prepListing($prior);
     }
     if (!isset($listing->stockpile_quantity)) {
         return $listing;
     }
     $listing->quantity = $this->itemAccount($listing->seller)->defaultQuantity($listing->stockpile_quantity);
     unset($listing->stockpile_quantity);
     return $listing;
 }
Exemplo n.º 3
0
 /**
  * when a listing changes, extract search vectors from that listing and update those cache keys
  * so that we can bust any cached search results that now may be invalid.
  */
 protected function updateListingSearchVectors(Listing $listing)
 {
     $this->updateSearchVector('seller' . $listing->seller);
     if ($listing->buyer) {
         $this->updateSearchVector('buyer' . $listing->buyer);
     }
     if ($listing->bidder) {
         $this->updateSearchVector('bidder' . $listing->bidder);
     }
     $prior = $listing->priorstate();
     if ($prior && $prior->bidder) {
         $this->updateSearchVector('bidder' . $prior->bidder);
     }
 }