4 CXGN::People::Roles - helper class for people's roles
8 my $person_roles = CXGN::Person::Roles->new( { bcs_schema => $schema } );
14 Nicolas Morales <nm529@cornell.edu>
20 package CXGN
::People
::Roles
;
24 use SGN
::Model
::Cvterm
;
27 use List
::MoreUtils qw
/any /;
30 isa
=> 'Bio::Chado::Schema',
37 my $dbh = $self->bcs_schema->storage->dbh;
39 my $q="SELECT sp_role_id FROM sgn_people.sp_roles where name=?;";
40 my $sth = $dbh->prepare($q);
42 my $count = $sth->rows;
44 print STDERR
"A role with that name already exists.\n";
48 my $q="INSERT INTO sgn_people.sp_roles (name) VALUES (?);";
49 my $sth = $dbh->prepare($q);
53 return "An error occurred while storing a new role. ($@)";
61 my $dbh = $self->bcs_schema->storage->dbh;
63 my $q="SELECT sp_role_id FROM sgn_people.sp_roles where name=?;";
64 my $sth = $dbh->prepare($q);
65 $sth->execute($old_name);
66 my $count = $sth->rows;
68 print STDERR
"No role with that name exists.\n";
72 my $q="UPDATE sgn_people.sp_roles SET name = ? WHERE name = ?;";
73 my $sth = $dbh->prepare($q);
74 $sth->execute($new_name,$old_name);
77 return "An error occurred while updating an existing role. ($@)";
81 sub get_breeding_program_roles
{
83 my $ascii_chars = shift;
84 my $dbh = $self->bcs_schema->storage->dbh;
85 my @breeding_program_roles;
86 my $q="SELECT username, sp_person_id, name, censor FROM sgn_people.sp_person
87 JOIN sgn_people.sp_person_roles using(sp_person_id)
88 JOIN sgn_people.sp_roles using(sp_role_id)
89 where disabled IS NULL and sp_person.censor = 0";
90 my $sth = $dbh->prepare($q);
92 while (my ($username, $sp_person_id, $sp_role, $censor) = $sth->fetchrow_array ) {
94 $username = unidecode
($username);
96 push(@breeding_program_roles, [$username, $sp_person_id, $sp_role, $censor] );
99 print STDERR Dumper \
@breeding_program_roles;
100 return \
@breeding_program_roles;
103 sub add_sp_person_role
{
105 my $sp_person_id = shift;
106 my $sp_role_id = shift;
107 my $dbh = $self->bcs_schema->storage->dbh;
108 my $q = "INSERT INTO sgn_people.sp_person_roles (sp_person_id, sp_role_id) VALUES (?,?);";
109 my $sth = $dbh->prepare($q);
110 $sth->execute($sp_person_id, $sp_role_id);
116 my $dbh = $self->bcs_schema->storage->dbh;
118 my $q="SELECT username, sp_person_id FROM sgn_people.sp_person WHERE disabled IS NULL and censor = 0 ORDER BY username ASC;";
119 my $sth = $dbh->prepare($q);
121 while (my ($username, $sp_person_id) = $sth->fetchrow_array ) {
122 push(@sp_persons, [$username, $sp_person_id] );
129 my $dbh = $self->bcs_schema->storage->dbh;
131 my $q="SELECT name, sp_role_id FROM sgn_people.sp_roles;";
132 my $sth = $dbh->prepare($q);
134 while (my ($name, $sp_role_id) = $sth->fetchrow_array ) {
135 push(@sp_roles, [$name, $sp_role_id] );
142 my $user_roles = shift;
143 my $program_name = shift;
145 if (!any
{ $_ eq "curator" || $_ eq "submitter" } (@
$user_roles)){
146 $check_roles{'invalid_role'} = 1;
150 map { $has_roles{$_} = 1; } @
$user_roles;
152 if (! ( (exists($has_roles{$program_name}) && exists($has_roles{submitter
})) || exists($has_roles{curator
}))) {
153 $check_roles{'invalid_program'} = 1;
156 return \
%check_roles;