1 package C4::Bookseller::Contact;
3 # Copyright 2013 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 C4::Bookseller::Contact - object class for contacts associated with vendors
26 This class provides an object-oriented interface for handling vendor contacts.
27 It uses Class::Accessor to provide access to the following fields:
35 ID of the contact. This is not used initially, since contacts are actually
36 stored in the aqbooksellers table.
48 Contact's primary phone number.
52 Contact's alternate phone number.
60 Contact's e-mail address.
68 Ranking of the contact so that the contact can be given the correct
73 ID of the bookseller the contact is associated with.
82 use base qw(Class::Accessor);
84 __PACKAGE__->mk_accessors(qw(id name position phone altphone fax email notes rank bookseller));
88 =head2 get_from_bookseller
90 my @contacts = @{C4::Bookseller::Contact->get_from_bookseller($booksellerid)};
92 Returns a reference to an array of C4::Bookseller::Contact objects for the
93 specified bookseller. This will always return at least one item, though that one
94 item may be an empty contact.
98 sub get_from_bookseller {
99 my ($class, $bookseller) = @_;
101 return unless $bookseller;
104 my $query = "SELECT * FROM aqcontacts WHERE booksellerid = ?";
105 my $dbh = C4::Context->dbh;
106 my $sth = $dbh->prepare($query);
107 $sth->execute($bookseller);
108 while (my $rec = $sth->fetchrow_hashref()) {
109 push @contacts, $class->new($rec);
112 push @contacts, $class->new() unless @contacts;
120 my $contact = C4::Bookseller::Contact->fetch($contactid);
122 Retrieves the specified contact from the database. Currently commented out
123 because there is no separate table from which contacts can be fetched.
128 my ($class, $id) = @_;
132 my $query = "SELECT * FROM aqcontacts WHERE id = ?";
133 my $dbh = C4::Context->dbh;
134 my $sth = $dbh->prepare($query);
136 $rec = $sth->fetchrow_hashref();
138 my $self = $class->new($rec);
147 Save a contact to the database.
155 my @params = ($self->name, $self->position, $self->phone, $self->altphone, $self->fax, $self->email, $self->notes, $self->rank, $self->bookseller);
157 $query = 'UPDATE aqcontacts SET name = ?, position = ?, phone = ?, altphone = ?, fax = ?, email = ?, notes = ?, rank = ?, booksellerid = ? WHERE id = ?;';
158 push @params, $self->id;
160 $query = 'INSERT INTO aqcontacts (name, position, phone, altphone, fax, email, notes, rank, booksellerid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);';
162 my $dbh = C4::Context->dbh;
163 my $sth = $dbh->prepare($query);
164 $sth->execute(@params);
165 $self->id($dbh->{'mysql_insertid'}) unless $self->id;
172 return unless $self->id;
174 my $dbh = C4::Context->dbh;
175 my $sth = $dbh->prepare("DELETE FROM aqcontacts WHERE id = ?;");
176 $sth->execute($self->id);
182 Jared Camins-Esakov <jcamins@cpbibliography.com>