OSDN Git Service

Model::Base: remove deprecated / unused functions
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Model / Topics.pm
1 package Newslash::Model::Topics;
2 use Newslash::Model::Base -base;
3
4 use Data::Dumper;
5
6 sub select {
7     my $self = shift;
8     my $params = {@_};
9
10     my $rs = $self->generic_select(table => 'topics',
11                                    unique_keys => [qw(tid keyword textname)],
12                                    keys => [qw(series submittable searchable storypickabe)],
13                                    params => $params);
14     return $rs;
15 }
16
17 sub get_topic_nexus {
18     my $self = shift;
19     my $rs = $self->generic_select(table => 'topic_nexus',
20                                    unique_keys => [qw(tid)],
21                                    keys => [qw(tid current_qid)]);
22     return $rs;
23 }
24
25 sub _select_topic_parents {
26     my $self = shift;
27     my $params = {@_};
28
29     my $rs = $self->generic_select(table => 'topic_parents',
30                                    keys => [qw(tid)],
31                                    params => $params);
32     return $rs;
33 }
34
35 sub get_primary_topic_from_tags {
36     my ($self, $tags) = @_;
37     return if !$tags || !@$tags;
38
39     my $dbh = $self->connect_db;
40
41     my @placeholders = map { "?" } @$tags;
42     my $placeholder = join(", ", @placeholders);
43
44     my $sql = <<"EOSQL";
45 SELECT * from topics
46   WHERE keyword IN ($placeholder)
47         OR textname IN ($placeholder)
48 EOSQL
49
50     my $sth = $dbh->prepare($sql);
51     $sth->execute(@$tags, @$tags);
52     my $rs = $sth->fetchall_arrayref({});
53     return if !$rs;
54
55     my $index = {};
56     for my $item (@$rs) {
57         $index->{$item->{keyword}} = $item;
58         $index->{$item->{textname}} = $item;
59     }
60
61     # scan topics by given order
62     my $topic;
63     for my $tag (@$tags) {
64         next if !defined $index->{$tag};
65         next if $index->{$tag}->{submittable} ne 'yes';
66         $topic = $index->{$tag};
67         last;
68     }
69
70     return $topic;
71 }
72
73
74 1;