@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @var string $tableName name of the database table. |
| 14 | 14 | */ |
| 15 | - protected $tableName = "Tag"; |
|
| 16 | - protected $tableIdColumn = "tagId"; |
|
| 15 | + protected $tableName = "Tag"; |
|
| 16 | + protected $tableIdColumn = "tagId"; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @var integer $id primary key auto incremented. |
| 24 | 24 | */ |
| 25 | - public $tagId; |
|
| 26 | - public $tag; |
|
| 27 | - public $postId; |
|
| 25 | + public $tagId; |
|
| 26 | + public $tag; |
|
| 27 | + public $postId; |
|
| 28 | 28 | } |
@@ -61,28 +61,28 @@ |
||
| 61 | 61 | * |
| 62 | 62 | * @return boolean true if okey, false if something went wrong. |
| 63 | 63 | */ |
| 64 | - public function callbackSubmit() |
|
| 65 | - { |
|
| 66 | - // Get values from the submitted form |
|
| 67 | - $acronym = $this->form->value("acronym"); |
|
| 68 | - $password = $this->form->value("password"); |
|
| 69 | - |
|
| 70 | - // Try to login |
|
| 71 | - $user = new User(); |
|
| 72 | - $user->setDb($this->di->get("dbqb")); |
|
| 73 | - $res = $user->verifyPassword($acronym, $password); |
|
| 74 | - |
|
| 75 | - if (!$res) { |
|
| 64 | + public function callbackSubmit() |
|
| 65 | + { |
|
| 66 | + // Get values from the submitted form |
|
| 67 | + $acronym = $this->form->value("acronym"); |
|
| 68 | + $password = $this->form->value("password"); |
|
| 69 | + |
|
| 70 | + // Try to login |
|
| 71 | + $user = new User(); |
|
| 72 | + $user->setDb($this->di->get("dbqb")); |
|
| 73 | + $res = $user->verifyPassword($acronym, $password); |
|
| 74 | + |
|
| 75 | + if (!$res) { |
|
| 76 | 76 | $this->form->rememberValues(); |
| 77 | 77 | $this->form->addOutput("User or password did not match."); |
| 78 | 78 | $this->di->get("session")->delete("acronym"); |
| 79 | 79 | return false; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->di->get("session")->set("userId", $user->acronym); |
|
| 83 | - $this->di->get("session")->set("userName", $acronym); |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 82 | + $this->di->get("session")->set("userId", $user->acronym); |
|
| 83 | + $this->di->get("session")->set("userName", $acronym); |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Redirect for create button |
@@ -96,37 +96,37 @@ |
||
| 96 | 96 | * |
| 97 | 97 | * @return object as a response object |
| 98 | 98 | */ |
| 99 | - public function viewAction(int $id) : object |
|
| 100 | - { |
|
| 101 | - $page = $this->di->get("page"); |
|
| 102 | - |
|
| 103 | - // posts |
|
| 104 | - $post = new Post(); |
|
| 105 | - $post->setDb($this->di->get("dbqb")); |
|
| 106 | - $posts = $post->find("postId", $id); |
|
| 107 | - |
|
| 108 | - // tags |
|
| 109 | - $tag = new Tag(); |
|
| 110 | - $tag->setDb($this->di->get("dbqb")); |
|
| 111 | - $tags = $tag->find("postId", $id); |
|
| 112 | - |
|
| 113 | - // comments |
|
| 114 | - $comment = new Comment(); |
|
| 115 | - $comment->setDb($this->di->get("dbqb")); |
|
| 116 | - $comments = $comment->find("postId", $id); |
|
| 117 | - |
|
| 118 | - $data = [ |
|
| 119 | - "post" => $posts, |
|
| 120 | - "comments" => $comments, |
|
| 121 | - "tags" => $tags, |
|
| 122 | - "userId" => $this->di->get("session")->get("userId"), |
|
| 123 | - "get" => $_GET |
|
| 124 | - ]; |
|
| 125 | - |
|
| 126 | - $page->add("post/crud/view-post", $data); |
|
| 127 | - |
|
| 128 | - return $page->render([ |
|
| 129 | - "title" => "Showing post", |
|
| 130 | - ]); |
|
| 131 | - } |
|
| 99 | + public function viewAction(int $id) : object |
|
| 100 | + { |
|
| 101 | + $page = $this->di->get("page"); |
|
| 102 | + |
|
| 103 | + // posts |
|
| 104 | + $post = new Post(); |
|
| 105 | + $post->setDb($this->di->get("dbqb")); |
|
| 106 | + $posts = $post->find("postId", $id); |
|
| 107 | + |
|
| 108 | + // tags |
|
| 109 | + $tag = new Tag(); |
|
| 110 | + $tag->setDb($this->di->get("dbqb")); |
|
| 111 | + $tags = $tag->find("postId", $id); |
|
| 112 | + |
|
| 113 | + // comments |
|
| 114 | + $comment = new Comment(); |
|
| 115 | + $comment->setDb($this->di->get("dbqb")); |
|
| 116 | + $comments = $comment->find("postId", $id); |
|
| 117 | + |
|
| 118 | + $data = [ |
|
| 119 | + "post" => $posts, |
|
| 120 | + "comments" => $comments, |
|
| 121 | + "tags" => $tags, |
|
| 122 | + "userId" => $this->di->get("session")->get("userId"), |
|
| 123 | + "get" => $_GET |
|
| 124 | + ]; |
|
| 125 | + |
|
| 126 | + $page->add("post/crud/view-post", $data); |
|
| 127 | + |
|
| 128 | + return $page->render([ |
|
| 129 | + "title" => "Showing post", |
|
| 130 | + ]); |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -31,45 +31,45 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return object as a response object |
| 33 | 33 | */ |
| 34 | - public function createAction(int $id) : object |
|
| 35 | - { |
|
| 36 | - $userId = $this->di->get("session")->get("userId"); |
|
| 37 | - if (!$userId) { |
|
| 38 | - $this->di->get("response")->redirect("user/login"); |
|
| 39 | - } |
|
| 34 | + public function createAction(int $id) : object |
|
| 35 | + { |
|
| 36 | + $userId = $this->di->get("session")->get("userId"); |
|
| 37 | + if (!$userId) { |
|
| 38 | + $this->di->get("response")->redirect("user/login"); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - //Form |
|
| 42 | - $form = new CreateForm($this->di, $id); |
|
| 43 | - $form->check(); |
|
| 41 | + //Form |
|
| 42 | + $form = new CreateForm($this->di, $id); |
|
| 43 | + $form->check(); |
|
| 44 | 44 | |
| 45 | - //Post |
|
| 46 | - $post = new Post(); |
|
| 47 | - $post->setDb($this->di->get("dbqb")); |
|
| 45 | + //Post |
|
| 46 | + $post = new Post(); |
|
| 47 | + $post->setDb($this->di->get("dbqb")); |
|
| 48 | 48 | |
| 49 | - //Post |
|
| 50 | - $comment = new Comment(); |
|
| 51 | - $comment->setDb($this->di->get("dbqb")); |
|
| 49 | + //Post |
|
| 50 | + $comment = new Comment(); |
|
| 51 | + $comment->setDb($this->di->get("dbqb")); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - $data = [ |
|
| 55 | - "comments" => $comment->find("postId", $id), |
|
| 56 | - "post" => $post->find("postId", $id), |
|
| 57 | - "userId" => $userId, |
|
| 58 | - "filter" => new MarkdownExtra() |
|
| 59 | - ]; |
|
| 54 | + $data = [ |
|
| 55 | + "comments" => $comment->find("postId", $id), |
|
| 56 | + "post" => $post->find("postId", $id), |
|
| 57 | + "userId" => $userId, |
|
| 58 | + "filter" => new MarkdownExtra() |
|
| 59 | + ]; |
|
| 60 | 60 | |
| 61 | - //Page |
|
| 62 | - $page = $this->di->get("page"); |
|
| 63 | - $page->add("post/crud/view-post", $data); |
|
| 61 | + //Page |
|
| 62 | + $page = $this->di->get("page"); |
|
| 63 | + $page->add("post/crud/view-post", $data); |
|
| 64 | 64 | |
| 65 | - $page->add("post/crud/create", [ |
|
| 66 | - "form" => $form->getHTML(), |
|
| 67 | - ]); |
|
| 65 | + $page->add("post/crud/create", [ |
|
| 66 | + "form" => $form->getHTML(), |
|
| 67 | + ]); |
|
| 68 | 68 | |
| 69 | - return $page->render([ |
|
| 70 | - "title" => "comment", |
|
| 71 | - ]); |
|
| 72 | - } |
|
| 69 | + return $page->render([ |
|
| 70 | + "title" => "comment", |
|
| 71 | + ]); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -79,32 +79,32 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return object as a response object |
| 81 | 81 | */ |
| 82 | - public function updateAction(int $id) : object |
|
| 83 | - { |
|
| 84 | - $userId = $this->di->get("session")->get("userId"); |
|
| 85 | - |
|
| 86 | - //Comment |
|
| 87 | - $comment = new Comment(); |
|
| 88 | - $comment->setDb($this->di->get("dbqb")); |
|
| 89 | - $comment->find("commentId", $id); |
|
| 90 | - |
|
| 91 | - if (!$userId || ($comment->id != $userId)) { |
|
| 92 | - $this->di->get("response")->redirect("user/login"); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - //Form |
|
| 96 | - $form = new UpdateForm($this->di, $id); |
|
| 97 | - $form->check(); |
|
| 98 | - |
|
| 99 | - //Page |
|
| 100 | - $page = $this->di->get("page"); |
|
| 101 | - $page->add("post/crud/update", [ |
|
| 102 | - "form" => $form->getHTML(), |
|
| 103 | - "type" => "comment" |
|
| 104 | - ]); |
|
| 105 | - |
|
| 106 | - return $page->render([ |
|
| 107 | - "title" => "Edit comment", |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 82 | + public function updateAction(int $id) : object |
|
| 83 | + { |
|
| 84 | + $userId = $this->di->get("session")->get("userId"); |
|
| 85 | + |
|
| 86 | + //Comment |
|
| 87 | + $comment = new Comment(); |
|
| 88 | + $comment->setDb($this->di->get("dbqb")); |
|
| 89 | + $comment->find("commentId", $id); |
|
| 90 | + |
|
| 91 | + if (!$userId || ($comment->id != $userId)) { |
|
| 92 | + $this->di->get("response")->redirect("user/login"); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + //Form |
|
| 96 | + $form = new UpdateForm($this->di, $id); |
|
| 97 | + $form->check(); |
|
| 98 | + |
|
| 99 | + //Page |
|
| 100 | + $page = $this->di->get("page"); |
|
| 101 | + $page->add("post/crud/update", [ |
|
| 102 | + "form" => $form->getHTML(), |
|
| 103 | + "type" => "comment" |
|
| 104 | + ]); |
|
| 105 | + |
|
| 106 | + return $page->render([ |
|
| 107 | + "title" => "Edit comment", |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -22,7 +22,6 @@ |
||
| 22 | 22 | * @param string $message with details. |
| 23 | 23 | * |
| 24 | 24 | * @throws Anax\Route\Exception\NotFoundException |
| 25 | - |
|
| 26 | 25 | * @return object as the response. |
| 27 | 26 | */ |
| 28 | 27 | public function catchAll(...$args) : object |
@@ -21,7 +21,6 @@ |
||
| 21 | 21 | * @param array $args as a variadic to catch all arguments. |
| 22 | 22 | * |
| 23 | 23 | * @throws Anax\Route\Exception\NotFoundException when route is not found. |
| 24 | - |
|
| 25 | 24 | * @return object as the response. |
| 26 | 25 | * |
| 27 | 26 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |