Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions IFComp/lib/IFComp/Controller/Admin/Questions.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package IFComp::Controller::Admin::Questions;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

IFComp::Controller::Admin::Questions - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

=head2 index

=cut

sub root : Chained('/admin/root') : PathPart('questions') : CaptureArgs(0) {
my ( $self, $c ) = @_;

unless ( $c->user && $c->check_any_user_role('cheez') ) {
$c->res->redirect('/');
$c->detach();
}

}

sub index : Chained('root') : PathPart('view') : Args(0) {
my ( $self, $c ) = @_;

my @questions = $c->model('IFCompDB::Question')->all;

$c->stash(
template => 'admin/questions/index.tt',
questions => \@questions,
);
}

sub save_questions : Chained('root') : PathPart('save') : Args(0) :
Method('POST') {
my ( $self, $c ) = @_;

my $params = $c->req->body_parameters;
my $guard = $c->model('IFCompDB')->txn_scope_guard;

foreach my $param_name ( keys %$params ) {

if ( $param_name =~ /^question_(\d+)$/ ) {
my $question_id = $1;
my $question_text = $params->{$param_name};

my $question_row =
$c->model('IFCompDB::Question')->find($question_id);

if ($question_row) {
if ( $params->{"disable_$question_id"} ) {
$question_row->update( { disabled => 1 } );
}
else {
$question_row->update( { disabled => 0 } );
}
$question_row->update( { question_text => $question_text } );
}
}
}

if ( $params->{new_question} && $params->{new_question} =~ /\S/ ) {
$c->model('IFCompDB::Question')
->create( { question_text => $params->{new_question} } );
}

$guard->commit;

$c->flash->{status_msg} = "Questions successfully updated.";
$c->res->redirect( $c->uri_for('/admin/questions/view') );
}

=encoding utf8

=head1 AUTHOR

Mark Musante

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
36 changes: 30 additions & 6 deletions IFComp/lib/IFComp/Controller/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ sub root : Chained('/') : PathPart('entry') : CaptureArgs(0) {
my @entries = $c->user->get_object->current_comp_entries;

my $current_comp = $c->model('IFCompDB::Comp')->current_comp;
my @questions = $c->model('IFCompDB::Question')->all;

$c->stash(
entries => \@entries,
current_comp => $current_comp,
entries => \@entries,
current_comp => $current_comp,
uk_compliance => \@questions,
);

}

