Add survey report see BT#15553

pull/2913/head
Julio Montoya 7 years ago
parent cd0f0b8419
commit cc9003b4a0
  1. 4
      main/inc/lib/myspace.lib.php
  2. 64
      main/survey/survey.lib.php

@ -53,6 +53,10 @@ class MySpace
'url' => api_get_path(WEB_CODE_PATH).'mySpace/exercise_category_report.php', 'url' => api_get_path(WEB_CODE_PATH).'mySpace/exercise_category_report.php',
'content' => get_lang('ExerciseCategoryAllSessionsReport'), 'content' => get_lang('ExerciseCategoryAllSessionsReport'),
], ],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/survey_report.php',
'content' => get_lang('SurveyReport'),
],
]; ];
return Display::actions($actions, null); return Display::actions($actions, null);

@ -2387,4 +2387,68 @@ class SurveyManager
return $invitations; return $invitations;
} }
/**
* @param array $userInfo
* @param int $answered
*
* @return string
*/
public static function surveyReport($userInfo, $answered = 0)
{
$userId = $userInfo['user_id'];
$answered = (int) $answered;
if (empty($userId)) {
return '';
}
$em = Database::getManager();
$repo = $em->getRepository('ChamiloCourseBundle:CSurveyInvitation');
$repoSurvey = $em->getRepository('ChamiloCourseBundle:CSurvey');
$invitations = $repo->findBy(['user' => $userId, 'answered' => $answered]);
$mainUrl = api_get_path(WEB_CODE_PATH).'survey/survey.php?';
$content = '';
if (!empty($invitations)) {
$table = new HTML_Table(['class' => 'table']);
$table->setHeaderContents(0, 0, get_lang('SurveyName'));
$table->setHeaderContents(0, 1, get_lang('Course'));
if (empty($answered)) {
$content .= Display::page_subheader(get_lang('Answered'));
} else {
$content .= Display::page_subheader(get_lang('Unanswered'));
}
// Not answered
/** @var CSurveyInvitation $invitation */
$row = 1;
foreach ($invitations as $invitation) {
$courseId = $invitation->getCId();
$courseInfo = api_get_course_info_by_id($courseId);
$sessionId = $invitation->getSessionId();
$surveyCode = $invitation->getSurveyCode();
$survey = $repoSurvey->findOneBy(['cId' => $courseId, 'sessionId' => $sessionId, 'code' => $surveyCode]);
if (empty($survey)) {
continue;
}
$url = $mainUrl.'survey_id='.$survey->getSurveyId().'&cidReq='.$courseInfo['code'].'&id_session='.$sessionId;
$title = $survey->getTitle();
$title = Display::url($title, $url);
if (!empty($sessionId)) {
$sessionInfo = api_get_session_info($sessionId);
$courseInfo['name'] .= ' ('.$sessionInfo['name'].')';
}
$table->setCellContents($row, 0, $title);
$table->setCellContents($row, 1, $courseInfo['name']);
$row++;
}
$content .= $table->toHtml();
}
return $content;
}
} }

Loading…
Cancel
Save