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;
23 my @tags = map { $self->search(name => $_)->first } @{$r->args};
25 if (@{$r->args} > 1) { # This is actually an n-level search
26 my $sth = $self->multi_search(@tags);
27 $r->{template_args}{photos} = [ $r->{template_args}{pager}->sth_to_objects($sth) ];
29 $r->{template_args}{tags} = \@tags;
34 $tag = $r->objects->[0];
36 $r->{template_args}{tag} = $tag;
37 $r->{template_args}{tags} = [$tag]; # For selector
38 $r->{template_args}{photos} =
39 [$pager->search_sorted_by_tag($tag->id)];
45 my ($self, @tags) = @_;
46 my $counter = "tagaaa";
50 push @stuff, { tag => $tag, id => $tag->id, counter => $counter++ };
52 my $sql = "select photo.id as id, photo.title as title, uploader, uploaded, x, y
53 from photo, ". (join ",", map{ "tagging ".$_->{counter} } @stuff).
54 " where ". (join " AND ", map { "$_->{counter}.tag=$_->{id} and photo.id
55 = $_->{counter}.photo" } @stuff);
57 $sql .= " order by photo.uploaded desc";
58 my $sth = $self->db_Main->prepare($sql);
63 my $page = $r->params->{page} || 1;
64 my $pager = Memories::Tagging->pager(
65 Memories->config->{photos_per_page}, $page
67 $r->{template_args}{pager} = $pager;
68 $r->objects([map {$_->tag} $pager->search_all]);
71 sub list_js :Exported {
73 $r->objects([ $self->retrieve_all ]);
76 package Memories::Tagging;
77 use base qw(Memories::DBI);
78 use Class::DBI::Pager;
79 __PACKAGE__->columns(TEMP => qw/count/);
80 __PACKAGE__->columns(Essential => qw/id tag photo/);
81 __PACKAGE__->set_sql(summary => qq/
82 SELECT id, tag, count(*) AS count
88 __PACKAGE__->set_sql(all => qq/
89 SELECT id, tag, count(*) AS count
94 __PACKAGE__->set_sql(user_summary => qq/
95 SELECT tagging.id id, tag, count(*) AS count
97 WHERE tagging.photo = photo.id AND photo.uploader = ?
102 Memories::Tagging->has_a("photo" => "Memories::Photo");
103 Memories::Tagging->has_a("tag" => "Memories::Tag");
105 Memories::Photo->has_many(tags => ["Memories::Tagging" => "tag"]);
106 Memories::Photo->has_many(taggings => "Memories::Tagging");
107 Memories::Tag->has_many(photos => ["Memories::Tagging" => "photo"] );
108 Memories::Tag->has_many(taggings => "Memories::Tagging");