pending.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\CoreBundle\Entity\Session;
  5. use Chamilo\CourseBundle\Entity\CSurvey;
  6. use Chamilo\CourseBundle\Entity\CSurveyInvitation;
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. $em = Database::getManager();
  11. $currentUser = api_get_user_entity(api_get_user_id());
  12. $avatarPath = UserManager::getUserPicture($currentUser->getId());
  13. $pending = SurveyUtil::getUserPendingInvitations($currentUser->getId());
  14. $surveysData = [];
  15. foreach ($pending as $i => $item) {
  16. if (is_a($item, 'Chamilo\CourseBundle\Entity\CSurveyInvitation')) {
  17. continue;
  18. }
  19. /** @var CSurvey $survey */
  20. $survey = $item;
  21. /** @var CSurveyInvitation invitation */
  22. $invitation = $pending[$i + 1];
  23. /** @var Course $course */
  24. $course = $em->find('ChamiloCoreBundle:Course', $survey->getCId());
  25. /** @var Session $session */
  26. $session = $em->find('ChamiloCoreBundle:Session', $survey->getSessionId());
  27. $course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null;
  28. $session = $session ? ['id' => $session->getId(), 'name' => $session->getName()] : null;
  29. $courseInfo = api_get_course_info_by_id($course->getId());
  30. $surveysData[$survey->getSurveyId()] = [
  31. 'title' => $survey->getTitle(),
  32. 'avail_from' => $survey->getAvailFrom(),
  33. 'avail_till' => $survey->getAvailTill(),
  34. 'course' => $course,
  35. 'session' => $session,
  36. 'link' => SurveyUtil::generateFillSurveyLink(
  37. $invitation->getInvitationCode(),
  38. $courseInfo,
  39. $survey->getSessionId()
  40. ),
  41. ];
  42. }
  43. $toolName = get_lang('PendingSurveys');
  44. $template = new Template($toolName);
  45. $template->assign('user', $currentUser);
  46. $template->assign('user_avatar', $avatarPath);
  47. $template->assign('surveys', $surveysData);
  48. $layout = $template->get_template('survey/pending.tpl');
  49. $content = $template->fetch($layout);
  50. $template->assign('header', $toolName);
  51. $template->assign('content', $content);
  52. $template->display_one_col_template();