[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / PGProblemEditor.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 979 Revision 980
63 $self->SUPER::go(@_); 63 $self->SUPER::go(@_);
64 } 64 }
65 65
66} 66}
67 67
68sub initialize {
69
70 my ($self, $setName, $problemNumber) = @_;
71 my $ce = $self->{ce};
72 my $r = $self->{r};
73 my $path_info = $r->path_info || "";
74 my $db = $self->{db};
75 my $user = $r->param('user');
76 my $effectiveUserName = $r->param('effectiveUser');
77 my $courseName = $ce->{courseName};
78
79# FIXME -- sometimes this doesn't find a set
80# my $set = $db->getGlobalUserSet($effectiveUserName, $setName);
81# my $setID = $set->set_id;
82
83 # Find URL for viewing problem
84
85 # find path to pg file for the problem
86 # FIXME there is a discrepancy in the way that the problems are found.
87 # FIXME more error checking is needed in case the problem doesn't exist.
88 # my $problem_record = $db->getUserProblem($user,$setID,1);
89 my $problem_record = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber);
90 my $templateDirectory = $ce->{courseDirs}->{templates};
91 my $problemPath = $templateDirectory."/".$problem_record->source_file;
92 my $editFileSuffix = 'tmp';
93 my $submit_button = $r->param('submit');
94
95 my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode};
96 my $problemSeed = ( defined($r->param('problemSeed')) ) ? $r->param('problemSeed') : $problem_record->problem_seed;
97 $problemSeed = '1234' unless defined($problemSeed) and $problemSeed =~/\S/;
98
99 my $problemContents = '';
100 my $currentSourceFilePath = '';
101 # update the .pg and .pg.tmp files in the directory
102 if (not defined($submit_button) ) {
103 # this is a fresh editing job
104 # copy the pg file to a new file with the same name with .tmp added
105 # store this name in the $ce->currentSourceFilePath for use in body
106
107 eval { $problemContents = WeBWorK::Utils::readFile($problemPath)
108 }; # try to read file
109 $problemContents = $@ if $@;
110 $currentSourceFilePath = "$problemPath.$editFileSuffix";
111 $ce->{currentSourceFilePath} = $currentSourceFilePath;
112 } elsif ($submit_button eq 'Refresh' ) {
113 # grab the problemContents from the form and save it to the tmp file
114 # store tmp file name in the $ce->currentSourceFilePath for use in body
115
116 $problemContents = $r->param('problemContents');
117 $currentSourceFilePath = "$problemPath.$editFileSuffix";
118 $ce->{currentSourceFilePath} = $currentSourceFilePath;
119 } elsif ($submit_button eq 'Save') {
120 # grab the problemContents from the form and save it to the permanent file
121 # unlink (delete) the temporary file
122 # store the permanent file name in the $ce->problemContents for use in body
123
124 $problemContents = $r->param('problemContents');
125 $currentSourceFilePath = "$problemPath";
126 $ce->{currentSourceFilePath} = $currentSourceFilePath;
127 } else {
128 # give a warning
129 die "Unrecognized submit command $submit_button";
130 }
131 # print changed pg files
132 # FIXME make sure that the permissions are set correctly!!!
133 # Make sure that the warning is being transmitted properly.
134 eval {
135 local *OUTPUTFILE;
136 open OUTPUTFILE, ">", $currentSourceFilePath
137 or die "Failed to write to $currentSourceFilePath: $!";
138 print OUTPUTFILE $problemContents;
139 close OUTPUTFILE;
140 };
141 my $errors = $@ if $@;
142 if ( $errors) {
143
144 $ce->{editErrors} = "Unable to write to $currentSourceFilePath: $errors";
145
146 } else { # unlink the temporary file if there are no errors.
147 $ce->{editErrors} = '';
148 unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save';
149
150 };
151
152
153 # return values. FIXME -- is this the right way to pass the values to body??
154 # Should temporary results be passed in self or in ce??
155 # $ce->{viewProblemURL} = $viewProblemURL;
156 $ce->{problemPath} = $problemPath;
157 $self->{displayMode} = $displayMode;
158 $self->{problemSeed} = $problemSeed;
159# $ce->{path_components} = join("/",$setID,$problemNumber);
160
161 # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!!
162
163
164
165}
68 166
69sub body { 167sub body {
70 my $self = shift; 168 my $self = shift;
71 169
72 # test area 170 # test area
190 ; 288 ;
191 289
192 290
193} 291}
194 292
195sub initialize {
196
197 my ($self, $setName, $problemNumber) = @_;
198 my $ce = $self->{ce};
199 my $r = $self->{r};
200 my $path_info = $r->path_info || "";
201 my $db = $self->{db};
202 my $user = $r->param('user');
203 my $effectiveUserName = $r->param('effectiveUser');
204 my $courseName = $ce->{courseName};
205
206# FIXME -- sometimes this doesn't find a set
207# my $set = $db->getGlobalUserSet($effectiveUserName, $setName);
208# my $setID = $set->set_id;
209
210 # Find URL for viewing problem
211
212 # find path to pg file for the problem
213 # FIXME there is a discrepancy in the way that the problems are found.
214 # FIXME more error checking is needed in case the problem doesn't exist.
215 # my $problem_record = $db->getUserProblem($user,$setID,1);
216 my $problem_record = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber);
217 my $templateDirectory = $ce->{courseDirs}->{templates};
218 my $problemPath = $templateDirectory."/".$problem_record->source_file;
219 my $editFileSuffix = 'tmp';
220 my $submit_button = $r->param('submit');
221
222 my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode};
223 my $problemSeed = ( defined($r->param('problemSeed')) ) ? $r->param('problemSeed') : $problem_record->problem_seed;
224 $problemSeed = '1234' unless defined($problemSeed) and $problemSeed =~/\S/;
225
226 my $problemContents = '';
227 my $currentSourceFilePath = '';
228 # update the .pg and .pg.tmp files in the directory
229 if (not defined($submit_button) ) {
230 # this is a fresh editing job
231 # copy the pg file to a new file with the same name with .tmp added
232 # store this name in the $ce->currentSourceFilePath for use in body
233
234 eval { $problemContents = WeBWorK::Utils::readFile($problemPath)
235 }; # try to read file
236 $problemContents = $@ if $@;
237 $currentSourceFilePath = "$problemPath.$editFileSuffix";
238 $ce->{currentSourceFilePath} = $currentSourceFilePath;
239 } elsif ($submit_button eq 'Refresh' ) {
240 # grab the problemContents from the form and save it to the tmp file
241 # store tmp file name in the $ce->currentSourceFilePath for use in body
242
243 $problemContents = $r->param('problemContents');
244 $currentSourceFilePath = "$problemPath.$editFileSuffix";
245 $ce->{currentSourceFilePath} = $currentSourceFilePath;
246 } elsif ($submit_button eq 'Save') {
247 # grab the problemContents from the form and save it to the permanent file
248 # unlink (delete) the temporary file
249 # store the permanent file name in the $ce->problemContents for use in body
250
251 $problemContents = $r->param('problemContents');
252 $currentSourceFilePath = "$problemPath";
253 $ce->{currentSourceFilePath} = $currentSourceFilePath;
254 } else {
255 # give a warning
256 die "Unrecognized submit command $submit_button";
257 }
258 # print changed pg files
259 # FIXME make sure that the permissions are set correctly!!!
260 # Make sure that the warning is being transmitted properly.
261 eval {
262 local *OUTPUTFILE;
263 open OUTPUTFILE, ">", $currentSourceFilePath
264 or die "Failed to write to $currentSourceFilePath: $!";
265 print OUTPUTFILE $problemContents;
266 close OUTPUTFILE;
267 };
268 my $errors = $@ if $@;
269 if ( $errors) {
270
271 $ce->{editErrors} = "Unable to write to $currentSourceFilePath: $errors";
272
273 } else { # unlink the temporary file if there are no errors.
274 $ce->{editErrors} = '';
275 unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save';
276
277 };
278
279
280 # return values. FIXME -- is this the right way to pass the values to body??
281 # Should temporary results be passed in self or in ce??
282 # $ce->{viewProblemURL} = $viewProblemURL;
283 $ce->{problemPath} = $problemPath;
284 $self->{displayMode} = $displayMode;
285 $self->{problemSeed} = $problemSeed;
286# $ce->{path_components} = join("/",$setID,$problemNumber);
287
288 # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!!
289
290
291
292}
293 293
294# sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) 294# sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function)
295# my $self = shift; 295# my $self = shift;
296# my $setName = shift; 296# my $setName = shift;
297# my $output = ""; 297# my $output = "";

Legend:
Removed from v.979  
changed lines
  Added in v.980

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9