--- /dev/null
+package Newslash::Model::Timeline;
+use Newslash::Model::Base -base;
+
+use Data::Dumper;
+
+sub select {
+ my $self = shift;
+ my $params = {@_};
+
+ my $uid = $params->{uid};
+ return if !$uid;
+
+ my ($limit_clause, $limit_values) = $self->build_limit_clause({columns => [qw(createtime)]}, $params);
+
+ my $sql = <<"EOSQL";
+SELECT firehose.*,
+ firehose_text.*,
+ topics.*,
+ users.nickname AS author
+ FROM firehose
+ JOIN firehose_text ON firehose.id = firehose_text.id
+ JOIN users ON firehose.uid = users.uid
+ JOIN topics ON firehose.tid = topics.tid
+ WHERE firehose.uid = ?
+ ORDER BY createtime DESC $limit_clause
+EOSQL
+ my @params;
+ push @params, $uid;
+ push @params, @$limit_values;
+
+ my $dbh = $self->connect_db;
+ my $sth = $dbh->prepare($sql);
+ $sth->execute(@params);
+ my $rs = $sth->fetchall_arrayref({});
+ $self->disconnect_db;
+
+ if ($rs) {
+ for my $item (@$rs) {
+ $self->_generalize($item);
+ }
+ }
+ return $rs;
+}
+
+sub _generalize {
+ my ($self, $item) = @_;
+
+ if ($item->{type} eq 'comment') {
+ $item->{cid} = $item->{srcid};
+ }
+ elsif ($item->{type} eq 'story') {
+ $item->{stoid} = $item->{srcid};
+ }
+ elsif ($item->{type} eq 'journal') {
+ $item->{id} = $item->{srcid};
+ }
+ elsif ($item->{type} eq 'submission') {
+ $item->{subid} = $item->{srcid};
+ }
+
+ $item->{content_type} = $item->{type};
+
+ $item->{time} = $item->{createtime};
+
+ $item->{primary_topic} = {};
+ for my $k (qw(tid keyword textname series
+ image witdh height submittable
+ searchable storypickable usersprite)) {
+ $item->{primary_topic}->{$k} = $item->{$k};
+ delete $item->{$k};
+ }
+
+ #my $max_weight = 0;
+ #for my $t (@{$item->{topics}}) {
+ # if ($t->{tid} == $item->{tid}) {
+ # $item->{primary_topic} = $t;
+ # }
+ #if ($t->{weight} && $t->{weight} > $max_weight) {
+ # $max_weight = $t->{weight};
+ #}
+ #}
+}
+
+
+1;