-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Learnpath: Enable survey access in LP without invitation - refs #5713 #5766
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use Chamilo\CourseBundle\Entity\CLpRelUser; | ||
use Chamilo\CoreBundle\Framework\Container; | ||
use Chamilo\CoreBundle\Repository\Node\CourseRepository; | ||
use Chamilo\CourseBundle\Entity\CSurvey; | ||
use Chamilo\CourseBundle\Repository\CLpRelUserRepository; | ||
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver; | ||
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder; | ||
|
@@ -2767,7 +2768,7 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false) | |
// then change the lp type to thread it as a normal Chamilo LP not a SCO. | ||
if (in_array( | ||
$lp_item_type, | ||
['quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication'] | ||
['quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication', 'survey'] | ||
) | ||
) { | ||
$lp_type = CLp::LP_TYPE; | ||
|
@@ -8015,6 +8016,27 @@ public static function rl_get_resource_link_for_learnpath( | |
} | ||
|
||
return $main_dir_path.'work/work.php?'.api_get_cidreq().'&id='.$rowItem->getPath().'&'.$extraParams; | ||
case TOOL_SURVEY: | ||
|
||
$surveyId = (int) $id; | ||
$repo = Container::getSurveyRepository(); | ||
if (!empty($surveyId)) { | ||
/** @var CSurvey $survey */ | ||
$survey = $repo->find($surveyId); | ||
$autoSurveyLink = SurveyUtil::generateFillSurveyLink( | ||
$survey, | ||
'auto', | ||
api_get_course_entity($course_id), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable "course_id" is not in valid camel caps format |
||
$session_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable "session_id" is not in valid camel caps format |
||
); | ||
$lpParams = [ | ||
'lp_id' => $learningPathId, | ||
'lp_item_id' => $id_in_path, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable "id_in_path" is not in valid camel caps format |
||
'origin' => 'learnpath', | ||
]; | ||
|
||
return $autoSurveyLink.'&'.http_build_query($lpParams).'&'.$extraParams; | ||
} | ||
} | ||
|
||
return $link; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,8 @@ | |
$courseId = $courseInfo['real_id']; | ||
$userInfo = api_get_user_info(); | ||
$sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : api_get_session_id(); | ||
$lpItemId = isset($_GET['lp_item_id']) ? (int) $_GET['lp_item_id'] : 0; | ||
$allowSurveyInLp = true; | ||
|
||
if (!empty($userInfo)) { | ||
$interbreadcrumb[] = [ | ||
|
@@ -89,6 +91,16 @@ | |
$surveyId = $survey->getIid(); | ||
$invitationCode = $_GET['invitationcode'] ?? null; | ||
|
||
$lpItemCondition = ''; | ||
if ($allowSurveyInLp && !empty($lpItemId)) { | ||
$lpItemCondition = " AND c_lp_item_id = $lpItemId"; | ||
} | ||
|
||
$sessionCondition = ''; | ||
if (true === api_get_setting('survey.show_surveys_base_in_sessions')) { | ||
$sessionCondition = api_get_session_condition($sessionId); | ||
} | ||
|
||
/*$surveyCode = isset($_GET['scode']) ? Database::escape_string($_GET['scode']) : ''; | ||
if ('' != $surveyCode) { | ||
// Firstly we check if this survey is ready for anonymous use: | ||
|
@@ -122,7 +134,9 @@ | |
$userid, | ||
$surveyCode, | ||
$courseId, | ||
$sessionId | ||
$sessionId, | ||
0, | ||
$lpItemId | ||
); | ||
$lastInvitation = current($invitations); | ||
|
||
|
@@ -142,7 +156,9 @@ | |
FROM $table_survey_invitation | ||
WHERE | ||
c_id = $courseId AND | ||
invitation_code = '".Database::escape_string($autoInvitationCode)."'"; | ||
invitation_code = '".Database::escape_string($autoInvitationCode)."' | ||
$sessionCondition | ||
$lpItemCondition"; | ||
$result = Database::query($sql); | ||
$now = api_get_utc_datetime(); | ||
if (0 == Database::num_rows($result)) { | ||
|
@@ -153,7 +169,7 @@ | |
'invitation_code' => $autoInvitationCode, | ||
'invitation_date' => $now, | ||
'answered' => 0, | ||
'c_lp_item_id' => 0, | ||
'c_lp_item_id' => $lpItemId, | ||
]; | ||
Database::insert($table_survey_invitation, $params); | ||
} | ||
|
@@ -167,7 +183,9 @@ | |
$sql = "SELECT * FROM $table_survey_invitation | ||
WHERE | ||
c_id = $courseId AND | ||
invitation_code = '".Database::escape_string($invitationCode)."'"; | ||
invitation_code = '".Database::escape_string($invitationCode)."' | ||
$sessionCondition | ||
$lpItemCondition"; | ||
$result = Database::query($sql); | ||
if (Database::num_rows($result) < 1) { | ||
api_not_allowed(true, get_lang('Wrong invitation code')); | ||
|
@@ -256,7 +274,8 @@ | |
SurveyUtil::remove_answer( | ||
$survey_invitation['user_id'], | ||
$surveyId, | ||
$survey_question_id | ||
$survey_question_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable "survey_question_id" is not in valid camel caps format |
||
$lpItemId | ||
); | ||
|
||
foreach ($value as $answer_key => &$answer_value) { | ||
|
@@ -273,7 +292,9 @@ | |
$survey, | ||
$question, | ||
$option_id, | ||
$option_value | ||
$option_value, | ||
'', | ||
$lpItemId | ||
); | ||
} | ||
} else { | ||
|
@@ -298,7 +319,8 @@ | |
SurveyUtil::remove_answer( | ||
$survey_invitation['user_id'], | ||
$surveyId, | ||
$survey_question_id | ||
$survey_question_id, | ||
$lpItemId | ||
); | ||
|
||
SurveyUtil::saveAnswer( | ||
|
@@ -307,7 +329,8 @@ | |
$question, | ||
$value, | ||
$option_value, | ||
$other | ||
$other, | ||
$lpItemId | ||
); | ||
} | ||
} | ||
|
@@ -358,15 +381,24 @@ | |
SurveyUtil::remove_answer( | ||
$survey_invitation['user_id'], | ||
$survey_invitation['survey_id'], | ||
$survey_question_id | ||
$survey_question_id, | ||
api_get_course_int_id(), | ||
$lpItemId | ||
); | ||
|
||
|
||
$surveyId = (int) $survey_invitation['survey_id']; | ||
$repo = Container::getSurveyRepository(); | ||
$survey = $repo->find($surveyId); | ||
|
||
SurveyUtil::saveAnswer( | ||
$survey_invitation['user_id'], | ||
$survey_invitation['survey_id'], | ||
api_get_user_entity($survey_invitation['user_id']), | ||
$survey, | ||
$questionList[$survey_question_id], | ||
$value, | ||
$option_value | ||
$option_value, | ||
'', | ||
$lpItemId | ||
); | ||
} | ||
} | ||
|
@@ -398,12 +430,16 @@ | |
} | ||
} | ||
|
||
$url = api_get_self().'?cid='.$courseId.'&sid='.$sessionId; | ||
$url = api_get_self().'?'.api_get_cidreq(); | ||
$listQueryParams = explode('&', $_SERVER['QUERY_STRING']); | ||
foreach ($listQueryParams as $param) { | ||
$url .= '&'.Security::remove_XSS($param); | ||
} | ||
|
||
if (!empty($lpItemId)) { | ||
$url .= '&lp_item_id='.$lpItemId; | ||
} | ||
|
||
// We use the same form as in auth/profile.php | ||
$form = new FormValidator('profile', 'post', $url); | ||
if (api_is_western_name_order()) { | ||
|
@@ -611,10 +647,10 @@ | |
if (isset($_POST['finish_survey'])) { | ||
echo Display::return_message(get_lang('You have finished this survey.'), 'confirm'); | ||
echo Security::remove_XSS($survey->getSurveythanks()); | ||
SurveyManager::updateSurveyAnswered($survey, $survey_invitation['user_id']); | ||
SurveyManager::updateSurveyAnswered($survey, $survey_invitation['user_id'], $lpItemId); | ||
SurveyUtil::flagSurveyAsAnswered($survey->getCode(), $survey_invitation['c_id']); | ||
|
||
if ($courseInfo && !api_is_anonymous()) { | ||
if ($courseInfo && !api_is_anonymous() && 'learnpath' !== api_get_origin()) { | ||
echo '<br /><br />'; | ||
echo Display::toolbarButton( | ||
get_lang('Return to Course Homepage'), | ||
|
@@ -1179,7 +1215,7 @@ | |
$g_cr = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : ''; | ||
$p_l = isset($_POST['language']) ? Security::remove_XSS($_POST['language']) : ''; | ||
$add_parameters = isset($_GET['user_id']) ? '&user_id='.intval($_GET['user_id']) : ''; | ||
$url = api_get_self().'?cid='.$courseId.'&sid='.$sessionId.$add_parameters. | ||
$url = api_get_self().'?'.api_get_cidreq().$add_parameters. | ||
'&course='.$g_c. | ||
'&invitationcode='.$g_ic. | ||
'&show='.$show. | ||
|
@@ -1189,6 +1225,11 @@ | |
$lang = Security::remove_XSS($_GET['language']); | ||
$url .= '&language='.$lang; | ||
} | ||
|
||
if (!empty($lpItemId)) { | ||
$url .= '&lp_item_id='.$lpItemId; | ||
} | ||
|
||
$form = new FormValidator( | ||
'question', | ||
'post', | ||
|
@@ -1256,7 +1297,7 @@ | |
} | ||
$form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div> '); | ||
|
||
$userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']); | ||
$userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id'], $lpItemId); | ||
$finalAnswer = null; | ||
|
||
if (!empty($userAnswerData[$user_id])) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CASE body must start on the line following the statement