line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Schema::ResultSet::Tag; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
68845
|
use strict; |
|
40
|
|
|
|
|
100
|
|
|
40
|
|
|
|
|
1010
|
|
4
|
40
|
|
|
40
|
|
230
|
use warnings; |
|
40
|
|
|
|
|
88
|
|
|
40
|
|
|
|
|
979
|
|
5
|
40
|
|
|
40
|
|
189
|
use parent qw/MojoMojo::Schema::Base::ResultSet/; |
|
40
|
|
|
|
|
82
|
|
|
40
|
|
|
|
|
203
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
MojoMojo::Schema::ResultSet::Tag - resultset methods on tags |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 METHODS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head2 most_used |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Returns a list of all tags and the amount each of these tags |
16
|
|
|
|
|
|
|
is used on any page. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub most_used { |
21
|
7
|
|
|
7
|
1
|
20373
|
my ( $self, $count ) = @_; |
22
|
7
|
|
|
|
|
87
|
return $self->search( |
23
|
|
|
|
|
|
|
{ page => { '!=', undef }, }, |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
select => [ 'me.tag', 'count(me.tag) as refcount' ], |
26
|
|
|
|
|
|
|
as => [ 'tag', 'refcount' ], |
27
|
|
|
|
|
|
|
group_by => ['me.tag'], |
28
|
|
|
|
|
|
|
order_by => ['refcount desc'], |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 by_page |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Same as L</most_used> but for a particular page. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# TODO: Use join instead of from which is undocumented (on purpose) |
40
|
|
|
|
|
|
|
sub by_page { |
41
|
3
|
|
|
3
|
1
|
10438
|
my ( $self, $page ) = @_; |
42
|
3
|
|
|
|
|
54
|
return $self->search( |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
'ancestor.id' => $page, |
45
|
|
|
|
|
|
|
'me.page' => \'=descendant.id', |
46
|
|
|
|
|
|
|
-or => [ |
47
|
|
|
|
|
|
|
-and => [ |
48
|
|
|
|
|
|
|
'descendant.lft' => \'> ancestor.lft', |
49
|
|
|
|
|
|
|
'descendant.rgt' => \'< ancestor.rgt', |
50
|
|
|
|
|
|
|
], |
51
|
|
|
|
|
|
|
'ancestor.id' => \'=descendant.id', |
52
|
|
|
|
|
|
|
], |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
from => 'page as ancestor, page as descendant, tag as me', |
56
|
|
|
|
|
|
|
select => [ 'me.page', 'me.tag', 'count(me.tag) as refcount' ], |
57
|
|
|
|
|
|
|
as => [ 'page', 'tag', 'refcount' ], |
58
|
|
|
|
|
|
|
group_by => [ \'me.page', \'me.tag'], |
59
|
|
|
|
|
|
|
order_by => ['refcount'], |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 by_photo |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Tags on photos with counts. Used to make the tag cloud for the gallery. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub by_photo { |
71
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
72
|
0
|
|
|
|
|
|
return $self->search( |
73
|
|
|
|
|
|
|
{ photo => { '!=' => undef } }, |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
select => [ 'me.photo', 'me.tag', 'count(me.tag) as refcount' ], |
76
|
|
|
|
|
|
|
as => [ 'photo', 'tag', 'refcount' ], |
77
|
|
|
|
|
|
|
group_by => [ 'me.photo', 'me.tag'], |
78
|
|
|
|
|
|
|
order_by => ['me.tag'], |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 related_to [<tag>] [<count>] |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns popular tags related to this. Defaults to self. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub related_to { |
90
|
0
|
|
|
0
|
1
|
|
my ( $self, $tag, $count ) = @_; |
91
|
0
|
|
0
|
|
|
|
$tag ||= $self->tag; |
92
|
0
|
|
0
|
|
|
|
$count ||= 10; |
93
|
0
|
|
|
|
|
|
return $self->search( |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
'me.tag' => $tag, |
96
|
|
|
|
|
|
|
'other.tag' => { '!=', $tag }, |
97
|
|
|
|
|
|
|
'me.page' => \'=other.page', |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
select => [ 'me.tag', 'count(me.tag) as refcount' ], |
101
|
|
|
|
|
|
|
as => [ 'tag', 'refcount' ], |
102
|
|
|
|
|
|
|
'group_by' => ['me.tag'], |
103
|
|
|
|
|
|
|
'from' => 'tag me, tag other', |
104
|
|
|
|
|
|
|
'order_by' => \'refcount', |
105
|
|
|
|
|
|
|
'rows' => $count, |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
117
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |