Bugzilla – Attachment 62160 Details for
Bug 17835
Move C4::Koha::GetItemTypes to Koha::ItemTypes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17835: Add an additional LEFT JOIN condition using DBIx::Class
Bug-17835-Add-an-additional-LEFT-JOIN-condition-us.patch (text/plain), 5.67 KB, created by
Marcel de Rooy
on 2017-04-14 08:49:32 UTC
(
hide
)
Description:
Bug 17835: Add an additional LEFT JOIN condition using DBIx::Class
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-04-14 08:49:32 UTC
Size:
5.67 KB
patch
obsolete
>From 8366e0e2faf2995284b6860b3164ec8b75c950bb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 3 Jan 2017 13:35:46 +0100 >Subject: [PATCH] Bug 17835: Add an additional LEFT JOIN condition using > DBIx::Class >Content-Type: text/plain; charset=utf-8 > >The previous query was wrong. If an item type did not contain the >translation in the interface's language, the ->search_with_localization >did not return it at all. > >What we need is definitely to add a second condition on the join. > >For reference: >http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Relationship/Base.pm#condition >https://blog.afoolishmanifesto.com/posts/dbix-class-parameterized-relationships/ > >That sounds hacky but seems to be the DBIx::Class path to follow. > >Bug 17835: follow-up > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Lari Taskula <lari.taskula@jns.fi> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/ItemTypes.pm | 12 ++++++++---- > Koha/Schema/Result/Itemtype.pm | 17 +++++++++++++---- > .../prog/en/modules/reports/reserves_stats.tt | 4 ++-- > suggestion/suggestion.pl | 1 + > t/db_dependent/Koha/ItemTypes.t | 14 +++++++++++++- > 5 files changed, 37 insertions(+), 11 deletions(-) > >diff --git a/Koha/ItemTypes.pm b/Koha/ItemTypes.pm >index daa808b..a3786cb 100644 >--- a/Koha/ItemTypes.pm >+++ b/Koha/ItemTypes.pm >@@ -46,11 +46,15 @@ sub search_with_localization { > my ( $self, $params, $attributes ) = @_; > > my $language = C4::Languages::getlanguage(); >- $params->{'-or'} = { 'localization.lang' => [ $language, undef ] }; >- $attributes->{order_by} = 'localization.translation' unless exists $attributes->{order_by}; >+ $Koha::Schema::Result::Itemtype::LANGUAGE = $language; >+ $attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by}; > $attributes->{join} = 'localization'; >- $attributes->{'+select'} = [ { coalesce => [qw( localization.translation me.description )] } ]; >- $attributes->{'+as'} = ['translated_description']; >+ $attributes->{'+select'} = [ >+ { >+ coalesce => [qw( localization.translation me.description )], >+ -as => 'translated_description' >+ } >+ ]; > $self->SUPER::search( $params, $attributes ); > } > >diff --git a/Koha/Schema/Result/Itemtype.pm b/Koha/Schema/Result/Itemtype.pm >index 5af2466..959f8a3 100644 >--- a/Koha/Schema/Result/Itemtype.pm >+++ b/Koha/Schema/Result/Itemtype.pm >@@ -199,11 +199,20 @@ __PACKAGE__->has_many( > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1GiikODklVISOurHX37qjA > > # Use the ItemtypeLocalization view to create the join on localization >+our $LANGUAGE; > __PACKAGE__->has_many( >- "localization", >- "Koha::Schema::Result::ItemtypeLocalization", >- { "foreign.code" => "self.itemtype" }, >- { cascade_copy => 0, cascade_delete => 0 }, >+ "localization" => "Koha::Schema::Result::ItemtypeLocalization", >+ sub { >+ my $args = shift; >+ >+ die "no lang specified!" unless $LANGUAGE; >+ >+ return ({ >+ "$args->{self_alias}.itemtype" => { -ident => "$args->{foreign_alias}.code" }, >+ "$args->{foreign_alias}.lang" => $LANGUAGE, >+ }); >+ >+ } > ); > > 1; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt >index ec9fda9..9b6c77d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt >@@ -223,8 +223,8 @@ > <td><input type="radio" name="Column" value="items.itype" /></td> > <td><select name="filter_items.itype" id="itype"> > <option value=""> </option> >- [% FOREACH itypeloo IN itemtypeloop %] >- [% IF ( itypeloo.selected ) %]<option value="[% itypeloo.code %]" selected="selected">[% itypeloo.description %]</option>[% ELSE %]<option value="[% itypeloo.code %]">[% itypeloo.description %]</option>[% END %] >+ [% FOREACH itemtype IN itemtypes %] >+ <option value="[% itemtype.itemtype %]">[% itemtype.translated_description %]</option> > [% END %] > </select> > </td> >diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl >index d993cca..fb97762 100755 >--- a/suggestion/suggestion.pl >+++ b/suggestion/suggestion.pl >@@ -24,6 +24,7 @@ use CGI qw ( -utf8 ); > use C4::Auth; # get_template_and_user > use C4::Output; > use C4::Suggestions; >+use C4::Koha; > use C4::Budgets; > use C4::Search; > use C4::Members; >diff --git a/t/db_dependent/Koha/ItemTypes.t b/t/db_dependent/Koha/ItemTypes.t >index da05fd4..8f3dad2 100755 >--- a/t/db_dependent/Koha/ItemTypes.t >+++ b/t/db_dependent/Koha/ItemTypes.t >@@ -57,6 +57,18 @@ Koha::ItemType->new( > } > )->store; > >+Koha::ItemType->new( >+ { >+ itemtype => 'type3', >+ description => 'description', >+ rentalcharge => '0.00', >+ imageurl => 'imageurl', >+ summary => 'summary', >+ checkinmsg => 'checkinmsg', >+ checkinmsgtype => 'checkinmsgtype', >+ } >+)->store; >+ > Koha::Localization->new( > { > entity => 'itemtypes', >@@ -103,7 +115,7 @@ is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); > is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); > > my $itemtypes = Koha::ItemTypes->search_with_localization; >-is( $itemtypes->count, 2, 'There are 2 item types' ); >+is( $itemtypes->count, 3, 'There are 3 item types' ); > my $first_itemtype = $itemtypes->next; > is( > $first_itemtype->translated_description, >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17835
:
58561
|
58562
|
58563
|
58564
|
58565
|
58600
|
60033
|
60046
|
60048
|
60049
|
60050
|
60051
|
60052
|
60053
|
60914
|
60915
|
60916
|
60917
|
61695
|
61696
|
61697
|
61698
|
61699
|
61700
|
61966
|
61967
|
61968
|
61969
|
61970
|
61971
|
62156
|
62157
|
62158
|
62159
| 62160 |
62161
|
62162
|
62370
|
62470