Skip to content
Snippets Groups Projects
Commit 81917154 authored by Sivaji Ganesh Jojodae's avatar Sivaji Ganesh Jojodae
Browse files

Incremental work on #418000, now users can configure email subject and body...

Incremental work on #418000, now users can configure email subject and body format with placeholders !rid, !score, !percentage etc
parent 1f8e987e
No related branches found
No related tags found
No related merge requests found
......@@ -380,7 +380,7 @@ function questions_import_submit_multichoice_csv(&$form, &$form_state) {
$node->answers[] = array(
'correct' => (trim($answer) == trim($option)) ? 1 : 0,
'answer' => trim($option),
'feedback' => ''
'feedback' => '',
);
}
questions_import_node_save(&$node);
......
......@@ -533,7 +533,7 @@ function quiz_admin_settings() {
$form['quiz_email_results'] = array(
'#type' => 'checkbox',
'#title' => t('Email Results to user', array('@quiz' => strtolower(QUIZ_NAME))),
'#title' => t('Enable Sending Quiz Results to User Email ID', array('@quiz' => strtolower(QUIZ_NAME))),
'#default_value' => variable_get('quiz_email_results', 1),
'#description' => t('Check this to send users quiz results over email at the end of quiz.')
);
......@@ -589,6 +589,20 @@ function quiz_admin_settings() {
);
$form['quiz_look_feel']['quiz_email_results_subject'] = array(
'#type' => 'textfield',
'#title' => t('Configure Email subject'),
'#description' => t('This format will be used to send Email to notify results at the end of quiz.'),
'#default_value' => variable_get('quiz_email_results_subject', quiz_email_results_format('subject')),
);
$form['quiz_look_feel']['quiz_email_results_body'] = array(
'#type' => 'textarea',
'#title' => t('Configure Email format'),
'#description' => t('This format will be used to send Email to notify results at the end of quiz. !title !sitename !username !date !desc !correct !total !percentage !url are placeholder.'),
'#default_value' => variable_get('quiz_email_results_body', quiz_email_results_format('body')),
);
return system_settings_form($form);
}
......
......@@ -1307,7 +1307,7 @@ function quiz_quiz_finished($quiz, $score, $rid) {
// function to export result in pdf, XML, CVS format
// function to display results visually
//function to send results over email
if ($user->uid && variable_get('quiz_email_results', 1)) { // email can be sent only for registered users
if ($user->uid && variable_get('quiz_email_results', 1) && variable_get('quiz_use_passfail', 1)) { // email can be sent only for registered users
drupal_mail('quiz', 'notice', $user->mail, NULL, array($quiz, $score, $rid));
}
}
......@@ -1319,25 +1319,52 @@ function quiz_quiz_finished($quiz, $score, $rid) {
*/
function quiz_mail($key, &$message, $params) {
global $user;
list($quiz, $score, $rid) = $params;
$substitutions = array(
'!title' => $quiz->title,
'!sitename' => variable_get('site_name', 'Test Center'),
'!username' => $user->name,
'!title' => $quiz->title,
'!date' => date("F j, Y, g:i a"),
'!desc' => $quiz->body,
'!correct'=> $score['numeric_score'],
'!total' => $score['question_count'],
'!percentage' => $score['percentage_score'],
'!url' => url('user/quiz/' . $rid . '/userresults'),
);
switch($key) {
case 'notice':
$message['subject'] = t("!title Results Notice from !sitename", array('!title' => $quiz->title, '!sitename' => variable_get('site_name', 'Test Center')));
$message['body'] = t("Dear !username \n\n", array('!username' => $quiz->name));
$message['body'] .= t("You have attened a !title quiz on !date \n\n", array('!title' => $quiz->title, '!date' => date("F j, Y, g:i a")));
$message['body'] .= t("Test Description : !desc \n\n", array('!desc' => $quiz->body));
$message['body'] .= t("You got !correct out of !total. Your percentage is !percentage \n\n.", array('!correct'=> $score['numeric_score'], '!total' => $score['question_count'], '!percentage' => $score['percentage_score']));
$message['body'] .= t("You can access your result in here !url\n", array('!url' => url("user/quiz/$rid/userresults", array('absolute' => TRUE))));
//drupal_set_message('Results has been sent to your email ID');
$subject = variable_get('quiz_email_results_subject', quiz_email_results_format('subject'));
$body = variable_get('quiz_email_results_body', quiz_email_results_format('body'));
foreach ($substitutions as $key => $value) {
$subject = str_replace($key, $value, $subject);
$body = str_replace($key, $value, $body);
}
$message['subject'] = $subject;
$message['body'] = $body;
break;
}
}
/*
* This functions returns the default email subject and body format which will be used at the end of quiz
*/
function quiz_email_results_format($type){
if ($type == 'subject') {
return t('!title Results Notice from !sitename');
}
if ($type == 'body') {
return t('Dear !username ') . "\n\n" .
t('You have attended a !title quiz on !date') . "\n" .
t('Test Description : !desc') . "\n" .
t('You got !correct out of !total. Your percentage is !percentage') . "\n" .
t('You can access your result here !url') . "\n";
}
}
/**
* Update a score for a quiz.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment