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

(-)a/C4/Koha.pm (-2 / +57 lines)
Lines 29-37 use Koha::Cache; Link Here
29
use Koha::DateUtils qw(dt_from_string);
29
use Koha::DateUtils qw(dt_from_string);
30
use DateTime::Format::MySQL;
30
use DateTime::Format::MySQL;
31
use Business::ISBN;
31
use Business::ISBN;
32
use autouse 'Data::Dumper' => qw(Dumper);
32
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
33
use DBI qw(:sql_types);
33
use DBI qw(:sql_types);
34
34
 use Data::Dumper;
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
36
36
37
BEGIN {
37
BEGIN {
Lines 43-48 BEGIN { Link Here
43
		&subfield_is_koha_internal_p
43
		&subfield_is_koha_internal_p
44
		&GetPrinters &GetPrinter
44
		&GetPrinters &GetPrinter
45
		&GetItemTypes &getitemtypeinfo
45
		&GetItemTypes &getitemtypeinfo
46
                &GetItemTypesCategorized &GetItemTypesByCategory
46
		&GetSupportName &GetSupportList
47
		&GetSupportName &GetSupportList
47
		&get_itemtypeinfos_of
48
		&get_itemtypeinfos_of
48
		&getframeworks &getframeworkinfo
49
		&getframeworks &getframeworkinfo
Lines 273-278 sub GetItemTypes { Link Here
273
    }
274
    }
274
}
275
}
275
276
277
=head2 GetItemTypesCategorized
278
279
    $categories = GetItemTypesCategorized();
280
281
Returns a hashref containing search categories.
282
A search category will be put in the hash if at least one of its itemtypes is visible in OPAC.
283
The categories must be part of Authorized Values (DOCTYPECAT)
284
285
=cut
286
287
sub GetItemTypesCategorized {
288
    my $dbh   = C4::Context->dbh;
289
    # Order is important, so that partially hidden (some items are not visible in OPAC) search
290
    # categories will be visible. hideinopac=0 must be last.
291
    my $query = q|
292
        SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) or length(searchcategory) = 0
293
        UNION
294
        SELECT DISTINCT searchcategory AS `itemtype`,
295
                        authorised_values.lib_opac AS description,
296
                        authorised_values.imageurl AS imageurl,
297
                        hideinopac, 1 as 'iscat'
298
        FROM itemtypes
299
        LEFT JOIN authorised_values ON searchcategory = authorised_value
300
        WHERE searchcategory > '' and hideinopac=1
301
        UNION
302
        SELECT DISTINCT searchcategory AS `itemtype`,
303
                        authorised_values.lib_opac AS description,
304
                        authorised_values.imageurl AS imageurl,
305
                        hideinopac, 1 as 'iscat'
306
        FROM itemtypes
307
        LEFT JOIN authorised_values ON searchcategory = authorised_value
308
        WHERE searchcategory > '' and hideinopac=0
309
        |;
310
return ($dbh->selectall_hashref($query,'itemtype'));
311
}
312
313
=head2 GetItemTypesByCategory
314
315
    @results = GetItemTypesByCategory( $searchcategory );
316
317
Returns the itemtype code of all itemtypes included in a searchcategory.
318
319
=cut
320
321
sub GetItemTypesByCategory {
322
    my ($category) = @_;
323
    my $count = 0;
324
    my @results;
325
    my $dbh = C4::Context->dbh;
326
    my $query = qq|SELECT itemtype FROM itemtypes WHERE searchcategory=?|;
327
    my $tmp=$dbh->selectcol_arrayref($query,undef,$category);
328
    return @$tmp;
329
}
330
276
sub get_itemtypeinfos_of {
331
sub get_itemtypeinfos_of {
277
    my @itemtypes = @_;
332
    my @itemtypes = @_;
278
333
(-)a/admin/authorised_values.pl (-1 / +1 lines)
Lines 246-252 sub default_form { Link Here
246
    }
246
    }
247
247
248
    # push koha system categories
248
    # push koha system categories
249
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS)) {
249
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS DOCTYPECAT)) {
250
        push @category_list, $_ unless $categories{$_};
250
        push @category_list, $_ unless $categories{$_};
251
    }
251
    }
