4 CXGN::People::PageComment - a package for adding user comments to database detail pages.
8 my $page_comment_obj = CXGN::People::PageComment->new($dbh, "map", $map_id, $referer);
10 print $page_comment_obj->get_html();
14 Handles the addition and deletion of user comments to SGN pages. Users have to be logged in using SGN's login system to post/delete messages.
18 The current implementation depends on CXGN::People::Forum.
20 =head1 USAGE ON DETAIL PAGES
22 On detail pages, the page comment feature should be added using a mason module, /page/comments.mas.
26 This class implements the following methods:
32 package CXGN
::People
::PageComment
;
36 use CXGN
::People
::Forum
;
38 use base qw
| CXGN
::DB
::Object
|;
40 =head2 constructor new()
42 Synopsis: my $pc = CXGN::People::PageComment -> new($dbh, "map", 9, $referer);
45 (2) A type, one of "BAC", "EST", "unigene", "marker", "map", "bac_end"
46 (3) the object\'s ID (an integer value that specifies the page).
47 (4) the refering page, including the page arguments
48 Returns: a handle to a Page_comment object
49 Side effects: Accesses the sgn_people database through the Forum.pm interface to search for comments for the specified type/ID and caches them.
62 my $self = $class->SUPER::new
($dbh);
64 $self->set_type($type);
67 # get a page object to decide if a user is logged in.
68 # my $page= CXGN::Page->new("", "Lukas");
69 $self->set_user_id(CXGN
::Login
->new($self->get_dbh())->has_session());
70 $self->set_refering_page($referer);
71 #print STDERR "Referer: ".($self->get_refering_page())."\n";
73 @
{$self->{posts
}}= ();
74 $self->fetch_page_comments();
79 =head2 function fetch_page_comments()
81 Usage: $pcobj -> fetch_page_comments();
82 Desc: populates the page comment object from the
83 database. Called by the constructor.
89 sub fetch_page_comments
{
91 # fetch the page comments using a function in the Topic class
94 #print STDERR "TYPE: ".$self->get_type.", ID: ".$self->get_id()."\n";
95 my $topic = CXGN
::People
::Forum
::Topic
->new_page_comment($self->get_dbh(), $self->get_type(), $self->get_id());
96 #print STDERR "TOPIC ID: ".$topic->get_forum_topic_id()."\n";
98 $self->set_topic($topic);
99 if ($self->get_topic()->get_forum_topic_id()) {
100 #print STDERR "Topic_id: ".$self->get_topic()->get_forum_topic_id()."\n";
101 my @posts = $self->get_topic()->get_all_posts();
102 # foreach my $p (@posts) { print STDERR "POSTS: ".($p->get_subject())."\n"; }
103 $self->set_posts(@posts);
107 #print STDERR "No topic could be found corresponding to type=".$self->get_type()." and id=".$self->get_id()."\n";
112 =head2 accessors set_refering_page(), get_refering_page()
114 Usage: $pc->set_refering_page('/detail?object_id=$id');
115 Property: the url of the page that the post is stored
117 Side Effects: the url will be embedded in links to get back to
118 the relevant detail page.
123 sub set_refering_page
{
125 $self->{refering_page
} = shift;
128 sub get_refering_page
{
130 return $self->{refering_page
};
133 =head2 accessors set_topic(), get_topic()
135 Usage: $pc->set_topic($topic_id)
136 Property: each post has an associated topic_id
144 $self->{topic
}=shift;
149 return $self->{topic
};
152 =head2 accessors set_posts(), get_posts()
154 Usage: $pc->set_posts(@posts)
155 Property: The posts for this type and id combination
163 @
{$self->{posts
}} = @_;
168 return @
{$self->{posts
}};
171 =head2 accessors set_type(), get_type()
173 Usage: $pc->set_type('marker');
174 Property: the type of page this page comment
175 is stored for. Supported are things like
176 bac, marker, pub, locus, etc.
189 return $self->{type
};
192 =head2 accessors set_id(), get_id()
194 Usage: $pc->set_id($id)
195 Property: the id of this post
211 =head2 accessors set_user_id(), get_user_id()
213 Usage: $pc->set_user_id($sp_person_id)
214 Property: the id of the user owning the post
222 $self->{user_id
}=shift;
227 return $self->{user_id
};
230 =head2 function get_html()
232 THIS FUNCTION IS DEPRECATED. USE /page/comments.mas IN NEW CODE.
233 Synopsis: print $cp -> get_html();
235 Returns: a string containing html code containing the user
245 my ($self, $passed_referer) = @_;
247 my @posts = $self->get_posts();
249 # We want to eventually return the user to the page they came from
250 #my $encoded_url = url_encode($self->get_refering_page());
252 # ...but if a referer is provided, we'll use that instead (helpful
254 my $encoded_url = url_encode
($self->get_refering_page()) || url_encode
($passed_referer);
255 # warn "UNENCODED URL IS $passed_referer";
256 # warn "ENCODED URL IS $encoded_url";
261 #$subtitle ="<span class=\"ghosted\">No user comments.</span>";
265 $s .= "<div class=\"indentedcontent\"><table width=\"700\" summary=\"\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" >";
266 foreach my $p (@posts) {
267 my $subject = $p->get_subject();
268 my $person_id = $p -> get_person_id
();
269 my $person = CXGN
::People
::Person
-> new
($self->get_dbh(), $person_id);
270 my $sp_person_id = $person -> get_sp_person_id
();
271 my $name = $person->get_first_name()." ".$person->get_last_name();
273 my $user_type = $person->get_user_type();
275 my $remove_link = " ";
276 if ($sp_person_id && ($self->get_user_id() == $sp_person_id || $user_type eq 'curator' )) {
277 $remove_link = "<a href=\"/forum/forum_post_delete.pl?post_id=".($p->get_forum_post_id())."&refering_page=$encoded_url\">Delete</a>\n";
280 if($user_type and $user_type ne 'user'){
281 $user_type=" ($user_type)";
286 my $text = $p -> get_post_text
();
287 my $date = $p -> get_formatted_post_time
();
289 my $poster_html = $sp_person_id
290 ?
"<a href=\"/solpeople/personal-info.pl?action=view&sp_person_id=$sp_person_id\">$name</a>$user_type"
293 $s .= "<tr><td><div class=\"boxbgcolor2\">
295 <table summary=\"\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td>Posted by <b>$poster_html</b> on $date </td><td class=\"right\">$remove_link </td></tr></table>
298 $s .= "<div class=\"boxbgcolor5\"><div class=\"indentedcontent\">$text</div></div></td></tr>";
300 $s .= "</table></div>";
303 $subtitle .= "<a href=\"/forum/add_post.pl?page_type=".$self->get_type()."&page_object_id=".$self->get_id()."&refering_page=$encoded_url\">[Add comment]</a>";
306 return CXGN
::Page
::FormattingHelpers
::info_section_html
(title
=> 'User comments',
315 $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;