source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/Obj.pm @ 1570

Last change on this file since 1570 was 1570, checked in by nanardon, 8 years ago

Add Remote/ tree for distant quering

File size: 1.6 KB
Line 
1package LATMOS::Accounts::Web::Controller::Remote::Obj;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Remote::Obj - 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 index :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    $c->stash->{data} = [
28        $c->model('Accounts')->db->list_supported_objects
29    ];
30}
31
32sub List :Path :Args(1) {
33    my ($self, $c, $otype) = @_;
34
35    if (!$c->model('Accounts')->db->is_supported_object($otype)) {
36        $c->res->status('404');
37        return;
38    }
39
40    $c->stash->{data} = [
41        $c->model('Accounts')->db->list_objects($otype)
42    ]
43}
44
45sub Show :Path :Args(2) {
46    my ($self, $c, $otype, $id) = @_;
47
48    my $base = $c->model('Accounts')->db;
49
50    if (!$base->is_supported_object($otype)) {
51        $c->res->status('404');
52        return;
53    }
54
55    my $obj = $base->get_object($otype, $id);
56
57    if (!$obj) {
58        $c->res->status('404');
59        return;
60    } 
61
62    foreach my $attr (sort { $a cmp $b } $base->list_canonical_fields($otype, 'r')) {
63        my $oattr = $obj->attribute($attr) or next;
64        if ($oattr->hidden) { next; }
65        my $val = $obj->get_c_field($attr);
66        $c->stash->{data}{$attr} = $val if ($val);
67    } 
68}
69
70=encoding utf8
71
72=head1 AUTHOR
73
74Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
75
76=head1 LICENSE
77
78This library is free software. You can redistribute it and/or modify
79it under the same terms as Perl itself.
80
81=cut
82
83__PACKAGE__->meta->make_immutable;
84
851;
Note: See TracBrowser for help on using the repository browser.