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

(-)a/C4/Koha.pm (+66 lines)
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 275-280 sub GetItemTypes { Link Here
275
    }
276
    }
276
}
277
}
277
278
279
=head2 GetItemTypesCategorized
280
281
    $categories = GetItemTypesCategorized();
282
283
Returns a hashref containing search categories.
284
A search category will be put in the hash if at least one of its itemtypes is visible in OPAC.
285
The categories must be part of Authorized Values (DOCTYPECAT)
286
287
=cut
288
289
sub GetItemTypesCategorized {
290
    my $dbh   = C4::Context->dbh;
291
    # Order is important, so that partially hidden (some items are not visible in OPAC) search
292
    # categories will be visible. hideinopac=0 must be last.
293
    my $query = qq|
294
        SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) or length(searchcategory) = 0
295
        UNION
296
        SELECT DISTINCT searchcategory AS `itemtype`,
297
                        authorised_values.lib_opac AS description,
298
                        authorised_values.imageurl AS imageurl,
299
                        hideinopac, 1 as 'iscat'
300
        FROM itemtypes
301
        LEFT JOIN authorised_values ON searchcategory = authorised_value
302
        WHERE searchcategory > '' and hideinopac=1
303
        UNION
304
        SELECT DISTINCT searchcategory AS `itemtype`,
305
                        authorised_values.lib_opac AS description,
306
                        authorised_values.imageurl AS imageurl,
307
                        hideinopac, 1 as 'iscat'
308
        FROM itemtypes
309
        LEFT JOIN authorised_values ON searchcategory = authorised_value
310
        WHERE searchcategory > '' and hideinopac=0
311
        |;
312
    my $sth = $dbh->prepare($query);
313
    $sth->execute;
314
315
    my %itemtypes;
316
    while ( my $IT = $sth->fetchrow_hashref ) {
317
        $itemtypes{ $IT->{'itemtype'} } = $IT;
318
    }
319
    return ( \%itemtypes );
320
}
321
322
=head2 GetItemTypesByCategory
323
324
    @results = GetItemTypesByCategory( $searchcategory );
325
326
Returns the itemtype code of all itemtypes included in a searchcategory.
327
328
=cut
329
330
sub GetItemTypesByCategory {
331
    my ($category) = @_;
332
    my $count = 0;
333
    my @results;
334
    my $dbh = C4::Context->dbh;
335
    my $sth = $dbh->prepare("SELECT itemtype FROM itemtypes WHERE searchcategory=?");
336
    $sth->execute($category);
337
338
    while ( my $data = $sth->fetchrow ) {
339
        push ( @results, $data );
340
    }
341
    return @results;
342
}
343
278
sub get_itemtypeinfos_of {
344
sub get_itemtypeinfos_of {
279
    my @itemtypes = @_;
345
    my @itemtypes = @_;
280
346
(-)a/admin/authorised_values.pl (-1 / +1 lines)
Lines 247-253 sub default_form { Link Here
247
    }
247
    }
248
248
249
    # push koha system categories
249
    # push koha system categories
250
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS)) {
250
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS DOCTYPECAT)) {
251
        push @category_list, $_ unless $categories{$_};
251
        push @category_list, $_ unless $categories{$_};
252
    }
252
    }
253
253
(-)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 1247-1252 CREATE TABLE `itemtypes` ( -- defines the item types Link Here
1247
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1247
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1248
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1248
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1249
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1249
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1250
  hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC
1251
  searchcategory varchar(20) default NULL, -- Group this item type with others with the same value on OPAC search options
1250
  PRIMARY KEY  (`itemtype`),
1252
  PRIMARY KEY  (`itemtype`),
1251
  UNIQUE KEY `itemtype` (`itemtype`)
1253
  UNIQUE KEY `itemtype` (`itemtype`)
1252
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1254
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(-)a/installer/data/mysql/updatedatabase.pl (+13 lines)
Lines 8589-8594 if ( CheckVersion($DBversion) ) { Link Here
8589
    SetVersion ($DBversion);
8589
    SetVersion ($DBversion);
8590
}
8590
}
8591
8591
8592
$DBversion = "3.17.00.XXX";
8593
if ( CheckVersion($DBversion) ) {
8594
    $dbh->do(q{
8595
        ALTER TABLE itemtypes
8596
            ADD hideinopac TINYINT(1) NOT NULL DEFAULT 0
8597
              AFTER sip_media_type,
8598
            ADD searchcategory VARCHAR(20) DEFAULT NULL
8599
              AFTER hideinopac;
8600
    });
8601
    print "Upgrade to $DBversion done (Bug 10937 - Option to hide and group itemtypes from advanced search)\n";
8602
    SetVersion($DBversion);
8603
}
8604
8592
=head1 FUNCTIONS
8605
=head1 FUNCTIONS
8593
8606
8594
=head2 TableExists($table)
8607
=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 278-284 Item types administration Link Here
278
      </a>
