-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCourseUser.pm
More file actions
167 lines (114 loc) · 3.39 KB
/
CourseUser.pm
File metadata and controls
167 lines (114 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package DB::Schema::Result::CourseUser;
use base qw/DBIx::Class::Core/;
use strict;
use warnings;
use feature 'signatures';
no warnings qw/experimental::signatures/;
use base qw/DBIx::Class::Core DB::Validation/;
=head1 DESCRIPTION
This is the database schema for a CourseUser. Note: this table has two purposes 1) a relationship table linking
the course and user tables (many-to-many) and 2) storing information about the user in the given course.
=head2 fields
=over
=item *
C<course_user_id>: database id (primary key, autoincrement integer)
=item *
C<course_id>: the database id of the course (foreign key)
=item *
C<user_id>: the database id of the user (foreign key)
=item *
C<role_id>: the role_id of the user (generally a string, but limited to a set of strings)
=item *
C<section>: the section the user is in (string)
=item *
C<recitation>: the recitation the user is in (string)
=item *
C<params>: a JSON object storing parameters. These are:
=over
=item *
C<comment>: general information that can be stored for the user (string)
=item *
C<useMathQuill>: whether or not the user uses MathQuill (boolean)
=item *
C<useMathView>: whether or not the user uses MathView (boolean)
=item *
C<displayMode>: the way to display mathematics (Mathjax, etc) a string
=item *
C<status>: the user's status in the course (enrolled, audit, drop), a string
=item *
C<lis_source_did>: information to link an LTI string
=item *
C<useWirisEditor>: whether or not the user uses WirisEditor (boolean)
=item *
C<showOldAnswers>: whether or not the user shows old answer (boolean)
=back
=back
=cut
__PACKAGE__->table('course_user');
__PACKAGE__->load_components(qw/InflateColumn::Serializer Core/);
__PACKAGE__->add_columns(
course_user_id => {
data_type => 'integer',
size => 16,
is_auto_increment => 1,
},
course_id => {
data_type => 'integer',
size => 16,
},
user_id => {
data_type => 'integer',
size => 16,
},
role_id => {
data_type => 'integer',
size => 16,
default_value => 0
},
section => {
data_type => 'text',
size => 16,
is_nullable => 1,
},
recitation => {
data_type => 'text',
size => 16,
is_nullable => 1,
},
# Store params as a JSON object.
course_user_params => {
data_type => 'text',
size => 256,
default_value => '{}',
retrieve_on_insert => 1,
serializer_class => 'JSON',
serializer_options => { utf8 => 1 }
}
);
__PACKAGE__->set_primary_key('course_user_id');
__PACKAGE__->add_unique_constraint([qw/course_id user_id/]);
__PACKAGE__->belongs_to(users => 'DB::Schema::Result::User', 'user_id');
__PACKAGE__->belongs_to(courses => 'DB::Schema::Result::Course', 'course_id');
__PACKAGE__->has_many(user_sets => 'DB::Schema::Result::UserSet', 'course_user_id');
# The cascade_delete => 0 prevents the role from being deleted if the course_user is deleted.
__PACKAGE__->has_one(
role => 'DB::Schema::Result::Role',
{ 'foreign.role_id' => 'self.role_id' },
{ cascade_delete => 0 }
);
=head2 C<valid_fields>
subroutine that returns a hash of the valid fields for json columns
=cut
sub valid_fields ($, $column_name) {
if ($column_name eq 'course_user_params') {
return {
comment => q{.*},
useMathQuill => 'bool',
displayMode => q{.*},
status => q{[A-Z]},
lis_source_did => q{.*},
showOldAnswers => 'bool'
};
}
}
1;