| … | |
… | |
| 270 | an exception is thrown. To add a password, a user with a matching user ID must |
270 | an exception is thrown. To add a password, a user with a matching user ID must |
| 271 | exist in the user table. |
271 | exist in the user table. |
| 272 | |
272 | |
| 273 | =cut |
273 | =cut |
| 274 | |
274 | |
| 275 | sub addPassword($$) { |
275 | sub addPassword { |
| 276 | my ($self, $Password) = @_; |
276 | my ($self, $Password) = @_; |
| 277 | |
277 | |
| 278 | croak "addPassword: requires 1 argument" |
278 | croak "addPassword: requires 1 argument" |
| 279 | unless @_ == 2; |
279 | unless @_ == 2; |
| 280 | croak "addPassword: argument 1 must be of type ", $self->{password}->{record} |
280 | croak "addPassword: argument 1 must be of type ", $self->{password}->{record} |
| … | |
… | |
| 295 | record's data will be returned. If no such record exists, an undefined value |
295 | record's data will be returned. If no such record exists, an undefined value |
| 296 | will be returned. |
296 | will be returned. |
| 297 | |
297 | |
| 298 | =cut |
298 | =cut |
| 299 | |
299 | |
| 300 | sub getPassword($$) { |
300 | sub getPassword { |
| 301 | my ($self, $userID) = @_; |
301 | my ($self, $userID) = @_; |
| 302 | |
302 | |
| 303 | croak "getPassword: requires 1 argument" |
303 | croak "getPassword: requires 1 argument" |
| 304 | unless @_ == 2; |
304 | unless @_ == 2; |
| 305 | croak "getPassword: argument 1 must contain a user_id" |
305 | croak "getPassword: argument 1 must contain a user_id" |
| 306 | unless defined $userID; |
306 | unless defined $userID; |
| 307 | |
307 | |
| 308 | return $self->{password}->get($userID); |
308 | return $self->{password}->get($userID); |
|
|
309 | } |
|
|
310 | |
|
|
311 | =item getPasswords(@uesrIDs) |
|
|
312 | |
|
|
313 | Return a list of password records associated with the user IDs given. If there |
|
|
314 | is no record associated with a given user ID, that element of the list will be |
|
|
315 | undefined. |
|
|
316 | |
|
|
317 | =cut |
|
|
318 | |
|
|
319 | sub getPasswords { |
|
|
320 | my ($self, @userIDs) = @_; |
|
|
321 | |
|
|
322 | croak "getPasswords: requires 1 or more argument" |
|
|
323 | unless @_ >= 2; |
|
|
324 | foreach my $i (0 .. $#userIDs) { |
|
|
325 | croak "getPasswords: element $i of argument list must contain a user_id" |
|
|
326 | unless defined $userIDs[$i]; |
|
|
327 | } |
|
|
328 | |
|
|
329 | return map { $self->getPassword($_) } @userIDs; |
| 309 | } |
330 | } |
| 310 | |
331 | |
| 311 | =item putPassword($Password) |
332 | =item putPassword($Password) |
| 312 | |
333 | |
| 313 | $Password is a record object. If a password record with the same user ID exists |
334 | $Password is a record object. If a password record with the same user ID exists |
| … | |
… | |
| 433 | unless defined $userID; |
454 | unless defined $userID; |
| 434 | |
455 | |
| 435 | return $self->{permission}->get($userID); |
456 | return $self->{permission}->get($userID); |
| 436 | } |
457 | } |
| 437 | |
458 | |
|
|
459 | =item getPermissionLevels(@uesrIDs) |
|
|
460 | |
|
|
461 | Return a list of permission level records associated with the user IDs given. If |
|
|
462 | there is no record associated with a given user ID, that element of the list |
|
|
463 | will be undefined. |
|
|
464 | |
|
|
465 | =cut |
|
|
466 | |
|
|
467 | sub getPermissionLevels { |
|
|
468 | my ($self, @userIDs) = @_; |
|
|
469 | |
|
|
470 | croak "getPermissionLevels: requires 1 or more argument" |
|
|
471 | unless @_ >= 2; |
|
|
472 | foreach my $i (0 .. $#userIDs) { |
|
|
473 | croak "getPermissionLevels: element $i of argument list must contain a user_id" |
|
|
474 | unless defined $userIDs[$i]; |
|
|
475 | } |
|
|
476 | |
|
|
477 | return map { $self->getPermissionLevel($_) } @userIDs; |
|
|
478 | } |
|
|
479 | |
| 438 | =item putPermissionLevel($PermissionLevel) |
480 | =item putPermissionLevel($PermissionLevel) |
| 439 | |
481 | |
| 440 | $PermissionLevel is a record object. If a permission level record with the same |
482 | $PermissionLevel is a record object. If a permission level record with the same |
| 441 | user ID exists in the permission table, the data in the record is replaced with |
483 | user ID exists in the permission table, the data in the record is replaced with |
| 442 | the data in $PermissionLevel. If a matching permission level record does not |
484 | the data in $PermissionLevel. If a matching permission level record does not |
| … | |
… | |
| 556 | unless defined $userID; |
598 | unless defined $userID; |
| 557 | |
599 | |
| 558 | return $self->{key}->get($userID); |
600 | return $self->{key}->get($userID); |
| 559 | } |
601 | } |
| 560 | |
602 | |
|
|
603 | =item getKeys(@uesrIDs) |
|
|
604 | |
|
|
605 | Return a list of key records associated with the user IDs given. If there is no |
|
|
606 | record associated with a given user ID, that element of the list will be |
|
|
607 | undefined. |
|
|
608 | |
|
|
609 | =cut |
|
|
610 | |
|
|
611 | sub getKeys { |
|
|
612 | my ($self, @userIDs) = @_; |
|
|
613 | |
|
|
614 | croak "getKeys: requires 1 or more argument" |
|
|
615 | unless @_ >= 2; |
|
|
616 | foreach my $i (0 .. $#userIDs) { |
|
|
617 | croak "getKeys: element $i of argument list must contain a user_id" |
|
|
618 | unless defined $userIDs[$i]; |
|
|
619 | } |
|
|
620 | |
|
|
621 | return map { $self->getKey($_) } @userIDs; |
|
|
622 | } |
|
|
623 | |
| 561 | =item putKey($Key) |
624 | =item putKey($Key) |
| 562 | |
625 | |
| 563 | $Key is a record object. If a key record with the same user ID exists in the |
626 | $Key is a record object. If a key record with the same user ID exists in the |
| 564 | key table, the data in the record is replaced with the data in $Key. If a |
627 | key table, the data in the record is replaced with the data in $Key. If a |
| 565 | matching key record does not exist, an exception is thrown. |
628 | matching key record does not exist, an exception is thrown. |
| … | |
… | |
| 673 | unless @_ == 2; |
736 | unless @_ == 2; |
| 674 | croak "getUser: argument 1 must contain a user_id" |
737 | croak "getUser: argument 1 must contain a user_id" |
| 675 | unless defined $userID; |
738 | unless defined $userID; |
| 676 | |
739 | |
| 677 | return $self->{user}->get($userID); |
740 | return $self->{user}->get($userID); |
|
|
741 | } |
|
|
742 | |
|
|
743 | =item getUsers(@uesrIDs) |
|
|
744 | |
|
|
745 | Return a list of user records associated with the user IDs given. If there is no |
|
|
746 | record associated with a given user ID, that element of the list will be |
|
|
747 | undefined. |
|
|
748 | |
|
|
749 | =cut |
|
|
750 | |
|
|
751 | sub getUsers { |
|
|
752 | my ($self, @userIDs) = @_; |
|
|
753 | |
|
|
754 | croak "getUsers: requires 1 or more argument" |
|
|
755 | unless @_ >= 2; |
|
|
756 | foreach my $i (0 .. $#userIDs) { |
|
|
757 | croak "getUsers: element $i of argument list must contain a user_id" |
|
|
758 | unless defined $userIDs[$i]; |
|
|
759 | } |
|
|
760 | |
|
|
761 | return map { $self->getUser($_) } @userIDs; |
| 678 | } |
762 | } |
| 679 | |
763 | |
| 680 | =item putUser($User) |
764 | =item putUser($User) |
| 681 | |
765 | |
| 682 | $User is a record object. If a user record with the same user ID exists in the |
766 | $User is a record object. If a user record with the same user ID exists in the |
| … | |
… | |
| 768 | unless @_ == 2; |
852 | unless @_ == 2; |
| 769 | croak "getGlobalSet: argument 1 must contain a set_id" |
853 | croak "getGlobalSet: argument 1 must contain a set_id" |
| 770 | unless defined $setID; |
854 | unless defined $setID; |
| 771 | |
855 | |
| 772 | return $self->{set}->get($setID); |
856 | return $self->{set}->get($setID); |
|
|
857 | } |
|
|
858 | |
|
|
859 | =item getGlobalSets(@setIDs) |
|
|
860 | |
|
|
861 | Return a list of global set records associated with the user IDs given. If there |
|
|
862 | is no record associated with a given user ID, that element of the list will be |
|
|
863 | undefined. |
|
|
864 | |
|
|
865 | =cut |
|
|
866 | |
|
|
867 | sub getGlobalSets { |
|
|
868 | my ($self, @setIDs) = @_; |
|
|
869 | |
|
|
870 | croak "getGlobalSets: requires 1 or more argument" |
|
|
871 | unless @_ >= 2; |
|
|
872 | foreach my $i (0 .. $#setIDs) { |
|
|
873 | croak "getGlobalSets: element $i of argument list must contain a set_id" |
|
|
874 | unless defined $setIDs[$i]; |
|
|
875 | } |
|
|
876 | |
|
|
877 | return map { $self->getGlobalSet($_) } @setIDs; |
| 773 | } |
878 | } |
| 774 | |
879 | |
| 775 | sub putGlobalSet($$) { |
880 | sub putGlobalSet($$) { |
| 776 | my ($self, $GlobalSet) = @_; |
881 | my ($self, $GlobalSet) = @_; |
| 777 | |
882 | |
| … | |
… | |
| 867 | unless defined $setID; |
972 | unless defined $setID; |
| 868 | |
973 | |
| 869 | return $self->{set_user}->get($userID, $setID); |
974 | return $self->{set_user}->get($userID, $setID); |
| 870 | } |
975 | } |
| 871 | |
976 | |
|
|
977 | =item getUserSets(@userSetIDs) |
|
|
978 | |
|
|
979 | Return a list of user set records associated with the user IDs given. If there |
|
|
980 | is no record associated with a given user ID, that element of the list will be |
|
|
981 | undefined. @userProblemIDs consists of references to arrays in which the first |
|
|
982 | element is the user_id and the second element is the set_id. |
|
|
983 | |
|
|
984 | =cut |
|
|
985 | |
|
|
986 | sub getUserSets { |
|
|
987 | my ($self, @userSetIDs) = @_; |
|
|
988 | |
|
|
989 | croak "getUserSets: requires 1 or more argument" |
|
|
990 | unless @_ >= 2; |
|
|
991 | foreach my $i (0 .. $#userSetIDs) { |
|
|
992 | croak "getUserSets: element $i of argument list must contain a <user_id, set_id> pair" |
|
|
993 | unless defined $userSetIDs[$i] |
|
|
994 | and ref $userSetIDs[$i] eq "ARRAY" |
|
|
995 | and @{$userSetIDs[$i]} == 2 |
|
|
996 | and defined $userSetIDs[$i]->[0] |
|
|
997 | and defined $userSetIDs[$i]->[1]; |
|
|
998 | } |
|
|
999 | |
|
|
1000 | return map { $self->getUserSet(@{$_}) } @userSetIDs; |
|
|
1001 | } |
|
|
1002 | |
| 872 | sub putUserSet($$) { |
1003 | sub putUserSet($$) { |
| 873 | my ($self, $UserSet) = @_; |
1004 | my ($self, $UserSet) = @_; |
| 874 | |
1005 | |
| 875 | croak "putUserSet: requires 1 argument" |
1006 | croak "putUserSet: requires 1 argument" |
| 876 | unless @_ == 2; |
1007 | unless @_ == 2; |
| … | |
… | |
| 953 | unless defined $problemID; |
1084 | unless defined $problemID; |
| 954 | |
1085 | |
| 955 | return $self->{problem}->get($setID, $problemID); |
1086 | return $self->{problem}->get($setID, $problemID); |
| 956 | } |
1087 | } |
| 957 | |
1088 | |
|
|
1089 | =item getGlobalProblems(@problemIDs) |
|
|
1090 | |
|
|
1091 | Return a list of global set records associated with the user IDs given. If there |
|
|
1092 | is no record associated with a given user ID, that element of the list will be |
|
|
1093 | undefined. @problemIDs consists of references to arrays in which the first |
|
|
1094 | element is the set_id, and the second element is the problem_id. |
|
|
1095 | |
|
|
1096 | =cut |
|
|
1097 | |
|
|
1098 | sub getGlobalProblems { |
|
|
1099 | my ($self, @problemIDs) = @_; |
|
|
1100 | |
|
|
1101 | croak "getGlobalProblems: requires 1 or more argument" |
|
|
1102 | unless @_ >= 2; |
|
|
1103 | foreach my $i (0 .. $#problemIDs) { |
|
|
1104 | croak "getUserSets: element $i of argument list must contain a <set_id, problem_id> pair" |
|
|
1105 | unless defined $problemIDs[$i] |
|
|
1106 | and ref $problemIDs[$i] eq "ARRAY" |
|
|
1107 | and @{$problemIDs[$i]} == 2 |
|
|
1108 | and defined $problemIDs[$i]->[0] |
|
|
1109 | and defined $problemIDs[$i]->[1]; |
|
|
1110 | } |
|
|
1111 | |
|
|
1112 | return map { $self->getGlobalProblem(@{$_}) } @problemIDs; |
|
|
1113 | } |
|
|
1114 | |
| 958 | sub putGlobalProblem($$) { |
1115 | sub putGlobalProblem($$) { |
| 959 | my ($self, $GlobalProblem) = @_; |
1116 | my ($self, $GlobalProblem) = @_; |
| 960 | |
1117 | |
| 961 | croak "putGlobalProblem: requires 1 argument" |
1118 | croak "putGlobalProblem: requires 1 argument" |
| 962 | unless @_ == 2; |
1119 | unless @_ == 2; |
| … | |
… | |
| 1055 | unless defined $setID; |
1212 | unless defined $setID; |
| 1056 | croak "getUserProblem: argument 3 must contain a problem_id" |
1213 | croak "getUserProblem: argument 3 must contain a problem_id" |
| 1057 | unless defined $problemID; |
1214 | unless defined $problemID; |
| 1058 | |
1215 | |
| 1059 | return $self->{problem_user}->get($userID, $setID, $problemID); |
1216 | return $self->{problem_user}->get($userID, $setID, $problemID); |
|
|
1217 | } |
|
|
1218 | |
|
|
1219 | =item getUserProblems(@userProblemIDs) |
|
|
1220 | |
|
|
1221 | Return a list of user set records associated with the user IDs given. If there |
|
|
1222 | is no record associated with a given user ID, that element of the list will be |
|
|
1223 | undefined. @userProblemIDs consists of references to arrays in which the first |
|
|
1224 | element is the user_id, the second element is the set_id, and the third element |
|
|
1225 | is the problem_id. |
|
|
1226 | |
|
|
1227 | =cut |
|
|
1228 | |
|
|
1229 | sub getUserProblems { |
|
|
1230 | my ($self, @userProblemIDs) = @_; |
|
|
1231 | |
|
|
1232 | croak "getUserProblems: requires 1 or more argument" |
|
|
1233 | unless @_ >= 2; |
|
|
1234 | foreach my $i (0 .. $#userProblemIDs) { |
|
|
1235 | croak "getUserProblems: element $i of argument list must contain a <user_id, set_id, problem_id> triple" |
|
|
1236 | unless defined $userProblemIDs[$i] |
|
|
1237 | and ref $userProblemIDs[$i] eq "ARRAY" |
|
|
1238 | and @{$userProblemIDs[$i]} == 3 |
|
|
1239 | and defined $userProblemIDs[$i]->[0] |
|
|
1240 | and defined $userProblemIDs[$i]->[1] |
|
|
1241 | and defined $userProblemIDs[$i]->[2]; |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | return map { $self->getUserProblem(@{$_}) } @userProblemIDs; |
| 1060 | } |
1245 | } |
| 1061 | |
1246 | |
| 1062 | sub putUserProblem($$) { |
1247 | sub putUserProblem($$) { |
| 1063 | my ($self, $UserProblem) = @_; |
1248 | my ($self, $UserProblem) = @_; |
| 1064 | |
1249 | |
| … | |
… | |
| 1130 | #$timer->continue("merged records"); |
1315 | #$timer->continue("merged records"); |
| 1131 | #$timer->stop; |
1316 | #$timer->stop; |
| 1132 | return $UserSet; |
1317 | return $UserSet; |
| 1133 | } |
1318 | } |
| 1134 | |
1319 | |
|
|
1320 | =item geMegedSets(@userSetIDs) |
|
|
1321 | |
|
|
1322 | Return a list of merged set records associated with the user IDs given. If there |
|
|
1323 | is no record associated with a given user ID, that element of the list will be |
|
|
1324 | undefined. @userProblemIDs consists of references to arrays in which the first |
|
|
1325 | element is the user_id and the second element is the set_id. |
|
|
1326 | |
|
|
1327 | =cut |
|
|
1328 | |
|
|
1329 | sub geMegedSets { |
|
|
1330 | my ($self, @userSetIDs) = @_; |
|
|
1331 | |
|
|
1332 | croak "geMegedSets: requires 1 or more argument" |
|
|
1333 | unless @_ >= 2; |
|
|
1334 | foreach my $i (0 .. $#userSetIDs) { |
|
|
1335 | croak "geMegedSets: element $i of argument list must contain a <user_id, set_id> pair" |
|
|
1336 | unless defined $userSetIDs[$i] |
|
|
1337 | and ref $userSetIDs[$i] eq "ARRAY" |
|
|
1338 | and @{$userSetIDs[$i]} == 2 |
|
|
1339 | and defined $userSetIDs[$i]->[0] |
|
|
1340 | and defined $userSetIDs[$i]->[1]; |
|
|
1341 | } |
|
|
1342 | |
|
|
1343 | return map { $self->getMergedSet(@{$_}) } @userSetIDs; |
|
|
1344 | } |
|
|
1345 | |
| 1135 | ################################################################################ |
1346 | ################################################################################ |
| 1136 | # problem+problem_user functions |
1347 | # problem+problem_user functions |
| 1137 | ################################################################################ |
1348 | ################################################################################ |
| 1138 | |
1349 | |
| 1139 | sub getGlobalUserProblem { |
1350 | sub getGlobalUserProblem { |
| … | |
… | |
| 1171 | #$timer->continue("merged records"); |
1382 | #$timer->continue("merged records"); |
| 1172 | #$timer->stop; |
1383 | #$timer->stop; |
| 1173 | return $UserProblem; |
1384 | return $UserProblem; |
| 1174 | } |
1385 | } |
| 1175 | |
1386 | |
|
|
1387 | =item getMergedProblems(@userProblemIDs) |
|
|
1388 | |
|
|
1389 | Return a list of merged set records associated with the user IDs given. If there |
|
|
1390 | is no record associated with a given user ID, that element of the list will be |
|
|
1391 | undefined. @userProblemIDs consists of references to arrays in which the first |
|
|
1392 | element is the user_id, the second element is the set_id, and the third element |
|
|
1393 | is the problem_id. |
|
|
1394 | |
|
|
1395 | =cut |
|
|
1396 | |
|
|
1397 | sub getMergedProblems { |
|
|
1398 | my ($self, @userProblemIDs) = @_; |
|
|
1399 | |
|
|
1400 | croak "getMergedProblems: requires 1 or more argument" |
|
|
1401 | unless @_ >= 2; |
|
|
1402 | foreach my $i (0 .. $#userProblemIDs) { |
|
|
1403 | croak "getMergedProblems: element $i of argument list must contain a <user_id, set_id, problem_id> triple" |
|
|
1404 | unless defined $userProblemIDs[$i] |
|
|
1405 | and ref $userProblemIDs[$i] eq "ARRAY" |
|
|
1406 | and @{$userProblemIDs[$i]} == 3 |
|
|
1407 | and defined $userProblemIDs[$i]->[0] |
|
|
1408 | and defined $userProblemIDs[$i]->[1] |
|
|
1409 | and defined $userProblemIDs[$i]->[2]; |
|
|
1410 | } |
|
|
1411 | |
|
|
1412 | return map { $self->getMergedProblem(@{$_}) } @userProblemIDs; |
|
|
1413 | } |
|
|
1414 | |
| 1176 | ################################################################################ |
1415 | ################################################################################ |
| 1177 | # debugging |
1416 | # debugging |
| 1178 | ################################################################################ |
1417 | ################################################################################ |
| 1179 | |
1418 | |
| 1180 | sub dumpDB($$) { |
1419 | sub dumpDB($$) { |