sub fetch_entry : Chained('root') : PathPart('') : CaptureArgs(1) {
my ( $self, $c, $id ) = @_;

my $entry = $c->model('IFCompDB::Entry')->find($id);
my $entry = $c->model('IFCompDB::Entry')
->find( $id, { prefetch => { 'entry_answers' => 'question' }, } );
if ( $entry && $entry->author->id eq $c->user->get_object->id ) {
$c->stash->{entry} = $entry;
$self->entry($entry);
Expand Down Expand Up @@ -113,7 +116,7 @@ sub create : Chained('root') : PathPart('create') : Args(0) {
);

$c->stash( entry =>
$c->model('IFCompDB::Entry')->new_result( \%new_result_args ) );
$c->model('IFCompDB::Entry')->new_result( \%new_result_args ), );
if ( $self->_process_form($c) ) {
$c->user->send_author_reminder_email;
$c->res->redirect( $c->uri_for_action('/entry/list') );
Expand Down Expand Up @@ -257,6 +260,8 @@ sub _process_form {
template => 'entry/update.tt',
);

my @questions = $c->model('IFCompDB::Question')->all;

my $params_ref = $c->req->parameters;
foreach (qw( main_upload walkthrough_upload cover_upload )) {
my $param = "entry.$_";
Expand Down Expand Up @@ -328,6 +333,21 @@ sub _process_form {
}
}

for my $q (@questions) {
my $val = "uk_compliance.q_" . $q->id;
my $ans = "no";
if ( defined( $params_ref->{$val} ) ) {
$ans = "yes";
}

$c->model('IFCompDB::EntryAnswer')->update_or_create(
{ entry_id => $entry->id,
question_id => $q->id,
answer => $ans,
}
);
}

my $genai_data = $params_ref->{"entry.genai"};
my $value = 0;
if ( ref($genai_data) eq 'ARRAY' ) {
Expand Down Expand Up @@ -427,8 +447,12 @@ sub _process_withdrawal_form {
my ( $self, $c ) = @_;

if ( $self->withdrawal_form->process( params => $c->req->parameters, ) ) {
$c->stash->{entry}->delete;
$c->flash->{entry_withdrawn} = $c->stash->{entry}->title;
my $entry =
$c->model('IFCompDB::Entry')->find( $c->stash->{entry}->id );
if ($entry) {
$entry->delete;
$c->flash->{entry_withdrawn} = $c->stash->{entry}->title;
}
$c->res->redirect( $c->uri_for_action('/entry/list') );
}

Expand Down
19 changes: 17 additions & 2 deletions IFComp/lib/IFComp/Schema/Result/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ __PACKAGE__->belongs_to(
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);

=head2 entry_answers

Type: has_many

Related object: L<IFComp::Schema::Result::EntryAnswer>

=cut

__PACKAGE__->has_many(
"entry_answers",
"IFComp::Schema::Result::EntryAnswer",
{ "foreign.entry_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 entry_coauthors

Type: has_many
Expand Down Expand Up @@ -520,8 +535,8 @@ __PACKAGE__->has_many(

#>>>

# Created by DBIx::Class::Schema::Loader v0.07052 @ 2024-08-05 22:40:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BA11TUZSbhEvXq6M5++njA
# Created by DBIx::Class::Schema::Loader v0.07053 @ 2026-06-16 20:51:39
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pZ9XCGIkzyTQGGz4JNbWpw

__PACKAGE__->add_columns( '+coauthor_code' =>
{ dynamic_default_on_create => '_generate_unique_coauthor_code', }, );
Expand Down
123 changes: 123 additions & 0 deletions IFComp/lib/IFComp/Schema/Result/EntryAnswer.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#<<<
use utf8;
package IFComp::Schema::Result::EntryAnswer;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

IFComp::Schema::Result::EntryAnswer

=cut

use strict;
use warnings;


=head1 BASE CLASS: L<IFComp::Schema::Result>

=cut

use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'IFComp::Schema::Result';

=head1 TABLE: C<entry_answers>

=cut

__PACKAGE__->table("entry_answers");

=head1 ACCESSORS

=head2 entry_id

data_type: 'integer'
extra: {unsigned => 1}
is_foreign_key: 1
is_nullable: 0

=head2 question_id

data_type: 'integer'
is_foreign_key: 1
is_nullable: 0

=head2 answer

data_type: 'varchar'
is_nullable: 1
size: 255

=cut

__PACKAGE__->add_columns(
"entry_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_foreign_key => 1,
is_nullable => 0,
},
"question_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"answer",
{ data_type => "varchar", is_nullable => 1, size => 255 },
);

=head1 PRIMARY KEY

=over 4

=item * L</entry_id>

=item * L</question_id>

=back

=cut

__PACKAGE__->set_primary_key("entry_id", "question_id");

=head1 RELATIONS

=head2 entry

Type: belongs_to

Related object: L<IFComp::Schema::Result::Entry>

=cut

__PACKAGE__->belongs_to(
"entry",
"IFComp::Schema::Result::Entry",
{ id => "entry_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
);

=head2 question

Type: belongs_to

Related object: L<IFComp::Schema::Result::Question>

=cut

__PACKAGE__->belongs_to(
"question",
"IFComp::Schema::Result::Question",
{ id => "question_id" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);

#>>>

# Created by DBIx::Class::Schema::Loader v0.07053 @ 2026-06-16 20:51:39
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zfm0Hfg8Ac4nMJbK/YwfTg

# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
Loading
Loading