[system] / trunk / webwork2 / lib / WebworkSOAP.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WebworkSOAP.pm

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

Revision 5035 Revision 6806
3use strict; 3use strict;
4 4
5use WeBWorK::Utils qw(pretty_print_rh); 5use WeBWorK::Utils qw(pretty_print_rh);
6use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse deleteCourse listCourses archiveCourse listArchivedCourses unarchiveCourse); 6use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse deleteCourse listCourses archiveCourse listArchivedCourses unarchiveCourse);
7use WeBWorK::DB; 7use WeBWorK::DB;
8use WeBWorK::DB::Utils qw(initializeUserProblem);
8use WeBWorK::CourseEnvironment; 9use WeBWorK::CourseEnvironment;
9use WeBWorK::ContentGenerator::Instructor; 10use WeBWorK::ContentGenerator::Instructor;
10 11
11use WebworkSOAP::Classes::GlobalSet; 12use WebworkSOAP::Classes::GlobalSet;
12use WebworkSOAP::Classes::UserSet; 13use WebworkSOAP::Classes::UserSet;
29 SOAPERROR_KEY_NOT_FOUND => 7, 30 SOAPERROR_KEY_NOT_FOUND => 7,
30 SOAPERROR_AUTHEN_FAILED => 8 31 SOAPERROR_AUTHEN_FAILED => 8
31}; 32};
32 33
33our %SeedCE; 34our %SeedCE;
35%WebworkSOAP::SeedCE = %WeBWorK::SeedCE;
36
37$WebworkSOAP::SeedCE{soap_authen_key} = "123456789123456789";
38#$WebworkSOAP::SeedCE{webwork_dir} = $ENV{WEBWORK_ROOT}|| warn "\$ENV{WEBWORK_ROOT} is undefined -- check your httpd configuration. Error caught ";
39
34 40
35sub new { 41sub new {
36 my($self,$authenKey,$courseName) = @_; 42 my($self,$authenKey,$courseName) = @_;
37 $self = {}; 43 $self = {};
38 #Construct Course 44 #Construct Course
39 my $ce = eval { new WeBWorK::CourseEnvironment({%WebworkSOAP::SeedCE, courseName => $courseName }) }; 45 my $ce = eval { new WeBWorK::CourseEnvironment({%SeedCE, courseName => $courseName }) };
40 $@ and soap_fault_major("Course Environment cannot be constructed."); 46 $@ and soap_fault_major("Course Environment cannot be constructed.<br>$@");
41 #Authentication Check 47 #Authentication Check
42 if($ce->{soap_authen_key} != $authenKey) { 48 if($ce->{soap_authen_key} != $authenKey) {
43 soap_fault_authen(); 49 soap_fault_authen();
44 } 50 }
45 #Construct DB handle 51 #Construct DB handle
46 my $db = eval { new WeBWorK::DB($ce->{dbLayout}); }; 52 my $db = eval { new WeBWorK::DB($ce->{dbLayout}); };
47 $@ and soap_fault_major("Failed to initialize database handle."); 53 $@ and soap_fault_major("Failed to initialize database handle.<br>$@");
48 $self->{db} = $db; 54 $self->{db} = $db;
49 $self->{ce} = $ce; 55 $self->{ce} = $ce;
50 bless $self; 56 bless $self;
51 return $self; 57 return $self;
52} 58}
53 59
60sub array_to_soap_string {
61 my @array = @_;
62 @array = map { SOAP::Data->type( 'string', $_ ) } @array;
63 return \@array;
64}
65
54sub soap_fault_authen { 66sub soap_fault_authen {
55 die SOAP::Fault->faultcode(SOAPERROR_AUTHEN_FAILED) 67 die SOAP::Fault->faultcode(SOAPERROR_AUTHEN_FAILED)
56 ->faultstring("SOAP Webservice Authentication Failed!"); 68 ->faultstring("SOAP Webservice Authentication Failed!");
57} 69}
58 70
88_RETURN @string 100_RETURN @string
89=end WSDL 101=end WSDL
90=cut 102=cut
91sub list_courses { 103sub list_courses {
92 my ($self,$authenKey) = @_; 104 my ($self,$authenKey) = @_;
93
94 my $ce = eval { new WeBWorK::CourseEnvironment({%WebworkSOAP::SeedCE })}; 105 my $ce = eval { new WeBWorK::CourseEnvironment({%WeBWorK::SeedCE })};
95 $@ and soap_fault_major("Course Environment cannot be constructed."); 106 $@ and soap_fault_major("Internal Course Environment cannot be constructed.");
96 if($authenKey != $ce->{soap_authen_key}) { 107 if($authenKey != $WebworkSOAP::SeedCE{soap_authen_key}) {
97 soap_fault_authen; 108 soap_fault_authen;
98 } 109 }
99 $@ and soap_fault_major("Course Environment cannot be constructed."); 110 $@ and soap_fault_major("Course Environment cannot be constructed.");
100 my @test = listCourses($ce); 111 my @test = listCourses($ce);
101 return \@test; 112 return array_to_soap_string( @test );
102} 113}
103 114
104=pod 115=pod
105=begin WSDL 116=begin WSDL
106_IN authenKey $string 117_IN authenKey $string
120 $newKey = join ("", @chars[map rand(@chars), 1 .. $length]); 131 $newKey = join ("", @chars[map rand(@chars), 1 .. $length]);
121 my $Key = $soapEnv->{db}->newKey(user_id=>$userID, key=>$newKey, timestamp=>$timestamp); 132 my $Key = $soapEnv->{db}->newKey(user_id=>$userID, key=>$newKey, timestamp=>$timestamp);
122 eval { $soapEnv->{db}->deleteKey($userID) }; 133 eval { $soapEnv->{db}->deleteKey($userID) };
123 eval { $soapEnv->{db}->addKey($Key) }; 134 eval { $soapEnv->{db}->addKey($Key) };
124 $@ and soap_fault(SOAPERROR_USER_NOT_FOUND,"User not found."); 135 $@ and soap_fault(SOAPERROR_USER_NOT_FOUND,"User not found.");
125 return $newKey; 136 return SOAP::Data->type( 'string', $newKey );
126} 137}
127 138
128=pod 139=pod
129=begin WSDL 140=begin WSDL
130_IN authenKey $string 141_IN authenKey $string
156 } 167 }
157 } 168 }
158 169
159 my @GlobalProblems = grep { defined $_ } $db->getAllGlobalProblems($setID); 170 my @GlobalProblems = grep { defined $_ } $db->getAllGlobalProblems($setID);
160 foreach my $GlobalProblem (@GlobalProblems) { 171 foreach my $GlobalProblem (@GlobalProblems) {
161 my @result = $db->assignProblemToUser($userID, $GlobalProblem); 172 my $seed = int( rand( 2423) ) + 36;
162 push @results, @result if @result and not $set_assigned; 173 my $UserProblem = $db->newUserProblem;
174 $UserProblem->user_id($userID);
175 $UserProblem->set_id($GlobalProblem->set_id);
176 $UserProblem->problem_id($GlobalProblem->problem_id);
177 initializeUserProblem($UserProblem, $seed);
178 eval { $db->addUserProblem($UserProblem) };
163 } 179 }
180 return array_to_soap_string( @results ); #FIXME WSDL says $string, not @string?
181}
182
183=pod
184=begin WSDL
185_IN authenKey $string
186_IN courseName $string
187_IN userIDs @string
188_IN setID $string
189_RETURN @string
190=end WSDL
191=cut
192sub grade_users_sets {
193 my ($self,$authenKey,$courseName,$userIDs,$setID) = @_;
194 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
195 my @grades;
196 #open (LOG, ">>/opt/webwork/tmp_log") or die "Can't open log file";
197 #print LOG "\n\nhi there\n\n";
198
199 my $db = $soapEnv->{db};
200 foreach my $userID (@{$userIDs}) {
201# my @problemData = $soapEnv->{db}->getAllMergedUserProblems($userID,$setID);
202#
203# my $grade = 0;
204# for(my $i=0;$i<@problemData;$i++) {
205# #print LOG "$userID problem Data",join(" ", %{$problemData[$i]}),"\n\n";
206# $grade += ($problemData[$i]->status)*($problemData[$i]->value);
207# #print LOG "grade is $grade\n";
208# }
209 #print LOG "grade_users_sets: get user $userID set $setID\n";
210 my $grade = get_wwassignment_grade_for_one_user($db, $userID,$setID );
211 #print LOG " grade is $grade \n\n";
212 push(@grades,$grade);
213 }
214 #close(LOG);
215 return array_to_soap_string( @grades );
216}
217
218=pod
219=begin WSDL
220_IN authenKey $string
221_IN courseName $string
222_IN setID $string
223_RETURN $WebworkSOAP::Classes::GlobalSet
224=end WSDL
225=cut
226sub get_set_data {
227 my ($self,$authenKey,$courseName,$setID) = @_;
228 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
229 my $setData = $soapEnv->{db}->getGlobalSet($setID);
230 if(not defined $setData) {
231 return -1;
232 }
233 my $set = new WebworkSOAP::Classes::GlobalSet($setData);
164 return @results; 234 return $set;
165} 235}
166
167 236
168#################################################################### 237####################################################################
169##FUNCTIONS DIRECTLY MAPPED TO FUNCTIONS IN DB.pm 238##FUNCTIONS DIRECTLY MAPPED TO FUNCTIONS IN DB.pm
170#################################################################### 239####################################################################
171################################################## 240###############################################
172##Password 241##Password
173################################################## 242###############################################
174 243
175=pod 244=pod
176=begin WSDL 245=begin WSDL
177_IN authenKey $string 246_IN authenKey $string
178_IN courseName $string 247_IN courseName $string
179_IN record $WebworkSOAP::Classes::Password 248_IN record $WebworkSOAP::Classes::Password
180_RETURN $integer 249_RETURN $string
181=end WSDL 250=end WSDL
182=cut 251=cut
183sub add_password { 252sub add_password {
184 my ($self,$authenKey,$courseName,$record) = @_; 253 my ($self,$authenKey,$courseName,$record) = @_;
185 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 254 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
186 my $newPassword = $soapEnv->{db}->newPassword; 255 my $newPassword = $soapEnv->{db}->newPassword;
187 %$newPassword = %$record; 256 %$newPassword = %$record;
188 return $soapEnv->{db}->addPassword($newPassword); 257 return SOAP::Data->type( 'string', $soapEnv->{db}->addPassword($newPassword) );
189} 258}
190 259
191=pod 260=pod
192=begin WSDL 261=begin WSDL
193_IN authenKey $string 262_IN authenKey $string
194_IN courseName $string 263_IN courseName $string
195_IN record $WebworkSOAP::Classes::Password 264_IN record $WebworkSOAP::Classes::Password
196_RETURN $integer 265_RETURN $string
197=end WSDL 266=end WSDL
198=cut 267=cut
199sub put_password { 268sub put_password {
200 my ($self,$authenKey,$courseName,$record) = @_; 269 my ($self,$authenKey,$courseName,$record) = @_;
201 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 270 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
202 return $soapEnv->{db}->putPassword($record); 271 return SOAP::Data->type( 'string', $soapEnv->{db}->putPassword($record) );
203} 272}
204 273
205=pod 274=pod
206=begin WSDL 275=begin WSDL
207_IN authenKey $string 276_IN authenKey $string
211=cut 280=cut
212sub list_password { 281sub list_password {
213 my ($self,$authenKey,$courseName) = @_; 282 my ($self,$authenKey,$courseName) = @_;
214 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 283 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
215 my @tempArray = $soapEnv->{db}->listPasswords; 284 my @tempArray = $soapEnv->{db}->listPasswords;
216 return \@tempArray; 285 return array_to_soap_string( @tempArray );
217} 286}
218 287
219=pod 288=pod
220=begin WSDL 289=begin WSDL
221_IN authenKey $string 290_IN authenKey $string
261=pod 330=pod
262=begin WSDL 331=begin WSDL
263_IN authenKey $string 332_IN authenKey $string
264_IN courseName $string 333_IN courseName $string
265_IN record $WebworkSOAP::Classes::Permission 334_IN record $WebworkSOAP::Classes::Permission
266_RETURN $integer 335_RETURN $string
267=end WSDL 336=end WSDL
268=cut 337=cut
269sub add_permission { 338sub add_permission {
270 my ($self,$authenKey,$courseName,$record) = @_; 339 my ($self,$authenKey,$courseName,$record) = @_;
271 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 340 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
272 my $newPermissionLevel = $soapEnv->{db}->newPermissionLevel; 341 my $newPermissionLevel = $soapEnv->{db}->newPermissionLevel;
273 %$newPermissionLevel = %$record; 342 %$newPermissionLevel = %$record;
274 return $soapEnv->{db}->addPermissionLevel($newPermissionLevel); 343 return SOAP::Data->type( 'string', $soapEnv->{db}->addPermissionLevel($newPermissionLevel) );
275} 344}
276 345
277=pod 346=pod
278=begin WSDL 347=begin WSDL
279_IN authenKey $string 348_IN authenKey $string
280_IN courseName $string 349_IN courseName $string
281_IN record $WebworkSOAP::Classes::Permission 350_IN record $WebworkSOAP::Classes::Permission
282_RETURN $integer 351_RETURN $string
283=end WSDL 352=end WSDL
284=cut 353=cut
285sub put_permission { 354sub put_permission {
286 my ($self,$authenKey,$courseName,$record) = @_; 355 my ($self,$authenKey,$courseName,$record) = @_;
287 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 356 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
288 return $soapEnv->{db}->putPermissionLevel($record); 357 my $newPermissionLevel = $soapEnv->{db}->newPermissionLevel;
358 %$newPermissionLevel = %$record;
359 return SOAP::Data->type( 'string',
360 $soapEnv->{db}->putPermissionLevel($newPermissionLevel) );
289} 361}
290 362
291=pod 363=pod
292=begin WSDL 364=begin WSDL
293_IN authenKey $string 365_IN authenKey $string
297=cut 369=cut
298sub list_permissions { 370sub list_permissions {
299 my ($self,$authenKey,$courseName) = @_; 371 my ($self,$authenKey,$courseName) = @_;
300 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 372 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
301 my @tempArray = $soapEnv->{db}->listPermissionLevels; 373 my @tempArray = $soapEnv->{db}->listPermissionLevels;
302 return \@tempArray; 374 return array_to_soap_string( @tempArray );
303} 375}
304 376
305=pod 377=pod
306=begin WSDL 378=begin WSDL
307_IN authenKey $string 379_IN authenKey $string
347=pod 419=pod
348=begin WSDL 420=begin WSDL
349_IN authenKey $string 421_IN authenKey $string
350_IN courseName $string 422_IN courseName $string
351_IN record $WebworkSOAP::Classes::Key 423_IN record $WebworkSOAP::Classes::Key
352_RETURN $integer 424_RETURN $string
353=end WSDL 425=end WSDL
354=cut 426=cut
355sub add_key { 427sub add_key {
356 my ($self,$authenKey,$courseName,$record) = @_; 428 my ($self,$authenKey,$courseName,$record) = @_;
357 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 429 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
358 my $newKey = $soapEnv->{db}->newKey; 430 my $newKey = $soapEnv->{db}->newKey;
359 %$newKey = %$record; 431 %$newKey = %$record;
360 return $soapEnv->{db}->addKey($newKey); 432 return SOAP::Data->type( 'string', $soapEnv->{db}->addKey($newKey) );
361} 433}
362 434
363=pod 435=pod
364=begin WSDL 436=begin WSDL
365_IN authenKey $string 437_IN authenKey $string
366_IN courseName $string 438_IN courseName $string
367_IN record $WebworkSOAP::Classes::Key 439_IN record $WebworkSOAP::Classes::Key
368_RETURN $integer 440_RETURN $string
369=end WSDL 441=end WSDL
370=cut 442=cut
371sub put_key { 443sub put_key {
372 my ($self,$authenKey,$courseName,$record) = @_; 444 my ($self,$authenKey,$courseName,$record) = @_;
373 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 445 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
374 return $soapEnv->{db}->putKey($record); 446 return SOAP::Data->type( 'string', $soapEnv->{db}->putKey($record) );
375} 447}
376 448
377=pod 449=pod
378=begin WSDL 450=begin WSDL
379_IN authenKey $string 451_IN authenKey $string
383=cut 455=cut
384sub list_keys { 456sub list_keys {
385 my ($self,$authenKey,$courseName) = @_; 457 my ($self,$authenKey,$courseName) = @_;
386 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 458 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
387 my @tempArray = $soapEnv->{db}->listKeys; 459 my @tempArray = $soapEnv->{db}->listKeys;
388 return \@tempArray; 460 return array_to_soap_string( @tempArray );
389} 461}
390 462
391=pod 463=pod
392=begin WSDL 464=begin WSDL
393_IN authenKey $string 465_IN authenKey $string
433=pod 505=pod
434=begin WSDL 506=begin WSDL
435_IN authenKey $string 507_IN authenKey $string
436_IN courseName $string 508_IN courseName $string
437_IN record $WebworkSOAP::Classes::User 509_IN record $WebworkSOAP::Classes::User
438_RETURN $integer 510_RETURN $string
439=end WSDL 511=end WSDL
440=cut 512=cut
441sub add_user { 513sub add_user {
442 my ($self,$authenKey,$courseName,$record) = @_; 514 my ($self,$authenKey,$courseName,$record) = @_;
443 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 515 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
444 my $newUser = $soapEnv->{db}->newUser; 516 my $newUser = $soapEnv->{db}->newUser;
445 %$newUser = %$record; 517 %$newUser = %$record;
446 return $soapEnv->{db}->addUser($newUser); 518 return SOAP::Data->type( 'string', $soapEnv->{db}->addUser($newUser) );
447} 519}
448 520
449=pod 521=pod
450=begin WSDL 522=begin WSDL
451_IN authenKey $string 523_IN authenKey $string
452_IN courseName $string 524_IN courseName $string
453_IN record $WebworkSOAP::Classes::User 525_IN record $WebworkSOAP::Classes::User
454_RETURN $integer 526_RETURN $string
455=end WSDL 527=end WSDL
456=cut 528=cut
457sub put_user { 529sub put_user {
458 my ($self,$authenKey,$courseName,$record) = @_; 530 my ($self,$authenKey,$courseName,$record) = @_;
459 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 531 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
460 return $soapEnv->{db}->putUser($record); 532 return SOAP::Data->type( 'string', $soapEnv->{db}->putUser($record) );
461} 533}
462 534
463=pod 535=pod
464=begin WSDL 536=begin WSDL
465_IN authenKey $string 537_IN authenKey $string
469=cut 541=cut
470sub list_users { 542sub list_users {
471 my ($self,$authenKey,$courseName) = @_; 543 my ($self,$authenKey,$courseName) = @_;
472 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 544 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
473 my @tempArray = $soapEnv->{db}->listUsers; 545 my @tempArray = $soapEnv->{db}->listUsers;
474 return \@tempArray; 546 return array_to_soap_string( @tempArray );
475} 547}
476 548
477=pod 549=pod
478=begin WSDL 550=begin WSDL
479_IN authenKey $string 551_IN authenKey $string
515=pod 587=pod
516=begin WSDL 588=begin WSDL
517_IN authenKey $string 589_IN authenKey $string
518_IN courseName $string 590_IN courseName $string
519_IN userID $string 591_IN userID $string
520_RETURN $integer 592_RETURN $string
521=end WSDL 593=end WSDL
522=cut 594=cut
523sub delete_user { 595sub delete_user {
524 my ($self,$authenKey,$courseName,$userID) = @_; 596 my ($self,$authenKey,$courseName,$userID) = @_;
525 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 597 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
526 return $soapEnv->{db}->deleteUser($userID); 598 return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUser($userID) );
527} 599}
528 600
529################################################## 601##################################################
530##Global Sets 602##Global Sets
531################################################## 603##################################################
533=pod 605=pod
534=begin WSDL 606=begin WSDL
535_IN authenKey $string 607_IN authenKey $string
536_IN courseName $string 608_IN courseName $string
537_IN record $WebworkSOAP::Classes::GlobalSet 609_IN record $WebworkSOAP::Classes::GlobalSet
538_RETURN $integer 610_RETURN $string
539=end WSDL 611=end WSDL
540=cut 612=cut
541sub add_global_set { 613sub add_global_set {
542 my ($self,$authenKey,$courseName,$record) = @_; 614 my ($self,$authenKey,$courseName,$record) = @_;
543 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 615 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
544 my $newGlobalSet = $soapEnv->{db}->newGlobalSet; 616 my $newGlobalSet = $soapEnv->{db}->newGlobalSet;
545 %$newGlobalSet = %$record; 617 %$newGlobalSet = %$record;
546 return $soapEnv->{db}->addGlobalSet($newGlobalSet); 618 return SOAP::Data->type( 'string', $soapEnv->{db}->addGlobalSet($newGlobalSet) );
547} 619}
548 620
549=pod 621=pod
550=begin WSDL 622=begin WSDL
551_IN authenKey $string 623_IN authenKey $string
552_IN courseName $string 624_IN courseName $string
553_IN record $WebworkSOAP::Classes::GlobalSet 625_IN record $WebworkSOAP::Classes::GlobalSet
554_RETURN $integer 626_RETURN $string
555=end WSDL 627=end WSDL
556=cut 628=cut
557sub put_global_set { 629sub put_global_set {
558 my ($self,$authenKey,$courseName,$record) = @_; 630 my ($self,$authenKey,$courseName,$record) = @_;
559 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 631 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
560 return $soapEnv->{db}->putGlobalSet($record); 632 return SOAP::Data->type( 'string', $soapEnv->{db}->putGlobalSet($record) );
561} 633}
562 634
563=pod 635=pod
564=begin WSDL 636=begin WSDL
565_IN authenKey $string 637_IN authenKey $string
569=cut 641=cut
570sub list_global_sets { 642sub list_global_sets {
571 my ($self,$authenKey,$courseName) = @_; 643 my ($self,$authenKey,$courseName) = @_;
572 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 644 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
573 my @tempArray = $soapEnv->{db}->listGlobalSets; 645 my @tempArray = $soapEnv->{db}->listGlobalSets;
574 return \@tempArray; 646 return array_to_soap_string( @tempArray );
575} 647}
576
577 648
578=pod 649=pod
579=begin WSDL 650=begin WSDL
580_IN authenKey $string 651_IN authenKey $string
581_IN courseName $string 652_IN courseName $string
616=pod 687=pod
617=begin WSDL 688=begin WSDL
618_IN authenKey $string 689_IN authenKey $string
619_IN courseName $string 690_IN courseName $string
620_IN setID $string 691_IN setID $string
621_RETURN $WebworkSOAP::Classes::GlobalSet of names objects. 692_RETURN $WebworkSOAP::Classes::GlobalSet
622=end WSDL 693=end WSDL
623=cut 694=cut
624sub get_global_set { 695sub get_global_set {
625 my ($self,$authenKey,$courseName,$setID) = @_; 696 my ($self,$authenKey,$courseName,$setID) = @_;
626 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 697 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
635=pod 706=pod
636=begin WSDL 707=begin WSDL
637_IN authenKey $string 708_IN authenKey $string
638_IN courseName $string 709_IN courseName $string
639_IN setID $string 710_IN setID $string
640_RETURN $integer 711_RETURN $string
641=end WSDL 712=end WSDL
642=cut 713=cut
643sub delete_global_user { 714sub delete_global_set {
644 my ($self,$authenKey,$courseName,$setID) = @_; 715 my ($self,$authenKey,$courseName,$setID) = @_;
645 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 716 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
646 return $soapEnv->{db}->deleteGlobalSet($setID); 717 return SOAP::Data->type( 'string', $soapEnv->{db}->deleteGlobalSet($setID) );
647} 718}
648 719
649################################################## 720##################################################
650##Global Problems 721##Global Problems
651################################################## 722##################################################
653=pod 724=pod
654=begin WSDL 725=begin WSDL
655_IN authenKey $string 726_IN authenKey $string
656_IN courseName $string 727_IN courseName $string
657_IN record $WebworkSOAP::Classes::GlobalProblem 728_IN record $WebworkSOAP::Classes::GlobalProblem
658_RETURN $integer 729_RETURN $string
659=end WSDL 730=end WSDL
660=cut 731=cut
661sub add_global_problem { 732sub add_global_problem {
662 my ($self,$authenKey,$courseName,$record) = @_; 733 my ($self,$authenKey,$courseName,$record) = @_;
663 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 734 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
664 my $newGlobalProblem = $soapEnv->{db}->newGlobalProblem; 735 my $newGlobalProblem = $soapEnv->{db}->newGlobalProblem;
665 %$newGlobalProblem = %$record; 736 %$newGlobalProblem = %$record;
666 return $soapEnv->{db}->addGlobalProblem($newGlobalProblem); 737 return SOAP::Data->type( 'string', $soapEnv->{db}->addGlobalProblem($newGlobalProblem) );
667} 738}
668 739
669=pod 740=pod
670=begin WSDL 741=begin WSDL
671_IN authenKey $string 742_IN authenKey $string
672_IN courseName $string 743_IN courseName $string
673_IN record $WebworkSOAP::Classes::GlobalProblem 744_IN record $WebworkSOAP::Classes::GlobalProblem
674_RETURN $integer 745_RETURN $string
675=end WSDL 746=end WSDL
676=cut 747=cut
677sub put_global_problem { 748sub put_global_problem {
678 my ($self,$authenKey,$courseName,$record) = @_; 749 my ($self,$authenKey,$courseName,$record) = @_;
679 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 750 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
680 return $soapEnv->{db}->putGlobalProblem($record); 751 return SOAP::Data->type( 'string', $soapEnv->{db}->putGlobalProblem($record) );
681} 752}
682 753
683=pod 754=pod
684=begin WSDL 755=begin WSDL
685_IN authenKey $string 756_IN authenKey $string
686_IN courseName $string 757_IN courseName $string
687_IN problemID $string 758_IN setID $string
688_RETURN @string of names objects. 759_RETURN @string of names objects.
689=end WSDL 760=end WSDL
690=cut 761=cut
691sub list_global_problems { 762sub list_global_problems {
692 my ($self,$authenKey,$courseName,$problemID) = @_; 763 my ($self,$authenKey,$courseName,$setID) = @_;
693 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 764 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
694 my @tempArray = $soapEnv->{db}->listGlobalProblems($problemID); 765 my @tempArray = $soapEnv->{db}->listGlobalProblems($setID);
695 return \@tempArray; 766 return array_to_soap_string( @tempArray );
696} 767}
697 768
698=pod 769=pod
699=begin WSDL 770=begin WSDL
700_IN authenKey $string 771_IN authenKey $string
716 787
717=pod 788=pod
718=begin 789=begin
719_IN authenKey $string 790_IN authenKey $string
720_IN courseName $string 791_IN courseName $string
721_IN problemIDs @string 792_IN problemIDs @string An array reference: [userID setID problemID]
722_RETURN @WebworkSOAP::Classes::GlobalProblem Array of user objects 793_RETURN @WebworkSOAP::Classes::GlobalProblem Array of user objects
723=end WSDL 794=end WSDL
724=cut 795=cut
725sub get_global_problems { 796sub get_global_problems {
726 my ($self,$authenKey,$courseName,$problemIDs) = @_; 797 my ($self,$authenKey,$courseName,$problemIDs) = @_;
727 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 798 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
728 my @problemData = $soapEnv->{db}->getGlobalProblems(@$problemIDs); 799 my @problemData = $soapEnv->{db}->getGlobalProblems(@$problemIDs);
729 my @problems; 800 my @problems;
730 for(my $i=0;$i<@problemData;$i++) { 801 for(my $i=0;$i<@problemData;$i++) {
731 push(@problems,new WebworkSOAP::Classes::GlobalProblem(@problemData[$i])); 802 push(@problems,new WebworkSOAP::Classes::GlobalProblem(@problemData[$i])); #FIXME $problemData[$i]?
732 } 803 }
733 return \@problems; 804 return \@problems;
734} 805}
735 806
736=pod 807=pod
757=begin WSDL 828=begin WSDL
758_IN authenKey $string 829_IN authenKey $string
759_IN courseName $string 830_IN courseName $string
760_IN setID $string 831_IN setID $string
761_IN problemID $string 832_IN problemID $string
762_RETURN $integer 833_RETURN $string
763=end WSDL 834=end WSDL
764=cut 835=cut
765sub delete_global_problem { 836sub delete_global_problem {
766 my ($self,$authenKey,$courseName,$setID,$problemID) = @_; 837 my ($self,$authenKey,$courseName,$setID,$problemID) = @_;
767 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 838 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
768 return $soapEnv->{db}->deleteGlobalProblem($setID,$problemID); 839 return SOAP::Data->type( 'string', $soapEnv->{db}->deleteGlobalProblem($setID,$problemID) );
769} 840}
770 841
771################################################## 842##################################################
772##USER PROBLEM 843##USER PROBLEM
773################################################## 844##################################################
775=pod 846=pod
776=begin WSDL 847=begin WSDL
777_IN authenKey $string 848_IN authenKey $string
778_IN courseName $string 849_IN courseName $string
779_IN record $WebworkSOAP::Classes::UserProblem 850_IN record $WebworkSOAP::Classes::UserProblem
780_RETURN $integer 851_RETURN $string
781=end WSDL 852=end WSDL
782=cut 853=cut
783sub add_user_problem { 854sub add_user_problem {
784 my ($self,$authenKey,$courseName,$record) = @_; 855 my ($self,$authenKey,$courseName,$record) = @_;
785 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 856 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
786 my $newUserProblem = $soapEnv->{db}->newUserProblem; 857 my $newUserProblem = $soapEnv->{db}->newUserProblem;
787 %$newUserProblem = %$record; 858 %$newUserProblem = %$record;
788 return $soapEnv->{db}->addUserProblem($newUserProblem); 859 return SOAP::Data->type( 'string', $soapEnv->{db}->addUserProblem($newUserProblem) );
789} 860}
790 861
791=pod 862=pod
792=begin WSDL 863=begin WSDL
793_IN authenKey $string 864_IN authenKey $string
794_IN courseName $string 865_IN courseName $string
795_IN record $WebworkSOAP::Classes::UserProblem 866_IN record $WebworkSOAP::Classes::UserProblem
796_RETURN $integer 867_RETURN $string
797=end WSDL 868=end WSDL
798=cut 869=cut
799sub put_user_problem { 870sub put_user_problem {
800 my ($self,$authenKey,$courseName,$record) = @_; 871 my ($self,$authenKey,$courseName,$record) = @_;
801 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 872 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
802 return $soapEnv->{db}->putUserProblem($record); 873 return SOAP::Data->type( 'string', $soapEnv->{db}->putUserProblem($record) );
803} 874}
804 875
805=pod 876=pod
806=begin WSDL 877=begin WSDL
807_IN authenKey $string 878_IN authenKey $string
879_IN courseName $string
808_IN courseName $string 880_IN userID $string
809_IN userID $string 881_IN setID $string
810_RETURN @string of names objects. 882_RETURN @string of names objects.
811=end WSDL 883=end WSDL
812=cut 884=cut
813sub list_user_problems { 885sub list_user_problems {
814 my ($self,$authenKey,$courseName,$userID) = @_; 886 my ($self,$authenKey,$courseName,$userID,$setID) = @_;
815 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 887 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
816 my @tempArray = $soapEnv->{db}->listUserProblems($userID); 888 my @tempArray = $soapEnv->{db}->listUserProblems($userID,$setID);
817 return \@tempArray; 889 return array_to_soap_string( @tempArray );
818} 890}
819 891
820=pod 892=pod
821=begin WSDL 893=begin WSDL
822_IN authenKey $string 894_IN authenKey $string
839 911
840=pod 912=pod
841=begin WSDL 913=begin WSDL
842_IN authenKey $string 914_IN authenKey $string
843_IN courseName $string 915_IN courseName $string
844_IN userProblemIDs @string 916_IN userProblemIDs @string A 3 element array: { user_ID, setID, problemID }
845_RETURN @WebworkSOAP::Classes::UserProblem of names objects. 917_RETURN @WebworkSOAP::Classes::UserProblem of names objects.
846=end WSDL 918=end WSDL
847=cut 919=cut
848sub get_user_problems { 920sub get_user_problems {
849 my ($self,$authenKey,$courseName,$userProblemIDs) = @_; 921 my ($self,$authenKey,$courseName,$userProblemIDs) = @_;
882_IN authenKey $string 954_IN authenKey $string
883_IN courseName $string 955_IN courseName $string
884_IN userID $string 956_IN userID $string
885_IN setID $string 957_IN setID $string
886_IN problemID $string 958_IN problemID $string
887_RETURN $integer 959_RETURN $string
888=end WSDL 960=end WSDL
889=cut 961=cut
890sub delete_user_problem { 962sub delete_user_problem {
891 my ($self,$authenKey,$courseName,$userID,$setID,$problemID) = @_; 963 my ($self,$authenKey,$courseName,$userID,$setID,$problemID) = @_;
892 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 964 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
893 return $soapEnv->{db}->deleteUserProblem($userID,$setID,$problemID); 965 return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUserProblem($userID,$setID,$problemID) );
894} 966}
895 967
896################################################## 968##################################################
897##USER SET 969##USER SET
898################################################## 970##################################################
900=pod 972=pod
901=begin WSDL 973=begin WSDL
902_IN authenKey $string 974_IN authenKey $string
903_IN courseName $string 975_IN courseName $string
904_IN record $WebworkSOAP::Classes::UserSet 976_IN record $WebworkSOAP::Classes::UserSet
905_RETURN $integer 977_RETURN $string
906=end WSDL 978=end WSDL
907=cut 979=cut
908sub add_user_set { 980sub add_user_set {
909 my ($self,$authenKey,$courseName,$record) = @_; 981 my ($self,$authenKey,$courseName,$record) = @_;
910 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 982 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
911 my $newUserSet = $soapEnv->{db}->newUserSet; 983 my $newUserSet = $soapEnv->{db}->newUserSet;
912 %$newUserSet = %$record; 984 %$newUserSet = %$record;
913 return $soapEnv->{db}->addUserSet($newUserSet); 985 return SOAP::Data->type( 'string', $soapEnv->{db}->addUserSet($newUserSet) );
914} 986}
915 987
916=pod 988=pod
917=begin WSDL 989=begin WSDL
918_IN authenKey $string 990_IN authenKey $string
919_IN courseName $string 991_IN courseName $string
920_IN record $WebworkSOAP::Classes::UserSet 992_IN record $WebworkSOAP::Classes::UserSet
921_RETURN $integer 993_RETURN $string
922=end WSDL 994=end WSDL
923=cut 995=cut
924sub put_user_set { 996sub put_user_set {
925 my ($self,$authenKey,$courseName,$record) = @_; 997 my ($self,$authenKey,$courseName,$record) = @_;
926 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 998 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
927 return $soapEnv->{db}->addUserSet($record); 999 return SOAP::Data->type( 'string', $soapEnv->{db}->addUserSet($record) );
928} 1000}
929 1001
930=pod 1002=pod
931=begin WSDL 1003=begin WSDL
932_IN authenKey $string 1004_IN authenKey $string
937=cut 1009=cut
938sub list_user_sets { 1010sub list_user_sets {
939 my ($self,$authenKey,$courseName,$userID) = @_; 1011 my ($self,$authenKey,$courseName,$userID) = @_;
940 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 1012 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
941 my @tempArray = $soapEnv->{db}->listUserSets($userID); 1013 my @tempArray = $soapEnv->{db}->listUserSets($userID);
942 return \@tempArray; 1014 return array_to_soap_string( @tempArray );
943} 1015}
944 1016
945=pod 1017=pod
946=begin WSDL 1018=begin WSDL
947_IN authenKey $string 1019_IN authenKey $string
1003=begin WSDL 1075=begin WSDL
1004_IN authenKey $string 1076_IN authenKey $string
1005_IN courseName $string 1077_IN courseName $string
1006_IN userID $string 1078_IN userID $string
1007_IN setID $string 1079_IN setID $string
1008_RETURN $integer 1080_RETURN $string
1009=end WSDL 1081=end WSDL
1010=cut 1082=cut
1011sub delete_user_set { 1083sub delete_user_set {
1012 my ($self,$authenKey,$courseName,$userID,$setID) = @_; 1084 my ($self,$authenKey,$courseName,$userID,$setID) = @_;
1013 my $soapEnv = new WebworkSOAP($authenKey,$courseName); 1085 my $soapEnv = new WebworkSOAP($authenKey,$courseName);
1014 return $soapEnv->{db}->deleteUserSet($userID,$setID); 1086 return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUserSet($userID,$setID) );
1015} 1087}
1016 1088
1017 1089
1090###########################################
1091# grading utilties -- to be moved to Utils::Grades
1092############################################
1093
1094############################################
1095# get_wwassignment_grade_for_one ($db $userID $setID);
1096#input $userID, $setID (or a UserSet record)?
1097#output set grade for a homework problem or maximum grade for a gateway problem with several set versions
1098############################################
1099sub get_wwassignment_grade_for_one_user{
1100 my($db, $userID, $setID) = @_;
1101 my $user_set = $db->getMergedSet($userID,$setID);
1102 print LOG "user $userID set $setID user_set ".ref($user_set)."\n";
1103 return " " unless ref($user_set); # return a blank grade if there is no user_set
1104 warn " user $userID $setID ".ref($user_set)."\n";
1105 my $setIsVersioned = ( defined($user_set->assignment_type) && $user_set->assignment_type =~ /gateway/)?1:0;
1106 my @setVersions=();
1107 if ( $setIsVersioned ) {
1108 my @vList = $db->listSetVersions($userID,$setID);
1109 # we have to have the merged set versions to
1110 # know what each of their assignment types
1111 # are (because proctoring can change)
1112 @setVersions = $db->getMergedSetVersions( map {[$userID, $setID, $_]} @vList );
1113
1114 # add the set versions to our list of sets
1115# foreach ( @setVersions ) {
1116# $setsByID{$_->set_id . ",v" . $_->version_id} = $_;
1117# }
1118# # flag the existence of set versions for this set
1119# $setVersionsByID{$setName} = [ @vList ];
1120# # and save the set names for display
1121# push( @allSetIDs, $setName );
1122# push( @allSetIDs, map { "$setName,v$_" } @vList );
1123
1124 } else {
1125# push( @allSetIDs, $setName );
1126# $setVersionsByID{$setName} = "None";
1127 }
1128 my $grade;
1129 if ($setIsVersioned) {
1130 if (@setVersions) {
1131 $grade =0;
1132 foreach my $setVersion (@setVersions) { # get highest grade among versions
1133 #print LOG "getting set $userID $setID version:".ref($setVersion)."\n";
1134 my $current_grade = get_set_grade_for_UserSet($db, $setVersion);
1135 $grade = $current_grade if $current_grade > $grade;
1136
1137 }
1138
1139 } else {
1140 $grade = " ";
1141 }
1142 } else { # not versioned
1143 $grade = get_set_grade_for_UserSet($db, $user_set);
1144 }
1145 $grade; # return grade
1146}
1147
1148############################################
1149# get_set_grade_for_UserSet ($db, $user_set);
1150#input $userID, $setID (UserSet record);
1151#output set grade for a homework problem or a single set version of a gateway quiz
1152############################################
1153
1154sub get_set_grade_for_UserSet{
1155 my $db = shift;
1156 my $user_set = shift;
1157 warn "get_set_grade_for_UserSet(db, user_set); an argument is missing db: $db user_set $user_set"
1158 unless ref($db) =~ /DB/ and ref($user_set) =~/Set/;
1159 my $setIsVersioned = ( defined( $user_set->assignment_type() )
1160 && $user_set->assignment_type() =~ /gateway/ )? 1:0;
1161 my @problemData=();
1162 print LOG "get_set_grade_for_UserSet: getting set ".$user_set->set_id." "." for ".$user_set->user_id."\n";
1163 if ($setIsVersioned) {
1164 @problemData = $db->getAllMergedProblemVersions( $user_set->user_id, $user_set->set_id, $user_set->version_id ) if $user_set->can('version_id');
1165 } else {
1166 @problemData = $db->getAllMergedUserProblems($user_set->user_id, $user_set->set_id);
1167 }
1168
1169 my $grade = 0;
1170 for(my $i=0;$i<@problemData;$i++) {
1171 #print LOG "$userID problem Data",join(" ", %{$problemData[$i]}),"\n\n";
1172 $grade += ($problemData[$i]->status)*($problemData[$i]->value);
1173 #print LOG "grade is $grade\n";
1174 }
1175 return $grade;
1176}
10181; 11771;

Legend:
Removed from v.5035  
changed lines
  Added in v.6806

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9