content.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. use Chamilo\PluginBundle\Entity\CourseHomeNotify\Notification;
  5. use Chamilo\PluginBundle\Entity\CourseHomeNotify\NotificationRelUser;
  6. api_block_anonymous_users(true);
  7. api_protect_course_script(true);
  8. $plugin = CourseHomeNotifyPlugin::create();
  9. $userId = api_get_user_id();
  10. $courseId = api_get_course_int_id();
  11. if (
  12. empty($courseId) ||
  13. empty($userId) ||
  14. 'true' !== $plugin->get(CourseHomeNotifyPlugin::SETTING_ENABLED)
  15. ) {
  16. api_not_allowed(true);
  17. }
  18. $user = api_get_user_entity($userId);
  19. $course = api_get_course_entity($courseId);
  20. $hash = isset($_GET['hash']) ? Security::remove_XSS($_GET['hash']) : null;
  21. $em = Database::getManager();
  22. /** @var Notification $notification */
  23. $notification = $em
  24. ->getRepository('ChamiloPluginBundle:CourseHomeNotify\Notification')
  25. ->findOneBy(['course' => $course, 'hash' => $hash]);
  26. if (!$notification) {
  27. api_not_allowed(true);
  28. }
  29. $notificationUser = $em
  30. ->getRepository('ChamiloPluginBundle:CourseHomeNotify\NotificationRelUser')
  31. ->findOneBy(['notification' => $notification, 'user' => $user]);
  32. if (!$notificationUser) {
  33. $notificationUser = new NotificationRelUser();
  34. $notificationUser
  35. ->setUser($user)
  36. ->setNotification($notification);
  37. $em->persist($notificationUser);
  38. $em->flush();
  39. }
  40. header('Location: '.$notification->getExpirationLink());