Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AdminController extends Controller {
- public function queue(Request $request) {
- if(!$this->validatePolicies(["logged", "trusted"])) $this->redirect();
- $articles = $this->db->getData("SELECT * FROM articles WHERE queue=:state ORDER BY publish_date ASC", [
- ":state" => true
- ]);
- $galleries = $this->db->getData("SELECT * FROM galleries WHERE queue=:state ORDER BY publish_date ASC", [
- ":state" => true
- ]);
- foreach($galleries as $key => $gallery)
- {
- $galleries[$key]["title"] = $galleries[$key]["name"];
- }
- //TODO GRAB PLACES AND EVENTS
- $total = array_merge($articles, $galleries);
- array_multisort(array_column($total, 'publish_date'), SORT_ASC, $total);
- $this->render("queue.html.php", [
- "pageTitle" => "Oczekujące",
- "items" => $total
- ]);
- }
- public function accept(Request $request) {
- if(!$this->validatePolicies(["logged", "trusted", "acceptDataProvided"])) $this->redirect();
- $tables = [
- "gallery" => "galleries",
- "article" => "articles",
- "event" => "events",
- "place" => "places"
- ];
- foreach($request->post("items") as $key => $item)
- {
- if(isset($item["type"]) && isset($item["id"]))
- {
- if(array_key_exists($item["type"], $tables))
- {
- $table = $tables[$item["type"]];
- $this->db->query("UPDATE {$table} SET queue=:state WHERE id=:id", [
- ":state" => false,
- ":id" => $item["id"]
- ]);
- }
- else
- {
- die(json_encode(["success" => false, "errorMsg" => "unknown type"]));
- }
- }
- else
- {
- die(json_encode(["success" => false, "errorMsg" => "not enough data given"]));
- }
- }
- echo json_encode(["success" => true]);
- }
- public function addCategory(Request $request) {
- if(!$this->validatePolicies(["admin", "addCategoryDataProvided"])) $this->redirect();
- //TODO: ADD CATEGORY TO DATABASE AND RETURN A JSON
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement