Requests::query PHP Method

query() public method

public query ( $index, $limit = 10, $sort, $order, $searchParams )
    public function query($index = 0, $limit = 10, $sort, $order, $searchParams)
    {
        $sth = $this->db->query('SELECT COUNT(*) FROM requests WHERE filled = 0');
        $arr = $sth->fetch();
        $totalCount = $arr[0];
        switch ($sort) {
            case 'votes':
                $sortColumn = 'votes';
                break;
            case 'reward':
                $sortColumn = 'krydda';
                break;
            case 'comments':
                $sortColumn = 'comments';
                break;
            case 'name':
                $sortColumn = 'request';
                break;
            default:
                $sortColumn = 'requestId';
        }
        if ($order == "asc") {
            $order = "ASC";
        } else {
            $order = "DESC";
        }
        $sth = $this->db->prepare('SELECT ' . implode(',', User::getDefaultFields()) . ', imdbinfo.imdbid AS imdbid2, requests.id AS requestId, requests.request, requests.added, requests.filled, requests.p2p, requests.ersatt, requests.comment, requests.comments, requests.season, requests.imdbid, requests.typ, requests.slug, (SELECT COUNT(*) AS cnt FROM reqvotes WHERE reqid = requests.id) AS votes, (SELECT SUM(krydda) FROM reqvotes WHERE reqid = requests.id) AS krydda FROM requests LEFT JOIN users ON requests.userid = users.id LEFT JOIN imdbinfo ON requests.imdbid = imdbinfo.id WHERE requests.filled = 0 ORDER BY ' . $sortColumn . ' ' . $order . ' LIMIT ?, ?');
        $sth->bindParam(1, $index, PDO::PARAM_INT);
        $sth->bindParam(2, $limit, PDO::PARAM_INT);
        $sth->execute();
        $result = array();
        while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
            $arr = array();
            $arr["id"] = $row["requestId"];
            $arr["added"] = $row["added"];
            $arr["filled"] = $row["filled"];
            $arr["request"] = $row["request"];
            $arr["p2p"] = $row["p2p"];
            $arr["comment"] = $row["comment"];
            $arr["comments"] = $row["comments"];
            $arr["ersatt"] = $row["ersatt"];
            $arr["season"] = $row["season"];
            $arr["slug"] = $row["slug"];
            $arr["imdbid"] = $row["imdbid"];
            $arr["type"] = $row["typ"];
            $arr["reward"] = $row["krydda"] += $this->getVoteTimeReward(strtotime($row["added"]));
            $arr["votes"] = $row["votes"];
            $arr["imdbid2"] = $row["imdbid2"];
            $arr["user"] = $this->user->generateUserObject($row);
            array_push($result, $arr);
        }
        return array($result, $totalCount);
    }