Survey: Avoid generate auto invitation code when invitation already exists - refs BT#15392

pull/2901/head
Angel Fernando Quiroz Campos 7 years ago
parent 56d5998d4b
commit 76c8c5e75a
  1. 12
      main/survey/fillsurvey.php
  2. 31
      main/survey/survey.lib.php

@ -99,8 +99,20 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
if ($isAnonymous) { if ($isAnonymous) {
$autoInvitationcode = 'auto-ANONY_'.md5(time())."-$surveyCode"; $autoInvitationcode = 'auto-ANONY_'.md5(time())."-$surveyCode";
} else { } else {
$invitations = SurveyManager::getUserInvitationsForSurveyInCourse(
$userid,
$surveyCode,
$courseInfo['real_id'],
$sessionId
);
$lastInvitation = current($invitations);
if (!$lastInvitation) {
// New invitation code from userid // New invitation code from userid
$autoInvitationcode = "auto-$userid-$surveyCode"; $autoInvitationcode = "auto-$userid-$surveyCode";
} else {
$autoInvitationcode = $lastInvitation->getInvitationCode();
}
} }
// The survey code must exist in this course, or the URL is invalid // The survey code must exist in this course, or the URL is invalid

@ -2356,4 +2356,35 @@ class SurveyManager
); );
} }
} }
/**
* @param int $userId
* @param string $surveyCode
* @param int $courseId
* @param int $sessionId
* @param int $groupId
*
* @return array|CSurveyInvitation[]
*/
public static function getUserInvitationsForSurveyInCourse(
$userId,
$surveyCode,
$courseId,
$sessionId = 0,
$groupId = 0
) {
$invitationRepo = Database::getManager()->getRepository('ChamiloCourseBundle:CSurveyInvitation');
$invitations = $invitationRepo->findBy(
[
'user' => $userId,
'cId' => $courseId,
'sessionId' => $sessionId,
'groupId' => $groupId,
'surveyCode' => $surveyCode,
],
['invitationDate' => 'DESC']
);
return $invitations;
}
} }

Loading…
Cancel
Save