source: server/trunk/web/lib/Sophie/Controller/0Explorer.pm @ 43

Last change on this file since 43 was 43, checked in by nanardon, 14 years ago
  • add search functions
File size: 2.0 KB
Line 
1package Sophie::Controller::0Explorer;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::0Explorer - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub dir :Local {
25    my ( $self, $c, @args ) = @_;
26    my $dir = join('/', map { "$_" } grep { $_ } @args);
27    $c->stash->{path} = $dir;
28    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
29
30    my $rsdist = $c->forward('/search/distrib_search', [ $c->session->{__explorer} ]);
31    $c->stash->{xmlrpc} = [ $c->model('Base')
32      ->resultset('Files')
33      ->search(
34          {
35              dirname => '/' . ($dir ? "$dir/" : ''),
36              pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },
37          },
38          {
39              order_by => [ 'basename' ],
40              group_by => [ 'basename' ], 
41              select => [ 'basename' ],
42          }
43      )->get_column('basename')->all ];
44}
45
46sub file :Local {
47    my ( $self, $c, @args ) = @_;
48    my $basename = pop(@args);
49    my $dir = join('/', map { "$_" } grep { $_ } @args);
50    $c->stash->{path} = $dir;
51    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
52
53    my $rsdist = $c->forward('/search/distrib_search', [ $c->session->{__explorer} ]);
54
55    $c->stash->{xmlrpc} = [ 
56        map { { pkgid => $_->get_column('pkgid') } }
57        $c->model('Base')
58      ->resultset('Files')
59      ->search({
60              dirname => '/' . ($dir ? "$dir/" : ''), basename => $basename,
61              pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },
62          },
63          { 
64              'select' => [
65                  'contents IS NULL as has_contents', 'pkgid'
66              ],
67              as => [ qw(has_content pkgid) ],
68              order_by => 'pkgid' 
69          }
70      )->all ];
71}
72
73=head1 AUTHOR
74
75Olivier Thauvin
76
77=head1 LICENSE
78
79This library is free software. You can redistribute it and/or modify
80it under the same terms as Perl itself.
81
82=cut
83
84__PACKAGE__->meta->make_immutable;
85
861;
Note: See TracBrowser for help on using the repository browser.