Merge pull request #42 from solgenomics/topic/duplicate_image_warning
[cxgn-corelibs.git] / lib / CXGN / Insitu / Organism.pm
blob83aee3026ed476a73b83869b5221af2974bb46b3
2 use strict;
3 use CXGN::Insitu::Experiment;
6 package CXGN::Insitu::Organism;
8 use base qw / CXGN::Insitu::DB /;
10 =head2 new
12 Usage:
13 Desc:
14 Ret:
15 Args:
16 Side Effects:
17 Example:
19 =cut
21 sub new {
22 my $class = shift;
23 my $dbh = shift;
24 my $id = shift;
25 my $self = $class -> SUPER::new($dbh);
27 if ($id) {
28 $self->set_organism_id($id);
29 $self->fetch_organism();
31 return $self;
34 sub fetch_organism {
35 my $self = shift;
36 my $query = "SELECT is_organism_id,
37 name,
38 common_name,
39 description,
40 user_id
41 FROM insitu.is_organism
42 WHERE is_organism_id=?";
43 my $sth = $self->get_dbh()->prepare($query);
44 $sth->execute($self->get_organism_id());
45 my ($organism_id, $name, $common_name, $description, $user_id) =
46 $sth->fetchrow_array();
47 $self->set_organism_id($organism_id);
48 $self->set_name($name);
49 $self->set_common_name($common_name);
50 $self->set_description($description);
51 $self->set_user_id($user_id);
54 =head2 store
56 Usage:
57 Desc:
58 Ret:
59 Args:
60 Side Effects:
61 Example:
63 =cut
65 sub store {
66 my $self = shift;
67 if ($self->get_organism_id()) {
68 my $query = "UPDATE insitu.is_organism SET
69 name=?,
70 common_name=?,
71 description=?,
72 user_id=?
73 WHERE is_organism_id=?";
74 my $sth = $self->get_dbh()->prepare($query);
75 $sth->execute(
76 $self->get_name(),
77 $self->get_common_name(),
78 $self->get_description(),
79 $self->get_organism_id(),
80 $self->get_user_id()
84 else {
85 my $query = "INSERT INTO insitu.is_organism
86 (name, common_name, description, user_id)
87 VALUES (?, ?, ?, ?)";
88 my $sth = $self->get_dbh()->prepare($query);
89 $sth->execute(
90 $self->get_name(),
91 $self->get_common_name(),
92 $self->get_description(),
93 $self->get_user_id()
95 return $self->get_dbh()->last_insert_id("is_organism");
99 =head2 get_all_organisms
101 Usage: my ($names_ref, $ids_ref) = CXGN::Insitu::Organism::get_all_organisms($dbh);
102 Desc: This is a static function.
103 Ret: Returns to arrayrefs. One array contains all the
104 organism names, and the other all the organism ids
105 with corresponding array indices.
106 Args: a database handle
107 Side Effects:
108 Example:
110 =cut
112 sub get_all_organisms {
113 my $dbh = shift;
114 my $query = "SELECT name, is_organism_id
115 FROM insitu.is_organism";
116 my $sth = $dbh->prepare($query);
117 $sth->execute();
118 my @names = ();
119 my @ids = ();
120 while (my($name, $organism_id) = $sth->fetchrow_array()) {
121 push @names, $name;
122 push @ids, $organism_id;
124 return (\@names, \@ids);
129 =head2 get_organism_id
131 Usage:
132 Desc:
133 Ret:
134 Args:
135 Side Effects:
136 Example:
138 =cut
140 sub get_organism_id {
141 my $self=shift;
142 return $self->{organism_id};
146 =head2 set_organism_id
148 Usage:
149 Desc:
150 Ret:
151 Args:
152 Side Effects:
153 Example:
155 =cut
157 sub set_organism_id {
158 my $self=shift;
159 $self->{organism_id}=shift;
162 =head2 get_name
164 Usage:
165 Desc:
166 Ret:
167 Args:
168 Side Effects:
169 Example:
171 =cut
173 sub get_name {
174 my $self=shift;
175 return $self->{name};
179 =head2 set_name
181 Usage:
182 Desc:
183 Ret:
184 Args:
185 Side Effects:
186 Example:
188 =cut
190 sub set_name {
191 my $self=shift;
192 $self->{name}=shift;
195 =head2 get_common_name
197 Usage:
198 Desc:
199 Ret:
200 Args:
201 Side Effects:
202 Example:
204 =cut
206 sub get_common_name {
207 my $self=shift;
208 return $self->{common_name};
212 =head2 set_common_name
214 Usage:
215 Desc:
216 Ret:
217 Args:
218 Side Effects:
219 Example:
221 =cut
223 sub set_common_name {
224 my $self=shift;
225 $self->{common_name}=shift;
228 =head2 get_description
230 Usage:
231 Desc:
232 Ret:
233 Args:
234 Side Effects:
235 Example:
237 =cut
239 sub get_description {
240 my $self=shift;
241 return $self->{description};
245 =head2 set_description
247 Usage:
248 Desc:
249 Ret:
250 Args:
251 Side Effects:
252 Example:
254 =cut
256 sub set_description {
257 my $self=shift;
258 $self->{description}=shift;
261 =head2 get_user_id
263 Usage:
264 Desc:
265 Ret:
266 Args:
267 Side Effects:
268 Example:
270 =cut
272 sub get_user_id {
273 my $self=shift;
274 return $self->{user_id};
278 =head2 set_user_id
280 Usage:
281 Desc:
282 Ret:
283 Args:
284 Side Effects:
285 Example:
287 =cut
289 sub set_user_id {
290 my $self=shift;
291 $self->{user_id}=shift;
297 =head2 get_associated_experiments
299 Usage:
300 Desc:
301 Ret:
302 Args:
303 Side Effects:
304 Example:
306 =cut
308 sub get_associated_experiments {
309 my $self = shift;
310 my $query = "SELECT experiment.experiment_id FROM insitu.experiment
311 WHERE is_organism_id=?";
312 my $sth = $self->get_dbh()->prepare($query);
313 $sth->execute($self->get_organism_id());
314 my @experiments = ();
315 while (my ($experiment_id) = $sth->fetchrow_array()) {
316 push @experiments, CXGN::Insitu::Experiment->new($self->get_dbh(), $experiment_id);
318 return @experiments;
325 return 1;