252
252
(-)a/admin/itemtypes.pl (-2 / +12 lines)
Lines 112-117 if ( $op eq 'add_form' ) { Link Here
112
        $remote_image = $data->{imageurl};
112
        $remote_image = $data->{imageurl};
113
    }
113
    }
114
114
115
    my $searchcategory = GetAuthorisedValues("DOCTYPECAT", $data->{'searchcategory'});
116
115
    $template->param(
117
    $template->param(
116
        itemtype        => $itemtype,
118
        itemtype        => $itemtype,
117
        description     => $data->{'description'},
119
        description     => $data->{'description'},
Lines 125-130 if ( $op eq 'add_form' ) { Link Here
125
        imagesets       => $imagesets,
127
        imagesets       => $imagesets,
126
        remote_image    => $remote_image,
128
        remote_image    => $remote_image,
127
        sip_media_type  => $data->{sip_media_type},
129
        sip_media_type  => $data->{sip_media_type},
130
        hideinopac      => $data->{'hideinopac'},
131
        searchcategory  => $searchcategory,
128
    );
132
    );
129
133
130
    # END $OP eq ADD_FORM
134
    # END $OP eq ADD_FORM
Lines 150-155 elsif ( $op eq 'add_validate' ) { Link Here
150
                 , checkinmsg = ?
154
                 , checkinmsg = ?
151
                 , checkinmsgtype = ?
155
                 , checkinmsgtype = ?
152
                 , sip_media_type = ?
156
                 , sip_media_type = ?
157
                 , hideinopac = ?
158
                 , searchcategory = ?
153
            WHERE itemtype = ?
159
            WHERE itemtype = ?
154
        ';
160
        ';
155
        $sth = $dbh->prepare($query2);
161
        $sth = $dbh->prepare($query2);
Lines 168-182 elsif ( $op eq 'add_validate' ) { Link Here
168
            $input->param('checkinmsg'),
174
            $input->param('checkinmsg'),
169
            $input->param('checkinmsgtype'),
175
            $input->param('checkinmsgtype'),
170
            $sip_media_type,
176
            $sip_media_type,
177
            $input->param('hideinopac') ? 1 : 0,
178
            $input->param('searchcategory'),
171
            $input->param('itemtype')
179
            $input->param('itemtype')
172
        );
180
        );
173
    }
181
    }
174
    else {    # add a new itemtype & not modif an old
182
    else {    # add a new itemtype & not modif an old
175
        my $query = "
183
        my $query = "
176
            INSERT INTO itemtypes
184
            INSERT INTO itemtypes
177
                (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type)
185
                (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type, hideinopac, searchcategory)
178
            VALUES
186
            VALUES
179
                (?,?,?,?,?,?,?,?,?);
187
                (?,?,?,?,?,?,?,?,?,?,?);
180
            ";
188
            ";
181
        my $sth = $dbh->prepare($query);
189
        my $sth = $dbh->prepare($query);
182
		my $image = $input->param('image');
190
		my $image = $input->param('image');
Lines 192-197 elsif ( $op eq 'add_validate' ) { Link Here
192
            $input->param('checkinmsg'),
200
            $input->param('checkinmsg'),
193
            $input->param('checkinmsgtype'),
201
            $input->param('checkinmsgtype'),
194
            $sip_media_type,
202
            $sip_media_type,
203
            $input->param('hideinopac') ? 1 : 0,
204
            $input->param('searchcategory'),
195
        );
205
        );
196
    }
206
    }
197
207
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 1276-1281 CREATE TABLE `itemtypes` ( -- defines the item types Link Here
1276
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1276
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1277
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1277
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1278
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1278
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1279
  hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC
1280
  searchcategory varchar(20) default NULL, -- Group this item type with others with the same value on OPAC search options
1279
  PRIMARY KEY  (`itemtype`),
1281
  PRIMARY KEY  (`itemtype`),
1280
  UNIQUE KEY `itemtype` (`itemtype`)
1282
  UNIQUE KEY `itemtype` (`itemtype`)
1281
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1283
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/updatedatabase.pl (+15 lines)
Lines 9608-9613 if ( CheckVersion($DBversion) ) { Link Here
9608
    SetVersion ($DBversion);
9608
    SetVersion ($DBversion);
9609
}
9609
}
9610
9610
9611
9611
$DBversion = "3.19.00.003";
9612
$DBversion = "3.19.00.003";
9612
if ( CheckVersion($DBversion) ) {
9613
if ( CheckVersion($DBversion) ) {
9613
    my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers GROUP BY userid HAVING COUNT(userid) > 1");
9614
    my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers GROUP BY userid HAVING COUNT(userid) > 1");
Lines 9669-9674 if ( CheckVersion($DBversion) ) { Link Here
9669
    SetVersion ($DBversion);
9670
    SetVersion ($DBversion);
9670
}
9671
}
9671
9672
9673
$DBversion = "3.19.00.XXX";
9674
if ( CheckVersion($DBversion) ) {
9675
    $dbh->do(q{
9676
        ALTER TABLE itemtypes
9677
            ADD hideinopac TINYINT(1) NOT NULL DEFAULT 0
9678
              AFTER sip_media_type,
9679
            ADD searchcategory VARCHAR(20) DEFAULT NULL
9680
              AFTER hideinopac;
9681
    });
9682
    print "Upgrade to $DBversion done (Bug 10937 - Option to hide and group itemtypes from advanced search)\n";
9683
    SetVersion($DBversion);
9684
}
9685
9686
9672
=head1 FUNCTIONS
9687
=head1 FUNCTIONS
9673
9688
9674
=head2 TableExists($table)
9689
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (+32 lines)
Lines 109-114 Item types administration Link Here
109
  [% END %]
109
  [% END %]
110
      <li>
110
      <li>
111
          <label for="description" class="required">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" required="required" /> <span class="required">Required</span></li>
111
          <label for="description" class="required">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" required="required" /> <span class="required">Required</span></li>
112
      <li>
113
          <span class="label">Search category</span>
114
          <select id="searchcategory" name="searchcategory">
115
          <option value="">None</option>
116
                [% FOREACH cat IN searchcategory %]
117
                    [% IF ( cat.selected ) %]
118
                        <option value="[% cat.authorised_value %]" selected="selected">
119
                            [% cat.lib %]
120
                        </option>
121
                    [% ELSE %]
122
                        <option value="[% cat.authorised_value %]" >
123
                            [% cat.lib %]
124
                        </option>
125
                    [% END %]
126
                [% END %]
127
          </select>
128
          (Options are defined as the authorized values for the DOCTYPECAT category)
129
      </li>
130
112
     [% IF ( noItemTypeImages ) %]
131
     [% IF ( noItemTypeImages ) %]
113
	 <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
132
	 <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
114
	 [% ELSE %]</ol>
133
	 [% ELSE %]</ol>
Lines 164-169 Item types administration Link Here
164
[% END %]
183
[% END %]
165
<ol>
184
<ol>
166
      <li>
185
      <li>
186
          <label for="hideinopac">Hide in OPAC: </label>
187
          [% IF ( hideinopac ) %]
188
              <input type="checkbox" id="hideinopac" name="hideinopac" checked="checked" value="1" />
189
          [% ELSE %]
190
              <input type="checkbox" id="hideinopac" name="hideinopac" value="1" />
191
          [% END %]
192
          (if checked, items of this type will be hidden as filters in OPAC's advanced search)
193
      </li>
194
      <li>
167
          <label for="notforloan">Not for loan: </label>   [% IF ( notforloan ) %]
195
          <label for="notforloan">Not for loan: </label>   [% IF ( notforloan ) %]
168
                <input type="checkbox" id="notforloan" name="notforloan" checked="checked" value="1" />
196
                <input type="checkbox" id="notforloan" name="notforloan" checked="checked" value="1" />
169
            [% ELSE %]
197
            [% ELSE %]
Lines 260-266 Item types administration Link Here
260
    [% UNLESS ( noItemTypeImages ) %]<th>Image</th>[% END %]
288
    [% UNLESS ( noItemTypeImages ) %]<th>Image</th>[% END %]
261
    <th>Code</th>
289
    <th>Code</th>
262
    <th>Description</th>
290
    <th>Description</th>
291
    <th>Search category</th>
263
    <th>Not for loan</th>
292
    <th>Not for loan</th>
293
    <th>Hide in OPAC</th>
264
    <th>Charge</th>
294
    <th>Charge</th>
265
    <th>Checkin message</th>
295
    <th>Checkin message</th>
266
    <th>Actions</th>
296
    <th>Actions</th>
Lines 274-280 Item types administration Link Here
274
      </a>
304
      </a>
275
    </td>
305
    </td>
276
    <td>[% loo.description %]</td>
306
    <td>[% loo.description %]</td>
307
    <td>[% loo.searchcategory %]</td>
277
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
308
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
309
    <td>[% IF ( loo.hideinopac ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
278
    <td>
310
    <td>
279
    [% UNLESS ( loo.notforloan ) %]
311
    [% UNLESS ( loo.notforloan ) %]
280
      [% loo.rentalcharge %]
312
      [% loo.rentalcharge %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt (-2 / +18 lines)
Lines 133-141 Link Here
133
                                    <legend>Limit to any of the following:</legend>
133
                                    <legend>Limit to any of the following:</legend>
134
                                    <div class="row-fluid">
134
                                    <div class="row-fluid">
135
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
135
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
136
                                            <div class="span3"><input type="checkbox" id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]" name="limit" value="mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %]"/><label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">[% UNLESS ( noItemTypeImages ) %][% IF ( itemtypeloo.imageurl ) %]<img src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />[% END %]&nbsp;[% END %]
136
                                            [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %]
137
                                            [% itemtypeloo.description %]</label></div>
137
                                                <div class="span3">
138
                                                    <input type="checkbox"
139
                                                        id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]"
140
                                                        name="[% IF ( itemtypeloo.cat == 1 ) %]searchcat[% ELSE %]limit[% END %]"
141
                                                        value="[% IF ( itemtypeloo.cat == 1 ) %][% itemtypeloo.code %][% ELSE %]mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %][% END %]"
142
                                                    />
143
                                                    <label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">
144
                                                        [% UNLESS ( noItemTypeImages ) %]
145
                                                            [% IF ( itemtypeloo.imageurl ) %]
146
                                                                <img border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />
147
                                                            [% END %]
148
                                                            &nbsp;
149
                                                        [% END %]
150
                                                        [% itemtypeloo.description %]
151
                                                    </label>
152
                                                </div>
138
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
153
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
154
                                            [% END %]
139
                                        [% END %]
155
                                        [% END %]
140
                                </fieldset>
156
                                </fieldset>
141
                            </div> <!-- / #advsearch-[% advsearchloo.advanced_search_type %] -->
157
                            </div> <!-- / #advsearch-[% advsearchloo.advanced_search_type %] -->
(-)a/opac/opac-search.pl (-3 / +22 lines)
Lines 84-90 my ($template,$borrowernumber,$cookie); Link Here
84
my $template_name;
84
my $template_name;
85
my $template_type = 'basic';
85
my $template_type = 'basic';
86
my @params = $cgi->param("limit");
86
my @params = $cgi->param("limit");
87
87
my @searchCategories = $cgi->param('searchcat');
88
88
89
my $format = $cgi->param("format") || '';
89
my $format = $cgi->param("format") || '';
90
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
90
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
Lines 194-200 my $languages_limit_loop = getLanguages($lang, 1); Link Here
194
$template->param(search_languages_loop => $languages_limit_loop,);
194
$template->param(search_languages_loop => $languages_limit_loop,);
195
195
196
# load the Type stuff
196
# load the Type stuff
197
my $itemtypes = GetItemTypes;
197
my $itemtypes = GetItemTypesCategorized;
198
# the index parameter is different for item-level itemtypes
198
# the index parameter is different for item-level itemtypes
199
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
199
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
200
my @advancedsearchesloop;
200
my @advancedsearchesloop;
Lines 228-235 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
228
                code => $thisitemtype,
228
                code => $thisitemtype,
229
                description => $itemtypes->{$thisitemtype}->{'description'},
229
                description => $itemtypes->{$thisitemtype}->{'description'},
230
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
230
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
231
                cat => $itemtypes->{$thisitemtype}->{'iscat'},
232
                hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'},
233
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
231
            );
234
            );
