AdminLogs::query PHP Method

query() public method

public query ( $postdata )
    public function query($postdata)
    {
        if ($this->user->getClass() < User::CLASS_ADMIN) {
            throw new Exception(L::get("PERMISSION_DENIED"), 401);
        }
        $limit = (int) $postdata["limit"] ?: 25;
        $index = (int) $postdata["index"] ?: 0;
        $search = $postdata["search"] ?: "";
        $where = "";
        if (strlen($search) > 0) {
            $searchWords = Helper::searchTextToWordParams($search);
            $where = "WHERE MATCH (adminlog.search_text) AGAINST (" . $this->db->quote($searchWords) . " IN BOOLEAN MODE)";
        }
        $sth = $this->db->query("SELECT COUNT(*) FROM adminlog " . $where);
        $res = $sth->fetch();
        $totalCount = $res[0];
        $sth = $this->db->prepare("SELECT adminlog.added, adminlog.id AS aid, adminlog.txt, users.id, users.username FROM adminlog LEFT JOIN users ON adminlog.userid = users.id " . $where . " ORDER BY adminlog.id DESC 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)) {
            $r = array();
            $r["id"] = $row["aid"];
            $r["added"] = $row["added"];
            $r["txt"] = str_replace("{{username}}", "[url=/user/" . $row["id"] . "/" . $row["username"] . "][b]" . $row["username"] . "[/b][/url]", $row["txt"]);
            array_push($result, $r);
        }
        return array($result, $totalCount);
    }

Usage Example

Example #1
0
     $comments = new Comments($db, $user);
     $reports = new Reports($db, $user, $torrent, $subtitles, $requests, $forum, $mailbox, $comments, $log);
     list($result, $totalCount) = $reports->query(array("limit" => $_GET["limit"], "index" => $_GET["index"]));
     httpResponse($result, $totalCount);
     break;
 case validateRoute('PATCH', 'reports/\\d+'):
     $reports = new Reports($db, $user);
     httpResponse($reports->update((int) $params[1], $postdata));
     break;
 case validateRoute('DELETE', 'reports/\\d+'):
     $reports = new Reports($db, $user);
     httpResponse($reports->delete((int) $params[1]));
     break;
 case validateRoute('GET', 'adminlogs'):
     $adminlogs = new AdminLogs($db, $user);
     list($result, $totalCount) = $adminlogs->query(array("limit" => $_GET["limit"], "index" => $_GET["index"], "search" => $_GET["searchText"]));
     httpResponse($result, $totalCount);
     break;
 case validateRoute('GET', 'recovery-logs'):
     $recoveryLog = new RecoveryLog($db, $user);
     list($result, $totalCount) = $recoveryLog->query(array("limit" => $_GET["limit"], "index" => $_GET["index"]));
     httpResponse($result, $totalCount);
     break;
 case validateRoute('GET', 'sqlerrors'):
     $sqlerrors = new SqlErrors($db, $user);
     list($result, $totalCount) = $sqlerrors->query(array("limit" => $_GET["limit"], "index" => $_GET["index"]));
     httpResponse($result, $totalCount);
     break;
 case validateRoute('GET', 'cheatlogs'):
     $cheatlogs = new CheatLogs($db, $user);
     list($result, $totalCount) = $cheatlogs->query(array("limit" => $_GET["limit"], "index" => $_GET["index"], "userid" => $_GET["userid"]));