Skip to content

Commit

Permalink
Experimental text template.
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrice1 committed Feb 18, 2025
1 parent ac8b6bb commit 3d26e40
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 127 deletions.
139 changes: 12 additions & 127 deletions lib/WeBWorK/ContentGenerator/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use Email::Stuffer;
use Try::Tiny;

use WeBWorK::Upload;
use WeBWorK::Utils qw(decodeAnswers createEmailSenderTransportSMTP fetchEmailRecipients);
use WeBWorK::Utils qw(createEmailSenderTransportSMTP fetchEmailRecipients);

# request paramaters used
#
Expand Down Expand Up @@ -136,67 +136,29 @@ sub initialize ($c) {
my $subject = $ce->{mail}{feedbackSubjectFormat} || 'WeBWorK question from %c: %u set %s/prob %p';
$subject =~ s/%([$chars])/defined $subject_map{$1} ? $subject_map{$1} : ''/eg;

# Get info about remote user.
my $remote_host = $c->tx->remote_address || 'UNKNOWN';
my $remote_port = $c->tx->remote_port || 'UNKNOWN';

my $systemURL = $c->url_for('root')->to_abs;

my $msg = sprintf("Message from %s (%s) via WeBWorK at\n%s\n\n", $user->full_name, $user->user_id, $systemURL);
$msg .= "To visit the page from which " . $user->first_name . " sent feedback, go to:\n$emailableURL\n\n";

if ($feedback) {
$msg .= sprintf("%s (%s) wrote:\n\n\n%s\n\n\n", $user->full_name, $user->user_id, $feedback);
}
if ($problem and $verbosity >= 1) {
$msg .=
qq/***** Data about the problem processor: ***** \n\n/
. 'Display Mode: '
. $c->param('displayMode') . "\n"
. 'Show Old Answers: '
. ($c->param('showOldAnswers') ? 'yes' : 'no') . "\n"
. 'Show Correct Answers: '
. ($c->param('showCorrectAnswers') ? 'yes' : 'no') . "\n"
. 'Show Hints: '
. ($c->param('showHints') ? 'yes' : 'no') . "\n"
. 'Show Solutions: '
. ($c->param('showSolutions') ? 'yes' : 'no') . "\n\n";
}

if ($user && $verbosity >= 1) {
$msg .= "***** Data about the user: *****\n\n";
$msg .= $c->format_user($user) . "\n";
$msg .= "$remote_host:$remote_port\n";
}

if ($problem && $verbosity >= 1) {
$msg .= "***** Data about the problem: *****\n\n";
$msg .= $c->format_userproblem($problem) . "\n";
}
if ($set && $verbosity >= 1) {
$msg .= "***** Data about the homework set: *****\n\n" . $c->format_userset($set) . "\n";
}
if ($ce && $verbosity >= 2) {
$msg .= "***** Data about the environment: *****\n\n" . Dumper($ce) . "\n\n";
}

my $email = Email::Stuffer->to(join(',', @recipients))->subject($subject)->html_body($c->render_to_string(
'ContentGenerator/Feedback/feedback_email',
my %data = (
user => $user,
emailableURL => $emailableURL,
feedback => $feedback,
problem => $problem,
set => $set,
verbosity => $verbosity,
remote_host => $remote_host,
remote_port => $remote_port
))->text_body($msg)->header('X-Remote-Host' => $remote_host);
remote_host => $c->tx->remote_address || 'UNKNOWN',
remote_port => $c->tx->remote_port || 'UNKNOWN'
);

my $email =
Email::Stuffer->to(join(',', @recipients))->subject($subject)
->text_body($c->render_to_string('ContentGenerator/Feedback/feedback_email', format => 'txt', %data))
->html_body($c->render_to_string('ContentGenerator/Feedback/feedback_email', %data))
->header('X-Remote-Host' => $data{remote_host});
if ($ce->{feedback_sender_email}) {
my $from_name = $user ? $user->full_name : $ce->{generic_sender_name};
$email->from("$from_name <$ce->{feedback_sender_email}>")->reply_to($sender);
} else {
$email->from($sender);
}

# Extra headers
$email->header('X-WeBWorK-Route', $route) if defined $route;
$email->header('X-WeBWorK-Course', $courseID) if defined $courseID;
Expand Down Expand Up @@ -271,81 +233,4 @@ sub page_title ($c) {
return $c->ce->{feedback_button_name} || $c->maketext('E-mail Instructor');
}

sub format_user ($c, $user) {
my $ce = $c->ce;

my $result = "User ID: " . $user->user_id . "\n";
$result .= "Name: " . $user->full_name . "\n";
$result .= "Email: " . $user->email_address . "\n";
unless ($ce->{blockStudentIDinFeedback}) {
$result .= "Student ID: " . $user->student_id . "\n";
}

my $status_name = $ce->status_abbrev_to_name($user->status);
my $status_string =
defined $status_name
? "$status_name ('" . $user->status . "')"
: $user->status . " (unknown status abbreviation)";
$result .= "Status: $status_string\n";

$result .= "Section: " . $user->section . "\n";
$result .= "Recitation: " . $user->recitation . "\n";
$result .= "Comment: " . $user->comment . "\n";

return $result;
}

sub format_userset ($c, $set) {
my $ce = $c->ce;

my $result = "Set ID: " . $set->set_id . "\n";
$result .= "Set header file: " . $set->set_header . "\n";
$result .= "Hardcopy header file: " . $set->hardcopy_header . "\n";

$result .= "Open date: " . $c->formatDateTime($set->open_date) . "\n";
$result .= "Due date: " . $c->formatDateTime($set->due_date) . "\n";
$result .= "Answer date: " . $c->formatDateTime($set->answer_date) . "\n";
$result .= "Visible: " . ($set->visible ? "yes" : "no") . "\n";
$result .= "Assignment type: " . $set->assignment_type . "\n";
if ($set->assignment_type =~ /gateway/) {
$result .= "Attempts per version: " . $set->assignment_type . "\n";
$result .= "Time interval: " . $set->time_interval . "\n";
$result .= "Versions per interval: " . $set->versions_per_interval . "\n";
$result .= "Version time limit: " . $set->version_time_limit . "\n";
$result .= "Version creation time: " . $c->formatDateTime($set->version_creation_time) . "\n";
$result .= "Problem randorder: " . $set->problem_randorder . "\n";
$result .= "Version last attempt time: " . $set->version_last_attempt_time . "\n";
}

return $result;
}

sub format_userproblem ($c, $problem) {
my $ce = $c->ce;

my $result = "Problem ID: " . $problem->problem_id . "\n";
$result .= "Source file: " . $problem->source_file . "\n";
$result .= "Value: " . $problem->value . "\n";
$result .=
"Max attempts " . ($problem->max_attempts == -1 ? "unlimited" : $problem->max_attempts) . "\n";
$result .= "Random seed: " . $problem->problem_seed . "\n";
$result .= "Status: " . $problem->status . "\n";
$result .= "Attempted: " . ($problem->attempted ? "yes" : "no") . "\n";

my %last_answer = decodeAnswers($problem->last_answer);
if (%last_answer) {
$result .= "Last answer:\n";
foreach my $key (sort keys %last_answer) {
$result .= "\t$key: $last_answer{$key}\n" if $last_answer{$key};
}
} else {
$result .= "Last answer: none\n";
}

$result .= "Number of correct attempts: " . $problem->num_correct . "\n";
$result .= "Number of incorrect attempts: " . $problem->num_incorrect . "\n";

return $result;
}

1;
99 changes: 99 additions & 0 deletions templates/ContentGenerator/Feedback/feedback_email.txt.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
% use WeBWorK::Utils qw(decodeAnswers);
%
Message from <%== $user->full_name %> (<%== $user->user_id %>) via WeBWorK at
<%== url_for('root')->to_abs %>

To visit the page from which <%== $user->first_name %> sent feedback, go to:
<%== $emailableURL %>

% if ($feedback) {
<%== $user->full_name %> (<%== $user->user_id %>) wrote:


<%== $feedback %>

% }
% if ($problem && $verbosity >= 1) {

***** Data about the problem processor: *****

Display Mode: <%== param('displayMode') %>
Show Old Answers: <%== param('showOldAnswers') ? 'yes' : 'no' %>
Show Correct Answers: <%== param('showCorrectAnswers') ? 'yes' : 'no' %>
Show Hints: <%== param('showHints') ? 'yes' : 'no' %>
Show Solutions: <%== param('showSolutions') ? 'yes' : 'no' %>
% }
% if ($user && $verbosity >= 1) {

***** Data about the user: *****

User ID: <%== $user->user_id %>
Name: <%== $user->full_name %>
Email: <%== $user->email_address %>
% unless ($ce->{blockStudentIDinFeedback}) {
Student ID: <%== $user->student_id %>
% }
% my $status_name = $ce->status_abbrev_to_name($user->status);
%my $status_string =
% defined $status_name
% ? "$status_name ('" . $user->status . q{')}
% : $user->status . ' (unknown status abbreviation)';
Status: <%== $status_string %>
Section: <%== $user->section %>
Recitation: <%== $user->recitation %>
Comment: <%== $user->comment %>
IP Address: <%== $remote_host %>:<%== $c->tx->remote_port || 'UNKNOWN' %>
% }
% if ($problem && $verbosity >= 1) {

***** Data about the problem: *****

Problem ID: <%== $problem->problem_id %>
Source file: <%== $problem->source_file %>
Value: <%== $problem->value %>
Max attempts <%== $problem->max_attempts == -1 ? 'unlimited' : $problem->max_attempts %>
Random seed: <%== $problem->problem_seed %>
Status: <%== $problem->status %>
Attempted: <%== $problem->attempted ? 'yes' : 'no' %>
% my %last_answer = decodeAnswers($problem->last_answer);
% if (%last_answer) {
Last answer:
% for my $key (sort keys %last_answer) {
% if ($last_answer{$key}) {
<%== $key %>: <%== $last_answer{$key} %>
% }
% }
% } else {
Last answer: none
% }
Number of correct attempts: <%== $problem->num_correct %>
Number of incorrect attempts: <%== $problem->num_incorrect %>
% }
% if ($set && $verbosity >= 1) {

***** Data about the homework set: *****

Set ID: <%== $set->set_id %>
Set header file: <%== $set->set_header %>
Hardcopy header file: <%== $set->hardcopy_header %>
Open date: <%== $c->formatDateTime($set->open_date) %>
Due date: <%== $c->formatDateTime($set->due_date) %>
Answer date: <%== $c->formatDateTime($set->answer_date) %>
Visible: <%== $set->visible ? 'yes' : 'no' %>
Assignment type: <%== $set->assignment_type %>
% if ($set->assignment_type =~ /gateway/) {
Attempts per version: <%== $set->assignment_type %>
Time interval: <%== $set->time_interval %>
Versions per interval: <%== $set->versions_per_interval %>
Version time limit: <%== $set->version_time_limit %>
Version creation time: <%== $c->formatDateTime($set->version_creation_time) %>
Problem randorder: <%== $set->problem_randorder %>
Version last attempt time: <%== $set->version_last_attempt_time %>
% }
% }
% if ($verbosity >= 2) {

Data about the environment

<%== dumper($ce) %>
% }

0 comments on commit 3d26e40

Please sign in to comment.