'startQuantity']; 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('startQuantity DESC'); } else if ($direction == self::NEXT_DIRECTION) { $select->order('startQuantity'); } 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( ['startQuantity' => $this->getData('endQuantity') + 1], $this->_db->quoteInto('`id` = ?', $nextPrice['id'], Qs_Db::INT_TYPE) ); } if (false != ($previousPrice = $this->getNeighborPrice($this->getPrimaryKey(), self::PREVIOUS_DIRECTION))) { $this->_getTable()->update( ['endQuantity' => $this->getData('startQuantity') - 1], $this->_db->quoteInto('`id` = ?', $previousPrice['id'], Qs_Db::INT_TYPE) ); } return $this; } }