]> git.decadent.org.uk Git - memories.git/blob - Memories/SystemTag.pm
0383db2f8bb60f325e7d29ca43caa45d47cd696a
[memories.git] / Memories / SystemTag.pm
1 package Memories::SystemTag;
2 use strict;
3 use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
4 __PACKAGE__->columns(Essential => qw/id name/);
5 __PACKAGE__->table("system_tag");
6
7 Memories::Photo->set_sql(sorted_by_system_tag => q/
8 SELECT photo.id as id, title, uploader, uploaded, x, y
9 FROM photo, system_tagging
10 WHERE system_tagging.photo = photo.id
11     AND system_tagging.tag = ?
12 ORDER BY photo.uploaded DESC
13 /
14 );
15 sub view :Exported {
16     my ($self, $r) = @_;
17     my $tag;
18     my $page = $r->params->{page} || 1;
19     my $pager = Class::DBI::Pager::_pager("Memories::Photo",
20         Memories->config->{photos_per_page}, $page);
21     $r->{template_args}{pager} = $pager;
22
23     if (!$r->objects) {
24         $tag = $self->search(name => $r->{args}->[0])->first;
25     } else {
26         $tag = $r->objects->[0]; # Should hardly happen
27     }
28     $r->{template_args}{tag} = $tag;
29     $r->{template_args}{tags} = [$tag]; # For selector
30     $r->{template_args}{photos} =
31         [$pager->search_sorted_by_system_tag($tag->id)];
32     $r->last_search;
33 }
34
35 package Memories::SystemTagging;
36 use base qw(Memories::DBI);
37 use Class::DBI::Pager;
38 1;