View | Details | Raw Unified | Return to bug 13892
Collapse All | Expand All

(-)a/Koha/Objects.pm (-3 / +3 lines)
Lines 96-112 my @objects = Koha::Objects->search($params); Link Here
96
=cut
96
=cut
97
97
98
sub search {
98
sub search {
99
    my ( $self, $params ) = @_;
99
    my ( $self, $params, $attributes ) = @_;
100
100
101
    if (wantarray) {
101
    if (wantarray) {
102
        my @dbic_rows = $self->_resultset()->search($params);
102
        my @dbic_rows = $self->_resultset()->search($params, $attributes);
103
103
104
        return $self->_wrap(@dbic_rows);
104
        return $self->_wrap(@dbic_rows);
105
105
106
    }
106
    }
107
    else {
107
    else {
108
        my $class = ref($self) ? ref($self) : $self;
108
        my $class = ref($self) ? ref($self) : $self;
109
        my $rs = $self->_resultset()->search($params);
109
        my $rs = $self->_resultset()->search($params, $attributes);
110
110
111
        return $class->_new_from_dbic($rs);
111
        return $class->_new_from_dbic($rs);
112
    }
112
    }
(-)a/circ/ysearch.pl (-40 / +41 lines)
Lines 22-82 Link Here
22
22
23
=head1 ysearch.pl
23
=head1 ysearch.pl
24
24
25
26
=cut
25
=cut
27
26
28
use strict;
27
use Modern::Perl;
29
#use warnings; FIXME - Bug 2505
30
use CGI qw ( -utf8 );
28
use CGI qw ( -utf8 );
31
use C4::Context;
29
use C4::Context;
32
use C4::Members;
33
use C4::Auth qw/check_cookie_auth/;
30
use C4::Auth qw/check_cookie_auth/;
31
use Koha::Borrowers;
32
33
use JSON qw( to_json );
34
34
35
my $input   = new CGI;
35
my $input = new CGI;
36
my $query   = $input->param('term');
36
my $query = $input->param('term');
37
37
38
binmode STDOUT, ":encoding(UTF-8)";
38
binmode STDOUT, ":encoding(UTF-8)";
39
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
39
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
40
40
41
my ($auth_status, $sessionID) = check_cookie_auth($input->cookie('CGISESSID'), { circulate => '*' });
41
my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } );
42
if ($auth_status ne "ok") {
42
if ( $auth_status ne "ok" ) {
43
    exit 0;
43
    exit 0;
44
}
44
}
45
45
46
my $dbh = C4::Context->dbh;
46
my $limit_on_branch;
47
my $sql = q(
48
    SELECT borrowernumber, surname, firstname, cardnumber, address, city, zipcode, country
49
    FROM borrowers
50
    WHERE ( surname LIKE ?
51
        OR firstname LIKE ?
52
        OR cardnumber LIKE ? )
53
);
54
if (   C4::Context->preference("IndependentBranches")
47
if (   C4::Context->preference("IndependentBranches")
55
    && C4::Context->userenv
48
    && C4::Context->userenv
56
    && !C4::Context->IsSuperLibrarian()
49
    && !C4::Context->IsSuperLibrarian()
57
    && C4::Context->userenv->{'branch'} )
50
    && C4::Context->userenv->{'branch'} ) {
58
{
51
    $limit_on_branch = 1;
59
    $sql .= " AND borrowers.branchcode ="
60
      . $dbh->quote( C4::Context->userenv->{'branch'} );
61
}
52
}
62
53
63
$sql    .= q( ORDER BY surname, firstname LIMIT 10);
54
my $borrowers_rs = Koha::Borrowers->search(
64
my $sth = $dbh->prepare( $sql );
55
    {   -or => {
65
$sth->execute("$query%", "$query%", "$query%");
56
            surname    => { -like => "$query%" },
57
            firstname  => { -like => "$query%" },
58
            cardnumber => { -like => "$query%" },
59
            ( $limit_on_branch ? { branchcode => C4::Context->userenv->{branch} } : () ),
60
        },
61
    },
62
    {
63
        # Get the first 10 results
64
        page     => 1,
65
        rows     => 10,
66
        order_by => [ 'surname', 'firstname' ],
67
    },
68
);
66
69
67
print "[";
70
my @borrowers;
68
my $i = 0;
71
while ( my $b = $borrowers_rs->next ) {
69
while ( my $rec = $sth->fetchrow_hashref ) {
72
    push @borrowers,
70
    if($i > 0){ print ","; }
73
      { borrowernumber => $b->borrowernumber,
71
    print "{\"borrowernumber\":\"" . $rec->{borrowernumber} . "\",\"" .
74
        surname        => $b->surname,
72
          "surname\":\"".$rec->{surname} . "\",\"" .
75
        firstname      => $b->firstname,
73
          "firstname\":\"".$rec->{firstname} . "\",\"" .
76
        cardnumber     => $b->cardnumber,
74
          "cardnumber\":\"".$rec->{cardnumber} . "\",\"" .
77
        address        => $b->address,
75
          "address\":\"".$rec->{address} . "\",\"" .
78
        city           => $b->city,
76
          "city\":\"".$rec->{city} . "\",\"" .
79
        zipcode        => $b->zipcode,
77
          "zipcode\":\"".$rec->{zipcode} . "\",\"" .
80
        country        => $b->country
78
          "country\":\"".$rec->{country} . "\"" .
81
      };
79
          "}";
80
    $i++;
81
}
82
}
82
print "]";
83
84
print to_json( \@borrowers );
83
- 

Return to bug 13892