Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 34fac169

Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt

  • ID 34fac1694565f2a835851d2d6a6aa0f83faee43b
  • Vorgänger 8925999b
  • Nachfolger c44615e9

SL::DB::Note: Funktion trans_object zum Auslesen des referenzierten Objekts

Ein Note-Objekt hängt immer an einem anderen Datenbankobject, das über
trans_module+trans_id referenziert wird. Diese Funktion entscheidet
anhand von trans_module, welche Rose-Klasse zu instantiieren ist, holt
das entsprechende Objekt aus der Datenbank und gibt es zurück.

Auch bei polymorphen Objekten wie Kunden/Lieferanten (für trans_module == ct) wird das richtige getan.

Unterschiede anzeigen:

SL/DB/Note.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4 1
package SL::DB::Note;
5 2

  
6 3
use strict;
7 4

  
5
use Carp;
6

  
8 7
use SL::DB::MetaSetup::Note;
9 8

  
10 9

  
......
21 20
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
22 21
__PACKAGE__->meta->make_manager_class;
23 22

  
23
sub trans_object {
24
  my $self = shift;
25

  
26
  croak "Method is not a setter" if @_;
27

  
28
  return undef if !$self->trans_id || !$self->trans_module;
29

  
30
  if ($self->trans_module eq 'fu') {
31
    require SL::DB::FollowUp;
32
    return SL::DB::Manager::FollowUp->find_by(id => $self->trans_id);
33
  }
34

  
35
  if ($self->trans_module eq 'ct') {
36
    require SL::DB::Customer;
37
    require SL::DB::Vendor;
38
    return SL::DB::Manager::Customer->find_by(id => $self->trans_id)
39
        || SL::DB::Manager::Vendor  ->find_by(id => $self->trans_id);
40
  }
41

  
42
  return undef;
43
}
24 44

  
25 45
1;
46
__END__
47

  
48
=pod
49

  
50
=encoding utf8
51

  
52
=head1 NAME
53

  
54
SL::DB::Note - Notes
55

  
56
=head1 FUNCTIONS
57

  
58
=over 4
59

  
60
=item C<trans_object>
61

  
62
A note object is always attached to another database entity. Which one
63
is determined by the columns C<trans_module> and C<trans_id>. This
64
function looks at both, retrieves the corresponding object from the
65
database and returns it.
66

  
67
Currently the following three types are supported:
68

  
69
=over 2
70

  
71
=item * C<SL::DB::FollowUp> for C<trans_module == 'fu'>
72

  
73
=item * C<SL::DB::Customer> or C<SL::DB::Vendor> for C<trans_module ==
74
'ct'> (which class is used depends on the value of C<trans_id>;
75
customers are looked up first)
76

  
77
=back
78

  
79
The method returns C<undef> in three cases: if no C<trans_id> or no
80
C<trans_module> has been assigned yet; if C<trans_module> is unknown;
81
if the referenced object doesn't exist.
82

  
83
This method is a getter only, not a setter.
84

  
85
=back
86

  
87
=head1 BUGS
88

  
89
Nothing here yet.
90

  
91
=head1 AUTHOR
92

  
93
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
94

  
95
=cut

Auch abrufbar als: Unified diff