Bug 5670 - DBRev 16.06.00.036
[koha.git] / Koha / Item / Search / Field.pm
blob74c1cf211eabdc494146a1ad878e42dbc7f3a66f
1 package Koha::Item::Search::Field;
3 use Modern::Perl;
4 use base qw( Exporter );
6 our @EXPORT_OK = qw(
7 AddItemSearchField
8 ModItemSearchField
9 DelItemSearchField
10 GetItemSearchField
11 GetItemSearchFields
14 use C4::Context;
16 sub AddItemSearchField {
17 my ($field) = @_;
19 my ( $name, $label, $tagfield, $tagsubfield, $av_category ) =
20 @$field{qw(name label tagfield tagsubfield authorised_values_category)};
22 return unless ($name and $label and $tagfield);
24 my $dbh = C4::Context->dbh;
25 my $query = q{
26 INSERT INTO items_search_fields (name, label, tagfield, tagsubfield, authorised_values_category)
27 VALUES (?, ?, ?, ?, ?)
29 my $sth = $dbh->prepare($query);
30 my $rv = $sth->execute($name, $label, $tagfield, $tagsubfield, $av_category);
32 return ($rv) ? $field : undef;
35 sub ModItemSearchField {
36 my ($field) = @_;
38 my ( $name, $label, $tagfield, $tagsubfield, $av_category ) =
39 @$field{qw(name label tagfield tagsubfield authorised_values_category)};
41 return unless ($name and $label and $tagfield);
43 my $dbh = C4::Context->dbh;
44 my $query = q{
45 UPDATE items_search_fields
46 SET label = ?,
47 tagfield = ?,
48 tagsubfield = ?,
49 authorised_values_category = ?
50 WHERE name = ?
52 my $sth = $dbh->prepare($query);
53 my $rv = $sth->execute($label, $tagfield, $tagsubfield, $av_category, $name);
55 return ($rv) ? $field : undef;
58 sub DelItemSearchField {
59 my ($name) = @_;
61 my $dbh = C4::Context->dbh;
62 my $query = q{
63 DELETE FROM items_search_fields
64 WHERE name = ?
66 my $sth = $dbh->prepare($query);
67 my $rv = $sth->execute($name);
69 my $is_deleted = $rv ? int($rv) : 0;
70 if (!$is_deleted) {
71 warn "DelItemSearchField: Field '$name' doesn't exist";
74 return $is_deleted;
77 sub GetItemSearchField {
78 my ($name) = @_;
80 my $dbh = C4::Context->dbh;
81 my $query = q{
82 SELECT * FROM items_search_fields
83 WHERE name = ?
85 my $sth = $dbh->prepare($query);
86 my $rv = $sth->execute($name);
88 my $field;
89 if ($rv) {
90 $field = $sth->fetchrow_hashref;
93 return $field;
96 sub GetItemSearchFields {
97 my $dbh = C4::Context->dbh;
98 my $query = q{
99 SELECT * FROM items_search_fields
101 my $sth = $dbh->prepare($query);
102 my $rv = $sth->execute();
104 my @fields;
105 if ($rv) {
106 my $fields = $sth->fetchall_arrayref( {} );
107 @fields = @$fields;
110 return @fields;