Lines 63-72
Contact's e-mail address.
Link Here
|
63 |
|
63 |
|
64 |
Notes about contact. |
64 |
Notes about contact. |
65 |
|
65 |
|
66 |
=item primary |
66 |
=item rank |
67 |
|
67 |
|
68 |
Flag to indicate whether a contact is "primary" or not. Initially unused since |
68 |
Ranking of the contact so that the contact can be given the correct |
69 |
each bookseller can have only one contact. |
69 |
priority in display. |
70 |
|
70 |
|
71 |
=item bookseller |
71 |
=item bookseller |
72 |
|
72 |
|
Lines 81-87
use C4::Context;
Link Here
|
81 |
|
81 |
|
82 |
use base qw(Class::Accessor); |
82 |
use base qw(Class::Accessor); |
83 |
|
83 |
|
84 |
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes primary bookseller)); |
84 |
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes rank bookseller)); |
85 |
|
85 |
|
86 |
=head1 METHODS |
86 |
=head1 METHODS |
87 |
|
87 |
|
Lines 90-96
__PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes pri
Link Here
|
90 |
my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)}; |
90 |
my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)}; |
91 |
|
91 |
|
92 |
Returns a reference to an array of C4::Bookseller::Contact objects for the |
92 |
Returns a reference to an array of C4::Bookseller::Contact objects for the |
93 |
specified bookseller. |
93 |
specified bookseller. This will always return at least one item, though that one |
|
|
94 |
item may be an empty contact. |
94 |
|
95 |
|
95 |
=cut |
96 |
=cut |
96 |
|
97 |
|
Lines 100-115
sub get_from_bookseller {
Link Here
|
100 |
return unless $bookseller; |
101 |
return unless $bookseller; |
101 |
|
102 |
|
102 |
my @contacts; |
103 |
my @contacts; |
103 |
my $query = "SELECT contact AS name, contpos AS position, contphone AS phone, contaltphone AS altphone, contfax AS fax, contemail AS email, contnotes AS notes, id AS bookseller FROM aqbooksellers WHERE id = ?"; |
104 |
my $query = "SELECT * FROM aqcontacts WHERE booksellerid = ?"; |
104 |
# When we have our own table, we can use: my $query = "SELECT * FROM aqcontacts WHERE bookseller = ?"; |
|
|
105 |
my $dbh = C4::Context->dbh; |
105 |
my $dbh = C4::Context->dbh; |
106 |
my $sth = $dbh->prepare($query); |
106 |
my $sth = $dbh->prepare($query); |
107 |
$sth->execute($bookseller); |
107 |
$sth->execute($bookseller); |
108 |
while (my $rec = $sth->fetchrow_hashref()) { |
108 |
while (my $rec = $sth->fetchrow_hashref()) { |
109 |
$rec->{'primary'} = 1; |
|
|
110 |
push @contacts, $class->new($rec); |
109 |
push @contacts, $class->new($rec); |
111 |
} |
110 |
} |
112 |
|
111 |
|
|
|
112 |
push @contacts, $class->new() unless @contacts; |
113 |
|
113 |
return \@contacts; |
114 |
return \@contacts; |
114 |
} |
115 |
} |
115 |
|
116 |
|
Lines 123-143
because there is no separate table from which contacts can be fetched.
Link Here
|
123 |
|
124 |
|
124 |
=cut |
125 |
=cut |
125 |
|
126 |
|
126 |
#sub fetch { |
127 |
sub fetch { |
127 |
# my ($class, $id) = @_; |
128 |
my ($class, $id) = @_; |
128 |
# |
129 |
|
129 |
# my $rec = { }; |
130 |
my $rec = { }; |
130 |
# if ($id) { |
131 |
if ($id) { |
131 |
# my $query = "SELECT * FROM aqcontacts WHERE id = ?"; |
132 |
my $query = "SELECT * FROM aqcontacts WHERE id = ?"; |
132 |
# my $dbh = C4::Context->dbh; |
133 |
my $dbh = C4::Context->dbh; |
133 |
# my $sth = $dbh->prepare($query); |
134 |
my $sth = $dbh->prepare($query); |
134 |
# $sth->execute($id); |
135 |
$sth->execute($id); |
135 |
# $rec = $sth->fetchrow_hashref(); |
136 |
$rec = $sth->fetchrow_hashref(); |
136 |
# } |
137 |
} |
137 |
# my $self = $class->SUPER::new($rec); |
138 |
my $self = $class->new($rec); |
138 |
# bless $self, $class; |
139 |
bless $self, $class; |
139 |
# return $self; |
140 |
return $self; |
140 |
#} |
141 |
} |
141 |
|
142 |
|
142 |
=head2 save |
143 |
=head2 save |
143 |
|
144 |
|
Lines 151-171
sub save {
Link Here
|
151 |
my ($self) = @_; |
152 |
my ($self) = @_; |
152 |
|
153 |
|
153 |
my $query; |
154 |
my $query; |
154 |
# if ($self->id) { |
155 |
my @params = ($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->rank, $self->bookseller); |
155 |
# $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, primary = ? WHERE id = ?;'; |
156 |
if ($self->id) { |
156 |
# } else { |
157 |
$query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, rank = ?, booksellerid = ? WHERE id = ?;'; |
157 |
# $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, primary) VALUES (?, ?, ?, ?, ? ,? ,?, ?);'; |
158 |
push @params, $self->id; |
158 |
# } |
|
|
159 |
if ($self->bookseller) { |
160 |
$query = 'UPDATE aqbooksellers SET contact = ?, contpos = ?, contphone = ?, contaltphone = ?, contfax = ?, contemail = ?, contnotes = ? WHERE id = ?;'; |
161 |
} else { |
159 |
} else { |
162 |
return; |
160 |
$query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, rank, booksellerid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);'; |
163 |
} |
161 |
} |
164 |
my $dbh = C4::Context->dbh; |
162 |
my $dbh = C4::Context->dbh; |
165 |
my $sth = $dbh->prepare($query); |
163 |
my $sth = $dbh->prepare($query); |
166 |
$sth->execute($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->bookseller); |
164 |
$sth->execute(@params); |
167 |
#$self->id = $dbh->last_insert_id(undef, undef, 'aqcontacts', undef); |
165 |
$self->id($dbh->{'mysql_insertid'}) unless $self->id; |
168 |
return $self->bookseller; |
166 |
return $self->id; |
|
|
167 |
} |
168 |
|
169 |
sub delete { |
170 |
my ($self) = @_; |
171 |
|
172 |
return unless $self->id; |
173 |
|
174 |
my $dbh = C4::Context->dbh; |
175 |
my $sth = $dbh->prepare("DELETE FROM aqcontacts WHERE id = ?;"); |
176 |
$sth->execute($self->id); |
177 |
return; |
169 |
} |
178 |
} |
170 |
|
179 |
|
171 |
=head1 AUTHOR |
180 |
=head1 AUTHOR |