Lines 27-32
use C4::Context;
Link Here
|
27 |
use C4::Branch qw(GetBranchesCount); |
27 |
use C4::Branch qw(GetBranchesCount); |
28 |
use Koha::Cache; |
28 |
use Koha::Cache; |
29 |
use Koha::DateUtils qw(dt_from_string); |
29 |
use Koha::DateUtils qw(dt_from_string); |
|
|
30 |
use C4::ItemType; |
30 |
use DateTime::Format::MySQL; |
31 |
use DateTime::Format::MySQL; |
31 |
use Business::ISBN; |
32 |
use Business::ISBN; |
32 |
use autouse 'Data::Dumper' => qw(Dumper); |
33 |
use autouse 'Data::Dumper' => qw(Dumper); |
Lines 129-212
sub subfield_is_koha_internal_p {
Link Here
|
129 |
|
130 |
|
130 |
=head2 GetSupportName |
131 |
=head2 GetSupportName |
131 |
|
132 |
|
132 |
$itemtypename = &GetSupportName($codestring); |
133 |
$lib = &GetSupportName($authorised_value); |
133 |
|
134 |
|
134 |
Returns a string with the name of the itemtype. |
135 |
Returns the name of the support corresponding to specified authorised value. |
135 |
|
136 |
|
136 |
=cut |
137 |
=cut |
137 |
|
138 |
|
138 |
sub GetSupportName{ |
139 |
sub GetSupportName { |
139 |
my ($codestring)=@_; |
140 |
my $authorised_value = shift; |
140 |
return if (! $codestring); |
141 |
return '' unless $authorised_value; |
141 |
my $resultstring; |
142 |
my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; |
142 |
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); |
143 |
if ( $supports_av eq 'itemtypes' ) { |
143 |
if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { |
144 |
my $itemtype = getitemtypeinfo($authorised_value); |
144 |
my $query = qq| |
145 |
return $itemtype->{'description'} if $itemtype; |
145 |
SELECT description |
146 |
} |
146 |
FROM itemtypes |
147 |
else { |
147 |
WHERE itemtype=? |
148 |
my $lib = GetKohaAuthorisedValueLib( $supports_av, $authorised_value ); |
148 |
order by description |
149 |
return $lib if $lib; |
149 |
|; |
150 |
} |
150 |
my $sth = C4::Context->dbh->prepare($query); |
151 |
return ''; |
151 |
$sth->execute($codestring); |
|
|
152 |
($resultstring)=$sth->fetchrow; |
153 |
return $resultstring; |
154 |
} else { |
155 |
my $sth = |
156 |
C4::Context->dbh->prepare( |
157 |
"SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?" |
158 |
); |
159 |
$sth->execute( $advanced_search_types, $codestring ); |
160 |
my $data = $sth->fetchrow_hashref; |
161 |
return $$data{'lib'}; |
162 |
} |
163 |
|
164 |
} |
152 |
} |
|
|
153 |
|
165 |
=head2 GetSupportList |
154 |
=head2 GetSupportList |
166 |
|
155 |
|
167 |
$itemtypes = &GetSupportList(); |
156 |
$supports = &GetSupportList(); |
168 |
|
157 |
|
169 |
Returns an array ref containing informations about Support (since itemtype is rather a circulation code when item-level-itypes is used). |
158 |
Returns an array ref containing informations about support : authorised_value, lib, imageurl |
170 |
|
159 |
|
171 |
build a HTML select with the following code : |
160 |
build a HTML select with the following code : |
172 |
|
161 |
|
173 |
=head3 in PERL SCRIPT |
162 |
=head3 in PERL SCRIPT |
174 |
|
163 |
|
175 |
my $itemtypes = GetSupportList(); |
164 |
my $supports = GetSupportList(); |
176 |
$template->param(itemtypeloop => $itemtypes); |
165 |
$template->param(supportsloop => $supports); |
177 |
|
166 |
|
178 |
=head3 in TEMPLATE |
167 |
=head3 in TEMPLATE |
179 |
|
168 |
|
180 |
<select name="itemtype" id="itemtype"> |
169 |
<select name="itemtype" id="itemtype"> |
181 |
<option value=""></option> |
|
|
182 |
[% FOREACH itemtypeloo IN itemtypeloop %] |
170 |
[% FOREACH itemtypeloo IN itemtypeloop %] |
183 |
[% IF ( itemtypeloo.selected ) %] |
171 |
[% IF ( itemtypeloo.selected ) %] |
184 |
<option value="[% itemtypeloo.itemtype %]" selected="selected">[% itemtypeloo.description %]</option> |
172 |
<option value="[% itemtypeloo.code %]" selected="selected">[% itemtypeloo.description %]</option> |
185 |
[% ELSE %] |
173 |
[% ELSE %] |
186 |
<option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.description %]</option> |
174 |
<option value="[% itemtypeloo.code %]">[% itemtypeloo.description %]</option> |
187 |
[% END %] |
175 |
[% END %] |
188 |
[% END %] |
176 |
[% END %] |
189 |
</select> |
177 |
</select> |
190 |
|
178 |
|
191 |
=cut |
179 |
=cut |
192 |
|
180 |
|
193 |
sub GetSupportList{ |
181 |
sub GetSupportList { |
194 |
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); |
182 |
my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; |
195 |
if (!$advanced_search_types or $advanced_search_types =~ /itemtypes/) { |
183 |
if ( $supports_av eq 'itemtypes' ) { |
196 |
my $query = qq| |
184 |
my @supports = map { |
197 |
SELECT * |
185 |
{ |
198 |
FROM itemtypes |
186 |
authorised_value => $_->{'itemtype'}, |
199 |
order by description |
187 |
lib => $_->{'description'}, |
200 |
|; |
188 |
imageurl => $_->{'imageurl'} |
201 |
my $sth = C4::Context->dbh->prepare($query); |
189 |
} |
202 |
$sth->execute; |
190 |
} C4::ItemType->all; |
203 |
return $sth->fetchall_arrayref({}); |
191 |
return \@supports; |
204 |
} else { |
192 |
} |
205 |
my $advsearchtypes = GetAuthorisedValues($advanced_search_types); |
193 |
else { |
206 |
my @results= map {{itemtype=>$$_{authorised_value},description=>$$_{lib},imageurl=>$$_{imageurl}}} @$advsearchtypes; |
194 |
return GetAuthorisedValues($supports_av); |
207 |
return \@results; |
195 |
} |
208 |
} |
|
|
209 |
} |
196 |
} |
|
|
197 |
|
210 |
=head2 GetItemTypes |
198 |
=head2 GetItemTypes |
211 |
|
199 |
|
212 |
$itemtypes = &GetItemTypes( style => $style ); |
200 |
$itemtypes = &GetItemTypes( style => $style ); |