New options added to setting 'email_alert_manager_on_new_quiz'

See BT#12303

- Fix Formvalidator to handle multiple checkboxes
- Rework exercise notifications
- CourseManager::saveCourseConfigurationSetting now accepts array
  will be converted into a string comma separated values.
  No database change needed.
remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 9a2455a17e
commit 4601bc570e
  1. 15
      main/course_info/infocours.php
  2. 214
      main/exercise/exercise.class.php
  3. 1
      main/exercise/exercise.php
  4. 14
      main/exercise/exercise_submit.php
  5. 6
      main/inc/lib/api.lib.php
  6. 7
      main/inc/lib/course.lib.php
  7. 14
      main/inc/lib/exercise.lib.php
  8. 4
      main/inc/lib/pear/HTML/QuickForm/checkbox.php
  9. 21
      main/inc/lib/pear/HTML/QuickForm/element.php
  10. 10
      main/lang/english/trad4all.inc.php

@ -348,9 +348,17 @@ $group[] = $form->createElement('radio', 'email_alert_on_new_doc_dropbox', null,
$form->addGroup($group, '', array(get_lang("DropboxEmailAlert")));
$group = array();
$group[] = $form->createElement('radio', 'email_alert_manager_on_new_quiz', get_lang('QuizEmailAlert'), get_lang('QuizEmailAlertActivate'), 1);
$group[] = $form->createElement('radio', 'email_alert_manager_on_new_quiz', null, get_lang('QuizEmailAlertDeactivate'), 0);
$form->addGroup($group, '', array(get_lang("QuizEmailAlert")));
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentStartQuiz'), ['value' => 2]);
// Default
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuiz'), ['value' => 1]);
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion'), ['value' => 3]);
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion'), ['value' => 4]);
//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailAlertDeactivate'), ['value' => 0]);
//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailSendToTeacherWhenStudentEndQuiz'), ['value' => 3]);
$form->addGroup($group, '', array(get_lang("Exercises")));
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
$form->addHtml('
@ -665,7 +673,6 @@ foreach ($courseSettings as $setting) {
$values[$setting] = $result;
}
}
$form->setDefaults($values);
// Validate form

@ -5355,6 +5355,7 @@ class Exercise
/**
* Sends a notification when a user ends an examn
*
* @param string $type 'start' or 'end' of an exercise
* @param array $question_list_answers
* @param string $origin
* @param int $exe_id
@ -5362,33 +5363,110 @@ class Exercise
* @param float $weight
* @return bool
*/
public function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id, $score, $weight)
{
if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) {
public function send_mail_notification_for_exam(
$type = 'end',
$question_list_answers,
$origin,
$exe_id,
$score = null,
$weight = null
) {
$setting = api_get_course_setting('email_alert_manager_on_new_quiz');
if (empty($setting)) {
return false;
}
// Email configuration settings
$courseCode = api_get_course_id();
$courseInfo = api_get_course_info($courseCode);
$sessionId = api_get_session_id();
if (empty($courseInfo)) {
return false;
}
$url_email = api_get_path(WEB_CODE_PATH)
. 'exercise/exercise_show.php?'
. api_get_cidreq()
. '&id_session='
. $sessionId
. '&id='
. $exe_id
. '&action=qualify';
$sessionId = api_get_session_id();
$sendStart = false;
$sendEnd = false;
$sendEndOpenQuestion = false;
$sendEndOralQuestion = false;
foreach ($setting as $option) {
switch ($option) {
case 0:
return false;
break;
case 1: // End
if ($type == 'end') {
$sendEnd = true;
}
break;
case 2: // start
if ($type == 'start') {
$sendStart = true;
}
break;
case 3: // end + open
if ($type == 'end') {
$sendEndOpenQuestion = true;
}
break;
case 4: // end + oral
if ($type == 'end') {
$sendEndOralQuestion = true;
}
break;
}
}
$user_info = api_get_user_info(api_get_user_id());
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise_show.php?'.api_get_cidreq().'&id_session='.$sessionId.'&id='.$exe_id.'&action=qualify';
if (!empty($sessionId)) {
$addGeneralCoach = true;
$setting = api_get_configuration_value('block_quiz_mail_notification_general_coach');
if ($setting === true) {
$addGeneralCoach = false;
}
$teachers = CourseManager::get_coach_list_from_course_code(
$courseCode,
$sessionId,
$addGeneralCoach
);
} else {
$teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
}
if ($sendEndOpenQuestion) {
$this->send_notification_for_open_questions(
$question_list_answers,
$origin,
$exe_id,
$user_info,
$url,
$teachers
);
}
if ($sendEndOralQuestion) {
$this->send_notification_for_oral_questions(
$question_list_answers,
$origin,
$exe_id,
$user_info,
$url,
$teachers
);
}
if (!$sendEnd && !$sendStart) {
return false;
}
$scoreLabel = '';
if (api_get_configuration_value('send_score_in_exam_notification_mail_to_manager') == true) {
if ($sendEnd && api_get_configuration_value('send_score_in_exam_notification_mail_to_manager') == true) {
$scoreLabel = ExerciseLib::show_score($score, $weight, false, true);
$scoreLabel = "<tr>
<td>".get_lang('Score')."</td>
@ -5396,20 +5474,25 @@ class Exercise
</tr>";
}
$msg = get_lang('ExerciseAttempted').'<br /><br />'
.get_lang('AttemptDetails').' : <br /><br />
if ($sendEnd) {
$msg = get_lang('ExerciseAttempted').'<br /><br />';
} else {
$msg = get_lang('StudentStartExercise').'<br /><br />';
}
$msg .= get_lang('AttemptDetails').' : <br /><br />
<table>
<tr>
<td><em>'.get_lang('CourseName').'</em></td>
<td>&nbsp;<b>#course#</b></td>
<td>'.get_lang('CourseName').'</td>
<td>#course#</td>
</tr>
<tr>
<td>'.get_lang('TestAttempted').'</td>
<td>'.get_lang('Exercise').'</td>
<td>&nbsp;#exercise#</td>
</tr>
<tr>
<td>'.get_lang('StudentName').'</td>
<td>&nbsp;#firstName# #lastName#</td>
<td>&nbsp;#student_complete_name#</td>
</tr>
<tr>
<td>'.get_lang('StudentEmail').'</td>
@ -5417,34 +5500,24 @@ class Exercise
</tr>
'.$scoreLabel.'
</table>';
$open_question_list = null;
$msg = str_replace("#email#", $user_info['email'], $msg);
$msg1 = str_replace("#exercise#", $this->exercise, $msg);
$msg = str_replace("#firstName#", $user_info['firstname'], $msg1);
$msg1 = str_replace("#lastName#", $user_info['lastname'], $msg);
$msg = str_replace("#course#", $courseInfo['name'], $msg1);
if ($origin != 'learnpath') {
$variables = [
'#email#' => $user_info['email'],
'#exercise#' => $this->exercise,
'#student_complete_name#' => $user_info['complete_name'],
'#course#' => $courseInfo['title']
];
if ($origin != 'learnpath' && $sendEnd) {
$msg .= '<br /><a href="#url#">'.get_lang('ClickToCommentAndGiveFeedback').'</a>';
$variables['#url#'] = $url;
}
$msg1 = str_replace("#url#", $url_email, $msg);
$mail_content = $msg1;
$subject = get_lang('ExerciseAttempted');
if (!empty($sessionId)) {
$addGeneralCoach = true;
$setting = api_get_configuration_value('block_quiz_mail_notification_general_coach');
if ($setting === true) {
$addGeneralCoach = false;
}
$teachers = CourseManager::get_coach_list_from_course_code(
$courseCode,
$sessionId,
$addGeneralCoach
);
$mail_content = str_replace(array_keys($variables), array_values($variables), $msg);
if ($sendEnd) {
$subject = get_lang('ExerciseAttempted');
} else {
$teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
$subject = get_lang('StudentStartExercise');
}
if (!empty($teachers)) {
@ -5465,23 +5538,17 @@ class Exercise
* @param int $exe_id
* @return null
*/
public function send_notification_for_open_questions($question_list_answers, $origin, $exe_id)
{
if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) {
return null;
}
private function send_notification_for_open_questions(
$question_list_answers,
$origin,
$exe_id,
$user_info,
$url_email,
$teachers
) {
// Email configuration settings
$courseCode = api_get_course_id();
$course_info = api_get_course_info($courseCode);
$url_email = api_get_path(WEB_CODE_PATH)
. 'exercise/exercise_show.php?'
. api_get_cidreq()
. '&id_session='
. api_get_session_id()
. '&id='
. $exe_id
. '&action=qualify';
$user_info = api_get_user_info(api_get_user_id());
$msg = get_lang('OpenQuestionsAttempted').'<br /><br />'
.get_lang('AttemptDetails').' : <br /><br />'
@ -5542,12 +5609,6 @@ class Exercise
$mail_content = $msg1;
$subject = get_lang('OpenQuestionsAttempted');
if (api_get_session_id()) {
$teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
} else {
$teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
}
if (!empty($teachers)) {
foreach ($teachers as $user_id => $teacher_data) {
MessageManager::send_message_simple(
@ -5567,25 +5628,18 @@ class Exercise
* @param int $exe_id
* @return null
*/
public function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id)
{
if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) {
return null;
}
private function send_notification_for_oral_questions(
$question_list_answers,
$origin,
$exe_id,
$user_info,
$url_email,
$teachers
) {
// Email configuration settings
$courseCode = api_get_course_id();
$course_info = api_get_course_info($courseCode);
$url_email = api_get_path(WEB_CODE_PATH)
. 'exercise/exercise_show.php?'
. api_get_cidreq()
. '&id_session='
. api_get_session_id()
. '&id='
. $exe_id
. '&action=qualify';
$user_info = api_get_user_info(api_get_user_id());
$oral_question_list = null;
foreach ($question_list_answers as $item) {
$question = $item['question'];
@ -5640,12 +5694,6 @@ class Exercise
$mail_content = $msg1;
$subject = get_lang('OralQuestionsAttempted');
if (api_get_session_id()) {
$teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
} else {
$teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
}
if (!empty($teachers)) {
foreach ($teachers as $user_id => $teacher_data) {
MessageManager::send_message_simple(

@ -1218,6 +1218,7 @@ if (empty($exerciseList) && $hotpotatoes_exist == false) {
echo '</table>';
echo '</div>';
}
if ($origin != 'learnpath') { //so we are not in learnpath tool
Display :: display_footer();
}

@ -369,6 +369,18 @@ if (empty($exercise_stat_info)) {
$learnpath_item_id,
$learnpath_item_view_id
);
// Send notification at the start
if (!api_is_allowed_to_edit(null, true) &&
!api_is_excluded_user_type()
) {
$objExercise->send_mail_notification_for_exam(
'start',
[],
$origin,
$exe_id
);
}
if ($debug) {
error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
}
@ -1375,5 +1387,5 @@ if ($origin != 'learnpath') {
// So we are not in learnpath tool
echo '</div>'; //End glossary div
}
var_dump(api_get_course_setting('email_alert_manager_on_new_quiz'));
Display :: display_footer();

@ -1656,6 +1656,12 @@ function api_get_course_setting($setting_name, $course_code = null)
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res);
if ($setting_name === 'email_alert_manager_on_new_quiz') {
if (!is_null($row['value'])) {
$result = explode(',', $row['value']);
$row['value'] = $result;
}
}
return $row['value'];
}
}

@ -5390,7 +5390,7 @@ class CourseManager
/**
* @param AppPlugin $appPlugin
* @param string $variable
* @param string $value
* @param string|array $value
* @param int $courseId
* @return bool
*/
@ -5404,6 +5404,11 @@ class CourseManager
}
$courseSettingTable = Database::get_course_table(TABLE_COURSE_SETTING);
if (is_array($value)) {
$value = implode(',', $value);
}
if (self::hasCourseSetting($variable, $courseId)) {
// Update
Database::update(

@ -3983,28 +3983,18 @@ HOTSPOT;
}
}
// Send notification
// Send notification at the end
if (!api_is_allowed_to_edit(null, true) &&
!api_is_excluded_user_type()
) {
$objExercise->send_mail_notification_for_exam(
'end',
$question_list_answers,
$origin,
$exe_id,
$total_score,
$total_weight
);
$objExercise->send_notification_for_open_questions(
$question_list_answers,
$origin,
$exe_id
);
$objExercise->send_notification_for_oral_questions(
$question_list_answers,
$origin,
$exe_id
);
}
}
}

@ -104,7 +104,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
if (!$checked) {
$this->removeAttribute('checked');
} else {
$this->updateAttributes(array('checked'=>'checked'));
$this->updateAttributes(array('checked' => 'checked'));
}
} //end func setChecked
@ -330,6 +330,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
// if no boxes were checked, then there is no value in the array
// yet we don't want to display default value in this case
@ -339,6 +340,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
$value = $this->_findValue($caller->_defaultValues);
}
}
if (null !== $value || $caller->isSubmitted()) {
$this->setChecked($value);
}

@ -426,10 +426,25 @@ class HTML_QuickForm_element extends HTML_Common
if (isset($values[$elementName])) {
return $values[$elementName];
} elseif (strpos($elementName, '[')) {
$myVar = "['" . str_replace(
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
// Fix checkbox
if ($this->_type === 'checkbox') {
$attributeValue = $this->getAttribute('value');
$elementNameCheckBox = str_replace('[]', '', $elementName);
if (isset($values[$elementNameCheckBox]) &&
is_array($values[$elementNameCheckBox])
) {
if (in_array($attributeValue, $values[$elementNameCheckBox])) {
return true;
}
return false;
}
}
$replacedName = str_replace(
array('\\', '\'', ']', '['),
array('\\\\', '\\\'', '', "']['"),
$elementName
) . "']";
);
$myVar = "['$replacedName']";
return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
} else {
return null;

@ -2505,7 +2505,7 @@ $EnterDataNewModule = "Enter information for section";
$CreateNewStep = "Create new rich media page";
$TicketUpdated = "Ticket updated";
$UseAnExistingResource = "Or use an existing resource :";
$Position = "In table of contents";
$Position = "Position";
$NewChapterCreated = "A new section has now been created. You may continue by adding a section or step.";
$NewLinksCreated = "The new link has been created";
$NewStudentPublicationCreated = "The new assignment has been created";
@ -5900,7 +5900,7 @@ $UnsubscribeUsersAlreadyAddedInCourse = "Unsubscribe users already added";
$ImportUsers = "Import users";
$HelpFolderLearningPaths = "INFORMATION VISIBLE TO THE TEACHER ONLY:\nThis folder contains documents which are created by the Learning Path tool. Inside this folder you can edit the HTML file which are generated by importing content from the Learning Path, as the ones imported by Chamilo Rapid, for example. We recommend hiding this folder to your students.";
$YouWillBeRedirectedInXSeconds = "Just a moment, please. You will be redirected in %s seconds...";
$ToProtectYourSiteMakeXReadOnlyAndDeleteY = "To protect your site, make the whole %s directory read-only (chmod 0555 on Linux) and delete the %s directory.";
$ToProtectYourSiteMakeXReadOnlyAndDeleteY = "To protect your site, make the whole %s directory read-only (chmod -R 0555 on Linux) and delete the %s directory.";
$NumberOfCoursesPublic = "Number of public courses";
$NumberOfCoursesOpen = "Number of open courses";
$NumberOfCoursesPrivate = "Number of private courses";
@ -8008,4 +8008,10 @@ $ReadingComprehensionLevelX = "%s words per minute";
$TutorXIsNotSubscribedToCourse = "Tutor %s is no subscribed to this course";
$UpdateTitleInLps = "Update this title in learning paths";
$WebRTCDialogHelp = "To enable video chat in your browser (if it supports it), make sure you click on the information icon on the left of the URL and then authorize the use of the webcam and microphone.";
$UpdateFile = "Update file";
$SendEmailToTeacherWhenStudentStartQuiz = "Send email to teacher when student start an exercise";
$SendEmailToTeacherWhenStudentEndQuiz = "Send email to teacher when student ends an exercise";
$SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion = "Send email to teacher when student ends an exercise only if an open question is answered.";
$SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion = "Send email to teacher when student ends an exercise only if an oral question is answered.";
$StudentStartExercise = "Student just start an exercise";
?>
Loading…
Cancel
Save