source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Attributes.pm @ 857

Last change on this file since 857 was 857, checked in by nanardon, 14 years ago
  • _get_attr_schema must return all attributes
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1package LATMOS::Accounts::Bases::Attributes;
2
3# $Id$
4
5use strict;
6use warnings;
7use LATMOS::Accounts::Log;
8
9=head1 NAME
10
11    LATMOS::Accounts::Bases::Attributes - Object to handle attribute schema
12
13=head1 FUNCTIONS
14
15=head2 new($attributes, $base_or_object, $maybe_otype)
16
17=cut
18
19sub new {
20    my ($class, $attributes, $base_or_object, $maybe_otype) = @_;
21   
22    my ($object, $base, $otype) =
23    $base_or_object->isa('LATMOS::Accounts::Bases::Objects')
24        ? ($base_or_object, $base_or_object->base, $base_or_object->type)
25        : (undef, $base_or_object, $maybe_otype);
26
27    my $attr_info = $base->get_attr_schema($otype, $attributes);
28
29    $attr_info->{_base} = $base;
30    $attr_info->{_object} = $object;
31    $attr_info->{_name} = $attributes;
32    $attr_info->{_otype} = $otype;
33
34    bless($attr_info, $class);
35}
36
37sub base  { $_[0]->{_base}  }
38sub name  { $_[0]->{_name}  }
39sub otype { $_[0]->{_otype} }
40
41=head2
42
43Return internal name of attributes
44
45=cut
46
47sub iname { $_[0]->{iname} || $_[0]->name }
48
49sub label { $_[0]->{label} || $_[0]->{_name} }
50
51sub can_values {
52    my ($self) = @_;
53    if (my @values = $self->base->obj_attr_allowed_values(
54            $self->otype,
55            $self->name)) {
56        return @values;
57    } elsif ($self->{can_values}) {
58        if (ref $self->{can_values} eq 'ARRAY') {
59            return @{$self->{can_values}};
60        } elsif (ref $self->{can_values} eq 'CODE') {
61            $self->{can_values}->($self);
62        } else {
63            return;
64        }
65    } else { return }
66}
67
68sub ro { $_[0]->{ro} || 0 }
69
70sub readonly { 
71    my ($self) = @_;
72    return 1 if ($self->ro);
73   
74    return ! $self->base->check_acl($self->object
75        ? ($self->object, $self->name, 'w')
76        : ($self->otype, '@CREATE', 'w'));
77}
78
79=head2 form_type
80
81Return the way the fields must be show in GUI:
82
83=over 4
84
85=item LABEL
86
87=item TEXT
88
89=item DATE
90
91=item LIST
92
93=item CHECKBOX
94
95=back
96
97=cut
98
99sub form_type { $_[0]->ro ? 'LABEL' : ($_[0]->{formtype} || 'TEXT') }
100
101sub uniq { $_[0]->{uniq} || 0 }
102
103sub multiple { $_[0]->{multiple} || 0 }
104
1051;
Note: See TracBrowser for help on using the repository browser.