| Total Complexity | 52 |
| Total Lines | 977 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like UserController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class UserController implements ContainerInjectableInterface |
||
| 27 | { |
||
| 28 | use ContainerInjectableTrait; |
||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * @var $data description |
||
| 34 | */ |
||
| 35 | //private $data; |
||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * The initialize method is optional and will always be called before the |
||
| 41 | * target method/action. This is a convienient method where you could |
||
| 42 | * setup internal properties that are commonly used by several methods. |
||
| 43 | * |
||
| 44 | * @return object or void |
||
| 45 | */ |
||
| 46 | public function initialize() |
||
| 87 | |||
| 88 | // $pic = [ |
||
| 89 | // // "content" => "<img src='../../htdocs/image/snail2.jpg' width='1100px'></img>", |
||
| 90 | // "content" => "<img src='{$baseURL}/image/snail2.jpg' width='1100px'></img>", |
||
| 91 | // ]; |
||
| 92 | // |
||
| 93 | // $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | /** |
||
| 99 | * Description. |
||
| 100 | * |
||
| 101 | * @param datatype $variable Description |
||
|
|
|||
| 102 | * |
||
| 103 | * @throws Exception |
||
| 104 | * |
||
| 105 | * @return object as a response object |
||
| 106 | */ |
||
| 107 | public function indexActionGet() : object |
||
| 108 | { |
||
| 109 | $page = $this->di->get("page"); |
||
| 110 | |||
| 111 | $page->add("anax/v2/article/default", [ |
||
| 112 | "content" => "An index page", |
||
| 113 | ]); |
||
| 114 | |||
| 115 | return $page->render([ |
||
| 116 | "title" => "A index page", |
||
| 117 | ]); |
||
| 118 | } |
||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | /** |
||
| 123 | * Description. |
||
| 124 | * |
||
| 125 | * @param datatype $variable Description |
||
| 126 | * |
||
| 127 | * @throws Exception |
||
| 128 | * |
||
| 129 | * @return object as a response object |
||
| 130 | */ |
||
| 131 | public function loginAction() : object |
||
| 132 | { |
||
| 133 | $page = $this->di->get("page"); |
||
| 134 | $form = new UserLoginForm($this->di); |
||
| 135 | $form->check(); |
||
| 136 | |||
| 137 | // var_dump($_SESSION); |
||
| 138 | |||
| 139 | if ($_SESSION["acronym"] ?? null) { |
||
| 140 | $response = $this->di->get("response"); |
||
| 141 | return $response->redirect("user/questions"); |
||
| 142 | } |
||
| 143 | |||
| 144 | $page->add("anax/v2/article/default", [ |
||
| 145 | "content" => $form->getHTML(), |
||
| 146 | ]); |
||
| 147 | |||
| 148 | // $data = [ |
||
| 149 | // "content" => "Inget konto?<br>Skapa ett <a href='create'>här</a>", |
||
| 150 | // ]; |
||
| 151 | |||
| 152 | $pic = [ |
||
| 153 | "content" => "<img src='../../htdocs/image/garden2.jpg' width='1000px'></img>", |
||
| 154 | ]; |
||
| 155 | |||
| 156 | $page->add("login-side", [], "sidebar-right"); |
||
| 157 | $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 158 | |||
| 159 | return $page->render([ |
||
| 160 | "title" => "A login page", |
||
| 161 | ]); |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | /** |
||
| 166 | * Description. |
||
| 167 | * |
||
| 168 | * @param datatype $variable Description |
||
| 169 | * |
||
| 170 | * @throws Exception |
||
| 171 | * |
||
| 172 | * @return object as a response object |
||
| 173 | */ |
||
| 174 | public function profileAction() : object |
||
| 175 | { |
||
| 176 | $page = $this->di->get("page"); |
||
| 177 | $request = $this->di->get("request"); |
||
| 178 | |||
| 179 | $res = new Functions(); |
||
| 180 | $acronym = $_SESSION["acronym"]; |
||
| 181 | $rows = "id, question, tags"; |
||
| 182 | $questions = $res->getProfileInfo($acronym, $this->di, "Question", $rows); |
||
| 183 | $rows2 = "id, questionId, answer"; |
||
| 184 | $answers = $res->getProfileInfo($acronym, $this->di, "Answers", $rows2); |
||
| 185 | $rows3 = "id, questionId, answerId, comment"; |
||
| 186 | $comments = $res->getProfileInfo($acronym, $this->di, "Comments", "*"); |
||
| 187 | $rows4 = "points, info, picture, created"; |
||
| 188 | $user = $res->getProfileInfo($acronym, $this->di, "User", $rows4); |
||
| 189 | // var_dump($comments); |
||
| 190 | |||
| 191 | $form = new FormElementFile("img", ["image/*"]); |
||
| 192 | $baseURL = $request->getBaseUrl(); |
||
| 193 | // var_dump($baseURL); |
||
| 194 | |||
| 195 | $filter = new \Anax\TextFilter\TextFilter(); |
||
| 196 | |||
| 197 | $page->add("profile", [ |
||
| 198 | "content" => $questions, |
||
| 199 | "acronym" => $acronym, |
||
| 200 | "answers" => $answers, |
||
| 201 | "comments" => $comments, |
||
| 202 | "user" => $user, |
||
| 203 | "form" => $form->getHTML(), |
||
| 204 | "baseURL" => $baseURL, |
||
| 205 | "filter" => $filter, |
||
| 206 | ]); |
||
| 207 | |||
| 208 | // $pic = [ |
||
| 209 | // "content" => "<img src='../../htdocs/image/car.png' width='1000px'></img>", |
||
| 210 | // ]; |
||
| 211 | // |
||
| 212 | // $page->add("login-side", [], "sidebar-right"); |
||
| 213 | // $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 214 | |||
| 215 | return $page->render([ |
||
| 216 | "title" => "Profile", |
||
| 217 | ]); |
||
| 218 | } |
||
| 219 | |||
| 220 | |||
| 221 | /** |
||
| 222 | * Description. |
||
| 223 | * |
||
| 224 | * @param datatype $variable Description |
||
| 225 | * |
||
| 226 | * @throws Exception |
||
| 227 | * |
||
| 228 | * @return object as a response object |
||
| 229 | */ |
||
| 230 | public function profileEditAction(string $acronym, string $toUpdate) : object |
||
| 231 | { |
||
| 232 | $page = $this->di->get("page"); |
||
| 233 | $request = $this->di->get("request"); |
||
| 234 | $response = $this->di->get("response"); |
||
| 235 | |||
| 236 | $res = new Functions(); |
||
| 237 | $rows = "points, info, picture, created"; |
||
| 238 | $user = $res->getProfileInfo($acronym, $this->di, "User", $rows); |
||
| 239 | $pictures = $res->getAllProfilePictures($this->di, $acronym); |
||
| 240 | |||
| 241 | $info = $_POST["info"] ?? null; |
||
| 242 | $picture = $_POST["picture"] ?? null; |
||
| 243 | if ($info) { |
||
| 244 | var_dump($info); |
||
| 245 | $res->setProfileInfo($this->di, $acronym, $info); |
||
| 246 | |||
| 247 | $response->redirect("user/profile"); |
||
| 248 | } elseif ($picture) { |
||
| 249 | var_dump($picture); |
||
| 250 | $res->setProfilePicture($this->di, $acronym, $picture); |
||
| 251 | |||
| 252 | $response->redirect("user/profile"); |
||
| 253 | } |
||
| 254 | |||
| 255 | // update table User, with toUpdate |
||
| 256 | |||
| 257 | $baseURL = $request->getBaseUrl(); |
||
| 258 | |||
| 259 | $page->add("profile-edit", [ |
||
| 260 | "acronym" => $acronym, |
||
| 261 | "user" => $user, |
||
| 262 | "baseURL" => $baseURL, |
||
| 263 | "pictures" => $pictures, |
||
| 264 | "toUpdate" => $toUpdate, |
||
| 265 | ]); |
||
| 266 | |||
| 267 | return $page->render([ |
||
| 268 | "title" => "Profile", |
||
| 269 | ]); |
||
| 270 | } |
||
| 271 | |||
| 272 | |||
| 273 | /** |
||
| 274 | * Description. |
||
| 275 | * |
||
| 276 | * @param datatype $variable Description |
||
| 277 | * |
||
| 278 | * @throws Exception |
||
| 279 | * |
||
| 280 | * @return object as a response object |
||
| 281 | */ |
||
| 282 | public function uploadAction() : object |
||
| 283 | { |
||
| 284 | $page = $this->di->get("page"); |
||
| 285 | $request = $this->di->get("request"); |
||
| 286 | |||
| 287 | $res = new Functions(); |
||
| 288 | |||
| 289 | $post = $request->getPost("submit"); |
||
| 290 | var_dump($post); |
||
| 291 | // var_dump($_POST["submit"]); |
||
| 292 | // var_dump($_POST); |
||
| 293 | var_dump($_FILES); |
||
| 294 | |||
| 295 | if ($post) { |
||
| 296 | // $res->setProfilePicture($this->di, $acronym, $post); |
||
| 297 | $target_dir = "C:/cygwin64/home/Lichn/dbwebb-kurser/ramverk1/me/kmom10/module/htdocs/img/profile/"; |
||
| 298 | $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); |
||
| 299 | $uploadOk = 1; |
||
| 300 | $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); |
||
| 301 | // Check if image file is a actual image or fake image |
||
| 302 | if(isset($_POST["submit"])) { |
||
| 303 | var_dump("smask"); |
||
| 304 | $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); |
||
| 305 | if($check !== false) { |
||
| 306 | echo "File is an image - " . $check["mime"] . "."; |
||
| 307 | $uploadOk = 1; |
||
| 308 | } else { |
||
| 309 | echo "File is not an image."; |
||
| 310 | $uploadOk = 0; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | // Check if file already exists |
||
| 314 | if (file_exists($target_file)) { |
||
| 315 | echo "Sorry, file already exists."; |
||
| 316 | $uploadOk = 0; |
||
| 317 | } |
||
| 318 | |||
| 319 | // Check file size |
||
| 320 | if ($_FILES["fileToUpload"]["size"] > 500000) { |
||
| 321 | echo "Sorry, your file is too large."; |
||
| 322 | $uploadOk = 0; |
||
| 323 | } |
||
| 324 | |||
| 325 | // Allow certain file formats |
||
| 326 | if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" |
||
| 327 | && $imageFileType != "gif" ) { |
||
| 328 | echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; |
||
| 329 | $uploadOk = 0; |
||
| 330 | } |
||
| 331 | |||
| 332 | // Check if $uploadOk is set to 0 by an error |
||
| 333 | if ($uploadOk == 0) { |
||
| 334 | echo "Sorry, your file was not uploaded."; |
||
| 335 | // if everything is ok, try to upload file |
||
| 336 | } else { |
||
| 337 | if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { |
||
| 338 | echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; |
||
| 339 | $res->setProfilePicture($this->di, $acronym, $_FILES["fileToUpload"]); |
||
| 340 | $res->addProfilePicture($this->di, $acronym, $_FILES["fileToUpload"]); |
||
| 341 | } else { |
||
| 342 | echo "Sorry, there was an error uploading your file."; |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } |
||
| 346 | |||
| 347 | $page->add("anax/v2/article/default", [ |
||
| 348 | "content" => "Hello", |
||
| 349 | ]); |
||
| 350 | |||
| 351 | // $pic = [ |
||
| 352 | // "content" => "<img src='../../htdocs/image/car.png' width='1000px'></img>", |
||
| 353 | // ]; |
||
| 354 | // |
||
| 355 | // $page->add("login-side", [], "sidebar-right"); |
||
| 356 | // $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 357 | |||
| 358 | return $page->render([ |
||
| 359 | "title" => "Profile", |
||
| 360 | ]); |
||
| 361 | } |
||
| 362 | |||
| 363 | |||
| 364 | /** |
||
| 365 | * Description. |
||
| 366 | * |
||
| 367 | * @param datatype $variable Description |
||
| 368 | * |
||
| 369 | * @throws Exception |
||
| 370 | * |
||
| 371 | * @return object as a response object |
||
| 372 | */ |
||
| 373 | public function viewProfileAction(string $acronym) : object |
||
| 374 | { |
||
| 375 | $page = $this->di->get("page"); |
||
| 376 | $request = $this->di->get("request"); |
||
| 377 | |||
| 378 | $res = new Functions(); |
||
| 379 | $rows = "id, question, tags"; |
||
| 380 | $questions = $res->getProfileInfo($acronym, $this->di, "Question", $rows); |
||
| 381 | foreach ($questions as $question) { |
||
| 382 | $answered = $res->checkIfAnswered($this->di, $question->id); |
||
| 383 | $question->answered = $answered; |
||
| 384 | } |
||
| 385 | $answers = $res->getProfileInfo($acronym, $this->di, "Answers", "*"); |
||
| 386 | $comments = $res->getProfileInfo($acronym, $this->di, "Comments", "*"); |
||
| 387 | $user = $res->getProfileInfo($acronym, $this->di, "User", "*"); |
||
| 388 | $baseURL = $request->getBaseUrl(); |
||
| 389 | $filter = new \Anax\TextFilter\TextFilter(); |
||
| 390 | |||
| 391 | $page->add("view-profile", [ |
||
| 392 | "content" => $questions, |
||
| 393 | "answers" => $answers, |
||
| 394 | "comments" => $comments, |
||
| 395 | "acronym" => $acronym, |
||
| 396 | "user" => $user, |
||
| 397 | "baseURL" => $baseURL, |
||
| 398 | "filter" => $filter, |
||
| 399 | ]); |
||
| 400 | |||
| 401 | return $page->render([ |
||
| 402 | "title" => "Profile", |
||
| 403 | ]); |
||
| 404 | } |
||
| 405 | |||
| 406 | |||
| 407 | /** |
||
| 408 | * Description. |
||
| 409 | * |
||
| 410 | * @param datatype $variable Description |
||
| 411 | * |
||
| 412 | * @throws Exception |
||
| 413 | * |
||
| 414 | * @return object as a response object |
||
| 415 | */ |
||
| 416 | public function askAction() : object |
||
| 417 | { |
||
| 418 | $page = $this->di->get("page"); |
||
| 419 | // $acronym = $_SESSION["acronym"]; |
||
| 420 | $acronym = $_SESSION["acronym"]; |
||
| 421 | // var_dump($_SESSION); |
||
| 422 | $form = new CreateQuestionForm($this->di, $acronym); |
||
| 423 | $form->check(); |
||
| 424 | |||
| 425 | $page->add("ask-question", [ |
||
| 426 | "content" => $form->getHTML(), |
||
| 427 | ]); |
||
| 428 | |||
| 429 | // $page->add("ask-question", [ |
||
| 430 | // "content" => "Hello", |
||
| 431 | // ]); |
||
| 432 | |||
| 433 | // $pic = [ |
||
| 434 | // "content" => "<img src='../../htdocs/image/car.png' width='1000px'></img>", |
||
| 435 | // ]; |
||
| 436 | |||
| 437 | $page->add("ask-tip", [], "sidebar-right"); |
||
| 438 | $page->add("ask-tag", [], "sidebar-right"); |
||
| 439 | // $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 440 | |||
| 441 | return $page->render([ |
||
| 442 | "title" => "Ställ en fråga", |
||
| 443 | ]); |
||
| 444 | } |
||
| 445 | |||
| 446 | |||
| 447 | /** |
||
| 448 | * Description. |
||
| 449 | * |
||
| 450 | * @param datatype $variable Description |
||
| 451 | * |
||
| 452 | * @throws Exception |
||
| 453 | * |
||
| 454 | * @return object as a response object |
||
| 455 | */ |
||
| 456 | public function createAction() : object |
||
| 457 | { |
||
| 458 | $page = $this->di->get("page"); |
||
| 459 | $form = new CreateUserForm($this->di); |
||
| 460 | $form->check(); |
||
| 461 | |||
| 462 | |||
| 463 | $page->add("anax/v2/article/default", [ |
||
| 464 | "content" => $form->getHTML(), |
||
| 465 | ]); |
||
| 466 | |||
| 467 | return $page->render([ |
||
| 468 | "title" => "A create user page", |
||
| 469 | ]); |
||
| 470 | } |
||
| 471 | |||
| 472 | |||
| 473 | /** |
||
| 474 | * Description. |
||
| 475 | * |
||
| 476 | * @param datatype $variable Description |
||
| 477 | * |
||
| 478 | * @throws Exception |
||
| 479 | * |
||
| 480 | * @return object as a response object |
||
| 481 | */ |
||
| 482 | public function logoutAction() : object |
||
| 497 | } |
||
| 498 | |||
| 499 | |||
| 500 | /** |
||
| 501 | * Description. |
||
| 502 | * |
||
| 503 | * @param datatype $variable Description |
||
| 504 | * |
||
| 505 | * @throws Exception |
||
| 506 | * |
||
| 507 | * @return object as a response object |
||
| 508 | */ |
||
| 509 | public function questionsAction() : object |
||
| 510 | { |
||
| 511 | $page = $this->di->get("page"); |
||
| 512 | |||
| 513 | $res = new Functions(); |
||
| 514 | $questions = $res->getAllQuestions($this->di); |
||
| 515 | |||
| 516 | rsort($questions); |
||
| 517 | $questions2 = array_slice($questions, 0, 3); |
||
| 518 | |||
| 519 | // Get list of all users. |
||
| 520 | $users = $res->getAllUsers($this->di); |
||
| 521 | $sums = []; |
||
| 522 | foreach ($users as $user) { |
||
| 523 | $acronym = $user->acronym; |
||
| 524 | // get all questions made by user |
||
| 525 | $quests = $res->getProfileInfo($acronym, $this->di, "Question", "question"); |
||
| 526 | // get all comments made by user |
||
| 527 | $com = $res->getProfileInfo($acronym, $this->di, "Comments", "comment"); |
||
| 528 | // get all answers made by user |
||
| 529 | $ans = $res->getProfileInfo($acronym, $this->di, "Answers", "answer"); |
||
| 530 | // sum up everything |
||
| 531 | $sums[$acronym] = sizeof($quests) + sizeof($com) + sizeof($ans); |
||
| 532 | } |
||
| 533 | |||
| 534 | arsort($sums); |
||
| 535 | |||
| 536 | // get all tags and count how many times they occur |
||
| 537 | $tags = $res->getAllTags($this->di); |
||
| 538 | $tags2 = $res->countTagsFrequency($tags); |
||
| 539 | arsort($tags2); |
||
| 540 | |||
| 541 | $data = [ |
||
| 542 | "questions" => $questions2, |
||
| 543 | "size" => sizeof($questions), |
||
| 544 | "userStatus" => array_slice($sums, 0, 3), |
||
| 545 | "tags" => array_slice($tags2, 0, 3), |
||
| 546 | ]; |
||
| 547 | |||
| 548 | $page->add("questions", $data); |
||
| 549 | |||
| 550 | return $page->render([ |
||
| 551 | "title" => "A create user page", |
||
| 552 | ]); |
||
| 553 | } |
||
| 554 | |||
| 555 | |||
| 556 | /** |
||
| 557 | * Description. |
||
| 558 | * |
||
| 559 | * @param datatype $variable Description |
||
| 560 | * |
||
| 561 | * @throws Exception |
||
| 562 | * |
||
| 563 | * @return object as a response object |
||
| 564 | */ |
||
| 565 | public function tagsAction() : object |
||
| 566 | { |
||
| 567 | $page = $this->di->get("page"); |
||
| 568 | |||
| 569 | // Get all from comments where id = $commentId. |
||
| 570 | $res = new Functions(); |
||
| 571 | $tags = $res->getAllTags($this->di); |
||
| 572 | $tags2 = $res->getTagsOnce($tags); |
||
| 573 | sort($tags2); |
||
| 574 | // var_dump($tags2); |
||
| 575 | |||
| 576 | $page->add("tags", [ |
||
| 577 | "tags" => $tags2, |
||
| 578 | ]); |
||
| 579 | |||
| 580 | return $page->render([ |
||
| 581 | "title" => "A create user page", |
||
| 582 | ]); |
||
| 583 | } |
||
| 584 | |||
| 585 | |||
| 586 | /** |
||
| 587 | * Description. |
||
| 588 | * |
||
| 589 | * @param datatype $variable Description |
||
| 590 | * |
||
| 591 | * @throws Exception |
||
| 592 | * |
||
| 593 | * @return object as a response object |
||
| 594 | */ |
||
| 595 | public function usersAction() : object |
||
| 611 | ]); |
||
| 612 | } |
||
| 613 | |||
| 614 | |||
| 615 | /** |
||
| 616 | * Description. |
||
| 617 | * |
||
| 618 | * @param datatype $variable Description |
||
| 619 | * |
||
| 620 | * @throws Exception |
||
| 621 | * |
||
| 622 | * @return object as a response object |
||
| 623 | */ |
||
| 624 | public function acceptAnswerAction(int $questionId, int $commentId) : object |
||
| 625 | { |
||
| 626 | $response = $this->di->get("response"); |
||
| 627 | $page = $this->di->get("page"); |
||
| 628 | |||
| 629 | // Get all from comments where id = $commentId. |
||
| 630 | $res = new Functions(); |
||
| 631 | $comment = $res->getOneQuestionComment($this->di, $commentId); |
||
| 632 | var_dump($comment); |
||
| 633 | |||
| 634 | $acronym = $comment[0]->acronym; |
||
| 635 | $answer = $comment[0]->comment; |
||
| 636 | $created = $comment[0]->created; |
||
| 637 | |||
| 638 | // Save as answer. |
||
| 639 | $res->saveAnswer($this->di, $questionId, $acronym, $answer, $created); |
||
| 640 | |||
| 641 | // Delete comment. |
||
| 642 | $res->deleteComment($this->di, $commentId); |
||
| 643 | |||
| 644 | var_dump($comment[0]->comment); |
||
| 645 | |||
| 646 | // $page->add("anax/v2/article/default", [ |
||
| 647 | // "content" => "Hello", |
||
| 648 | // ]); |
||
| 649 | // |
||
| 650 | // return $page->render([ |
||
| 651 | // "title" => "A create user page", |
||
| 652 | // ]); |
||
| 653 | |||
| 654 | |||
| 655 | $response->redirect("user/viewQuestion/{$questionId}"); |
||
| 656 | } |
||
| 657 | |||
| 658 | |||
| 659 | /** |
||
| 660 | * Description. |
||
| 661 | * |
||
| 662 | * @param datatype $variable Description |
||
| 663 | * |
||
| 664 | * @throws Exception |
||
| 665 | * |
||
| 666 | * @return object as a response object |
||
| 667 | */ |
||
| 668 | public function showQuestionsAction() : object |
||
| 735 | ]); |
||
| 736 | } |
||
| 737 | |||
| 738 | |||
| 739 | /** |
||
| 740 | * Description. |
||
| 741 | * |
||
| 742 | * @param datatype $variable Description |
||
| 743 | * |
||
| 744 | * @throws Exception |
||
| 745 | * |
||
| 746 | * @return object as a response object |
||
| 747 | */ |
||
| 748 | public function viewQuestionAction(int $id) : object |
||
| 749 | { |
||
| 750 | $page = $this->di->get("page"); |
||
| 751 | $request = $this->di->get("request"); |
||
| 752 | |||
| 753 | // get all questions to show in the view. |
||
| 754 | $res = new Functions(); |
||
| 755 | $question = $res->getOneQuestion($this->di, $id); |
||
| 756 | $submit = $request->getPost("submit-sort") ?? null; |
||
| 757 | $answers = $res->getAnswersOrdered($this->di, $id, "created"); |
||
| 758 | if ($submit) { |
||
| 759 | $sort = $request->getPost("sort") ?? null; |
||
| 760 | // var_dump($sort); |
||
| 761 | $answers = $res->getAnswersOrdered($this->di, $id, $sort); |
||
| 762 | } |
||
| 763 | $comments = $res->getQuestionComments($this->di, $id); |
||
| 764 | |||
| 765 | // get answerId and make an array of all |
||
| 766 | // comments connected to all answers...? |
||
| 767 | // Lägg till alla aComments som tillhör $answers[0] |
||
| 768 | // till $answers. |
||
| 769 | $aComments = $res->getAnswerComments($this->di, 1); |
||
| 770 | // $smask = $answers; |
||
| 771 | |||
| 772 | foreach ($answers as $answer) { |
||
| 773 | // var_dump($answer->id); |
||
| 774 | $aComments2 = $res->getAnswerComments($this->di, $answer->id); |
||
| 775 | $answer->comments = $aComments2; |
||
| 776 | // $smask->comments = $aComments2; |
||
| 777 | } |
||
| 778 | // var_dump($answers); |
||
| 779 | |||
| 780 | // var_dump($comments); |
||
| 781 | $qId = $question[0]->id; |
||
| 782 | |||
| 783 | $user = $_SESSION["acronym"]; |
||
| 784 | |||
| 785 | $form = new CreateCommentsForm($this->di, $user, $qId); |
||
| 786 | $form->check(); |
||
| 787 | |||
| 788 | $acronym = $res->changeCharacter($question[0]->acronym); |
||
| 789 | // $aForm = new CreateAnswerCommentsForm($this->di, $acronym, $aId ?? 1); |
||
| 790 | // $aForm->check(); |
||
| 791 | |||
| 792 | // $textfilter = new TextFilter(); |
||
| 793 | $filter = new \Anax\TextFilter\TextFilter(); |
||
| 794 | // var_dump($form); |
||
| 795 | $up = "<img src='../../../htdocs/image/up.png' width='30px'></img>"; |
||
| 796 | $down = "<img src='../../../htdocs/image/down.png' width='30px'></img>"; |
||
| 797 | |||
| 798 | |||
| 799 | |||
| 800 | $page->add("view-question", [ |
||
| 801 | "res" => $question, |
||
| 802 | "answers" => $answers, |
||
| 803 | "qComments" => $comments, |
||
| 804 | "aComments" => $aComments, |
||
| 805 | "qComForm" => $form->getHTML(), |
||
| 806 | // "aComForm" => $aForm->getHTML(), |
||
| 807 | "acronym" => $acronym, |
||
| 808 | "filter" => $filter, |
||
| 809 | "up" => $up, |
||
| 810 | "down" => $down, |
||
| 811 | "user" => $user, |
||
| 812 | "qId" => $id, |
||
| 813 | ]); |
||
| 814 | |||
| 815 | $tags = $question[0]->tags ?? "Grönsaker, Plantor"; |
||
| 816 | $tagsArray = explode("; ", $tags); |
||
| 817 | |||
| 818 | $page->add("show-tags", [ |
||
| 819 | "res" => $tagsArray, |
||
| 820 | ], "sidebar-right"); |
||
| 821 | |||
| 822 | $pic = [ |
||
| 823 | // "content" => "<img src='../../../htdocs/image/snail2.jpg' width='1100px'></img>", |
||
| 824 | "content" => "<h1>Allt om trädgård</h1>", |
||
| 825 | ]; |
||
| 826 | |||
| 827 | $page->add("anax/v2/article/default", $pic, "flash"); |
||
| 828 | |||
| 829 | $content = "<h2>Info</h2><p>Betygsätt en fråga, svar eller kommentar genom att klicka pil upp, om du tyckte den var bra, eller pil ner, om den var dålig.</p>"; |
||
| 830 | $page->add("anax/v2/article/default", [ |
||
| 831 | "content" => $content, |
||
| 832 | ], "sidebar-right"); |
||
| 833 | |||
| 834 | $page->add("ask-tip", [], "sidebar-right"); |
||
| 835 | |||
| 836 | return $page->render([ |
||
| 837 | "title" => "View question", |
||
| 838 | ]); |
||
| 839 | } |
||
| 840 | |||
| 841 | |||
| 842 | /** |
||
| 843 | * Description. |
||
| 844 | * |
||
| 845 | * @param datatype $variable Description |
||
| 846 | * |
||
| 847 | * @throws Exception |
||
| 848 | * |
||
| 849 | * @return object as a response object |
||
| 850 | */ |
||
| 851 | public function editPostAction(int $id, string $table) : object |
||
| 922 | ]); |
||
| 923 | } |
||
| 924 | |||
| 925 | |||
| 926 | /** |
||
| 927 | * Description. |
||
| 928 | * |
||
| 929 | * @param datatype $variable Description |
||
| 930 | * |
||
| 931 | * @throws Exception |
||
| 932 | * |
||
| 933 | * @return object as a response object |
||
| 934 | */ |
||
| 935 | public function viewTagQuestionsAction(string $tag) : object |
||
| 972 | ]); |
||
| 973 | } |
||
| 974 | |||
| 975 | |||
| 976 | /** |
||
| 977 | * Description. |
||
| 978 | * |
||
| 979 | * @param string $table Informs if points should be changed |
||
| 980 | * for question/answer/comment. |
||
| 981 | * @param int $qId The id of the question previously shown. |
||
| 982 | * @param int $id The id of the question/answer/comment. |
||
| 983 | * |
||
| 984 | * @throws Exception |
||
| 985 | * |
||
| 986 | * @return |
||
| 987 | */ |
||
| 988 | public function pointsAction(string $table, int $qId, int $id, int $points) |
||
| 1003 | } |
||
| 1004 | } |
||
| 1005 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths