|
Lines 541-604
sub _UpdateCourseItem {
Link Here
|
| 541 |
if ( $course_item->is_enabled ) { |
541 |
if ( $course_item->is_enabled ) { |
| 542 |
my $item_fields = {}; |
542 |
my $item_fields = {}; |
| 543 |
|
543 |
|
| 544 |
# Find newly enabled field and add item value to storage |
544 |
for my $field ( qw( itype ccode location homebranch holdingbranch ) ) { |
| 545 |
if ( $params{itype_enabled} && !$course_item->itype_enabled ) { |
|
|
| 546 |
$enabled{itype_storage} = $item->itype; |
| 547 |
$item_fields->{itype} = $params{itype}; |
| 548 |
} |
| 549 |
# Find newly disabled field and copy the storage value to the item, unset storage value |
| 550 |
elsif ( !$params{itype_enabled} && $course_item->itype_enabled ) { |
| 551 |
$item_fields->{itype} = $course_item->itype_storage; |
| 552 |
$enabled{itype_storage} = undef; |
| 553 |
} |
| 554 |
# The field was already enabled, copy the incoming value to the item. |
| 555 |
# The "original" ( when not on course reserve ) value is already in the storage field |
| 556 |
elsif ( $course_item->itype_enabled) { |
| 557 |
$item_fields->{itype} = $params{itype}; |
| 558 |
} |
| 559 |
|
| 560 |
if ( $params{ccode_enabled} && !$course_item->ccode_enabled ) { |
| 561 |
$enabled{ccode_storage} = $item->ccode; |
| 562 |
$item_fields->{ccode} = $params{ccode}; |
| 563 |
} |
| 564 |
elsif ( !$params{ccode_enabled} && $course_item->ccode_enabled ) { |
| 565 |
$item_fields->{ccode} = $course_item->ccode_storage; |
| 566 |
$enabled{ccode_storage} = undef; |
| 567 |
} elsif ( $course_item->ccode_enabled) { |
| 568 |
$item_fields->{ccode} = $params{ccode}; |
| 569 |
} |
| 570 |
|
545 |
|
| 571 |
if ( $params{location_enabled} && !$course_item->location_enabled ) { |
546 |
my $field_enabled = sprintf "%s_enabled", $field; |
| 572 |
$enabled{location_storage} = $item->location; |
547 |
my $field_storage = sprintf "%s_storage", $field; |
| 573 |
$item_fields->{location} = $params{location}; |
|
|
| 574 |
} |
| 575 |
elsif ( !$params{location_enabled} && $course_item->location_enabled ) { |
| 576 |
$item_fields->{location} = $course_item->location_storage; |
| 577 |
$enabled{location_storage} = undef; |
| 578 |
} elsif ( $course_item->location_enabled) { |
| 579 |
$item_fields->{location} = $params{location}; |
| 580 |
} |
| 581 |
|
548 |
|
| 582 |
if ( $params{homebranch_enabled} && !$course_item->homebranch_enabled ) { |
549 |
# Find newly enabled field and add item value to storage |
| 583 |
$enabled{homebranch_storage} = $item->homebranch; |
550 |
if ( $params{$field_enabled} && !$course_item->$field_enabled ) { |
| 584 |
$item_fields->{homebranch} = $params{homebranch}; |
551 |
$enabled{$field_storage} = $item->$field; |
| 585 |
} |
552 |
$item_fields->{$field} = $params{$field}; |
| 586 |
elsif ( !$params{homebranch_enabled} && $course_item->homebranch_enabled ) { |
553 |
} |
| 587 |
$item_fields->{homebranch} = $course_item->homebranch_storage; |
554 |
# Find newly disabled field and copy the storage value to the item, unset storage value |
| 588 |
$enabled{homebranch_storage} = undef; |
555 |
elsif ( !$params{$field_enabled} && $course_item->$field_enabled ) { |
| 589 |
} elsif ( $course_item->homebranch_enabled) { |
556 |
$item_fields->{$field} = $course_item->$field_storage; |
| 590 |
$item_fields->{homebranch} = $params{homebranch}; |
557 |
$enabled{$field_storage} = undef; |
| 591 |
} |
558 |
} |
| 592 |
|
559 |
# The field was already enabled, copy the incoming value to the item. |
| 593 |
if ( $params{holdingbranch_enabled} && !$course_item->holdingbranch_enabled ) { |
560 |
# The "original" ( when not on course reserve ) value is already in the storage field |
| 594 |
$enabled{holdingbranch_storage} = $item->holdingbranch; |
561 |
elsif ( $course_item->$field_enabled) { |
| 595 |
$item_fields->{holdingbranch} = $params{holdingbranch}; |
562 |
$item_fields->{$field} = $params{$field}; |
| 596 |
} |
563 |
} |
| 597 |
elsif ( !$params{holdingbranch_enabled} && $course_item->holdingbranch_enabled ) { |
|
|
| 598 |
$item_fields->{holdingbranch} = $course_item->holdingbranch_storage; |
| 599 |
$enabled{holdingbranch_storage} = undef; |
| 600 |
} elsif ( $course_item->holdingbranch_enabled) { |
| 601 |
$item_fields->{holdingbranch} = $params{holdingbranch}; |
| 602 |
} |
564 |
} |
| 603 |
|
565 |
|
| 604 |
$item->set( $item_fields )->store |
566 |
$item->set( $item_fields )->store |
| 605 |
- |
|
|