my $dbh = C4::Context->dbh;
local $dbh->{RaiseError} = 1;
while ( my ( $record_id, $value ) = each %{$self->{values}} ) {
+ next unless defined $value;
my $updated = $dbh->do(q|
UPDATE additional_field_values
SET value = ?
sub all {
my ( $class, $args ) = @_;
- die "BAD CALL: Don't use fetch_all_values as a static method"
+ die "BAD CALL: Don't use fetch_all_values as an instance method"
if ref $class and UNIVERSAL::can($class,'can');
my $tablename = $args->{tablename};
my $searchable = $args->{searchable};
sub fetch_all_values {
my ( $class, $args ) = @_;
- die "BAD CALL: Don't use fetch_all_values as a static method"
+ die "BAD CALL: Don't use fetch_all_values as an instance method"
if ref $class and UNIVERSAL::can($class,'can');
my $record_id = $args->{record_id};
sub get_matching_record_ids {
my ( $class, $args ) = @_;
- die "BAD CALL: Don't use fetch_all_values as a static method"
+ die "BAD CALL: Don't use fetch_all_values as an instance method"
if ref $class and UNIVERSAL::can($class,'can');
my $fields = $args->{fields} // [];
my $tablename = $args->{tablename};
+ my $exact_match = $args->{exact_match} // 1;
return [] unless @$fields;
my $dbh = C4::Context->dbh;
WHERE afv.field_id = af.id
AND af.name = ?
AND af.tablename = ?
- AND value = ?
+ AND value LIKE ?
) AS field$i USING (id)
WHERE field$i.id IS NOT NULL
) AS values$i |;
$subquery .= ' USING (record_id)' if $i > 1;
push @subqueries, $subquery;
- push @args, $field->{name}, $tablename, $field->{value};
+ push @args, $field->{name}, $tablename, ( $exact_match ? $field->{value} : "%$field->{value}%" );
}
$query .= join( ' LEFT JOIN ', @subqueries ) . ' WHERE 1';
for my $j ( 1 .. $i ) {
#!/usr/bin/perl
use Modern::Perl;
-use Test::More tests => 34;
+use Test::More tests => 37;
use C4::Context;
use Koha::AdditionalField;
use C4::Biblio;
use C4::Budgets;
use C4::Serials;
+use C4::Serials::Frequency;
+use C4::Serials::Numberpattern;
my $booksellerid = C4::Bookseller::AddBookseller(
{
my $budgetid;
my $bpid = AddBudgetPeriod({
budget_period_startdate => '01-01-2015',
- budget_period_enddate => '12-31-2015',
+ budget_period_enddate => '01-01-2016',
budget_description => "budget desc"
});
budget_period_id => $bpid
});
+my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
+my $pattern_id = AddSubscriptionNumberpattern({
+ label => 'Test numberpattern 1',
+ numberingmethod => '{X}'
+});
+
my $subscriptionid1 = NewSubscription(
- undef, "", undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
- undef, undef, undef, undef, undef, undef, undef, undef,
- undef, undef, undef, undef, undef, undef, undef, undef,
- undef, undef, undef, undef, undef, undef, undef, 1,
- "notes", undef, undef, undef, undef, undef, undef, 0,
- "intnotes", 0, undef, undef, 0, undef, '31-12-2013',
+ undef, "", undef, undef, $budget_id, $biblionumber,
+ '2013-01-01', $frequency_id, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '2013-01-01', undef, $pattern_id,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-01-01', 0
);
my $subscriptionid2 = NewSubscription(
- undef, "", undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
- undef, undef, undef, undef, undef, undef, undef, undef,
- undef, undef, undef, undef, undef, undef, undef, undef,
- undef, undef, undef, undef, undef, undef, undef, 1,
- "notes", undef, undef, undef, undef, undef, undef, 0,
- "intnotes", 0, undef, undef, 0, undef, '31-12-2013',
+ undef, "", undef, undef, $budget_id, $biblionumber,
+ '2013-01-01', $frequency_id, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '2013-01-01', undef, $pattern_id,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-01-01', 0
);
# insert
$exists = grep /not_existent_id/, @$matching_record_ids;
is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
+$fields = [
+ {
+ name => 'common',
+ value => q|common|,
+ }
+];
+$matching_record_ids = Koha::AdditionalField->get_matching_record_ids({ tablename => 'subscription', fields => $fields, exact_match => 0 });
+$exists = grep /$subscriptionid1/, @$matching_record_ids;
+is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription1" );
+$exists = grep /$subscriptionid2/, @$matching_record_ids;
+is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription2 too" );
+$exists = grep /not_existent_id/, @$matching_record_ids;
+is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
+
+
$dbh->rollback;