public function testMissingSetNoAndSeqNo() { $product = new Product(); $track11 = new Track(); $product->addTrack($track11); $track12 = new Track(); $track12->setSetNo(1); $track12->setSeqNo(2); $product->addTrack($track12); $position = new TrackPosition($product); $this->assertEquals(1, $position->getPosition($track11)); $this->assertEquals(1, $position->getPosition($track12)); }
public function getPosition(Track $track) { $set = (int) $track->getSetNo(); $sequence = (int) $track->getSeqNo(); if (!array_key_exists($set, $this->sets)) { return 1; } if (!array_key_exists($sequence, $this->sets[$set])) { return 1; } if (!$set) { return 1; } if ($set === 1) { return $sequence; } $position = 0; for ($x = 1; $x < $set; $x++) { if (array_key_exists($x, $this->sets)) { $position += count($this->sets[$x]); } } return $position + $sequence; }