|
|
@ -227,188 +227,14 @@ if (!empty($learnpath_id) && $saveResults) { |
|
|
|
Exercise::saveExerciseInLp($learnpath_item_id, $exeId); |
|
|
|
Exercise::saveExerciseInLp($learnpath_item_id, $exeId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$notifications = api_get_configuration_value('exercise_finished_notification_settings'); |
|
|
|
ExerciseLib::sendNotification( |
|
|
|
if (!empty($notifications)) { |
|
|
|
api_get_user_id(), |
|
|
|
$exerciseExtraFieldValue = new ExtraFieldValue('exercise'); |
|
|
|
$objExercise, |
|
|
|
$attemptCountToSend = $attempt_count++; |
|
|
|
$exercise_stat_info, |
|
|
|
$wrongAnswersCount = $stats['failed_answers_count']; |
|
|
|
$courseInfo, |
|
|
|
$exercisePassed = $stats['exercise_passed']; |
|
|
|
$attempt_count++, |
|
|
|
$countPendingQuestions = $stats['count_pending_questions']; |
|
|
|
$stats |
|
|
|
// If there are no pending questions (Open questions). |
|
|
|
); |
|
|
|
if (0 === $countPendingQuestions) { |
|
|
|
|
|
|
|
$totalScore = ExerciseLib::show_score($total_score, $max_score, false, true); |
|
|
|
|
|
|
|
$subject = sprintf(get_lang('WrongAttemptXInCourseX'), $attemptCountToSend, $courseInfo['title']); |
|
|
|
|
|
|
|
if ($exercisePassed) { |
|
|
|
|
|
|
|
$subject = sprintf(get_lang('ExerciseValidationInCourseX'), $courseInfo['title']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($exercisePassed) { |
|
|
|
|
|
|
|
$extraFieldData = $exerciseExtraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$objExercise->iId, |
|
|
|
|
|
|
|
'MailSuccess' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$extraFieldData = $exerciseExtraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$objExercise->iId, |
|
|
|
|
|
|
|
'MailAttempt'.$attemptCountToSend |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$content = ''; |
|
|
|
|
|
|
|
if ($extraFieldData && isset($extraFieldData['value'])) { |
|
|
|
|
|
|
|
$content = $extraFieldData['value']; |
|
|
|
|
|
|
|
$content = ExerciseLib::parseContent($content, $stats, $objExercise, $exercise_stat_info); |
|
|
|
|
|
|
|
if (false === $exercisePassed) { |
|
|
|
|
|
|
|
if (0 !== $wrongAnswersCount) { |
|
|
|
|
|
|
|
$content .= $stats['failed_answers_html']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send to student |
|
|
|
|
|
|
|
MessageManager::send_message($currentUserId, $subject, $content); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Subject for notifications |
|
|
|
|
|
|
|
/*$subject = sprintf(get_lang('WrongAttemptXInCourseX'), $attemptCountToSend, $courseInfo['title']); |
|
|
|
|
|
|
|
if ($exercisePassed) { |
|
|
|
|
|
|
|
$subject = sprintf(get_lang('ExerciseValidationInCourseX'), $courseInfo['title']); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
$extraFieldData = $exerciseExtraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$objExercise->iId, |
|
|
|
|
|
|
|
'notifications' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$exerciseNotification = ''; |
|
|
|
|
|
|
|
if ($extraFieldData && isset($extraFieldData['value'])) { |
|
|
|
|
|
|
|
$exerciseNotification = $extraFieldData['value']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($exerciseNotification) && !empty($notifications)) { |
|
|
|
|
|
|
|
foreach ($notifications as $name => $notificationList) { |
|
|
|
|
|
|
|
if ($exerciseNotification !== $name) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach ($notificationList as $attemptData) { |
|
|
|
|
|
|
|
$email = isset($attemptData['email']) ? $attemptData['email'] : ''; |
|
|
|
|
|
|
|
$emailList = explode(',', $email); |
|
|
|
|
|
|
|
if (empty($emailList)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$attempts = $attemptData['attempts']; |
|
|
|
|
|
|
|
foreach ($attempts as $attempt) { |
|
|
|
|
|
|
|
$sendMessage = false; |
|
|
|
|
|
|
|
if (isset($attempt['attempt']) && $attemptCountToSend !== (int) $attempt['attempt']) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($attempt['status'])) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ($attempt['status']) { |
|
|
|
|
|
|
|
case 'passed': |
|
|
|
|
|
|
|
if ($exercisePassed) { |
|
|
|
|
|
|
|
$sendMessage = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'failed': |
|
|
|
|
|
|
|
if (false === $exercisePassed) { |
|
|
|
|
|
|
|
$sendMessage = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'all': |
|
|
|
|
|
|
|
$sendMessage = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($sendMessage) { |
|
|
|
|
|
|
|
$attachments = []; |
|
|
|
|
|
|
|
if (isset($attempt['add_pdf']) && $attempt['add_pdf']) { |
|
|
|
|
|
|
|
// Get pdf content |
|
|
|
|
|
|
|
$pdfExtraData = $exerciseExtraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$objExercise->iId, |
|
|
|
|
|
|
|
$attempt['add_pdf'] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($pdfExtraData && isset($pdfExtraData['value'])) { |
|
|
|
|
|
|
|
$pdfContent = ExerciseLib::parseContent( |
|
|
|
|
|
|
|
$pdfExtraData['value'], |
|
|
|
|
|
|
|
$stats, |
|
|
|
|
|
|
|
$objExercise, |
|
|
|
|
|
|
|
$exercise_stat_info |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@$pdf = new PDF(); |
|
|
|
|
|
|
|
$filename = get_lang('Exercise'); |
|
|
|
|
|
|
|
$cssFile = api_get_path(SYS_CSS_PATH).'themes/chamilo/default.css'; |
|
|
|
|
|
|
|
$pdfPath = @$pdf->content_to_pdf( |
|
|
|
|
|
|
|
"<html><body>$pdfContent</body></html>", |
|
|
|
|
|
|
|
file_get_contents($cssFile), |
|
|
|
|
|
|
|
$filename, |
|
|
|
|
|
|
|
api_get_course_id(), |
|
|
|
|
|
|
|
'F', |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
true |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$attachments[] = ['filename' => $filename, 'path' => $pdfPath]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$content = isset($attempt['content_default']) ? $attempt['content_default'] : ''; |
|
|
|
|
|
|
|
if (isset($attempt['content'])) { |
|
|
|
|
|
|
|
$extraFieldData = $exerciseExtraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$objExercise->iId, |
|
|
|
|
|
|
|
$attempt['content'] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if ($extraFieldData && isset($extraFieldData['value']) && !empty($extraFieldData['value'])) { |
|
|
|
|
|
|
|
$content = $extraFieldData['value']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($content)) { |
|
|
|
|
|
|
|
$content = ExerciseLib::parseContent( |
|
|
|
|
|
|
|
$content, |
|
|
|
|
|
|
|
$stats, |
|
|
|
|
|
|
|
$objExercise, |
|
|
|
|
|
|
|
$exercise_stat_info |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
foreach ($emailList as $email) { |
|
|
|
|
|
|
|
if (empty($email)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
api_mail_html( |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
$email, |
|
|
|
|
|
|
|
$subject, |
|
|
|
|
|
|
|
$content, |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
[], |
|
|
|
|
|
|
|
$attachments |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($attempt['post_actions'])) { |
|
|
|
|
|
|
|
foreach ($attempt['post_actions'] as $action => $params) { |
|
|
|
|
|
|
|
switch ($action) { |
|
|
|
|
|
|
|
case 'subscribe_student_to_courses': |
|
|
|
|
|
|
|
foreach ($params as $code) { |
|
|
|
|
|
|
|
CourseManager::subscribeUser($currentUserId, $code); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hookQuizEnd = HookQuizEnd::create(); |
|
|
|
$hookQuizEnd = HookQuizEnd::create(); |
|
|
|
$hookQuizEnd->setEventData(['exe_id' => $exeId]); |
|
|
|
$hookQuizEnd->setEventData(['exe_id' => $exeId]); |
|
|
|