308
      </a>
279
    </td>
309
    </td>
280
    <td>[% loo.description %]</td>
310
    <td>[% loo.description %]</td>
311
    <td>[% loo.searchcategory %]</td>
281
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
312
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
313
    <td>[% IF ( loo.hideinopac ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
282
    <td>
314
    <td>
283
    [% UNLESS ( loo.notforloan ) %]
315
    [% UNLESS ( loo.notforloan ) %]
284
      [% loo.rentalcharge %]
316
      [% loo.rentalcharge %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt (-2 / +18 lines)
Lines 141-149 Link Here
141
                                    <legend>Limit to any of the following:</legend>
141
                                    <legend>Limit to any of the following:</legend>
142
                                    <div class="row-fluid">
142
                                    <div class="row-fluid">
143
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
143
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
144
                                            <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 %]
144
                                            [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %]
145
                                            [% itemtypeloo.description %]</label></div>
145
                                                <div class="span3">
146
                                                    <input type="checkbox"
147
                                                        id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]"
148
                                                        name="[% IF ( itemtypeloo.cat == 1 ) %]searchcat[% ELSE %]limit[% END %]"
149
                                                        value="[% IF ( itemtypeloo.cat == 1 ) %][% itemtypeloo.code %][% ELSE %]mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %][% END %]"
150
                                                    />
151
                                                    <label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">
152
                                                        [% UNLESS ( noItemTypeImages ) %]
153
                                                            [% IF ( itemtypeloo.imageurl ) %]
154
                                                                <img border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />
155
                                                            [% END %]
156
                                                            &nbsp;
157
                                                        [% END %]
158
                                                        [% itemtypeloo.description %]
159
                                                    </label>
160
                                                </div>
146
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
161
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
162
                                            [% END %]
147
                                        [% END %]
163
                                        [% END %]
148
                                </fieldset>
164
                                </fieldset>
149
                            </div> <!-- / #advsearch-[% advsearchloo.advanced_search_type %] -->
165
                            </div> <!-- / #advsearch-[% advsearchloo.advanced_search_type %] -->
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt (-2 / +18 lines)
Lines 187-194 Link Here
187
    <table>
187
    <table>
188
        <tr>
188
        <tr>
189
    [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
189
    [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
190
        <td><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 border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />[% END %]&nbsp;[% END %]
190
            [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %]
191
        [% itemtypeloo.description %]</label></td>
191
                <td>
192
                    <input type="checkbox"
193
                        id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]"
194
                        name="[% IF ( itemtypeloo.cat == 1 ) %]searchcat[% ELSE %]limit[% END %]"
195
                        value="[% IF ( itemtypeloo.cat == 1 ) %][% itemtypeloo.code %][% ELSE %]mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %][% END %]"
196
                    />
197
                    <label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">
198
                        [% UNLESS ( noItemTypeImages ) %]
199
                            [% IF ( itemtypeloo.imageurl ) %]
200
                                <img border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]"/>
201
                            [% END %]
202
                            &nbsp;
203
                        [% END %]
204
                        [% itemtypeloo.description %]
205
                    </label>
206
                </td>
207
            [% END %]
192
        [% IF ( loop.last ) %]</tr>[% ELSE %][% UNLESS ( loop.count % 5 ) %]</tr><tr>[% END %][% END %]
208
        [% IF ( loop.last ) %]</tr>[% ELSE %][% UNLESS ( loop.count % 5 ) %]</tr><tr>[% END %][% END %]
193
    [% END %]
209
    [% END %]
194
    </table>
210
    </table>
(-)a/opac/opac-search.pl (-3 / +21 lines)
Lines 92-98 my ($template,$borrowernumber,$cookie); Link Here
92
my $template_name;
92
my $template_name;
93
my $template_type = 'basic';
93
my $template_type = 'basic';
94
my @params = $cgi->param("limit");
94
my @params = $cgi->param("limit");
95
95
my @searchCategories = $cgi->param('searchcat');
96
96
97
my $format = $cgi->param("format") || '';
97
my $format = $cgi->param("format") || '';
98
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
98
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
Lines 202-208 my $languages_limit_loop = getLanguages($lang, 1); Link Here
202
$template->param(search_languages_loop => $languages_limit_loop,);
202
$template->param(search_languages_loop => $languages_limit_loop,);
203
203
204
# load the Type stuff
204
# load the Type stuff
205
my $itemtypes = GetItemTypes;
205
my $itemtypes = GetItemTypesCategorized;
206
# the index parameter is different for item-level itemtypes
206
# the index parameter is different for item-level itemtypes
207
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
207
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
208
my @advancedsearchesloop;
208
my @advancedsearchesloop;
Lines 220-227 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
220
                code => $thisitemtype,
220
                code => $thisitemtype,
221
                description => $itemtypes->{$thisitemtype}->{'description'},
221
                description => $itemtypes->{$thisitemtype}->{'description'},
222
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
222
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
223
                cat => $itemtypes->{$thisitemtype}->{'iscat'},
224
                hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'},
225
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
223
            );
