TopicManagementController.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class TopicManagementController implements IController {
  3. public function execute() {
  4. $view = new View();
  5. $database = new Database();
  6. $permissionDecider = new PermissionDecider();
  7. $headRenderer = new HeadRenderer();
  8. $user = new User();
  9. $loginViewDecider = new LoginViewDecider();
  10. $form = new Form();
  11. $topicModel = new TopicModel();
  12. $user->populate();
  13. $userId = $user->getId();
  14. $topicId = $form->getCleanDefaulted('id', 0);
  15. $topicData = $topicModel->getCurrentTopic($topicId);
  16. $sql = sprintf("SELECT *
  17. FROM user_topic_acl acl
  18. JOIN users u ON acl.user_id = u.user_id
  19. WHERE rank_id = 2 AND topic_id = '%s'", $topicId);
  20. $ownerData = $database->query($sql);
  21. $sql = sprintf("SELECT *
  22. FROM user_topic_acl acl
  23. JOIN users u ON acl.user_id = u.user_id
  24. WHERE rank_id = 3 AND topic_id = '%s'", $topicId);
  25. $moderatorData = $database->query($sql);
  26. $sql = sprintf("SELECT t.topic_id, t.display_name, t.description
  27. FROM topic_topic_associations tt
  28. JOIN topics t ON t.topic_id = tt.subtopic_id
  29. WHERE tt.topic_id = '%s'", $topicId);
  30. $subtopics = $database->query($sql);
  31. $topicAccess = $permissionDecider->hasTopicAccess($topicId);
  32. $viewData = array(
  33. "header" => $headRenderer->render(),
  34. "topicData" => $topicData,
  35. "owner" => $ownerData[0],
  36. "moderators" => $moderatorData,
  37. "topicAccess" => $topicAccess,
  38. "subtopics" => $subtopics
  39. );
  40. if ($userId) {
  41. return $view->render('topicManagementView.inc', $viewData);
  42. } else {
  43. return $view->render("logInPromptView.inc", $viewData);
  44. }
  45. }
  46. }