Skip to content

Commit df7c214

Browse files
committed
WIP: initial checkin of some changes to handling settings.
WIP: work on course_settings WIP: continued work on the course settings WIP: continued work on course_settings. TEST: mojolicious route testing for settings. WIP: continued work on course settings
1 parent 2a9c342 commit df7c214

File tree

25 files changed

+2593
-764
lines changed

25 files changed

+2593
-764
lines changed
Lines changed: 143 additions & 142 deletions
Large diffs are not rendered by default.

lib/DB/Exception.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ use Exception::Class (
1818
fields => ['message'],
1919
description => 'There is an invalid field type'
2020
},
21+
'DB::Expection::SettingNotFound' => {
22+
fields => ['name'],
23+
description => 'A global setting is not found'
24+
},
2125
'DB::Exception::UndefinedParameter' => {
2226
fields => ['field_names'],
2327
description => 'There is an undefined parameter'

lib/DB/Schema/Result/Course.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ __PACKAGE__->has_many(problem_sets => 'DB::Schema::Result::ProblemSet', 'course_
8080
# set up the one-to-many relationship to problem_pools
8181
__PACKAGE__->has_many(problem_pools => 'DB::Schema::Result::ProblemPool', 'course_id');
8282

83-
# set up the one-to-one relationship to course settings;
84-
__PACKAGE__->has_one(course_settings => 'DB::Schema::Result::CourseSettings', 'course_id');
83+
# set up the one-to-many relationship to course settings;
84+
__PACKAGE__->has_many(course_settings => 'DB::Schema::Result::CourseSetting', 'course_id');
8585

8686
1;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package DB::Schema::Result::CourseSetting;
2+
use base qw/DBIx::Class::Core/;
3+
use strict;
4+
use warnings;
5+
6+
=head1 DESCRIPTION
7+
8+
This is the database schema for a CourseSetting.
9+
10+
=head2 fields
11+
12+
=over
13+
14+
=item *
15+
16+
C<course_setting_id>: database id (autoincrement integer)
17+
18+
=item *
19+
20+
C<course_id>: database id of the course for the setting (foreign key)
21+
22+
=item *
23+
24+
C<setting_id>: database id that the given setting is related to (foreign key)
25+
26+
=item *
27+
28+
C<value>: the value of the setting
29+
30+
=back
31+
32+
=cut
33+
34+
__PACKAGE__->table('course_setting');
35+
36+
__PACKAGE__->add_columns(
37+
course_setting_id => {
38+
data_type => 'integer',
39+
size => 16,
40+
is_nullable => 0,
41+
is_auto_increment => 1,
42+
},
43+
course_id => {
44+
data_type => 'integer',
45+
size => 16,
46+
is_nullable => 0,
47+
},
48+
setting_id => {
49+
data_type => 'integer',
50+
size => 16,
51+
is_nullable => 0,
52+
},
53+
value => {
54+
data_type => 'text',
55+
is_nullable => 0,
56+
},
57+
);
58+
59+
__PACKAGE__->set_primary_key('course_setting_id');
60+
61+
__PACKAGE__->add_unique_constraint([qw/course_id setting_id/]);
62+
63+
__PACKAGE__->belongs_to(course => 'DB::Schema::Result::Course', 'course_id');
64+
65+
__PACKAGE__->belongs_to(global_setting => 'DB::Schema::Result::GlobalSetting', 'setting_id');
66+
67+
1;

lib/DB/Schema/Result/CourseSettings.pm

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package DB::Schema::Result::GlobalSetting;
2+
use base qw/DBIx::Class::Core/;
3+
use strict;
4+
use warnings;
5+
6+
=head1 DESCRIPTION
7+
8+
This is the database schema for the Global Course Settings.
9+
10+
=head2 fields
11+
12+
=over
13+
14+
=item *
15+
16+
C<setting_id>: database id (autoincrement integer)
17+
18+
=item *
19+
20+
C<setting_name>: the name of the setting
21+
22+
=item *
23+
24+
C<default_value>: a JSON object of the default value for the setting
25+
26+
=item *
27+
28+
C<description>: a short description of the setting
29+
30+
=item *
31+
32+
C<doc>: more extensive help documentation.
33+
34+
=item *
35+
36+
C<type>: a string representation of the type of setting (boolean, text, list, ...)
37+
38+
=item *
39+
40+
C<options>: a JSON object that stores options if the setting is an list or multilist
41+
42+
=item *
43+
44+
C<category>: the category the setting falls into
45+
46+
=item *
47+
48+
C<subcategory>: the subcategory of the setting (may be null)
49+
50+
=back
51+
52+
=cut
53+
54+
__PACKAGE__->table('global_setting');
55+
56+
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
57+
58+
__PACKAGE__->add_columns(
59+
setting_id => {
60+
data_type => 'integer',
61+
size => 16,
62+
is_nullable => 0,
63+
is_auto_increment => 1,
64+
},
65+
setting_name => {
66+
data_type => 'varchar',
67+
size => 256,
68+
is_nullable => 0,
69+
},
70+
default_value => {
71+
data_type => 'text',
72+
is_nullable => 0,
73+
default_value => '\'\'',
74+
serializer_class => 'JSON',
75+
serializer_options => { utf8 => 1 }
76+
},
77+
description => {
78+
data_type => 'text',
79+
is_nullable => 0,
80+
default_value => '',
81+
},
82+
doc => {
83+
data_type => 'text',
84+
is_nullable => 1,
85+
},
86+
type => {
87+
data_type => 'varchar',
88+
size => 16,
89+
is_nullable => 0,
90+
default_value => '',
91+
},
92+
options => {
93+
data_type => 'text',
94+
is_nullable => 1,
95+
serializer_class => 'JSON',
96+
serializer_options => { utf8 => 1 }
97+
},
98+
category => {
99+
data_type => 'varchar',
100+
size => 64,
101+
is_nullable => 0,
102+
default_value => ''
103+
},
104+
subcategory => {
105+
data_type => 'varchar',
106+
size => 64,
107+
is_nullable => 1
108+
}
109+
);
110+
111+
__PACKAGE__->set_primary_key('setting_id');
112+
113+
__PACKAGE__->has_many(course_settings => 'DB::Schema::Result::CourseSetting', 'setting_id');
114+
115+
# __PACKAGE__->belongs_to(course => 'DB::Schema::Result::Course', 'course_id');
116+
117+
1;

0 commit comments

Comments
 (0)