Skip to content

Commit

Permalink
FIX: change assessor names of dbix::classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pstaabp committed Aug 25, 2022
1 parent a32c75b commit 7498263
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 87 deletions.
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/Course.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __PACKAGE__->set_primary_key('course_id');

# set up the many-to-many relationship to users
__PACKAGE__->has_many(course_users => 'DB::Schema::Result::CourseUser', 'course_id');
__PACKAGE__->many_to_many(users => 'course_users', 'users');
__PACKAGE__->many_to_many(users => 'course_users', 'user');

# set up the one-to-many relationship to problem_sets
__PACKAGE__->has_many(problem_sets => 'DB::Schema::Result::ProblemSet', 'course_id');
Expand Down
7 changes: 3 additions & 4 deletions lib/DB/Schema/Result/CourseUser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ __PACKAGE__->add_columns(
__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__->belongs_to(user => 'DB::Schema::Result::User', 'user_id');
__PACKAGE__->belongs_to(course => '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 }
{ 'foreign.role_id' => 'self.role_id' }, { cascade_delete => 0 }
);

=head2 C<valid_fields>
Expand Down
4 changes: 2 additions & 2 deletions lib/DB/Schema/Result/DBPermRole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key('db_perm_role_id');
__PACKAGE__->add_unique_constraint([qw/db_perm_id role_id/]);

__PACKAGE__->belongs_to(perms => 'DB::Schema::Result::DBPermission', 'db_perm_id');
__PACKAGE__->belongs_to(roles => 'DB::Schema::Result::Role', 'role_id');
__PACKAGE__->belongs_to(db_permission => 'DB::Schema::Result::DBPermission', 'db_perm_id');
__PACKAGE__->belongs_to(role => 'DB::Schema::Result::Role', 'role_id');

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/DBPermission.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key('db_perm_id');
__PACKAGE__->has_many(db_perm_roles => 'DB::Schema::Result::DBPermRole', 'db_perm_id');
__PACKAGE__->many_to_many(roles => 'db_perm_roles', 'roles');
__PACKAGE__->many_to_many(roles => 'db_perm_roles', 'role');

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/PoolProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ sub required_params ($=) {

__PACKAGE__->set_primary_key('pool_problem_id');

__PACKAGE__->belongs_to(problem_pool_id => 'DB::Schema::Result::ProblemPool');
__PACKAGE__->belongs_to(problem_pool => 'DB::Schema::Result::ProblemPool', 'problem_pool_id');

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/ProblemPool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ __PACKAGE__->add_unique_constraint([qw/course_id pool_name/]);

__PACKAGE__->has_many(pool_problems => 'DB::Schema::Result::PoolProblem', 'problem_pool_id');

__PACKAGE__->belongs_to(courses => 'DB::Schema::Result::Course', 'course_id');
__PACKAGE__->belongs_to(course => 'DB::Schema::Result::Course', 'course_id');

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/ProblemSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ __PACKAGE__->typecast_map(
__PACKAGE__->set_primary_key('set_id');
__PACKAGE__->add_unique_constraint([qw/course_id set_name/]);

__PACKAGE__->belongs_to(courses => 'DB::Schema::Result::Course', 'course_id');
__PACKAGE__->belongs_to(course => 'DB::Schema::Result::Course', 'course_id');
__PACKAGE__->has_many(problems => 'DB::Schema::Result::SetProblem', 'set_id');
__PACKAGE__->has_many(user_sets => 'DB::Schema::Result::UserSet', 'set_id');

Expand Down
4 changes: 3 additions & 1 deletion lib/DB/Schema/Result/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key('role_id');
__PACKAGE__->add_unique_constraint([qw/role_name/]);

__PACKAGE__->belongs_to(course_user => 'DB::Schema::Result::CourseUser', 'role_id');

__PACKAGE__->has_many(db_perm_roles => 'DB::Schema::Result::DBPermRole', 'role_id');
__PACKAGE__->many_to_many(db_perms => 'db_perm_roles', 'db_perms');
__PACKAGE__->many_to_many(db_permissions => 'db_perm_roles', 'db_permission');

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ __PACKAGE__->set_primary_key('user_id');
__PACKAGE__->add_unique_constraint([qw/username/]);

__PACKAGE__->has_many(course_users => 'DB::Schema::Result::CourseUser', 'user_id');
__PACKAGE__->many_to_many(courses => 'course_users', 'courses');
__PACKAGE__->many_to_many(course => 'course_users', 'course');

1;
4 changes: 2 additions & 2 deletions lib/DB/Schema/Result/UserProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key('user_problem_id');

__PACKAGE__->belongs_to(problems => 'DB::Schema::Result::SetProblem', 'set_problem_id');
__PACKAGE__->belongs_to(user_sets => 'DB::Schema::Result::UserSet', 'user_set_id');
__PACKAGE__->belongs_to(problem => 'DB::Schema::Result::SetProblem', 'set_problem_id');
__PACKAGE__->belongs_to(user_set => 'DB::Schema::Result::UserSet', 'user_set_id');

__PACKAGE__->has_many(attempts => 'DB::Schema::Result::Attempt', 'user_problem_id');

Expand Down
6 changes: 2 additions & 4 deletions lib/DB/Schema/Result/UserSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key('user_set_id');
__PACKAGE__->add_unique_constraint([qw/set_id course_user_id set_version/]);
__PACKAGE__->belongs_to(
course_users => 'DB::Schema::Result::CourseUser',
{ 'foreign.course_user_id' => 'self.course_user_id' }
);
__PACKAGE__->belongs_to(course_user => 'DB::Schema::Result::CourseUser', 'course_user_id');

__PACKAGE__->belongs_to(problem_set => 'DB::Schema::Result::ProblemSet', 'set_id');
__PACKAGE__->has_many(user_problems => 'DB::Schema::Result::UserProblem', 'user_set_id');

Expand Down
6 changes: 2 additions & 4 deletions lib/DB/Schema/ResultSet/Course.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,14 @@ sub getUserCourses ($self, %args) {
my $user = $self->result_source->schema->resultset('User')
->getGlobalUser(info => getUserInfo($args{info}), as_result_set => 1);

# my @user_courses = $user->courses->search({});

my @user_courses = $user->course_users->search({}, { prefetch => [qw/role/] });
my @user_courses = $user->course_users;

return @user_courses if $args{as_result_set};
my @user_courses_hashref = ();
for my $user_course (@user_courses) {

my $params = {
$user_course->get_inflated_columns, $user_course->courses->get_inflated_columns,
$user_course->get_inflated_columns, $user_course->course->get_inflated_columns,
role => $user_course->role->role_name
};
push(@user_courses_hashref, $params);
Expand Down
16 changes: 8 additions & 8 deletions lib/DB/Schema/ResultSet/ProblemPool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sub getAllProblemPools ($self, %args) {
my @problem_pools = $self->search({});
return @problem_pools if $args{as_result_set};
return map {
{ $_->get_inflated_columns, course_name => $_->courses->course_name };
{ $_->get_inflated_columns, course_name => $_->course->course_name };
} @problem_pools;
}

Expand All @@ -59,10 +59,10 @@ sub getProblemPools ($self, %args) {

my @pools = $self->search(
{
'courses.course_id' => $course->course_id
'course.course_id' => $course->course_id
},
{
join => [qw/courses/]
join => 'course'
}
);

Expand All @@ -84,9 +84,9 @@ sub getProblemPool ($self, %args) {
my $course = $self->rs('Course')->getCourse(info => getCourseInfo($args{info}), as_result_set => 1);

my $search_info = getPoolInfo($args{info});
$search_info->{'courses.course_id'} = $course->course_id;
$search_info->{'course.course_id'} = $course->course_id;

my $pool = $self->find($search_info, { join => [qw/courses/] });
my $pool = $self->find($search_info, { join => 'course' });

unless ($pool) {
my $course_name = $course->course_name;
Expand All @@ -112,10 +112,10 @@ sub addProblemPool ($self, %args) {

my $existing_pool = $self->find(
{
'courses.course_id' => $course->course_id,
pool_name => $args{params}->{pool_name}
'course.course_id' => $course->course_id,
pool_name => $args{params}->{pool_name}
},
{ prefetch => [qw/courses/] }
{ prefetch => 'course' }
);

DB::Exception::PoolAlreadyInCourse->throw(
Expand Down
10 changes: 5 additions & 5 deletions lib/DB/Schema/ResultSet/ProblemSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sub getAllProblemSets ($self, %args) {
my @all_sets = ();
for my $set (@problem_sets) {
my $expanded_set =
{ $set->get_inflated_columns, $set->courses->get_inflated_columns, set_type => $set->set_type };
{ $set->get_inflated_columns, $set->course->get_inflated_columns, set_type => $set->set_type };
delete $expanded_set->{type};
push(@all_sets, $expanded_set);
}
Expand Down Expand Up @@ -134,11 +134,11 @@ sub getHWSets ($self, %args) {
my $p = getCourseInfo($args{info}); # pull out the course_info that is passed
my $search_params = {};
for my $key (keys %$p) {
$search_params->{"courses.$key"} = $p->{$key};
$search_params->{"course.$key"} = $p->{$key};
}
$search_params->{'type'} = 1;

my @problem_sets = $self->search($search_params, { join => 'courses' });
my @problem_sets = $self->search($search_params, { join => 'course' });
my $sets = _formatSets(\@problem_sets);
return $args{as_result_set} ? @problem_sets : @$sets;
}
Expand Down Expand Up @@ -174,11 +174,11 @@ sub getQuizzes ($self, %args) {
my $p = getCourseInfo($args{info}); # pull out the course_info that is passed
my $search_params = {};
for my $key (keys %$p) {
$search_params->{"courses.$key"} = $p->{$key};
$search_params->{"course.$key"} = $p->{$key};
}
$search_params->{'type'} = 2;

my @problem_sets = $self->search($search_params, { join => 'courses' });
my @problem_sets = $self->search($search_params, { join => 'course' });
my $sets = _formatSets(\@problem_sets);
return $args{as_result_set} ? @problem_sets : @$sets;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DB/Schema/ResultSet/SetProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sub getSetProblem ($self, %args) {
. ' is not found for set: '
. $problem_set->set_name
. ' is the course: '
. $problem_set->courses->course_name
. $problem_set->course->course_name
) unless $problem;

return $problem if $args{as_result_set};
Expand Down
2 changes: 1 addition & 1 deletion lib/DB/Schema/ResultSet/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ sub _getCourseUser {
sub _getMergedUser {
my $course_user = shift;
return removeLoginParams({
$course_user->get_inflated_columns, $course_user->users->get_inflated_columns,
$course_user->get_inflated_columns, $course_user->user->get_inflated_columns,
role => $course_user->role->role_name
});
}
Expand Down
34 changes: 17 additions & 17 deletions lib/DB/Schema/ResultSet/UserProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ sub getUserProblems ($self, %args) {
my $course = $self->rs('Course')->getCourse(info => $args{info}, as_result_set => 1);
my @user_problems = $self->search(
{
'courses.course_id' => $course->course_id
'course.course_id' => $course->course_id
},
{
join => { problems => { problem_set => 'courses' } }
join => { problem => { problem_set => 'course' } }
}
);

Expand Down Expand Up @@ -147,11 +147,11 @@ sub getUserProblemsForSet ($self, %args) {
my $problem_set = $self->rs('ProblemSet')->getProblemSet(info => $args{info}, as_result_set => 1);
my @user_problems = $self->search(
{
'courses.course_id' => $course->course_id,
'course.course_id' => $course->course_id,
'problem_set.set_id' => $problem_set->set_id
},
{
join => { problems => { problem_set => 'courses' } }
join => { problem => { problem_set => 'course' } }
}
);

Expand Down Expand Up @@ -200,16 +200,16 @@ sub getUserProblemsForUser ($self, %args) {
my $user = $self->rs('User')->getGlobalUser(info => $args{info}, as_result_set => 1);
my @user_problems = $self->search(
{
'courses.course_id' => $course->course_id,
'users.user_id' => $user->user_id
'course.course_id' => $course->course_id,
'user.user_id' => $user->user_id
},
{
join => [
{
problems => { problem_set => 'courses' }
problem => { problem_set => 'course' }
},
{
user_sets => { course_users => 'users' }
user_set => { course_user => 'user' }
}
]
}
Expand Down Expand Up @@ -344,11 +344,11 @@ sub addUserProblem ($self, %args) {
);

DB::Exception::UserProblemExists->throw(message => 'The user '
. $user_problem->user_sets->course_users->users->username
. $user_problem->user_set->course_user->user->username
. ' already has problem number '
. $user_problem->problems->problem_number
. $user_problem->problem->problem_number
. ' in set with name '
. $user_problem->user_sets->problem_set->set_name)
. $user_problem->user_set->problem_set->set_name)
if $user_problem;

my $problem = $self->rs('SetProblem')->getSetProblem(info => $args{params}, as_result_set => 1);
Expand Down Expand Up @@ -560,11 +560,11 @@ sub checkParams ($self, $params) {
sub _mergeUserProblem ($user_problem) {
my $user_problem_fields = _getUserProblem($user_problem);
delete $user_problem_fields->{problem_params};
my $problem_fields = { $user_problem->problems->get_inflated_columns };
my $problem_fields = { $user_problem->problem->get_inflated_columns };
delete $problem_fields->{problem_params};

# Merge the params (problem_params and problem_params).
my $params = updateAllFields($user_problem->problems->problem_params, $user_problem->problem_params);
my $params = updateAllFields($user_problem->problem->problem_params, $user_problem->problem_params);

# Merge the main fields.
my $merged_params = updateAllFields($problem_fields, $user_problem_fields);
Expand All @@ -576,10 +576,10 @@ sub _mergeUserProblem ($user_problem) {
sub _getUserProblem ($user_problem) {
return {
$user_problem->get_inflated_columns,
problem_number => $user_problem->problems->problem_number,
username => $user_problem->user_sets->course_users->users->username,
set_name => $user_problem->problems->problem_set->set_name,
course_name => $user_problem->problems->problem_set->courses->course_name
problem_number => $user_problem->problem->problem_number,
username => $user_problem->user_set->course_user->user->username,
set_name => $user_problem->problem->problem_set->set_name,
course_name => $user_problem->problem->problem_set->course->course_name
};
}

Expand Down
Loading

0 comments on commit 7498263

Please sign in to comment.