232
	    push @itypesloop, \%row;
235
            if ( !$itemtypes->{$thisitemtype}->{'hideinopac'} ) {
236
                push @itypesloop, \%row;
237
            }
233
	}
238
	}
234
        my %search_code = (  advanced_search_type => $advanced_srch_type,
239
        my %search_code = (  advanced_search_type => $advanced_srch_type,
235
                             code_loop => \@itypesloop );
240
                             code_loop => \@itypesloop );
Lines 247-252 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
247
				ccl => $advanced_srch_type,
252
				ccl => $advanced_srch_type,
248
                code => $thisitemtype->{authorised_value},
253
                code => $thisitemtype->{authorised_value},
249
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
254
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
255
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
250
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
256
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
251
                );
257
                );
252
		push @authvalueloop, \%row;
258
		push @authvalueloop, \%row;
Lines 426-431 my @nolimits = $cgi->param('nolimit'); Link Here
426
my %is_nolimit = map { $_ => 1 } @nolimits;
432
my %is_nolimit = map { $_ => 1 } @nolimits;
427
@limits = grep { not $is_nolimit{$_} } @limits;
433
@limits = grep { not $is_nolimit{$_} } @limits;
428
434
435
if (@searchCategories > 0) {
436
    my @tabcat;
437
    foreach my $typecategory (@searchCategories) {
438
        push (@tabcat, GetItemTypesByCategory($typecategory));
439
    }
440
441
    foreach my $itemtypeInCategory (@tabcat) {
442
        push (@limits, "mc-$itype_or_itemtype,phr:".$itemtypeInCategory);
443
    }
444
}
445
446
@limits = map { uri_unescape($_) } @limits;
447
429
if($params->{'multibranchlimit'}) {
448
if($params->{'multibranchlimit'}) {
430
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
449
    my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
431
    push @limits, $multibranch if ($multibranch ne  '()');
450
    push @limits, $multibranch if ($multibranch ne  '()');
(-)a/t/db_dependent/Koha.t (-3 / +44 lines)
Lines 7-18 use strict; Link Here
7
use warnings;
7
use warnings;
8
use C4::Context;
8
use C4::Context;
9
use Koha::DateUtils qw(dt_from_string);
9
use Koha::DateUtils qw(dt_from_string);
10
use Data::Dumper;
10
11
11
use Test::More tests => 8;
12
use Test::More tests => 9;
12
use DateTime::Format::MySQL;
13
use DateTime::Format::MySQL;
13
14
14
BEGIN {
15
BEGIN {
15
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote ));
16
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesByCategory GetItemTypesCategorized));
16
    use_ok('C4::Members');
17
    use_ok('C4::Members');
17
}
18
}
18
19
Lines 312-315 subtest 'GetFrameworksLoop() tests' => sub { Link Here
312
    );
313
    );
313
};
314
};
314
315
316
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
317
    plan tests => 7;
318
319
    my $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Qwertyware');
320
    ok($insertGroup, "Create group Qwertyware");
321
322
    my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
323
    my $insertSth = C4::Context->dbh->prepare($query);
324
    $insertSth->execute('BKghjklo1', 'One type of book', '', 0);
325
    $insertSth->execute('BKghjklo2', 'Another type of book', 'Qwertyware', 0);
326
    $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0);
327
328
    # Azertyware should not exist.
329
    my @results = GetItemTypesByCategory('Azertyware');
330
    is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing');
331
332
    @results = GetItemTypesByCategory('Qwertyware');
333
    my @expected = ( 'BKghjklo2', 'BKghjklo3' );
334
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
335
336
    # add more data since GetItemTypesCategorized's search is more subtle
337
    $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Veryheavybook');
338
    $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryheavybook', 1);
339
340
    my $hrCat = GetItemTypesCategorized();
341
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: fully visible category exists');
342
    ok($hrCat->{Veryheavybook} &&
343
       $hrCat->{Veryheavybook}->{hideinopac}==1, 'GetItemTypesCategorized: non-visible category hidden' );
344
345
    $insertSth->execute('BKghjklo5', 'An hidden book', 'Qwertyware', 1);
346
    $hrCat = GetItemTypesCategorized();
347
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists');
348
349
    my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryheavybook' );
350
    @results = ();
351
    foreach my $key (@only) {
352
        push @results, $key if exists $hrCat->{$key};
353
    }
354
    @expected = ( 'BKghjklo1', 'Qwertyware', 'Veryheavybook' );
355
    is_deeply(\@results,\@expected, 'GetItemTypesCategorized: grouped and ungrouped items returned as expected.');
356
};
315
$dbh->rollback();
357
$dbh->rollback();
316
- 

Return to bug 10937