public function createOrUpdate($postData, $reqId = null)
{
if ($this->user->getClass() < User::CLASS_ACTOR) {
throw new Exception(L::get("PERMISSION_DENIED"), 401);
}
if ($reqId) {
$request = $this->get($reqId);
if ($request["user"]["id"] != $this->user->getId() && $this->user->getClass() < User::CLASS_ADMIN) {
throw new Exception(L::get("PERMISSION_DENIED"));
}
} else {
if ($this->user->getRequestSlots() <= count($this->myRequests())) {
throw new Exception(L::get("REQUEST_SLOTS_EXCEEDED"), 401);
}
}
if ($postData["category"] < Config::$categories["DVDR_PAL"]["id"] || $postData["category"] > Config::$categories["SUBPACK"]["id"]) {
throw new Exception(L::get("REQUEST_INVALID_CATEGORY"));
}
if (in_array($postData["category"], array(1, 2, 3, 4, 5, 6, 7)) && strlen($postData["imdbInfo"]) < 2) {
throw new Exception(L::get("REQUEST_NO_IMDB_URL"));
}
if (in_array($postData["category"], array(8, 9, 10, 11, 12)) && strlen($postData["customName"]) < 2) {
throw new Exception(L::get("REQUEST_NAME_TOO_SHORT"));
}
$requestName = $postData["imdbInfo"];
if (in_array($postData["category"], array(8, 9, 10, 11, 12))) {
$requestName = $postData["customName"];
}
$slug = Helper::slugify($requestName);
$searchText = Helper::searchfield($requestName);
$userid = $this->user->getId();
if ($reqId) {
$sth = $this->db->prepare("UPDATE requests SET userid = ?, request = ?, comment = ?, search_text = ?, season = ?, imdbid = ?, typ = ?, slug = ? WHERE id = " . $request["id"]);
$userid = $request["user"]["id"];
} else {
$sth = $this->db->prepare("INSERT INTO requests(userid, request, added, comment, search_text, season, imdbid, typ, slug) VALUES(?, ?, NOW(), ?, ?, ?, ?, ?, ?)");
}
$sth->bindParam(1, $userid, PDO::PARAM_INT);
$sth->bindParam(2, $requestName, PDO::PARAM_STR);
$sth->bindParam(3, $postData["comment"], PDO::PARAM_STR);
$sth->bindParam(4, $searchText, PDO::PARAM_STR);
$sth->bindParam(5, $postData["season"], PDO::PARAM_INT);
$sth->bindParam(6, $postData["imdbId"], PDO::PARAM_INT);
$sth->bindParam(7, $postData["category"], PDO::PARAM_INT);
$sth->bindParam(8, $slug, PDO::PARAM_STR);
$sth->execute();
if ($reqId) {
return array("id" => $request["id"], "slug" => $slug);
} else {
$insertId = $this->db->lastInsertId();
$this->log->log(1, L::get("REQUEST_SITE_LOG", [$insertId, $slug, $requestName], Config::DEFAULT_LANGUAGE), $this->user->getId(), false);
$this->vote($insertId, 0);
return array("id" => $insertId, "name" => $requestName);
}
}