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 276-281 sub GetItemTypes { Link Here
276
    }
277
    }
277
}
278
}
278
279
280
=head2 GetItemTypesCategorized
281
282
    $categories = GetItemTypesCategorized();
283
284
Returns a hashref containing search categories.
285
A search category will be put in the hash if at least one of its itemtypes is visible in OPAC.
286
The categories must be part of Authorized Values (DOCTYPECAT)
287
288
=cut
289
290
sub GetItemTypesCategorized {
291
    my $dbh   = C4::Context->dbh;
292
    # Order is important, so that partially hidden (some items are not visible in OPAC) search
293
    # categories will be visible. hideinopac=0 must be last.
294
    my $query = qq|
295
        SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) or length(searchcategory) = 0
296
        UNION
297
        SELECT DISTINCT searchcategory AS `itemtype`,
298
                        authorised_values.lib_opac AS description,
299
                        authorised_values.imageurl AS imageurl,
300
                        hideinopac, 1 as 'iscat'
301
        FROM itemtypes
302
        LEFT JOIN authorised_values ON searchcategory = authorised_value
303
        WHERE searchcategory > '' and hideinopac=1
304
        UNION
305
        SELECT DISTINCT searchcategory AS `itemtype`,
306
                        authorised_values.lib_opac AS description,
307
                        authorised_values.imageurl AS imageurl,
308
                        hideinopac, 1 as 'iscat'
309
        FROM itemtypes
310
        LEFT JOIN authorised_values ON searchcategory = authorised_value
311
        WHERE searchcategory > '' and hideinopac=0
312
        |;
313
    my $sth = $dbh->prepare($query);
314
    $sth->execute;
315
316
    my %itemtypes;
317
    while ( my $IT = $sth->fetchrow_hashref ) {
318
        $itemtypes{ $IT->{'itemtype'} } = $IT;
319
    }
320
    return ( \%itemtypes );
321
}
322
323
=head2 GetItemTypesByCategory
324
325
    @results = GetItemTypesByCategory( $searchcategory );
326
327
Returns the itemtype code of all itemtypes included in a searchcategory.
328
329
=cut
330
331
sub GetItemTypesByCategory {
332
    my ($category) = @_;
333
    my $count = 0;
334
    my @results;
335
    my $dbh = C4::Context->dbh;
336
    my $sth = $dbh->prepare("SELECT itemtype FROM itemtypes WHERE searchcategory=?");
337
    $sth->execute($category);
338
339
    while ( my $data = $sth->fetchrow ) {
340
        push ( @results, $data );
341
    }
342
    return @results;
343
}
344
279
sub get_itemtypeinfos_of {
345
sub get_itemtypeinfos_of {
280
    my @itemtypes = @_;
346
    my @itemtypes = @_;
281
347
(-)a/admin/authorised_values.pl (-1 / +1 lines)
Lines 245-251 sub default_form { Link Here
245
    }
245
    }
246
246
247
    # push koha system categories
247
    # push koha system categories
248
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS)) {
248
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS DOCTYPECAT)) {
249
        push @category_list, $_ unless $categories{$_};
249
        push @category_list, $_ unless $categories{$_};
250
    }
250
    }
251
251
(-)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 1249-1254 CREATE TABLE `itemtypes` ( -- defines the item types Link Here
1249
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1249
  checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
1250
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1250
  checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
1251
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1251
  sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
1252
  hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC
1253
  searchcategory varchar(20) default NULL, -- Group this item type with others with the same value on OPAC search options
1252
  PRIMARY KEY  (`itemtype`),
1254
  PRIMARY KEY  (`itemtype`),
1253
  UNIQUE KEY `itemtype` (`itemtype`)
1255
  UNIQUE KEY `itemtype` (`itemtype`)
1254
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1256
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(-)a/installer/data/mysql/updatedatabase.pl (+12 lines)
Lines 8778-8783 if ( CheckVersion($DBversion) ) { Link Here
8778
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('StatisticsFields','location|itype|ccode','Define fields (from the items table) used for statistics members',NULL,'Free')
8778
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('StatisticsFields','location|itype|ccode','Define fields (from the items table) used for statistics members',NULL,'Free')
8779
    });
8779
    });
8780
    print "Upgrade to $DBversion done (Bug 12728: Checked syspref StatisticsFields)\n";
8780
    print "Upgrade to $DBversion done (Bug 12728: Checked syspref StatisticsFields)\n";
8781
}
8782
8783
$DBversion = "3.17.00.XXX";
8784
if ( CheckVersion($DBversion) ) {
8785
    $dbh->do(q{
8786
        ALTER TABLE itemtypes
8787
            ADD hideinopac TINYINT(1) NOT NULL DEFAULT 0
8788
              AFTER sip_media_type,
8789
            ADD searchcategory VARCHAR(20) DEFAULT NULL
8790
              AFTER hideinopac;
8791
    });
8792
    print "Upgrade to $DBversion done (Bug 10937 - Option to hide and group itemtypes from advanced search)\n";
8781
    SetVersion($DBversion);
8793
    SetVersion($DBversion);
8782
}
8794
}
8783
8795
(-)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 132-140 Link Here
132
                                    <legend>Limit to any of the following:</legend>
132
                                    <legend>Limit to any of the following:</legend>
133
                                    <div class="row-fluid">
133
                                    <div class="row-fluid">
134
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
134
                                        [% FOREACH itemtypeloo IN advsearchloo.code_loop %]
135
                                            <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 %]
135
                                            [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %]
136
                                            [% itemtypeloo.description %]</label></div>
136
                                                <div class="span3">
137
                                                    <input type="checkbox"
138
                                                        id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]"
139
                                                        name="[% IF ( itemtypeloo.cat == 1 ) %]searchcat[% ELSE %]limit[% END %]"
140
                                                        value="[% IF ( itemtypeloo.cat == 1 ) %][% itemtypeloo.code %][% ELSE %]mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %][% END %]"
141
                                                    />
142
                                                    <label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">
143
                                                        [% UNLESS ( noItemTypeImages ) %]
144
                                                            [% IF ( itemtypeloo.imageurl ) %]
145
                                                                <img border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />
146
                                                            [% END %]
147
                                                            &nbsp;
148
                                                        [% END %]
149
                                                        [% itemtypeloo.description %]
150
                                                    </label>
151
                                                </div>
137
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
152
                                            [% IF ( loop.last ) %]</div>[% ELSE %][% UNLESS ( loop.count % 4 ) %]</div><div class="row-fluid">[% END %][% END %]
153
                                            [% END %]
138
                                        [% END %]
154
                                        [% END %]
139
                                </fieldset>
155
                                </fieldset>
140
                            </div> <!-- / #advsearch-[% advsearchloo.advanced_search_type %] -->
156
                            </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 93-99 my ($template,$borrowernumber,$cookie); Link Here
93
my $template_name;
93
my $template_name;
94
my $template_type = 'basic';
94
my $template_type = 'basic';
95
my @params = $cgi->param("limit");
95
my @params = $cgi->param("limit");
96
96
my @searchCategories = $cgi->param('searchcat');
97
97
98
my $format = $cgi->param("format") || '';
98
my $format = $cgi->param("format") || '';
99
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
99
my $build_grouped_results = C4::Context->preference('OPACGroupResults');
Lines 203-209 my $languages_limit_loop = getLanguages($lang, 1); Link Here
203
$template->param(search_languages_loop => $languages_limit_loop,);
203
$template->param(search_languages_loop => $languages_limit_loop,);
204
204
205
# load the Type stuff
205
# load the Type stuff
206
my $itemtypes = GetItemTypes;
206
my $itemtypes = GetItemTypesCategorized;
207
# the index parameter is different for item-level itemtypes
207
# the index parameter is different for item-level itemtypes
208
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
208
my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
209
my @advancedsearchesloop;
209
my @advancedsearchesloop;
Lines 237-244 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
237
                code => $thisitemtype,
237
                code => $thisitemtype,
238
                description => $itemtypes->{$thisitemtype}->{'description'},
238
                description => $itemtypes->{$thisitemtype}->{'description'},
239
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
239
                imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
240
                cat => $itemtypes->{$thisitemtype}->{'iscat'},
241
                hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'},
242
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
240
            );
243
            );
241
	    push @itypesloop, \%row;
244
            if ( !$itemtypes->{$thisitemtype}->{'hideinopac'} ) {
245
                push @itypesloop, \%row;
246
            }
242
	}
247
	}
243
        my %search_code = (  advanced_search_type => $advanced_srch_type,
248
        my %search_code = (  advanced_search_type => $advanced_srch_type,
244
                             code_loop => \@itypesloop );
249
                             code_loop => \@itypesloop );
Lines 256-261 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
256
				ccl => $advanced_srch_type,
261
				ccl => $advanced_srch_type,
257
                code => $thisitemtype->{authorised_value},
262
                code => $thisitemtype->{authorised_value},
258
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
263
                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
264
                searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'},
259
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
265
                imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
260
                );
266
                );
261
		push @authvalueloop, \%row;
267
		push @authvalueloop, \%row;
Lines 423-428 my @limits = $cgi->param('limit'); Link Here
423
my @nolimits = $cgi->param('nolimit');
429
my @nolimits = $cgi->param('nolimit');
424
my %is_nolimit = map { $_ => 1 } @nolimits;
430
my %is_nolimit = map { $_ => 1 } @nolimits;
425
@limits = grep { not $is_nolimit{$_} } @limits;
431
@limits = grep { not $is_nolimit{$_} } @limits;
432
433
if (@searchCategories > 0) {
434
    my @tabcat;
435
    foreach my $typecategory (@searchCategories) {
436
        push (@tabcat, GetItemTypesByCategory($typecategory));
437
    }
438
439
    foreach my $itemtypeInCategory (@tabcat) {
440
        push (@limits, "mc-$itype_or_itemtype,phr:".$itemtypeInCategory);
441
    }
442
}
443
426
@limits = map { uri_unescape($_) } @limits;
444
@limits = map { uri_unescape($_) } @limits;
427
445
428
if($params->{'multibranchlimit'}) {
446
if($params->{'multibranchlimit'}) {
(-)a/t/db_dependent/Koha.t (-2 / +43 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 => 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 305-308 subtest 'GetFrameworksLoop() tests' => sub { Link Here
305
    );
306
    );
306
};
307
};
307
308
309
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
310
    plan tests => 7;
311
312
    my $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Qwertyware');
313
    ok($insertGroup, "Create group Qwertyware");
314
315
    my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)";
316
    my $insertSth = C4::Context->dbh->prepare($query);
317
    $insertSth->execute('BKghjklo1', 'One type of book', '', 0);
318
    $insertSth->execute('BKghjklo2', 'Another type of book', 'Qwertyware', 0);
319
    $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0);
320
321
    # Azertyware should not exist.
322
    my @results = GetItemTypesByCategory('Azertyware');
323
    is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing');
324
325
    @results = GetItemTypesByCategory('Qwertyware');
326
    my @expected = ( 'BKghjklo2', 'BKghjklo3' );
327
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
328
329
    # add more data since GetItemTypesCategorized's search is more subtle
330
    $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Veryveryheavybook');
331
    $insertSth->execute('BKghjklo4', 'Another hidden book', 'Veryveryheavybook', 1);
332
333
    my $hrCat = GetItemTypesCategorized();
334
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: fully visible category exists');
335
    ok($hrCat->{Veryveryheavybook} &&
336
       $hrCat->{Veryveryheavybook}->{hideinopac}==1, 'GetItemTypesCategorized: non-visible category hidden' );
337
338
    $insertSth->execute('BKghjklo5', 'An hidden book', 'Qwertyware', 1);
339
    $hrCat = GetItemTypesCategorized();
340
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists');
341
342
    my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryveryheavybook' );
343
    @results = ();
344
    foreach my $key (@only) {
345
        push @results, $key if exists $hrCat->{$key};
346
    }
347
    @expected = ( 'BKghjklo1', 'Qwertyware', 'Veryveryheavybook' );
348
    is_deeply(\@results,\@expected, 'GetItemTypesCategorized: grouped and ungrouped items returned as expected.');
349
}
308
$dbh->rollback();
350
$dbh->rollback();
309
- 

Return to bug 10937