Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. class AdminController extends Controller {
  4.  
  5. public function queue(Request $request) {
  6. if(!$this->validatePolicies(["logged", "trusted"])) $this->redirect();
  7.  
  8. $articles = $this->db->getData("SELECT * FROM articles WHERE queue=:state ORDER BY publish_date ASC", [
  9. ":state" => true
  10. ]);
  11.  
  12. $galleries = $this->db->getData("SELECT * FROM galleries WHERE queue=:state ORDER BY publish_date ASC", [
  13. ":state" => true
  14. ]);
  15. foreach($galleries as $key => $gallery)
  16. {
  17. $galleries[$key]["title"] = $galleries[$key]["name"];
  18. }
  19.  
  20. //TODO GRAB PLACES AND EVENTS
  21.  
  22. $total = array_merge($articles, $galleries);
  23.  
  24. array_multisort(array_column($total, 'publish_date'), SORT_ASC, $total);
  25.  
  26. $this->render("queue.html.php", [
  27. "pageTitle" => "Oczekujące",
  28. "items" => $total
  29. ]);
  30. }
  31.  
  32. public function accept(Request $request) {
  33. if(!$this->validatePolicies(["logged", "trusted", "acceptDataProvided"])) $this->redirect();
  34.  
  35. $tables = [
  36. "gallery" => "galleries",
  37. "article" => "articles",
  38. "event" => "events",
  39. "place" => "places"
  40. ];
  41.  
  42. foreach($request->post("items") as $key => $item)
  43. {
  44. if(isset($item["type"]) && isset($item["id"]))
  45. {
  46. if(array_key_exists($item["type"], $tables))
  47. {
  48. $table = $tables[$item["type"]];
  49. $this->db->query("UPDATE {$table} SET queue=:state WHERE id=:id", [
  50. ":state" => false,
  51. ":id" => $item["id"]
  52. ]);
  53. }
  54. else
  55. {
  56. die(json_encode(["success" => false, "errorMsg" => "unknown type"]));
  57. }
  58. }
  59. else
  60. {
  61. die(json_encode(["success" => false, "errorMsg" => "not enough data given"]));
  62. }
  63. }
  64.  
  65. echo json_encode(["success" => true]);
  66. }
  67.  
  68. public function addCategory(Request $request) {
  69. if(!$this->validatePolicies(["admin", "addCategoryDataProvided"])) $this->redirect();
  70.  
  71. //TODO: ADD CATEGORY TO DATABASE AND RETURN A JSON
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement