@@ -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 |
@@ -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) |
@@ -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,9 +22,9 @@ 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 | |
29 | 29 | public function findAllTagsWhere($where, $value) |
30 | 30 | { |
@@ -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->findAllTagsWhere("post.postId", $id); |
|
112 | - |
|
113 | - // comments |
|
114 | - $comment = new Comment(); |
|
115 | - $comment->setDb($this->di->get("dbqb")); |
|
116 | - $comments = $comment->findAllCommentsWhere("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->findAllTagsWhere("post.postId", $id); |
|
112 | + |
|
113 | + // comments |
|
114 | + $comment = new Comment(); |
|
115 | + $comment->setDb($this->di->get("dbqb")); |
|
116 | + $comments = $comment->findAllCommentsWhere("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 | } |
@@ -32,51 +32,51 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return object as a response object |
34 | 34 | */ |
35 | - public function createAction(int $id) : object |
|
36 | - { |
|
37 | - $userId = $this->di->get("session")->get("userId"); |
|
38 | - if (!$userId) { |
|
39 | - $this->di->get("response")->redirect("user/login"); |
|
40 | - } |
|
35 | + public function createAction(int $id) : object |
|
36 | + { |
|
37 | + $userId = $this->di->get("session")->get("userId"); |
|
38 | + if (!$userId) { |
|
39 | + $this->di->get("response")->redirect("user/login"); |
|
40 | + } |
|
41 | 41 | |
42 | - //Form |
|
43 | - $form = new CreateForm($this->di, $id); |
|
44 | - $form->check(); |
|
42 | + //Form |
|
43 | + $form = new CreateForm($this->di, $id); |
|
44 | + $form->check(); |
|
45 | 45 | |
46 | - //Post |
|
47 | - $post = new Post(); |
|
48 | - $post->setDb($this->di->get("dbqb")); |
|
46 | + //Post |
|
47 | + $post = new Post(); |
|
48 | + $post->setDb($this->di->get("dbqb")); |
|
49 | 49 | |
50 | - //Post |
|
51 | - $comment = new Comment(); |
|
52 | - $comment->setDb($this->di->get("dbqb")); |
|
50 | + //Post |
|
51 | + $comment = new Comment(); |
|
52 | + $comment->setDb($this->di->get("dbqb")); |
|
53 | 53 | |
54 | - // tags |
|
55 | - $tag = new Tag(); |
|
56 | - $tag->setDb($this->di->get("dbqb")); |
|
57 | - $tags = $tag->findAllTagsWhere("post.postId", $id); |
|
54 | + // tags |
|
55 | + $tag = new Tag(); |
|
56 | + $tag->setDb($this->di->get("dbqb")); |
|
57 | + $tags = $tag->findAllTagsWhere("post.postId", $id); |
|
58 | 58 | |
59 | 59 | |
60 | - $data = [ |
|
61 | - "comments" => $comment->findAllCommentsWhere("postId", $id), |
|
62 | - "post" => $post->find("postId", $id), |
|
63 | - "userId" => $userId, |
|
64 | - "tags" => $tags, |
|
65 | - "filter" => new MarkdownExtra() |
|
66 | - ]; |
|
60 | + $data = [ |
|
61 | + "comments" => $comment->findAllCommentsWhere("postId", $id), |
|
62 | + "post" => $post->find("postId", $id), |
|
63 | + "userId" => $userId, |
|
64 | + "tags" => $tags, |
|
65 | + "filter" => new MarkdownExtra() |
|
66 | + ]; |
|
67 | 67 | |
68 | - //Page |
|
69 | - $page = $this->di->get("page"); |
|
70 | - $page->add("post/crud/view-post", $data); |
|
68 | + //Page |
|
69 | + $page = $this->di->get("page"); |
|
70 | + $page->add("post/crud/view-post", $data); |
|
71 | 71 | |
72 | - $page->add("post/crud/create", [ |
|
73 | - "form" => $form->getHTML(), |
|
74 | - ]); |
|
72 | + $page->add("post/crud/create", [ |
|
73 | + "form" => $form->getHTML(), |
|
74 | + ]); |
|
75 | 75 | |
76 | - return $page->render([ |
|
77 | - "title" => "comment", |
|
78 | - ]); |
|
79 | - } |
|
76 | + return $page->render([ |
|
77 | + "title" => "comment", |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | 82 | /** |
@@ -86,32 +86,32 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return object as a response object |
88 | 88 | */ |
89 | - public function updateAction(int $id) : object |
|
90 | - { |
|
91 | - $userId = $this->di->get("session")->get("userId"); |
|
92 | - |
|
93 | - //Comment |
|
94 | - $comment = new Comment(); |
|
95 | - $comment->setDb($this->di->get("dbqb")); |
|
96 | - $comment->find("commentId", $id); |
|
97 | - |
|
98 | - if (!$userId || ($comment->id != $userId)) { |
|
99 | - $this->di->get("response")->redirect("user/login"); |
|
100 | - } |
|
101 | - |
|
102 | - //Form |
|
103 | - $form = new UpdateForm($this->di, $id); |
|
104 | - $form->check(); |
|
105 | - |
|
106 | - //Page |
|
107 | - $page = $this->di->get("page"); |
|
108 | - $page->add("post/crud/update", [ |
|
109 | - "form" => $form->getHTML(), |
|
110 | - "type" => "comment" |
|
111 | - ]); |
|
112 | - |
|
113 | - return $page->render([ |
|
114 | - "title" => "Edit comment", |
|
115 | - ]); |
|
116 | - } |
|
89 | + public function updateAction(int $id) : object |
|
90 | + { |
|
91 | + $userId = $this->di->get("session")->get("userId"); |
|
92 | + |
|
93 | + //Comment |
|
94 | + $comment = new Comment(); |
|
95 | + $comment->setDb($this->di->get("dbqb")); |
|
96 | + $comment->find("commentId", $id); |
|
97 | + |
|
98 | + if (!$userId || ($comment->id != $userId)) { |
|
99 | + $this->di->get("response")->redirect("user/login"); |
|
100 | + } |
|
101 | + |
|
102 | + //Form |
|
103 | + $form = new UpdateForm($this->di, $id); |
|
104 | + $form->check(); |
|
105 | + |
|
106 | + //Page |
|
107 | + $page = $this->di->get("page"); |
|
108 | + $page->add("post/crud/update", [ |
|
109 | + "form" => $form->getHTML(), |
|
110 | + "type" => "comment" |
|
111 | + ]); |
|
112 | + |
|
113 | + return $page->render([ |
|
114 | + "title" => "Edit comment", |
|
115 | + ]); |
|
116 | + } |
|
117 | 117 | } |