-sub construct_query {
- my ($params) = @_;
-
- my ( $sql_query, @sql_params );
-
- if ( $params->{recordtype} eq "bibs" ) {
- if ( $params->{timestamp} ) {
- my $biblioitemstable = $params->{biblioitemstable};
- $sql_query = " (
- SELECT biblionumber
- FROM $biblioitemstable
- LEFT JOIN items USING(biblionumber)
- WHERE $biblioitemstable.timestamp >= ?
- OR items.timestamp >= ?
- ) UNION (
- SELECT biblionumber
- FROM $biblioitemstable
- LEFT JOIN deleteditems USING(biblionumber)
- WHERE $biblioitemstable.timestamp >= ?
- OR deleteditems.timestamp >= ?
- ) ";
- my $ts = $timestamp->output('iso');
- @sql_params = ( $ts, $ts, $ts, $ts );
- }
- else {
- my $biblioitemstable = $params->{biblioitemstable};
- my $itemstable = $params->{itemstable};
- my $StartingBiblionumber = $params->{StartingBiblionumber};
- my $EndingBiblionumber = $params->{EndingBiblionumber};
- my $branch = $params->{branch};
- my $start_callnumber = $params->{start_callnumber};
- my $end_callnumber = $params->{end_callnumber};
- my $start_accession = $params->{star_accession};
- my $end_accession = $params->{end_accession};
- my $itemtype = $params->{itemtype};
- my $items_filter =
- $branch
- || $start_callnumber
- || $end_callnumber
- || $start_accession
- || $end_accession
- || ( $itemtype && C4::Context->preference('item-level_itypes') );
- $sql_query = $items_filter
- ? "SELECT DISTINCT $biblioitemstable.biblionumber
- FROM $biblioitemstable JOIN $itemstable
- USING (biblionumber) WHERE 1"
- : "SELECT $biblioitemstable.biblionumber FROM $biblioitemstable WHERE biblionumber >0 ";
-
- if ($StartingBiblionumber) {
- $sql_query .= " AND $biblioitemstable.biblionumber >= ? ";
- push @sql_params, $StartingBiblionumber;
- }
-
- if ($EndingBiblionumber) {
- $sql_query .= " AND $biblioitemstable.biblionumber <= ? ";
- push @sql_params, $EndingBiblionumber;
- }
-
- if ($branch) {
- $sql_query .= " AND homebranch = ? ";
- push @sql_params, $branch;
- }
-
- if ($start_callnumber) {
- $sql_query .= " AND itemcallnumber <= ? ";
- push @sql_params, $start_callnumber;
- }
-
- if ($end_callnumber) {
- $sql_query .= " AND itemcallnumber >= ? ";
- push @sql_params, $end_callnumber;
- }
- if ($start_accession) {
- $sql_query .= " AND dateaccessioned >= ? ";
- push @sql_params, $start_accession->output('iso');
- }
-
- if ($end_accession) {
- $sql_query .= " AND dateaccessioned <= ? ";
- push @sql_params, $end_accession->output('iso');
- }
-
- if ($itemtype) {
- $sql_query .=
- ( C4::Context->preference('item-level_itypes') )
- ? " AND items.itype = ? "
- : " AND biblioitems.itemtype = ?";
- push @sql_params, $itemtype;
- }
- }
- }
- elsif ( $params->{recordtype} eq "auths" ) {
- if ( $params->{timestamp} ) {
-
- #TODO
- }
- else {
- my $starting_authid = $params->{starting_authid};
- my $ending_authid = $params->{ending_authid};
- my $authtype = $params->{authtype};
- $sql_query =
- "SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1";
-
- if ($starting_authid) {
- $sql_query .= " AND auth_header.authid >= ? ";
- push @sql_params, $starting_authid;
- }
-
- if ($ending_authid) {
- $sql_query .= " AND auth_header.authid <= ? ";
- push @sql_params, $ending_authid;
- }
-
- if ($authtype) {
- $sql_query .= " AND auth_header.authtypecode = ? ";
- push @sql_params, $authtype;
- }
- }
- }
- return ( $sql_query, \@sql_params );
-}
-