3 use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
4 __PACKAGE__->columns(Essential => qw/id name/);
6 Memories::Photo->set_sql(sorted_by_tag => q/
7 SELECT photo.id as id, title, uploader, uploaded, x, y
8 FROM photo, tag, tagging
9 WHERE tagging.photo = photo.id
10 AND tagging.tag = tag.id
12 ORDER BY photo.uploaded DESC
19 my $page = $r->params->{page} || 1;
20 my $pager = Class::DBI::Pager::_pager("Memories::Photo",
21 Memories->config->{photos_per_page}, $page);
22 $r->{template_args}{pager} = $pager;
24 if (@{$r->args} > 1) { # This is actually an n-level search
25 $self->multi_search($r);
28 $tag = $self->search(name => $r->{args}->[0])->first;
30 $tag = $r->objects->[0]; # Should hardly happen
32 $r->{template_args}{tag} = $tag;
33 $r->{template_args}{tags} = [$tag]; # For selector
34 $r->{template_args}{photos} =
35 [$pager->search_sorted_by_tag($tag->id)];
41 my $counter = "tagaaa";
44 my $tag = $self->search(name => $_)->first;
46 push @tags, { tag => $tag, id => $tag-> id, counter => $counter++ };
48 my $sql = "select photo.id as id, photo.title as title, uploader, uploaded, x, y
49 from photo, ". (join ",", map{ "tagging ".$_->{counter} } @tags).
50 " where ". (join " AND ", map { "$_->{counter}.tag=$_->{id} and photo.id = $_->{counter}.photo" } @tags);
52 $sql .= " order by photo.uploaded desc";
53 my $sth = $self->db_Main->prepare($sql);
54 $r->{template_args}{photos} = [ $r->{template_args}{pager}->sth_to_objects($sth) ];
56 $r->{template_args}{tags} = [ map { $_->{tag} } @tags ];
61 my $page = $r->params->{page} || 1;
62 my $pager = Memories::Tagging->pager(
63 Memories->config->{photos_per_page}, $page
65 $r->{template_args}{pager} = $pager;
66 $r->objects([map {$_->tag} $pager->search_all]);
69 sub list_js :Exported {
71 $r->objects([ $self->retrieve_all ]);
74 package Memories::Tagging;
75 use base qw(Memories::DBI);
76 use Class::DBI::Pager;
77 __PACKAGE__->columns(TEMP => qw/count/);
78 __PACKAGE__->columns(Essential => qw/id tag photo/);
79 __PACKAGE__->set_sql(summary => qq/
80 SELECT id, tag, count(*) AS count
86 __PACKAGE__->set_sql(all => qq/
87 SELECT id, tag, count(*) AS count
92 Memories::Tagging->has_a("photo" => "Memories::Photo");
93 Memories::Tagging->has_a("tag" => "Memories::Tag");
95 Memories::Photo->has_many(tags => ["Memories::Tagging" => "tag"]);
96 Memories::Photo->has_many(taggings => "Memories::Tagging");
97 Memories::Tag->has_many(photos => ["Memories::Tagging" => "photo"] );
98 Memories::Tag->has_many(taggings => "Memories::Tagging");