[system] / branches / rel-2-4-patches / webwork-modperl / lib / WebworkSOAP.pm Repository:
ViewVC logotype

View of /branches/rel-2-4-patches/webwork-modperl/lib/WebworkSOAP.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6063 - (download) (as text) (annotate)
Fri Jun 26 00:37:00 2009 UTC (3 years, 11 months ago) by gage
File size: 28997 byte(s)
syncing with HEAD

    1 package WebworkSOAP;
    2 
    3 use strict;
    4 
    5 use WeBWorK::Utils qw(pretty_print_rh);
    6 use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse deleteCourse listCourses archiveCourse listArchivedCourses unarchiveCourse);
    7 use WeBWorK::DB;
    8 use WeBWorK::DB::Utils qw(initializeUserProblem);
    9 use WeBWorK::CourseEnvironment;
   10 use WeBWorK::ContentGenerator::Instructor;
   11 
   12 use WebworkSOAP::Classes::GlobalSet;
   13 use WebworkSOAP::Classes::UserSet;
   14 use WebworkSOAP::Classes::GlobalProblem;
   15 use WebworkSOAP::Classes::UserProblem;
   16 use WebworkSOAP::Classes::User;
   17 use WebworkSOAP::Classes::Key;
   18 use WebworkSOAP::Classes::Password;
   19 use WebworkSOAP::Classes::Permission;
   20 
   21 #init
   22 
   23 use constant {
   24         SOAPERROR_MAJOR             => 1,
   25         SOAPERROR_MINOR             => 2,
   26         SOAPERROR_CLASS_NOT_FOUND   => 3,
   27         SOAPERROR_USER_NOT_FOUND    => 4,
   28         SOAPERROR_SET_NOT_FOUND     => 5,
   29         SOAPERROR_PROBLEM_NOT_FOUND => 6,
   30         SOAPERROR_KEY_NOT_FOUND     => 7,
   31         SOAPERROR_AUTHEN_FAILED     => 8
   32 };
   33 
   34 our %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 
   40 
   41 sub new {
   42     my($self,$authenKey,$courseName) = @_;
   43     $self = {};
   44     #Construct Course
   45     my $ce = eval { new WeBWorK::CourseEnvironment({%SeedCE, courseName => $courseName }) };
   46     $@ and soap_fault_major("Course Environment cannot be constructed.<br>$@");
   47     #Authentication Check
   48     if($ce->{soap_authen_key} != $authenKey) {
   49         soap_fault_authen();
   50     }
   51     #Construct DB handle
   52     my $db = eval { new WeBWorK::DB($ce->{dbLayout}); };
   53     $@ and soap_fault_major("Failed to initialize database handle.<br>$@");
   54     $self->{db} = $db;
   55     $self->{ce} = $ce;
   56     bless $self;
   57     return $self;
   58 }
   59 
   60 sub array_to_soap_string {
   61   my @array = @_;
   62   @array = map { SOAP::Data->type( 'string', $_ ) } @array;
   63   return \@array;
   64 }
   65 
   66 sub soap_fault_authen {
   67     die SOAP::Fault->faultcode(SOAPERROR_AUTHEN_FAILED)
   68                     ->faultstring("SOAP Webservice Authentication Failed!");
   69 }
   70 
   71 sub soap_fault {
   72     my ($errorCode,$errorMsg) = @_;
   73     die SOAP::Fault->faultcode($errorCode)
   74                    ->faultstring($errorMsg);
   75 }
   76 
   77 sub soap_fault_major {
   78     my ($errorMsg) = @_;
   79     soap_fault(SOAPERROR_MAJOR,$errorMsg);
   80 }
   81 ####################################################################################
   82 #SOAP CALLABLE FUNCTIONS
   83 ####################################################################################
   84 
   85 =pod
   86 =begin WSDL
   87 _RETURN $string Hello World!
   88 =cut
   89 sub hello {
   90     return "Hello world!";
   91 }
   92 
   93 #################################################
   94 #Course
   95 #################################################
   96 
   97 =pod
   98 =begin WSDL
   99 _IN authenKey $string
  100 _RETURN @string
  101 =end WSDL
  102 =cut
  103 sub list_courses {
  104     my ($self,$authenKey) = @_;
  105     my $ce = eval { new WeBWorK::CourseEnvironment({%WeBWorK::SeedCE })};
  106     $@ and soap_fault_major("Internal Course Environment cannot be constructed.");
  107     if($authenKey != $WebworkSOAP::SeedCE{soap_authen_key}) {
  108         soap_fault_authen;
  109     }
  110     $@ and soap_fault_major("Course Environment cannot be constructed.");
  111     my @test = listCourses($ce);
  112     return array_to_soap_string( @test );
  113 }
  114 
  115 =pod
  116 =begin WSDL
  117 _IN authenKey $string
  118 _IN courseName $string
  119 _IN userID $string
  120 _RETURN $string
  121 =end WSDL
  122 =cut
  123 sub login_user {
  124     my ($self,$authenKey,$courseName,$userID) = @_;
  125     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  126     my $newKey;
  127     my $timestamp = time;
  128     my @chars = @{ $soapEnv->{ce}->{sessionKeyChars} };
  129     my $length = $soapEnv->{ce}->{sessionKeyLength};
  130     srand;
  131     $newKey = join ("", @chars[map rand(@chars), 1 .. $length]);
  132     my $Key = $soapEnv->{db}->newKey(user_id=>$userID, key=>$newKey, timestamp=>$timestamp);
  133     eval { $soapEnv->{db}->deleteKey($userID) };
  134     eval { $soapEnv->{db}->addKey($Key) };
  135     $@ and soap_fault(SOAPERROR_USER_NOT_FOUND,"User not found.");
  136     return SOAP::Data->type( 'string', $newKey );
  137 }
  138 
  139 =pod
  140 =begin WSDL
  141 _IN authenKey $string
  142 _IN courseName $string
  143 _IN userID $string
  144 _IN setID $string
  145 _RETURN $string
  146 =end WSDL
  147 =cut
  148 sub assign_set_to_user {
  149     my ($self,$authenKey,$courseName,$userID,$setID) = @_;
  150     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  151     my $GlobalSet = eval {$soapEnv->{db}->getGlobalSet($setID)};
  152     $@ and soap_fault(SOAPERROR_SET_NOT_FOUND,"Set not found.");
  153     my $setID = $GlobalSet->set_id;
  154     my $db = $soapEnv->{db};
  155     my $UserSet = $db->newUserSet;
  156     $UserSet->user_id($userID);
  157     $UserSet->set_id($setID);
  158     my @results;
  159     my $set_assigned = 0;
  160     eval { $db->addUserSet($UserSet) };
  161     if ($@) {
  162       if ($@ =~ m/user set exists/) {
  163         push @results, "set $setID is already assigned to user $userID.";
  164         $set_assigned = 1;
  165       } else {
  166           die $@;
  167         }
  168     }
  169 
  170     my @GlobalProblems = grep { defined $_ } $db->getAllGlobalProblems($setID);
  171     foreach my $GlobalProblem (@GlobalProblems) {
  172         my $seed = int( rand( 2423) ) + 36;
  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) };
  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
  192 sub grade_users_sets {
  193     my ($self,$authenKey,$courseName,$userIDs,$setID) = @_;
  194     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  195     my @grades;
  196     foreach my $userID (@{$userIDs}) {
  197         my @problemData = $soapEnv->{db}->getAllUserProblems($userID,$setID);
  198 
  199         my $grade = 0;
  200         for(my $i=0;$i<@problemData;$i++) {
  201                 $grade += @problemData[$i]->status;
  202         }
  203         push(@grades,$grade);
  204     }
  205     return array_to_soap_string( @grades );
  206 }
  207 
  208 =pod
  209 =begin WSDL
  210 _IN authenKey $string
  211 _IN courseName $string
  212 _IN setID $string
  213 _RETURN $WebworkSOAP::Classes::GlobalSet
  214 =end WSDL
  215 =cut
  216 sub get_set_data {
  217     my ($self,$authenKey,$courseName,$setID) = @_;
  218     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  219     my $setData = $soapEnv->{db}->getGlobalSet($setID);
  220     if(not defined $setData) {
  221         return -1;
  222     }
  223     my $set = new WebworkSOAP::Classes::GlobalSet($setData);
  224     return $set;
  225 }
  226 
  227 ####################################################################
  228 ##FUNCTIONS DIRECTLY MAPPED TO FUNCTIONS IN DB.pm
  229 ####################################################################
  230 ###############################################
  231 ##Password
  232 ###############################################
  233 
  234 =pod
  235 =begin WSDL
  236 _IN authenKey $string
  237 _IN courseName $string
  238 _IN record $WebworkSOAP::Classes::Password
  239 _RETURN $string
  240 =end WSDL
  241 =cut
  242 sub add_password {
  243     my ($self,$authenKey,$courseName,$record) = @_;
  244     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  245     my $newPassword = $soapEnv->{db}->newPassword;
  246     %$newPassword = %$record;
  247     return SOAP::Data->type( 'string', $soapEnv->{db}->addPassword($newPassword) );
  248 }
  249 
  250 =pod
  251 =begin WSDL
  252 _IN authenKey $string
  253 _IN courseName $string
  254 _IN record $WebworkSOAP::Classes::Password
  255 _RETURN $string
  256 =end WSDL
  257 =cut
  258 sub put_password {
  259     my ($self,$authenKey,$courseName,$record) = @_;
  260     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  261     return SOAP::Data->type( 'string', $soapEnv->{db}->putPassword($record) );
  262 }
  263 
  264 =pod
  265 =begin WSDL
  266 _IN authenKey $string
  267 _IN courseName $string
  268 _RETURN @string
  269 =end WSDL
  270 =cut
  271 sub list_password {
  272     my ($self,$authenKey,$courseName) = @_;
  273     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  274     my @tempArray = $soapEnv->{db}->listPasswords;
  275     return array_to_soap_string( @tempArray );
  276 }
  277 
  278 =pod
  279 =begin WSDL
  280 _IN authenKey $string
  281 _IN courseName $string
  282 _IN userIDs @string
  283 _RETURN @WebworkSOAP::Classes::Password Array of user objects
  284 =end WSDL
  285 =cut
  286 sub get_passwords {
  287     my ($self,$authenKey,$courseName,$userIDs) = @_;
  288     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  289     my @passwordData = $soapEnv->{db}->getPasswords(@$userIDs);
  290     my @passwords;
  291     for(my $i=0;$i<@passwordData;$i++) {
  292         push(@passwords,new WebworkSOAP::Classes::Password(@passwordData[$i]));
  293     }
  294     return \@passwords;
  295 }
  296 
  297 =pod
  298 =begin WSDL
  299 _IN authenKey $string
  300 _IN courseName $string
  301 _IN userID $string
  302 _RETURN $WebworkSOAP::Classes::Password of names objects.
  303 =end WSDL
  304 =cut
  305 sub get_password {
  306     my ($self,$authenKey,$courseName,$userID) = @_;
  307     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  308     my $passwordData = $soapEnv->{db}->getPassword($userID);
  309     if(not defined $passwordData) {
  310         return -1;
  311     }
  312     my $password = new WebworkSOAP::Classes::Password($passwordData);
  313     return ($password);
  314 }
  315 
  316 ##################################################
  317 ##Permission
  318 ##################################################
  319 
  320 =pod
  321 =begin WSDL
  322 _IN authenKey $string
  323 _IN courseName $string
  324 _IN record $WebworkSOAP::Classes::Permission
  325 _RETURN $string
  326 =end WSDL
  327 =cut
  328 sub add_permission {
  329     my ($self,$authenKey,$courseName,$record) = @_;
  330     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  331     my $newPermissionLevel = $soapEnv->{db}->newPermissionLevel;
  332     %$newPermissionLevel = %$record;
  333     return SOAP::Data->type( 'string', $soapEnv->{db}->addPermissionLevel($newPermissionLevel) );
  334 }
  335 
  336 =pod
  337 =begin WSDL
  338 _IN authenKey $string
  339 _IN courseName $string
  340 _IN record $WebworkSOAP::Classes::Permission
  341 _RETURN $string
  342 =end WSDL
  343 =cut
  344 sub put_permission {
  345     my ($self,$authenKey,$courseName,$record) = @_;
  346     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  347     return SOAP::Data->type( 'string', $soapEnv->{db}->putPermissionLevel($record) );
  348 }
  349 
  350 =pod
  351 =begin WSDL
  352 _IN authenKey $string
  353 _IN courseName $string
  354 _RETURN @string
  355 =end WSDL
  356 =cut
  357 sub list_permissions {
  358     my ($self,$authenKey,$courseName) = @_;
  359     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  360     my @tempArray = $soapEnv->{db}->listPermissionLevels;
  361     return array_to_soap_string( @tempArray );
  362 }
  363 
  364 =pod
  365 =begin WSDL
  366 _IN authenKey $string
  367 _IN courseName $string
  368 _IN userIDs @string
  369 _RETURN @WebworkSOAP::Classes::Permission Array of user objects
  370 =end WSDL
  371 =cut
  372 sub get_permissions {
  373     my ($self,$authenKey,$courseName,$userIDs) = @_;
  374     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  375     my @permissionData = $soapEnv->{db}->getPermissionLevels(@$userIDs);
  376     my @permissions;
  377     for(my $i=0;$i<@permissionData;$i++) {
  378         push(@permissions,new WebworkSOAP::Classes::Permission(@permissionData[$i]));
  379     }
  380     return \@permissions;
  381 }
  382 
  383 =pod
  384 =begin WSDL
  385 _IN authenKey $string
  386 _IN courseName $string
  387 _IN userID $string
  388 _RETURN $WebworkSOAP::Classes::Permission of names objects.
  389 =end WSDL
  390 =cut
  391 sub get_permission {
  392     my ($self,$authenKey,$courseName,$userID) = @_;
  393     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  394     my $permissionData = $soapEnv->{db}->getPermissionLevel($userID);
  395     if(not defined $permissionData) {
  396         return -1;
  397     }
  398     my $permission = new WebworkSOAP::Classes::Permission($permissionData);
  399     return ($permission);
  400 }
  401 
  402 ##################################################
  403 ##Key
  404 ##################################################
  405 
  406 =pod
  407 =begin WSDL
  408 _IN authenKey $string
  409 _IN courseName $string
  410 _IN record $WebworkSOAP::Classes::Key
  411 _RETURN $string
  412 =end WSDL
  413 =cut
  414 sub add_key {
  415     my ($self,$authenKey,$courseName,$record) = @_;
  416     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  417     my $newKey = $soapEnv->{db}->newKey;
  418     %$newKey = %$record;
  419     return SOAP::Data->type( 'string', $soapEnv->{db}->addKey($newKey) );
  420 }
  421 
  422 =pod
  423 =begin WSDL
  424 _IN authenKey $string
  425 _IN courseName $string
  426 _IN record $WebworkSOAP::Classes::Key
  427 _RETURN $string
  428 =end WSDL
  429 =cut
  430 sub put_key {
  431     my ($self,$authenKey,$courseName,$record) = @_;
  432     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  433     return SOAP::Data->type( 'string', $soapEnv->{db}->putKey($record) );
  434 }
  435 
  436 =pod
  437 =begin WSDL
  438 _IN authenKey $string
  439 _IN courseName $string
  440 _RETURN @string
  441 =end WSDL
  442 =cut
  443 sub list_keys {
  444     my ($self,$authenKey,$courseName) = @_;
  445     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  446     my @tempArray = $soapEnv->{db}->listKeys;
  447     return array_to_soap_string( @tempArray );
  448 }
  449 
  450 =pod
  451 =begin WSDL
  452 _IN authenKey $string
  453 _IN courseName $string
  454 _IN userIDs @string
  455 _RETURN @WebworkSOAP::Classes::Key Array of user objects
  456 =end WSDL
  457 =cut
  458 sub get_keys {
  459     my ($self,$authenKey,$courseName,$userIDs) = @_;
  460     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  461     my @keyData = $soapEnv->{db}->getKeys(@$userIDs);
  462     my @keys;
  463     for(my $i=0;$i<@keyData;$i++) {
  464         push(@keys,new WebworkSOAP::Classes::Key(@keyData[$i]));
  465     }
  466     return \@keys;
  467 }
  468 
  469 =pod
  470 =begin WSDL
  471 _IN authenKey $string
  472 _IN courseName $string
  473 _IN userID $string
  474 _RETURN $WebworkSOAP::Classes::Key of names objects.
  475 =end WSDL
  476 =cut
  477 sub get_key {
  478     my ($self,$authenKey,$courseName,$userID) = @_;
  479     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  480     my $keyData = $soapEnv->{db}->getKey($userID);
  481     if(not defined $keyData) {
  482         return -1;
  483     }
  484     my $key = new WebworkSOAP::Classes::Key($keyData);
  485     return ($key);
  486 }
  487 
  488 ##################################################
  489 ##User
  490 ##################################################
  491 
  492 =pod
  493 =begin WSDL
  494 _IN authenKey $string
  495 _IN courseName $string
  496 _IN record $WebworkSOAP::Classes::User
  497 _RETURN $string
  498 =end WSDL
  499 =cut
  500 sub add_user {
  501     my ($self,$authenKey,$courseName,$record) = @_;
  502     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  503     my $newUser = $soapEnv->{db}->newUser;
  504     %$newUser = %$record;
  505     return SOAP::Data->type( 'string', $soapEnv->{db}->addUser($newUser) );
  506 }
  507 
  508 =pod
  509 =begin WSDL
  510 _IN authenKey $string
  511 _IN courseName $string
  512 _IN record $WebworkSOAP::Classes::User
  513 _RETURN $string
  514 =end WSDL
  515 =cut
  516 sub put_user {
  517     my ($self,$authenKey,$courseName,$record) = @_;
  518     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  519     return SOAP::Data->type( 'string', $soapEnv->{db}->putUser($record) );
  520 }
  521 
  522 =pod
  523 =begin WSDL
  524 _IN authenKey $string
  525 _IN courseName $string
  526 _RETURN @string of names objects.
  527 =end WSDL
  528 =cut
  529 sub list_users {
  530     my ($self,$authenKey,$courseName) = @_;
  531     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  532     my @tempArray = $soapEnv->{db}->listUsers;
  533     return array_to_soap_string( @tempArray );
  534 }
  535 
  536 =pod
  537 =begin WSDL
  538 _IN authenKey $string
  539 _IN courseName $string
  540 _IN userID $string
  541 _RETURN $WebworkSOAP::Classes::User of names objects.
  542 =end WSDL
  543 =cut
  544 sub get_user {
  545     my ($self,$authenKey,$courseName,$userID) = @_;
  546     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  547     my $userData = $soapEnv->{db}->getUser($userID);
  548     if(not defined $userData) {
  549         return -1;
  550     }
  551     my $user = new WebworkSOAP::Classes::User($userData);
  552     return ($user);
  553 }
  554 
  555 =pod
  556 =begin WSDL
  557 _IN authenKey $string
  558 _IN courseName $string
  559 _IN userIDs @string
  560 _RETURN @WebworkSOAP::Classes::User Array of user objects
  561 =end WSDL
  562 =cut
  563 sub get_users {
  564     my ($self,$authenKey,$courseName,$userIDs) = @_;
  565     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  566     my @userData = $soapEnv->{db}->getUsers(@$userIDs);
  567     my @users;
  568     for(my $i=0;$i<@userData;$i++) {
  569         push(@users,new WebworkSOAP::Classes::User(@userData[$i]));
  570     }
  571     return \@users;
  572 }
  573 
  574 =pod
  575 =begin WSDL
  576 _IN authenKey $string
  577 _IN courseName $string
  578 _IN userID $string
  579 _RETURN $string
  580 =end WSDL
  581 =cut
  582 sub delete_user {
  583     my ($self,$authenKey,$courseName,$userID) = @_;
  584     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  585     return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUser($userID) );
  586 }
  587 
  588 ##################################################
  589 ##Global Sets
  590 ##################################################
  591 
  592 =pod
  593 =begin WSDL
  594 _IN authenKey $string
  595 _IN courseName $string
  596 _IN record $WebworkSOAP::Classes::GlobalSet
  597 _RETURN $string
  598 =end WSDL
  599 =cut
  600 sub add_global_set {
  601     my ($self,$authenKey,$courseName,$record) = @_;
  602     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  603     my $newGlobalSet = $soapEnv->{db}->newGlobalSet;
  604     %$newGlobalSet = %$record;
  605     return SOAP::Data->type( 'string', $soapEnv->{db}->addGlobalSet($newGlobalSet) );
  606 }
  607 
  608 =pod
  609 =begin WSDL
  610 _IN authenKey $string
  611 _IN courseName $string
  612 _IN record $WebworkSOAP::Classes::GlobalSet
  613 _RETURN $string
  614 =end WSDL
  615 =cut
  616 sub put_global_set {
  617     my ($self,$authenKey,$courseName,$record) = @_;
  618     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  619     return SOAP::Data->type( 'string', $soapEnv->{db}->putGlobalSet($record) );
  620 }
  621 
  622 =pod
  623 =begin WSDL
  624 _IN authenKey $string
  625 _IN courseName $string
  626 _RETURN @string of names objects.
  627 =end WSDL
  628 =cut
  629 sub list_global_sets {
  630     my ($self,$authenKey,$courseName) = @_;
  631     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  632     my @tempArray = $soapEnv->{db}->listGlobalSets;
  633     return array_to_soap_string( @tempArray );
  634 }
  635 
  636 =pod
  637 =begin WSDL
  638 _IN authenKey $string
  639 _IN courseName $string
  640 _RETURN @WebworkSOAP::Classes::GlobalSet Array of user objects
  641 =end WSDL
  642 =cut
  643 sub get_all_global_sets {
  644     my ($self,$authenKey,$courseName) = @_;
  645     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  646     my @tempArray = $soapEnv->{db}->listGlobalSets;
  647     my @setData = $soapEnv->{db}->getGlobalSets(@tempArray);
  648     my @sets;
  649     for(my $i=0;$i<@setData;$i++) {
  650         push(@sets,new WebworkSOAP::Classes::GlobalSet(@setData[$i]));
  651     }
  652     return \@sets;
  653 }
  654 
  655 =pod
  656 =begin WSDL
  657 _IN authenKey $string
  658 _IN courseName $string
  659 _IN setIDs @string
  660 _RETURN @WebworkSOAP::Classes::GlobalSet Array of user objects
  661 =end WSDL
  662 =cut
  663 sub get_global_sets {
  664     my ($self,$authenKey,$courseName,$setIDs) = @_;
  665     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  666     my @setData = $soapEnv->{db}->getGlobalSets(@$setIDs);
  667     my @sets;
  668     for(my $i=0;$i<@setData;$i++) {
  669         push(@sets,new WebworkSOAP::Classes::GlobalSet(@setData[$i]));
  670     }
  671     return \@sets;
  672 }
  673 
  674 =pod
  675 =begin WSDL
  676 _IN authenKey $string
  677 _IN courseName $string
  678 _IN setID $string
  679 _RETURN $WebworkSOAP::Classes::GlobalSet
  680 =end WSDL
  681 =cut
  682 sub get_global_set {
  683     my ($self,$authenKey,$courseName,$setID) = @_;
  684     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  685     my $setData = $soapEnv->{db}->getGlobalSet($setID);
  686     if(not defined $setData) {
  687         return -1;
  688     }
  689     my $set = new WebworkSOAP::Classes::GlobalSet($setData);
  690     return ($set);
  691 }
  692 
  693 =pod
  694 =begin WSDL
  695 _IN authenKey $string
  696 _IN courseName $string
  697 _IN setID $string
  698 _RETURN $string
  699 =end WSDL
  700 =cut
  701 sub delete_global_set {
  702     my ($self,$authenKey,$courseName,$setID) = @_;
  703     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  704     return SOAP::Data->type( 'string', $soapEnv->{db}->deleteGlobalSet($setID) );
  705 }
  706 
  707 ##################################################
  708 ##Global Problems
  709 ##################################################
  710 
  711 =pod
  712 =begin WSDL
  713 _IN authenKey $string
  714 _IN courseName $string
  715 _IN record $WebworkSOAP::Classes::GlobalProblem
  716 _RETURN $string
  717 =end WSDL
  718 =cut
  719 sub add_global_problem {
  720     my ($self,$authenKey,$courseName,$record) = @_;
  721     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  722     my $newGlobalProblem = $soapEnv->{db}->newGlobalProblem;
  723     %$newGlobalProblem = %$record;
  724     return SOAP::Data->type( 'string', $soapEnv->{db}->addGlobalProblem($newGlobalProblem) );
  725 }
  726 
  727 =pod
  728 =begin WSDL
  729 _IN authenKey $string
  730 _IN courseName $string
  731 _IN record $WebworkSOAP::Classes::GlobalProblem
  732 _RETURN $string
  733 =end WSDL
  734 =cut
  735 sub put_global_problem {
  736     my ($self,$authenKey,$courseName,$record) = @_;
  737     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  738     return SOAP::Data->type( 'string', $soapEnv->{db}->putGlobalProblem($record) );
  739 }
  740 
  741 =pod
  742 =begin WSDL
  743 _IN authenKey $string
  744 _IN courseName $string
  745 _IN setID $string
  746 _RETURN @string of names objects.
  747 =end WSDL
  748 =cut
  749 sub list_global_problems {
  750     my ($self,$authenKey,$courseName,$setID) = @_;
  751     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  752     my @tempArray = $soapEnv->{db}->listGlobalProblems($setID);
  753     return array_to_soap_string( @tempArray );
  754 }
  755 
  756 =pod
  757 =begin WSDL
  758 _IN authenKey $string
  759 _IN courseName $string
  760 _IN setID $string
  761 _RETURN @WebworkSOAP::Classes::GlobalProblem Array of user objects
  762 =end WSDL
  763 =cut
  764 sub get_all_global_problems {
  765     my ($self,$authenKey,$courseName,$setID) = @_;
  766     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  767     my @problemData = $soapEnv->{db}->getAllGlobalProblems($setID);
  768     my @problems;
  769     for(my $i=0;$i<@problemData;$i++) {
  770         push(@problems,new WebworkSOAP::Classes::GlobalProblem(@problemData[$i]));
  771     }
  772     return \@problems;
  773 }
  774 
  775 =pod
  776 =begin
  777 _IN authenKey $string
  778 _IN courseName $string
  779 _IN problemIDs @string An array reference: [userID setID problemID]
  780 _RETURN @WebworkSOAP::Classes::GlobalProblem Array of user objects
  781 =end WSDL
  782 =cut
  783 sub get_global_problems {
  784     my ($self,$authenKey,$courseName,$problemIDs) = @_;
  785     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  786     my @problemData = $soapEnv->{db}->getGlobalProblems(@$problemIDs);
  787     my @problems;
  788     for(my $i=0;$i<@problemData;$i++) {
  789         push(@problems,new WebworkSOAP::Classes::GlobalProblem(@problemData[$i])); #FIXME $problemData[$i]?
  790     }
  791     return \@problems;
  792 }
  793 
  794 =pod
  795 =begin WSDL
  796 _IN authenKey $string
  797 _IN courseName $string
  798 _IN setID $string
  799 _IN problemID $string
  800 _RETURN $WebworkSOAP::Classes::GlobalProblem of names objects.
  801 =end WSDL
  802 =cut
  803 sub get_global_problem {
  804     my ($self,$authenKey,$courseName,$setID,$problemID) = @_;
  805     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  806     my $problemData = $soapEnv->{db}->getGlobalProblem($setID,$problemID);
  807     if(not defined $problemData) {
  808         return -1;
  809     }
  810     my $problem = new WebworkSOAP::Classes::GlobalProblem($problemData);
  811     return ($problem);
  812 }
  813 
  814 =pod
  815 =begin WSDL
  816 _IN authenKey $string
  817 _IN courseName $string
  818 _IN setID $string
  819 _IN problemID $string
  820 _RETURN $string
  821 =end WSDL
  822 =cut
  823 sub delete_global_problem {
  824     my ($self,$authenKey,$courseName,$setID,$problemID) = @_;
  825     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  826     return SOAP::Data->type( 'string', $soapEnv->{db}->deleteGlobalProblem($setID,$problemID) );
  827 }
  828 
  829 ##################################################
  830 ##USER PROBLEM
  831 ##################################################
  832 
  833 =pod
  834 =begin WSDL
  835 _IN authenKey $string
  836 _IN courseName $string
  837 _IN record $WebworkSOAP::Classes::UserProblem
  838 _RETURN $string
  839 =end WSDL
  840 =cut
  841 sub add_user_problem {
  842     my ($self,$authenKey,$courseName,$record) = @_;
  843     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  844     my $newUserProblem = $soapEnv->{db}->newUserProblem;
  845     %$newUserProblem = %$record;
  846     return SOAP::Data->type( 'string', $soapEnv->{db}->addUserProblem($newUserProblem) );
  847 }
  848 
  849 =pod
  850 =begin WSDL
  851 _IN authenKey $string
  852 _IN courseName $string
  853 _IN record $WebworkSOAP::Classes::UserProblem
  854 _RETURN $string
  855 =end WSDL
  856 =cut
  857 sub put_user_problem {
  858     my ($self,$authenKey,$courseName,$record) = @_;
  859     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  860     return SOAP::Data->type( 'string', $soapEnv->{db}->putUserProblem($record) );
  861 }
  862 
  863 =pod
  864 =begin WSDL
  865 _IN authenKey $string
  866 _IN courseName $string
  867 _IN userID $string
  868 _IN setID $string
  869 _RETURN @string of names objects.
  870 =end WSDL
  871 =cut
  872 sub list_user_problems {
  873     my ($self,$authenKey,$courseName,$userID,$setID) = @_;
  874     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  875     my @tempArray = $soapEnv->{db}->listUserProblems($userID,$setID);
  876     return array_to_soap_string( @tempArray );
  877 }
  878 
  879 =pod
  880 =begin WSDL
  881 _IN authenKey $string
  882 _IN courseName $string
  883 _IN userID $string
  884 _IN setID $string
  885 _RETURN @WebworkSOAP::Classes::UserProblem of names objects.
  886 =end WSDL
  887 =cut
  888 sub get_all_user_problems {
  889     my ($self,$authenKey,$courseName,$userID,$setID) = @_;
  890     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  891     my @problemData = $soapEnv->{db}->getAllUserProblems($userID,$setID);
  892     my @problems;
  893     for(my $i=0;$i<@problemData;$i++) {
  894         push(@problems,new WebworkSOAP::Classes::UserProblem(@problemData[$i]));
  895     }
  896     return \@problems;
  897 }
  898 
  899 =pod
  900 =begin WSDL
  901 _IN authenKey $string
  902 _IN courseName $string
  903 _IN userProblemIDs @string A 3 element array: { user_ID, setID, problemID }
  904 _RETURN @WebworkSOAP::Classes::UserProblem of names objects.
  905 =end WSDL
  906 =cut
  907 sub get_user_problems {
  908     my ($self,$authenKey,$courseName,$userProblemIDs) = @_;
  909     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  910     my @problemData = $soapEnv->{db}->getUserProblems(@$userProblemIDs);
  911     my @problems;
  912     for(my $i=0;$i<@problemData;$i++) {
  913         push(@problems,new WebworkSOAP::Classes::UserProblem(@problemData[$i]));
  914     }
  915     return \@problems;
  916 }
  917 
  918 =pod
  919 =begin WSDL
  920 _IN authenKey $string
  921 _IN courseName $string
  922 _IN userID $string
  923 _IN setID $string
  924 _IN problemID $string
  925 _RETURN $WebworkSOAP::Classes::UserProblem of names objects.
  926 =end WSDL
  927 =cut
  928 sub get_user_problem {
  929     my ($self,$authenKey,$courseName,$userID,$setID,$problemID) = @_;
  930     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  931     my $problemData = $soapEnv->{db}->getUserProblem($userID,$setID,$problemID);
  932     if(not defined $problemData) {
  933         return -1;
  934     }
  935     my $problem = new WebworkSOAP::Classes::UserProblem($problemData);
  936     return ($problem);
  937 }
  938 
  939 =pod
  940 =begin WSDL
  941 _IN authenKey $string
  942 _IN courseName $string
  943 _IN userID $string
  944 _IN setID $string
  945 _IN problemID $string
  946 _RETURN $string
  947 =end WSDL
  948 =cut
  949 sub delete_user_problem {
  950     my ($self,$authenKey,$courseName,$userID,$setID,$problemID) = @_;
  951     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  952     return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUserProblem($userID,$setID,$problemID) );
  953 }
  954 
  955 ##################################################
  956 ##USER SET
  957 ##################################################
  958 
  959 =pod
  960 =begin WSDL
  961 _IN authenKey $string
  962 _IN courseName $string
  963 _IN record $WebworkSOAP::Classes::UserSet
  964 _RETURN $string
  965 =end WSDL
  966 =cut
  967 sub add_user_set {
  968     my ($self,$authenKey,$courseName,$record) = @_;
  969     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  970     my $newUserSet = $soapEnv->{db}->newUserSet;
  971     %$newUserSet = %$record;
  972     return SOAP::Data->type( 'string', $soapEnv->{db}->addUserSet($newUserSet) );
  973 }
  974 
  975 =pod
  976 =begin WSDL
  977 _IN authenKey $string
  978 _IN courseName $string
  979 _IN record $WebworkSOAP::Classes::UserSet
  980 _RETURN $string
  981 =end WSDL
  982 =cut
  983 sub put_user_set {
  984     my ($self,$authenKey,$courseName,$record) = @_;
  985     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  986     return SOAP::Data->type( 'string', $soapEnv->{db}->addUserSet($record) );
  987 }
  988 
  989 =pod
  990 =begin WSDL
  991 _IN authenKey $string
  992 _IN courseName $string
  993 _IN userID $string
  994 _RETURN @string of names objects.
  995 =end WSDL
  996 =cut
  997 sub list_user_sets {
  998     my ($self,$authenKey,$courseName,$userID) = @_;
  999     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
 1000     my @tempArray = $soapEnv->{db}->listUserSets($userID);
 1001     return array_to_soap_string( @tempArray );
 1002 }
 1003 
 1004 =pod
 1005 =begin WSDL
 1006 _IN authenKey $string
 1007 _IN courseName $string
 1008 _RETURN @WebworkSOAP::Classes::UserSet of names objects.
 1009 =end WSDL
 1010 =cut
 1011 sub get_all_user_sets {
 1012     my ($self,$authenKey,$courseName) = @_;
 1013     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
 1014     my @setData = $soapEnv->{db}->getAllUserSets();
 1015     my @sets;
 1016     for(my $i=0;$i<@setData;$i++) {
 1017         push(@sets,new WebworkSOAP::Classes::UserSet(@setData[$i]));
 1018     }
 1019     return \@sets;
 1020 }
 1021 
 1022 =pod
 1023 =begin WSDL
 1024 _IN authenKey $string
 1025 _IN courseName $string
 1026 _IN userSetIDs $string
 1027 _RETURN @WebworkSOAP::Classes::UserSet of names objects.
 1028 =end WSDL
 1029 =cut
 1030 sub get_user_sets {
 1031     my ($self,$authenKey,$courseName,$userSetIDs) = @_;
 1032     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
 1033     my @setData = $soapEnv->{db}->getUserSets(@$userSetIDs);
 1034     my @sets;
 1035     for(my $i=0;$i<@setData;$i++) {
 1036         push(@sets,new WebworkSOAP::Classes::UserSet(@setData[$i]));
 1037     }
 1038     return \@sets;
 1039 }
 1040 
 1041 =pod
 1042 =begin WSDL
 1043 _IN authenKey $string
 1044 _IN courseName $string
 1045 _IN userID $string
 1046 _IN setID $string
 1047 _RETURN $WebworkSOAP::Classes::UserSet of names objects.
 1048 =end WSDL
 1049 =cut
 1050 sub get_user_set {
 1051     my ($self,$authenKey,$courseName,$userID,$setID) = @_;
 1052     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
 1053     my $setData = $soapEnv->{db}->getUserSet($userID,$setID);
 1054     if(not defined $setData) {
 1055         return -1;
 1056     }
 1057     my $set = new WebworkSOAP::Classes::UserSet($setData);
 1058     return $set;
 1059 }
 1060 
 1061 =pod
 1062 =begin WSDL
 1063 _IN authenKey $string
 1064 _IN courseName $string
 1065 _IN userID $string
 1066 _IN setID $string
 1067 _RETURN $string
 1068 =end WSDL
 1069 =cut
 1070 sub delete_user_set {
 1071     my ($self,$authenKey,$courseName,$userID,$setID) = @_;
 1072     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
 1073     return SOAP::Data->type( 'string', $soapEnv->{db}->deleteUserSet($userID,$setID) );
 1074 }
 1075 
 1076 
 1077 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9