1 package Newslash::Model::Discussions;
2 use Newslash::Model::Base -base;
7 #========================================================================
9 =head2 select($query_type, $value)
21 query key, one of "id", "sid", "stoid"
31 HASH of discussion contents
38 my ($self, $query_type, $value) = @_;
40 if ($query_type !~ m/\A(id|sid|stoid)\z/) {
44 my $dbh = $self->connect_db;
48 WHERE discussions.$query_type = ?
51 my $sth = $dbh->prepare($sql);
53 $sth->execute($value);
54 my $discuss = $sth->fetchrow_hashref;
64 #========================================================================
66 =head2 create(\%options)
88 # extract from "discussion_kinds" table
89 my $discussion_kinds = {
101 my ($self, $params, $options) = @_;
104 || length $params->{title} == 0
105 || !$params->{url}) {
109 my $default_comment_status = "enabled";
110 my $mainpage_skid = 1; # mainpage
113 if ($params->{kind}) {
114 # getDescriptions('discussion_kinds') method is used in slash's original implement,
115 # but here, use static table.
116 $dkid = $discussion_kinds->{$params->{kind}} || 1;
118 my $uid = $params->{uid} || 0;
120 my $dbh = $options->{dbh} || $self->connect_db;
122 INSERT INTO discussions
123 (dkid, stoid, sid, title, url, topic, ts, type, uid, primaryskid, commentstatus)
125 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
127 my $rs = $dbh->do($sql, undef,
129 $params->{stoid} || 0,
133 $params->{topic} || 0,
135 $params->{type} || "open", #type
137 $params->{primaryskid} || $mainpage_skid,
138 $params->{commentstatus} || $default_comment_status,
140 my $discussion_id = 0;
142 $discussion_id = $dbh->last_insert_id(undef, undef, undef, undef);
144 $self->set_error($dbh->{mysql_errno});
147 if (!$options->{dbh}) {
151 if (!$discussion_id) {
154 return $discussion_id;