Example #1
0
 /**
  * Gets a page worth of threads for the given board.
  * @param Board $board
  * @param int $pageNo
  * @param bool $onlyActive only show active threads
  * @return Thread[] array of threads.
  */
 function getPageOfThreads(Board $board, int $pageNo, bool $onlyActive = false) : array
 {
     if ($pageNo < 1) {
         throw new InvalidArgumentException("Invalid page number given");
     }
     $pageNo--;
     $prefix = alphanum($board->getName()) . "_";
     $perpage = (int) $board->getThreadsPerPage();
     $tTable = $prefix . "thread";
     $number = $pageNo * $perpage;
     $pageQuery = "SELECT {$tTable}.*  FROM {$tTable} " . ($onlyActive ? "WHERE {$tTable}.active = 1 " : "") . "ORDER BY {$tTable}.active DESC, {$tTable}.sticky DESC, {$tTable}.lastreply DESC " . "LIMIT {$number},{$perpage}";
     $q = $this->conn_ro->query($pageQuery);
     return array_map(function ($row) use($board) {
         return Thread::fromArray($board, $row);
     }, $q->fetchAll(PDO::FETCH_ASSOC));
 }