@@ -, +, @@ automatic item modification by age tool and cronjob. --confirm --- C4/Items.pm | 17 ++++- .../tools/automatic_item_modification_by_age.tt | 76 +++++++++++++++++++--- .../prog/js/automatic_item_modification_by_age.js | 12 ++++ tools/automatic_item_modification_by_age.pl | 18 ++++- 4 files changed, 111 insertions(+), 12 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2827,6 +2827,8 @@ sub ToggleNewStatus { my $report; for my $rule ( @rules ) { my $age = $rule->{age}; + my $unit = $rule->{unit}; + my $age_starting_point = $rule->{age_starting_point}; my $conditions = $rule->{conditions}; my $substitutions = $rule->{substitutions}; my @params; @@ -2855,8 +2857,19 @@ sub ToggleNewStatus { } } if ( defined $age ) { - $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; - push @params, $age; + # Calculate item age based on hours since item last altered + if ( defined $rule && defined $age_starting_point && $unit eq "hours" && $age_starting_point eq "itemaltered" ) { + $query .= q| AND HOUR(TIMEDIFF(NOW(), items.timestamp)) >= ? |; + push @params, $age; + } elsif ( defined $rule && defined $age_starting_point && $unit eq "days" && $age_starting_point eq "itemaltered" ) { + # Calculate item age based on days since item last altered + $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.timestamp) >= ? |; + push @params, $age; + } else { + # Calculate item age based on days since item was created + $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.dateaccessioned) >= ? |; + push @params, $age; + } } my $sth = $dbh->prepare($query); $sth->execute( @params ); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt @@ -70,10 +70,39 @@ Rule [% loop.count %] Remove this rule
-
Age in days
+
Age
-
+
+
Unit
+

Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point will default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.

+ +
+ [% IF rule.unit == "days" %] +
+
Age starting point (starting point from which the item age is calculated)
+ +
+ [% END %] +
Conditions
[% FOR condition IN rule.conditions %]
@@ -87,7 +116,6 @@ [% END %] [% END %] - = Add a condition Remove condition @@ -108,7 +136,6 @@ [% END %] [% END %] - = Add a substitution Remove substitution @@ -131,9 +158,26 @@ Rule Remove this rule
-
Age in days
+
Age
+
+
Unit
+

Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point will default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.

+ +
+
+
Age starting point (starting point from which the item age is calculated)
+ +
Conditions
@@ -143,7 +187,6 @@ [% END %] - = Add a condition Remove condition @@ -158,7 +201,6 @@ [% END %] - = Add a substitution Remove substitution @@ -173,6 +215,7 @@ Age + Age starting point Conditions Substitutions @@ -181,13 +224,28 @@ [% FOR rule IN rules %] - [% IF rule.age.defined and rule.age.length > 0 %] - [% rule.age %] days + [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %] + [% IF rule.age == 1 %] + [% IF rule.unit == "days" %] + [% rule.age %] day + [% ELSE %] + [% rule.age %] hour + [% END %] + [% ELSE %] + [% rule.age %] [% rule.unit %] + [% END %] [% ELSE %] There is no age for this rule. [% END %] + [% IF rule.age_starting_point.defined %] + [% rule.age_starting_point %] + [% ELSE %] + There is no age starting point for this rule. + [% END %] + + [% FOR condition IN rule.conditions %] [% IF condition.field %]
--- a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js +++ a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js @@ -52,6 +52,8 @@ function update_rule_count(){ $(document).ready(function() { $("#new_rule .remove_rule").hide(); $("#new_rule a.remove_block").hide(); + $("#new_rule_age_starting_point_div").hide(); + $("#rules a.remove_block").click(function(e){ e.preventDefault(); remove_block_action($(this)); @@ -61,6 +63,16 @@ $(document).ready(function() { remove_rule_action($(this)); }); + $("#new_rule_unit").change(function(){ + var unitselected = $(this).find("option:selected").attr("id"); + var newruleagestart = document.getElementById("new_rule_age_starting_point_div"); + if (unitselected == "days") { + newruleagestart.style.display = "block" + } else { + newruleagestart.style.display = "none"; + } + }); + var unique_id = $(".rule").length + 1; $(".add_rule").click(function(e){ e.preventDefault(); --- a/tools/automatic_item_modification_by_age.pl +++ a/tools/automatic_item_modification_by_age.pl @@ -39,7 +39,7 @@ use C4::Context; use C4::Items; use C4::Output; use C4::Koha; - +use Data::Dumper; use Koha::Items; use Koha::Biblioitems; @@ -86,9 +86,25 @@ if ( $op eq 'update' ) { push @{ $rule->{conditions} }, {} unless @{ $rule->{conditions} }; $rule->{age} = $cgi->param("age_$unique_id"); + + if ($cgi->param("unit_$unique_id")) { + $rule->{unit} = $cgi->param("unit_$unique_id"); + } else { + $rule->{unit} = $cgi->param("unit"); + } + + if ($cgi->param("age_starting_point_$unique_id")) { + $rule->{age_starting_point} = $cgi->param("age_starting_point_$unique_id"); + } elsif ($cgi->param("age_starting_point")) { + $rule->{age_starting_point} = $cgi->param("age_starting_point"); + } else { + $rule->{age_starting_point} = "itemaltered" + } + push @rules, $rule; } my $syspref_content = to_json( \@rules ); + C4::Context->set_preference($syspref_name, $syspref_content); $op = 'show'; --