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

(-)a/C4/Koha.pm (-74 lines)
Lines 41-47 BEGIN { Link Here
41
		&GetPrinters &GetPrinter
41
		&GetPrinters &GetPrinter
42
		&GetItemTypes &getitemtypeinfo
42
		&GetItemTypes &getitemtypeinfo
43
                &GetItemTypesCategorized &GetItemTypesByCategory
43
                &GetItemTypesCategorized &GetItemTypesByCategory
44
		&GetSupportName &GetSupportList
45
		&getframeworks &getframeworkinfo
44
		&getframeworks &getframeworkinfo
46
        &GetFrameworksLoop
45
        &GetFrameworksLoop
47
		&getallthemes
46
		&getallthemes
Lines 92-170 Koha.pm provides many functions for Koha scripts. Link Here
92
91
93
=cut
92
=cut
94
93
95
=head2 GetSupportName
96
97
  $itemtypename = &GetSupportName($codestring);
98
99
Returns a string with the name of the itemtype.
100
101
=cut
102
103
sub GetSupportName{
104
	my ($codestring)=@_;
105
	return if (! $codestring); 
106
	my $resultstring;
107
	my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
108
	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {  
109
		my $query = qq|
110
			SELECT description
111
			FROM   itemtypes
112
			WHERE itemtype=?
113
			order by description
114
		|;
115
		my $sth = C4::Context->dbh->prepare($query);
116
		$sth->execute($codestring);
117
		($resultstring)=$sth->fetchrow;
118
		return $resultstring;
119
	} else {
120
        my $sth =
121
            C4::Context->dbh->prepare(
122
                    "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?"
123
                    );
124
        $sth->execute( $advanced_search_types, $codestring );
125
        my $data = $sth->fetchrow_hashref;
126
        return $$data{'lib'};
127
	}
128
129
}
130
=head2 GetSupportList
131
132
  $itemtypes = &GetSupportList();
133
134
Returns an array ref containing informations about Support (since itemtype is rather a circulation code when item-level-itypes is used).
135
136
build a HTML select with the following code :
137
138
=head3 in PERL SCRIPT
139
140
    my $itemtypes = GetSupportList();
141
    $template->param(itemtypeloop => $itemtypes);
142
143
=head3 in TEMPLATE
144
145
    <select name="itemtype" id="itemtype">
146
        <option value=""></option>
147
        [% FOREACH itemtypeloo IN itemtypeloop %]
148
             [% IF ( itemtypeloo.selected ) %]
149
                <option value="[% itemtypeloo.itemtype %]" selected="selected">[% itemtypeloo.description %]</option>
150
            [% ELSE %]
151
                <option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.description %]</option>
152
            [% END %]
153
       [% END %]
154
    </select>
155
156
=cut
157
158
sub GetSupportList{
159
	my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
160
    if (!$advanced_search_types or $advanced_search_types =~ /itemtypes/) {
161
        return GetItemTypes( style => 'array' );
162
	} else {
163
		my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
164
		my @results= map {{itemtype=>$$_{authorised_value},description=>$$_{lib},imageurl=>$$_{imageurl}}} @$advsearchtypes;
165
		return \@results;
166
	}
167
}
168
=head2 GetItemTypes
94
=head2 GetItemTypes
169
95
170
  $itemtypes = &GetItemTypes( style => $style );
96
  $itemtypes = &GetItemTypes( style => $style );
(-)a/t/db_dependent/Suggestions.t (-14 / +1 lines)
Lines 28-39 use Koha::Library; Link Here
28
use Koha::Libraries;
28
use Koha::Libraries;
29
29
30
use DateTime::Duration;
30
use DateTime::Duration;
31
use Test::More tests => 106;
31
use Test::More tests => 102;
32
use Test::Warn;
32
use Test::Warn;
33
33
34
BEGIN {
34
BEGIN {
35
    use_ok('C4::Suggestions');
35
    use_ok('C4::Suggestions');
36
    use_ok('C4::Koha');
37
}
36
}
38
37
39
my $dbh = C4::Context->dbh;
38
my $dbh = C4::Context->dbh;
Lines 349-365 $suggestions = GetSuggestionByStatus('CHECKED'); Link Here
349
is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' );
348
is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' );
350
is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
349
is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
351
350
352
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
353
t::lib::Mocks::mock_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode');
354
my $itemtypes1 = C4::Koha::GetSupportList();
355
is(@$itemtypes1, 8, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes");
356
357
t::lib::Mocks::mock_preference("AdvancedSearchTypes", 'itemtypes');
358
my $itemtypes2 = C4::Koha::GetSupportList();
359
is(@$itemtypes2, 8, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes");
360
361
is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
362
363
# Test budgetid fk
351
# Test budgetid fk
364
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
352
$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
365
my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion);
353
my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion);
366
- 

Return to bug 17099