2 =head1 PACKAGE CXGN::People::Forum::Post
4 A package that deals with the posts.
11 package CXGN
::People
::Forum
::Post
;
13 use base qw
| CXGN
::People
::Forum
|;
15 =head2 constructor new()
18 Arguments: an database handle and an id for a post
19 or undef as id to create an empty object.
20 Returns: a CXGN::People::Forum::Post object
31 my $self = $class->SUPER::new
($dbh);
34 $self->set_forum_post_id($id);
35 $self->fetch_forum_post();
43 sub fetch_forum_post
{
45 my $h = $self->get_sql('fetch');
46 $h->execute($self->get_forum_post_id());
47 while (my ($forum_post_id, $post_text, $parent_post_id, $person_id, $post_time, $subject)=$h->fetchrow_array()) {
48 $post_text = $self->format_post_text($post_text);
49 $self->set_post_text($post_text);
50 $self->set_parent_post_id($parent_post_id);
51 $self->set_person_id($person_id);
52 $self->set_post_time($post_time);
53 $self->set_subject($subject);
60 =head2 function store()
62 Synopsis: $post->store();
64 Returns: the id of the new object in the database
65 if successful, undef otherwise
66 Side effects: stores the post to the database.
67 If an id is already available, an update occurs.
68 if an id is not available, an insert occurs.
76 if ($self->get_forum_post_id()) {
77 my $sth = $self->get_sql('update');
79 $self->get_post_text(), $self->get_person_id(), $self->get_forum_post_id(), $self->get_forum_topic_id(), $self->get_subject()
80 , $self->get_forum_post_id
85 my $sth = $self->get_sql('insert');
87 $self->get_post_text(),
88 $self->get_person_id(),
89 $self->get_forum_topic_id(),
93 $sth = $self->get_sql('currval');
95 my ($lid) = $sth->fetchrow_array();
97 $self->set_forum_post_id($lid);
101 my $subject="[Forum.pm] New post stored: ".$self->get_subject();
102 my $body="New post: \n".$self->get_post_text()."\n\n";
103 eval { CXGN
::Contact
::send_email
($subject,$body,'cxgn-devel\@sgn.cornell.edu'); };
104 return $return_value;
107 =head2 function delete()
111 Returns: the number of rows deleted, usually 1 if
113 Side effects: the post with the corresponding id is
114 permanently removed from the database.
121 my $sth = $self->get_sql('delete');
122 $sth->execute($self->get_forum_post_id());
126 =head2 function get_forum_post_id()
128 Synopsis: retrieves the forum_post_id of this object
132 Description: Posts with no id are automatically
133 treated as inserts in the store() function, and
134 the new id is then available using the accessor.
138 sub get_forum_post_id
{
140 return $self->{forum_post_id
};
143 =head2 Other accessor functions
161 return $self->{subject
};
166 $self->{subject
} = shift;
168 sub set_forum_post_id
{
170 $self->{forum_post_id
} = shift;
173 sub get_forum_topic_id
{
175 return $self->{forum_topic_id
};
178 sub set_forum_topic_id
{
180 $self->{forum_topic_id
} = shift;
185 return $self->{person_id
};
190 $self->{person_id
} = shift;
195 return $self->{post_text
};
200 $self->{post_text
} = shift;
203 sub get_parent_post_id
{
205 return $self->{parent_post_id
};
208 sub set_parent_post_id
{
210 $self->{parent_post_id
} = shift;
215 return $self->{timestamp
};
218 sub get_formatted_post_time
{
220 my $posttime = $self->get_post_time();
221 if ($posttime =~ m/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/) {
222 $posttime = "$2\/$3\/$1 $4\:$5";
224 if ($posttime =~/(.*)(\..*)$/) {
232 $self->{timestamp
} = shift;
237 return $self->{post_level
};
242 $self->{post_level
}=shift;
253 forum_post_id, post_text, parent_post_id,
254 person_id, post_time, subject
256 sgn_people.forum_post
264 UPDATE sgn_people.forum_post
267 post_text=?, person_id=?, forum_post_id=?,
268 forum_topic_id=?, subject=?
276 INSERT INTO sgn_people.forum_post
277 (post_text, person_id, forum_topic_id, subject)
284 SELECT currval('sgn_people.forum_post_forum_post_id_seq')
290 DELETE FROM sgn_people.forum_post
291 WHERE forum_post_id=?
296 while(my($k,$v) = each %{$self->{queries
}}){
297 $self->{query_handles
}->{$k}=$self->get_dbh()->prepare($v);
305 return $self->{query_handles
}->{$name};