private function buildTableData(array $torrentList, $sort, $limit) { $rows = []; foreach ($torrentList as $torrent) { $rows[] = [$torrent[Torrent\Get::NAME], $torrent[Torrent\Get::ID], $torrent['age'], TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), TorrentUtils::getSizeInGb($torrent['uploaded']), $torrent['per_day'], $torrent['profit']]; } $rows = TableUtils::sortRowsByColumnNumber($rows, $sort); $rows = TableUtils::limitRows($rows, $limit); return ['headers' => ['Name', 'Id', 'Age, days', 'Size, GB', 'Uploaded, GB', 'Per day, GB', 'Profit, %'], 'rows' => $rows, 'totals' => ['Total: ' . count($rows), '', '', TorrentListUtils::sumArrayField($rows, 3), TorrentListUtils::sumArrayField($rows, 4), TorrentListUtils::sumArrayField($rows, 5), TorrentListUtils::sumArrayField($rows, 6)]]; }
public function testGetTorrentsSize() { $torrentSize = TorrentListUtils::sumArrayField($this->expectedTorrentList, Torrent\Get::TOTAL_SIZE); $this->assertEquals(7, $torrentSize); }