/** * @param TablePosition $a * @param TablePosition $b * * @return int */ public static function compare($a, $b) { if ($a->getRow() == $b->getRow()) { return $a->getCell() - $b->getCell(); } return $a->getRow() - $b->getRow(); }
/** * @param TablePosition $position * @param int $offset * * @return TablePosition|null */ public function getPositionAfter(TablePosition $position, $offset = 1) { $cellsToMove = $offset; $newRow = $position->getRow(); $newCell = $position->getCell(); while ($cellsToMove > 0 && $newRow < count($this->rows)) { $cellCount = count($this->getRow($newRow)->getCells()); $cellsLeft = $cellCount - $newCell - 1; if ($cellsToMove > $cellsLeft) { ++$newRow; $cellsToMove -= $cellsLeft - 1; $newCell = 0; } else { $newCell = $newCell + $cellsToMove; $cellsToMove -= $cellsLeft; } } if ($newRow >= 0 && $newCell >= 0) { return new TablePosition($newRow, $newCell); } return; }