ChangeSubscriptionController.inc 991 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class ChangeSubscriptionController implements IController {
  3. const SUBSCRIBE = 1;
  4. const UNSUBSCRIBE = 0;
  5. public function execute() {
  6. $view = new View();
  7. $session = new Session();
  8. $userId = $session->getValue("logged_in");
  9. $viewData = array();
  10. if ($userId) {
  11. $form = new Form();
  12. $database = new Database();
  13. $topicId = $form->getCleanDefaulted('id', 0);
  14. $subscribeAction = $form->getCleanDefaulted('s', ChangeSubscriptionController::UNSUBSCRIBE);
  15. switch ($subscribeAction) {
  16. case ChangeSubscriptionController::SUBSCRIBE:
  17. $sql = sprintf("INSERT IGNORE
  18. INTO user_topic_subscription (user_id, topic_id)
  19. VALUES ('%s', '%s')", $userId, $topicId);
  20. $database->query($sql);
  21. break;
  22. case ChangeSubscriptionController::UNSUBSCRIBE:
  23. $sql = sprintf("DELETE IGNORE
  24. FROM user_topic_subscription
  25. WHERE user_id = '%s' AND topic_id = '%s'", $userId, $topicId);
  26. $database->query($sql);
  27. break;
  28. }
  29. }
  30. }
  31. }