public function query($userId, $imdbId = null)
{
if ($userId != $this->user->getId() && $this->getClass() < self::CLASS_ADMIN) {
throw new Exception(L::get("PERMISSION_DENIED"), 401);
}
if ($imdbId) {
$sth = $this->db->query("SELECT bevaka.*, imdbinfo.imdbid, imdbinfo.title, imdbinfo.year, imdbinfo.imdbid AS imdbid2 FROM bevaka JOIN imdbinfo ON bevaka.imdbid = imdbinfo.id WHERE bevaka.userid = " . $userId . " AND bevaka.imdbid = " . $imdbId);
} else {
$sth = $this->db->query("SELECT bevaka.*, imdbinfo.imdbid, imdbinfo.title, imdbinfo.year, imdbinfo.imdbid AS imdbid2 FROM bevaka JOIN imdbinfo ON bevaka.imdbid = imdbinfo.id WHERE bevaka.userid = " . $userId . " ORDER BY imdbinfo.title ASC");
}
$fixed = array();
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$row["swesub"] = $row["swesub"] == 1;
if ($row["typ"] == 0) {
$formatsArray = explode(",", $row["format"]);
$row["formats"] = array("hd720" => array_search("4", $formatsArray) > -1, "hd1080" => array_search("5", $formatsArray) > -1, "dvdrpal" => array_search("1", $formatsArray) > -1, "dvdrcustom" => array_search("2", $formatsArray) > -1, "bluray" => array_search("13", $formatsArray) > -1);
} else {
$row["formats"] = array("hd720" => strpos($row["format"], "6") > -1, "hd1080" => strpos($row["format"], "7") > -1, "dvdrpal" => strpos($row["format"], "3") > -1, "dvdrcustom" => strpos($row["format"], "2") > -1);
}
array_push($fixed, $row);
}
return $fixed;
}