1 | package LATMOS::Accounts::Bases::Attributes; |
---|
2 | |
---|
3 | # $Id$ |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | use 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 | |
---|
19 | sub 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 | |
---|
37 | sub base { $_[0]->{_base} } |
---|
38 | sub name { $_[0]->{_name} } |
---|
39 | sub otype { $_[0]->{_otype} } |
---|
40 | |
---|
41 | =head2 |
---|
42 | |
---|
43 | Return internal name of attributes |
---|
44 | |
---|
45 | =cut |
---|
46 | |
---|
47 | sub iname { $_[0]->{iname} || $_[0]->name } |
---|
48 | |
---|
49 | sub label { $_[0]->{label} || $_[0]->{_name} } |
---|
50 | |
---|
51 | sub 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 | |
---|
68 | sub ro { $_[0]->{ro} || 0 } |
---|
69 | |
---|
70 | sub 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 | |
---|
81 | Return 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 | |
---|
99 | sub form_type { $_[0]->ro ? 'LABEL' : ($_[0]->{formtype} || 'TEXT') } |
---|
100 | |
---|
101 | sub uniq { $_[0]->{uniq} || 0 } |
---|
102 | |
---|
103 | sub multiple { $_[0]->{multiple} || 0 } |
---|
104 | |
---|
105 | 1; |
---|