[system] / trunk / webwork-modperl / lib / WeBWorK / DB / Webwork.pm Repository:
ViewVC logotype

Diff of /trunk/webwork-modperl/lib/WeBWorK/DB/Webwork.pm

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

Revision 361 Revision 362
36 return $package; 36 return $package;
37} 37}
38 38
39# ----- 39# -----
40 40
41# getSets($userID) - returns a list of sets in the current database for the
42# specified user
43# $userID - the user ID (a.k.a. login name) of the user to get sets for
44
45
46# -----
47
48# getSet($userID, $setID) - returns a WeBWorK::Set object containing data
49# from the specified set.
50# $userID - the user ID (a.k.a. login name) of the set to retrieve
51# $setID - the ID (a.k.a. name) of the set to retrieve
52
53# setSet($set) - if a set with the same ID for the specified user
54# exists, it is replaced. If not, a new set is added.
55# returns true on success, undef on failure.
56# $set - a WeBWorK::Set object containing the set data
57
58# deleteSet($userID, $setID) - removes the set with the specified userID and
59# setID. Returns true on success, undef on failure.
60# $userID - the user ID (a.k.a. login name) of the set to delete
61# $setID - the ID (a.k.a. name) of the set to delete
62
63# -----
64
65# getSetDefaults($setID) - returns a WeBWorK::Set object containing the default
66# values for a particular set. (See NOTE)
67# setID - id of set to fetch
68
69# setSetDefaults($set) - Replace set defaults with the given set. (See NOTE)
70# $set - a WeBWorK::Set object containing set defaults
71
72# deleteSetDefaults($setID) - Remove set defaults with the given ID. (See NOTE)
73# $setID - the ID of the set defaults to delete
74
75# -----
76
77# getProblems($userID, $setID) - returns a list of problems in the specified
78# set for the specified user.
79# $userID - the user ID of the user to get problems for
80# $setID - the set ID to get problems from
81
82# -----
83
84# getProblem($userID, $setID, $problemNumber) - returns a WeBWorK::Problem
85# object containing the problem
86# requested
87# $userID - the user for which to retrieve the problem
88# $setID - the set from which to retrieve the problem
89# $problemNumber - the number of the problem to retrieve
90
91# setProblem($problem) - if a problem with the same ID for the specified user
92# exists, it is replaced. If not, a new problem is added.
93# returns true on success, undef on failure.
94# $problem - a WeBWorK::Problem object containing the object data
95
96# deleteProblem($userID, $setID, $problemNumber) - removes a problem with the
97# specified parameters.
98# $userID - the user ID of the problem to delete
99# $setID - the ID of the problem's set
100# $problemNumber - the problem number of the problem to delete
101
102# -----
103
104# getProblemDefaults($setID, $problemNumber) - Returns a WeBWorK::Problem object
105# containing the default values for
106# a particular problem. (See NOTE)
107# $setID - set id of problem to retrieve
108# $problemNumber - problem number of problem to retrieve
109
110# setProblemDefaults($problem) - Replace or add problem defaults with the given
111# problem. (See NOTE)
112# $problem - a WeBWorK::Problem object containing problem defaults
113
114# deleteProblemDefaults($setID, $problemNumber) - remove problem defaults with
115# the given set and problem ID.
116# (See NOTE)
117# $setID - the set ID of the problem defaults to delete
118# $problemNumber - the problem number of the problem defaults to delete
119
120# -----
121
122# getPSVN($userID, $setID) - look up a PSVN given a user ID and set ID (PSVN
123# stands for Problem Set Version Number and
124# uniquely identifies a user's version of a set.)
125# $userID - the user ID to lookup
126# $serID - the set ID to lookup
127
128# -----
129
130# decode($string) - decodes a quasi-URL-encoded hash from a hash-based
131# webwork database. unescapes \& and \= in VALUES ONLY.
132# $string - string to decode
41sub decode($) { 133sub decode($) {
42 my $string = shift; 134 my $string = shift;
43 my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g; 135 my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g;
44 $hash{$_} =~ s/\\(.)/$1/ foreach (keys %hash); # unescape anything 136 $hash{$_} =~ s/\\(.)/$1/ foreach (keys %hash); # unescape anything
45 return %hash; 137 return %hash;
46} 138}
47 139
140# encode(%hash) - encodes a hash as a quasi-URL-encoded string for insertion
141# into a hash-based webwork database. Escapes & and = in
142# VALUES ONLY.
143# %hash - hash to encode
48sub encode(@) { 144sub encode(%) {
49 my %hash = @_; 145 my %hash = @_;
50 my $string; 146 my $string;
51 foreach (keys %hash) { 147 foreach (keys %hash) {
52 $hash{$_} =~ s/(=|&)/\\$1/; # escape & and = 148 $hash{$_} =~ s/(=|&)/\\$1/; # escape & and =
53 $string .= "$_=$hash{$_}&"; 149 $string .= "$_=$hash{$_}&";
61# hash2set(%hash) - places selected fields from a webwork database record 157# hash2set(%hash) - places selected fields from a webwork database record
62# in a WeBWorK::Set object, which is then returned. 158# in a WeBWorK::Set object, which is then returned.
63# %hash - a hash representing a database record 159# %hash - a hash representing a database record
64sub hash2set(%) { 160sub hash2set(%) {
65 my %hash = @_; 161 my %hash = @_;
162 my $set = WeBWorK::Set->new;
163 $set->id ( $hash{stnm} ) if defined $hash{stnm};
164 $set->login_id ( $hash{stlg} ) if defined $hash{stlg};
165 $set->set_header ( $hash{shfn} ) if defined $hash{shfn};
166 $set->problem_header ( $hash{phfn} ) if defined $hash{phfn};
167 $set->open_date ( $hash{opdt} ) if defined $hash{opdt};
168 $set->due_date ( $hash{dudt} ) if defined $hash{dudt};
169 $set->answer_date ( $hash{andt} ) if defined $hash{andt};
170 return $set;
66} 171}
67 172
68# set2hash($set) - unpacks a WeBWorK::Set object and returns PART of a hash 173# set2hash($set) - unpacks a WeBWorK::Set object and returns PART of a hash
69# suitable for storage in the webwork database. 174# suitable for storage in the webwork database.
70# $set - a WeBWorK::Set object. 175# $set - a WeBWorK::Set object.
71sub set2hash($) { 176sub set2hash($) {
72 my $set = shift; 177 my $set = shift;
178 my %hash;
179 $hash{stnm} = $set->id if defined $set->id;
180 $hash{stlg} = $set->login_id if defined $set->login_id;
181 $hash{shfn} = $set->set_header if defined $set->set_header;
182 $hash{phfn} = $set->problem_header if defined $set->problem_header;
183 $hash{opdt} = $set->open_date if defined $set->open_date;
184 $hash{dudt} = $set->due_date if defined $set->due_date;
185 $hash{andt} = $set->answer_date if defined $set->answer_date;
73} 186}
74 187
75# -----
76
77# hash@problem($problemNumber, %hash) - places selected fields from a webwork 188# hash@problem($n, %hash) - places selected fields from a webwork
78# database record in a WeBWorK::Problem 189# database record in a WeBWorK::Problem
79# object, which is then returned. 190# object, which is then returned.
80# $problemNumber - the problem number to extract 191# $n - the problem number to extract
81# %hash - a hash representing a database record 192# %hash - a hash representing a database record
82sub hash2problem($%) { 193sub hash2problem($%) {
83 my $problemNumber = shift; 194 my $n = shift;
84 my %hash = @_; 195 my %hash = @_;
196 my $problem = WeBWorK::Problem->new(id => $n);
197 $problem->set_id ( $hash{stnm} ) if defined $hash{stnm};
198 $problem->source_file ( $hash{"pfn$n"} ) if defined $hash{"pfn$n"};
199 $problem->value ( $hash{"pva$n"} ) if defined $hash{"pva$n"};
200 $problem->max_attempts ( $hash{"pmia$n"}) if defined $hash{"pmia$n"};
201 $problem->problem_seed ( $hash{"pse$n"} ) if defined $hash{"pse$n"};
202 $problem->status ( $hash{"pst$n"} ) if defined $hash{"pst$n"};
203 $problem->attempted ( $hash{"pat$n"} ) if defined $hash{"pat$n"};
204 $problem->last_answer ( $hash{"pan$n"} ) if defined $hash{"pan$n"};
205 $problem->num_correct ( $hash{"pca$n"} ) if defined $hash{"pca$n"};
206 $problem->num_incorrect ( $hash{"pia$n"} ) if defined $hash{"pia$n"};
207
85} 208}
86 209
87# problem2hash($problem) - unpacks a WeBWorK::Problem object and returns PART 210# problem2hash($problem) - unpacks a WeBWorK::Problem object and returns PART
88# of a hash suitable for storage in the webwork 211# of a hash suitable for storage in the webwork
89# database. 212# database.
90# $problem - a WeBWorK::Problem object 213# $problem - a WeBWorK::Problem object
91sub problem2hash($) { 214sub problem2hash($) {
92 my $problem = shift; 215 my $problem = shift;
216 my $n = $problem->id;
217 $hash{stnm} = $problem->set_id if defined $problem->set_id;
218 $hash{"pfn$n"} = $problem->source_file if defined $problem->source_file;
219 $hash{"pva$n"} = $problem->value if defined $problem->value;
220 $hash{"pmia$n"}= $problem->max_attempts if defined $problem->max_attempts;
221 $hash{"pse$n"} = $problem->problem_seed if defined $problem->problem_seed;
222 $hash{"pst$n"} = $problem->status if defined $problem->status;
223 $hash{"pat$n"} = $problem->attempted if defined $problem->attempted;
224 $hash{"pan$n"} = $problem->last_answer if defined $problem->last_answer;
225 $hash{"pca$n"} = $problem->num_correct if defined $problem->num_correct;
226 $hash{"pia$n"} = $problem->num_incorrect if defined $problem->num_incorrect;
227 return %hash;
93} 228}
94 229
951; 2301;

Legend:
Removed from v.361  
changed lines
  Added in v.362

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9