As requested by RM on Bugzilla comment53.
This pref allows you to always display the link on search results.
Which is the previous behavior ;) It will raise false positives, whereas
the algorithm may result in false positives or negatives (depending on
default item type and circulation rules).
When upgrading the pref is set to always (current behavior), new installs
get the new calc value using the algorithm in may_article_request.
Test plan:
Run t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t
Run t/db_dependent/ArticleRequests.t
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
'article requested'. Constructed by an intelligent guess in the
issuing rules (see article_requestable_rules).
+ Note: pref ArticleRequestsLinkControl overrides the algorithm.
+
Optional parameters: categorycode.
Note: the routine is used in opac-search to obtain a reasonable
my ( $class, $params ) = @_;
my $category = $params->{categorycode};
return {} if !C4::Context->preference('ArticleRequests');
+ return { '*' => 1 } if C4::Context->preference('ArticleRequestsLinkControl') eq 'always';
my $cache = Koha::Caches->get_instance;
my $last_article_requestable_guesses = $cache->get_from_cache(GUESSED_ITEMTYPES_KEY);
--- /dev/null
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('ArticleRequestsLinkControl', 'always', 'always\|calc', 'Control display of article request link on search results', 'Choice')
+ |);
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 17530 - Add pref ArticleRequestsLinkControl)\n";
+}
('AnonSuggestions','0',NULL,'Set to enable Anonymous suggestions to AnonymousPatron borrowernumber','YesNo'),
('AnonymousPatron','0',NULL,'Set the identifier (borrowernumber) of the anonymous patron. Used for Suggestion and reading history privacy',''),
('ArticleRequests', '0', NULL, 'Enables the article request feature', 'YesNo'),
+('ArticleRequestsLinkControl', 'calc', 'always|calc', 'Control display of article request link on search results', 'Choice'),
('ArticleRequestsMandatoryFields', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''yes''', 'multiple'),
('ArticleRequestsMandatoryFieldsItemsOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''item_only''', 'multiple'),
('ArticleRequestsMandatoryFieldsRecordOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''bib_only''', 'multiple'),
no: "Don't enable"
- patrons to place article requests.
-
+ - pref: ArticleRequestsLinkControl
+ choices:
+ always: Always show
+ calc: Use algorithm to show or hide
+ - article request link on search results.
+ -
- For records that are record level or item level requestable, make the following fields mandatory
- pref: ArticleRequestsMandatoryFields
multiple:
};
subtest 'may_article_request' => sub {
- plan tests => 3;
+ plan tests => 4;
# mocking
t::lib::Mocks::mock_preference('ArticleRequests', 1);
+ t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
$cache->set_in_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY, {
'*' => { 'CR' => 1 },
'S' => { '*' => 1 },
is( $itemtype->may_article_request, 1, 'SER/* should be true' );
is( $itemtype->may_article_request({ categorycode => 'S' }), 1, 'SER/S should be true' );
is( $itemtype->may_article_request({ categorycode => 'PT' }), '', 'SER/PT should be false' );
+ t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always');
+ is( $itemtype->may_article_request({ categorycode => 'PT' }), '1', 'Result should be true when LinkControl is set to always' );
# Cleanup
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
our $cache = Koha::Caches->get_instance;
subtest 'guess_article_requestable_itemtypes' => sub {
- plan tests => 12;
+ plan tests => 13;
t::lib::Mocks::mock_preference('ArticleRequests', 1);
+ t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
Koha::IssuingRules->delete;
my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
+ # Finally test the overriding pref
+ t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always');
+ $res = Koha::IssuingRules->guess_article_requestable_itemtypes({});
+ is( $res->{'*'}, 1, 'Override algorithm with pref setting' );
+
$cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
};