| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/DB.pm,v 1.49 2004/06/15 18:55:26 sh002i Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/DB.pm,v 1.50 2004/06/16 17:13:28 sh002i Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 1145 | } |
1145 | } |
| 1146 | |
1146 | |
| 1147 | sub countSetUsers { |
1147 | sub countSetUsers { |
| 1148 | my ($self, $setID) = @_; |
1148 | my ($self, $setID) = @_; |
| 1149 | |
1149 | |
|
|
1150 | croak "countSetUsers: requires 1 argument" |
|
|
1151 | unless @_ == 2; |
|
|
1152 | croak "countSetUsers: argument 1 must contain a set_id" |
|
|
1153 | unless defined $setID; |
|
|
1154 | |
|
|
1155 | # inefficient way |
|
|
1156 | #return scalar $self->{set_user}->list(undef, $setID); |
|
|
1157 | |
|
|
1158 | # efficient way |
|
|
1159 | return $self->{set_user}->count(undef, $setID); |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | sub listSetUsers { |
|
|
1163 | my ($self, $setID) = @_; |
|
|
1164 | |
|
|
1165 | carp "listSetUsers called in SCALAR context: use countSetUsers instead!\n" |
|
|
1166 | unless wantarray; |
|
|
1167 | |
| 1150 | croak "listSetUsers: requires 1 argument" |
1168 | croak "listSetUsers: requires 1 argument" |
| 1151 | unless @_ == 2; |
1169 | unless @_ == 2; |
| 1152 | croak "listSetUsers: argument 1 must contain a set_id" |
1170 | croak "listSetUsers: argument 1 must contain a set_id" |
| 1153 | unless defined $setID; |
1171 | unless defined $setID; |
| 1154 | |
1172 | |
| 1155 | # inefficient way |
|
|
| 1156 | #return scalar $self->{set_user}->list(undef, $setID); |
|
|
| 1157 | |
|
|
| 1158 | # efficient way |
|
|
| 1159 | return $self->{set_user}->count(undef, $setID); |
|
|
| 1160 | } |
|
|
| 1161 | |
|
|
| 1162 | sub listSetUsers { |
|
|
| 1163 | my ($self, $setID) = @_; |
|
|
| 1164 | |
|
|
| 1165 | carp "listSetUsers called in SCALAR context: use countSetUsers instead!\n" |
|
|
| 1166 | unless wantarray; |
|
|
| 1167 | |
|
|
| 1168 | croak "listSetUsers: requires 1 argument" |
|
|
| 1169 | unless @_ == 2; |
|
|
| 1170 | croak "listSetUsers: argument 1 must contain a set_id" |
|
|
| 1171 | unless defined $setID; |
|
|
| 1172 | |
|
|
| 1173 | return map { $_->[0] } # extract user_id |
1173 | return map { $_->[0] } # extract user_id |
| 1174 | $self->{set_user}->list(undef, $setID); |
1174 | $self->{set_user}->list(undef, $setID); |
|
|
1175 | } |
|
|
1176 | |
|
|
1177 | sub countUserSets { |
|
|
1178 | my ($self, $userID) = @_; |
|
|
1179 | |
|
|
1180 | croak "countUserSets: requires 1 argument" |
|
|
1181 | unless @_ == 2; |
|
|
1182 | croak "countUserSets: argument 1 must contain a user_id" |
|
|
1183 | unless defined $userID; |
|
|
1184 | |
|
|
1185 | return $self->{set_user}->count($userID, undef); |
| 1175 | } |
1186 | } |
| 1176 | |
1187 | |
| 1177 | sub listUserSets { |
1188 | sub listUserSets { |
| 1178 | my ($self, $userID) = @_; |
1189 | my ($self, $userID) = @_; |
| 1179 | |
1190 | |