'startPrice'); public function getNeighborPrice($id, $direction = self::PREVIOUS_DIRECTION) { $select = $this->_db->select(); $select->from($this->_getPair()); if ($id) { if ($direction == self::PREVIOUS_DIRECTION) { $select->where('`id` < ?', $id, Qs_Db::INT_TYPE); } else if ($direction == self::NEXT_DIRECTION) { $select->where('`id` > ?', $id, Qs_Db::INT_TYPE); } else { throw new Qs_Exception("Wrong direction was set: $direction"); } } if ($direction == self::PREVIOUS_DIRECTION) { $select->order('startPrice DESC'); } else if ($direction == self::NEXT_DIRECTION) { $select->order('startPrice'); } else { throw new Qs_Exception("Wrong direction was set: $direction"); } $select->limit(1); return $this->_db->fetchRow($select); } public function updateNeighbors() { if (false != ($nextPrice = $this->getNeighborPrice($this->getPrimaryKey(), self::NEXT_DIRECTION))) { $this->_getTable()->update( array('startPrice' => $this->getData('endPrice') + self::PRICE_MIN_DELAY), $this->_db->quoteInto('`id` = ?', $nextPrice['id'], Qs_Db::INT_TYPE) ); } if (false != ($previousPrice = $this->getNeighborPrice($this->getPrimaryKey(), self::PREVIOUS_DIRECTION))) { $this->_getTable()->update( array('endPrice' => $this->getData('startPrice') - self::PRICE_MIN_DELAY), $this->_db->quoteInto('`id` = ?', $previousPrice['id'], Qs_Db::INT_TYPE) ); } return $this; } public function getPercentByPrice($price) { return (float) $this->_getTable()->searchBy(array('price' => $price), 'orderPercent'); } public function getFirstShippingPriceItem() { $select = $this->_db->select(); $select->from($this->_getPair()); $select->order('startPrice'); $select->limit(1); return $this->_db->fetchRow($select); } }