[1570] | 1 | package LATMOS::Accounts::Web::Controller::Remote::Obj; |
---|
| 2 | use Moose; |
---|
| 3 | use namespace::autoclean; |
---|
| 4 | |
---|
| 5 | BEGIN { extends 'Catalyst::Controller'; } |
---|
| 6 | |
---|
| 7 | =head1 NAME |
---|
| 8 | |
---|
| 9 | LATMOS::Accounts::Web::Controller::Remote::Obj - Catalyst Controller |
---|
| 10 | |
---|
| 11 | =head1 DESCRIPTION |
---|
| 12 | |
---|
| 13 | Catalyst Controller. |
---|
| 14 | |
---|
| 15 | =head1 METHODS |
---|
| 16 | |
---|
| 17 | =cut |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | =head2 index |
---|
| 21 | |
---|
| 22 | =cut |
---|
| 23 | |
---|
| 24 | sub index :Path :Args(0) { |
---|
| 25 | my ( $self, $c ) = @_; |
---|
| 26 | |
---|
| 27 | $c->stash->{data} = [ |
---|
| 28 | $c->model('Accounts')->db->list_supported_objects |
---|
| 29 | ]; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | sub 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} = [ |
---|
[1882] | 41 | $c->req->param('oalias') |
---|
| 42 | ? $c->model('Accounts')->db->listRealObjects($otype) |
---|
| 43 | : $c->model('Accounts')->db->list_objects($otype) |
---|
[1570] | 44 | ] |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | sub Show :Path :Args(2) { |
---|
| 48 | my ($self, $c, $otype, $id) = @_; |
---|
| 49 | |
---|
| 50 | my $base = $c->model('Accounts')->db; |
---|
| 51 | |
---|
| 52 | if (!$base->is_supported_object($otype)) { |
---|
| 53 | $c->res->status('404'); |
---|
| 54 | return; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | my $obj = $base->get_object($otype, $id); |
---|
| 58 | |
---|
| 59 | if (!$obj) { |
---|
| 60 | $c->res->status('404'); |
---|
| 61 | return; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | foreach my $attr (sort { $a cmp $b } $base->list_canonical_fields($otype, 'r')) { |
---|
| 65 | my $oattr = $obj->attribute($attr) or next; |
---|
| 66 | if ($oattr->hidden) { next; } |
---|
| 67 | my $val = $obj->get_c_field($attr); |
---|
| 68 | $c->stash->{data}{$attr} = $val if ($val); |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | =encoding utf8 |
---|
| 73 | |
---|
| 74 | =head1 AUTHOR |
---|
| 75 | |
---|
| 76 | Olivier Thauvin,Guyancourt - B1428,+33 1 80285052, |
---|
| 77 | |
---|
| 78 | =head1 LICENSE |
---|
| 79 | |
---|
| 80 | This library is free software. You can redistribute it and/or modify |
---|
| 81 | it under the same terms as Perl itself. |
---|
| 82 | |
---|
| 83 | =cut |
---|
| 84 | |
---|
| 85 | __PACKAGE__->meta->make_immutable; |
---|
| 86 | |
---|
| 87 | 1; |
---|