226
            );
224
	    push @itypesloop, \%row;
227
            if ( !$itemtypes->{$thisitemtype}->{'hideinopac'} ) {
228
                push @itypesloop, \%row;
229
            }
225
	}
230
	}
226
        my %search_code = (  advanced_search_type => $advanced_srch_type,
231
        my %search_code = (  advanced_search_type => $advanced_srch_type,
227
                             code_loop => \@itypesloop );
232
                             code_loop => \@itypesloop );
Lines 236-241 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
236
				ccl => $advanced_srch_type,
241
				ccl => $advanced_srch_type,
237
                code => $thisitemtype->{authorised_value},
242
                code => $thisitemtype->{authorised_value},
238
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
243
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
244
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
239
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
245
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
240
                );
246
                );
241
		push @authvalueloop, \%row;
247
		push @authvalueloop, \%row;
Lines 403-408 my @limits = $cgi->param('limit'); Link Here
403
my @nolimits = $cgi->param('nolimit');
409
my @nolimits = $cgi->param('nolimit');
404
my %is_nolimit = map { $_ => 1 } @nolimits;
410
my %is_nolimit = map { $_ => 1 } @nolimits;
405
@limits = grep { not $is_nolimit{$_} } @limits;
411
@limits = grep { not $is_nolimit{$_} } @limits;
412
413
if (@searchCategories > 0) {
414
    my @tabcat;
415
    foreach my $typecategory (@searchCategories) {
416
        push (@tabcat, GetItemTypesByCategory($typecategory));
417
    }
418
419
    foreach my $itemtypeInCategory (@tabcat) {
420
        push (@limits, "mc-$itype_or_itemtype,phr:".$itemtypeInCategory);
421
    }
422
}
423
406
@limits = map { uri_unescape($_) } @limits;
424
@limits = map { uri_unescape($_) } @limits;
407
425
408
if($params->{'multibranchlimit'}) {
426
if($params->{'multibranchlimit'}) {
(-)a/t/db_dependent/Koha.t (-3 / +45 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 => 7;
12
use Test::More tests => 8;
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 261-263 subtest 'getFacets() tests' => sub { Link Here
261
        'location facet present with singleBranchMode on (bug 10078)'
262
        'location facet present with singleBranchMode on (bug 10078)'
262
    );
263
    );
263
};
264
};
264
- 
265
266
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
267
    plan tests => 7;
268
269
    my $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Qwertyware');
270
    ok($insertGroup, "Create group Qwertyware");
271
272
    my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
273
    my $insertSth = C4::Context->dbh->prepare($query);
274
    $insertSth->execute('BKghjklo1', 'One type of book', '', 0);
275
    $insertSth->execute('BKghjklo2', 'Another type of book', 'Qwertyware', 0);
276
    $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0);
277
278
    # Azertyware should not exist.
279
    my @results = GetItemTypesByCategory('Azertyware');
280
    is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing');
281
282
    @results = GetItemTypesByCategory('Qwertyware');
283
    my @expected = ( 'BKghjklo2', 'BKghjklo3' );
284
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
285
286
    # add more data since GetItemTypesCategorized's search is more subtle
287
    $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Veryveryheavybook');
288
    $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryveryheavybook', 1);
289
290
    my $hrCat = GetItemTypesCategorized();
291
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: fully visible category exists');
292
    ok($hrCat->{Veryveryheavybook} &&
293
       $hrCat->{Veryveryheavybook}->{hideinopac}==1, 'GetItemTypesCategorized: non-visible category hidden' );
294
295
    $insertSth->execute('BKghjklo5', 'An hidden book', 'Qwertyware', 1);
296
    $hrCat = GetItemTypesCategorized();
297
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists');
298
299
    my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryveryheavybook' );
300
    @results = ();
301
    foreach my $key (@only) {
302
        push @results, $key if exists $hrCat->{$key};
303
    }
304
    @expected = ( 'BKghjklo1', 'Qwertyware', 'Veryveryheavybook' );
305
    is_deeply(\@results,\@expected, 'GetItemTypesCategorized: grouped and ungrouped items returned as expected.');
306
}

Return to bug 10937