Lines 216-226
The mapping should be:
Link Here
|
216 |
|
216 |
|
217 |
<branchcode>:<item field>:<comparator>:<item field value>:<sort bin number> |
217 |
<branchcode>:<item field>:<comparator>:<item field value>:<sort bin number> |
218 |
|
218 |
|
|
|
219 |
The field comparison triplet is repeatable, so you may include multiple sections |
220 |
|
221 |
:<item field>:<comparator>:<item field value>: |
222 |
|
219 |
For example: |
223 |
For example: |
220 |
|
224 |
|
221 |
CPL:itype:eq:BOOK:1 |
225 |
CPL:itype:eq:BOOK:1 |
222 |
CPL:location:eq:OFFICE:2 |
226 |
CPL:location:eq:OFFICE:2 |
223 |
CPL:classmark:<:339.6:3 |
227 |
CPL:classmark:<:339.6:3 |
|
|
228 |
CPL:itype:eq:BOOK:ccode:eq:TEEN:4 |
224 |
|
229 |
|
225 |
This will give: |
230 |
This will give: |
226 |
|
231 |
|
Lines 232-237
This will give:
Link Here
|
232 |
|
237 |
|
233 |
=item * sort_bin = "3" for items at the CPL branch with a classmark less than 339.6 |
238 |
=item * sort_bin = "3" for items at the CPL branch with a classmark less than 339.6 |
234 |
|
239 |
|
|
|
240 |
=item * sort_bin = "4" for items at the CPL branch with an itype of BOOK and a ccode of TEEN |
241 |
|
235 |
=back |
242 |
=back |
236 |
|
243 |
|
237 |
Returns the ID of the appropriate sort_bin, if there is one, or undef. |
244 |
Returns the ID of the appropriate sort_bin, if there is one, or undef. |
Lines 245-255
sub _get_sort_bin {
Link Here
|
245 |
return unless $item; |
252 |
return unless $item; |
246 |
|
253 |
|
247 |
my @lines; |
254 |
my @lines; |
|
|
255 |
|
248 |
# Mapping in SIP config takes precedence over syspref |
256 |
# Mapping in SIP config takes precedence over syspref |
249 |
if ( my $mapping = $account->{sort_bin_mapping} ) { |
257 |
if ( my $mapping = $account->{sort_bin_mapping} ) { |
250 |
@lines = map { $_->{mapping} } @$mapping; |
258 |
@lines = map { $_->{mapping} } @$mapping; |
251 |
} |
259 |
} else { |
252 |
else { |
260 |
|
253 |
# Get the mapping and split on newlines |
261 |
# Get the mapping and split on newlines |
254 |
my $raw_map = C4::Context->preference('SIP2SortBinMapping'); |
262 |
my $raw_map = C4::Context->preference('SIP2SortBinMapping'); |
255 |
return unless $raw_map; |
263 |
return unless $raw_map; |
Lines 258-293
sub _get_sort_bin {
Link Here
|
258 |
|
266 |
|
259 |
# Iterate over the mapping. The first hit wins. |
267 |
# Iterate over the mapping. The first hit wins. |
260 |
my $rule = 0; |
268 |
my $rule = 0; |
261 |
foreach my $line (@lines) { |
269 |
RULE: foreach my $line (@lines) { |
|
|
270 |
|
271 |
my $match = 0; |
262 |
|
272 |
|
263 |
# Split the line into fields |
273 |
# Split the line into fields |
264 |
my ( $branchcode, $item_property, $comparator, $value, $sort_bin ) = |
274 |
my @fields = split /:/, $line; |
265 |
split /:/, $line; |
275 |
|
266 |
if ( $value =~ s/^\$// ) { |
276 |
# Capture branchcode from first field |
267 |
$value = $item->$value; |
277 |
my $branchcode = shift @fields; |
268 |
} |
278 |
next RULE unless ( $branch eq $branchcode ); |
269 |
# Check the fields against values in the item |
279 |
|
270 |
if ( $branch eq $branchcode ) { |
280 |
# Capture sort_bin from last field |
|
|
281 |
my $sort_bin = pop @fields; |
282 |
|
283 |
# Capture rule sets |
284 |
while ( my ( $item_property, $comparator, $value ) = splice( @fields, 0, 3 ) ) { |
285 |
|
286 |
# Skip badly formed rules |
287 |
next RULE if ( !defined($item_property) || !defined($comparator) || !defined($value) ); |
288 |
|
289 |
if ( $value =~ s/^\$// ) { |
290 |
$value = $item->$value; |
291 |
} |
292 |
|
293 |
# Check the fields against values in the item |
271 |
my $property = $item->$item_property; |
294 |
my $property = $item->$item_property; |
272 |
if ( ( $comparator eq 'eq' || $comparator eq '=' ) && ( $property eq $value ) ) { |
295 |
if ( ( $comparator eq 'eq' || $comparator eq '=' ) && ( $property eq $value ) ) { |
273 |
return $sort_bin; |
296 |
$match = 1; |
274 |
} |
297 |
} elsif ( ( $comparator eq 'ne' || $comparator eq '!=' ) && ( $property ne $value ) ) { |
275 |
if ( ( $comparator eq 'ne' || $comparator eq '!=' ) && ( $property ne $value ) ) { |
298 |
$match = 1; |
276 |
return $sort_bin; |
299 |
} elsif ( ( $comparator eq '<' ) && ( $property < $value ) ) { |
277 |
} |
300 |
$match = 1; |
278 |
if ( ( $comparator eq '<' ) && ( $property < $value ) ) { |
301 |
} elsif ( ( $comparator eq '>' ) && ( $property > $value ) ) { |
279 |
return $sort_bin; |
302 |
$match = 1; |
280 |
} |
303 |
} elsif ( ( $comparator eq '<=' ) && ( $property <= $value ) ) { |
281 |
if ( ( $comparator eq '>' ) && ( $property > $value ) ) { |
304 |
$match = 1; |
282 |
return $sort_bin; |
305 |
} elsif ( ( $comparator eq '>=' ) && ( $property >= $value ) ) { |
283 |
} |
306 |
$match = 1; |
284 |
if ( ( $comparator eq '<=' ) && ( $property <= $value ) ) { |
307 |
} else { |
285 |
return $sort_bin; |
308 |
|
286 |
} |
309 |
# No match, skip to next rule |
287 |
if ( ( $comparator eq '>=' ) && ( $property >= $value ) ) { |
310 |
next RULE; |
288 |
return $sort_bin; |
|
|
289 |
} |
311 |
} |
290 |
} |
312 |
} |
|
|
313 |
|
314 |
# Return sort bin if match |
315 |
return $sort_bin if $match; |
316 |
|
291 |
} |
317 |
} |
292 |
|
318 |
|
293 |
# Return undef if no hits were found |
319 |
# Return undef if no hits were found |