|
Lines 44-50
use Koha::Exceptions::BadParameter;
Link Here
|
| 44 |
fromBranch => 'CPL', |
44 |
fromBranch => 'CPL', |
| 45 |
toBranch => 'FFL', |
45 |
toBranch => 'FFL', |
| 46 |
floating => ['ALWAYS'|'POSSIBLE'|'CONDITIONAL'], |
46 |
floating => ['ALWAYS'|'POSSIBLE'|'CONDITIONAL'], |
| 47 |
conditionRules => "items->{itype} eq 'BK' && $items->{permanent_location} eq 'CART'" |
47 |
conditionRules => "items->{itype} eq 'BK' && $items->{permanent_location} =~ 'CART'" |
| 48 |
}); |
48 |
}); |
| 49 |
|
49 |
|
| 50 |
BranchRule defines the floating rule for one transfer route. |
50 |
BranchRule defines the floating rule for one transfer route. |
|
Lines 59-67
We check if there is a floating rule for that fromBranch-toBranch -combination a
Link Here
|
| 59 |
sub new { |
59 |
sub new { |
| 60 |
my ($class, $params) = @_; |
60 |
my ($class, $params) = @_; |
| 61 |
|
61 |
|
|
|
62 |
bless $params, $class; |
| 62 |
ValidateParams($params); |
63 |
ValidateParams($params); |
| 63 |
|
64 |
|
| 64 |
bless $params, $class; |
|
|
| 65 |
return $params; |
65 |
return $params; |
| 66 |
} |
66 |
} |
| 67 |
|
67 |
|
|
Lines 124-130
sub ValidateParams {
Link Here
|
| 124 |
$errorMsg = "'conditionRules' text is too long. Maximum length is '$maximumConditionRulesDatabaseLength' characters"; |
124 |
$errorMsg = "'conditionRules' text is too long. Maximum length is '$maximumConditionRulesDatabaseLength' characters"; |
| 125 |
} |
125 |
} |
| 126 |
elsif ($params->{conditionRules}) { |
126 |
elsif ($params->{conditionRules}) { |
| 127 |
ParseConditionRules(undef, $params->{conditionRules}); |
127 |
$params->setConditionRules($params->{conditionRules}); |
| 128 |
} |
128 |
} |
| 129 |
|
129 |
|
| 130 |
if ($errorMsg) { |
130 |
if ($errorMsg) { |
|
Lines 138-164
sub ValidateParams {
Link Here
|
| 138 |
|
138 |
|
| 139 |
=head parseConditionRules, Static method |
139 |
=head parseConditionRules, Static method |
| 140 |
|
140 |
|
| 141 |
my $evalCondition = ParseConditionRules($item, $conditionRules); |
141 |
my $evalCondition = ParseConditionRules($conditionRules); |
| 142 |
my $evalCondition = ParseConditionRules(undef, $conditionRules); |
142 |
my $evalCondition = ParseConditionRules($conditionRules); |
| 143 |
|
143 |
|
| 144 |
Parses the given Perl boolean expression into an eval()-able expression. |
144 |
Parses the given Perl boolean expression into an eval()-able expression. |
| 145 |
If Item is given, uses the Item's columns to create a executable expression to check for |
145 |
If Item is given, uses the Item's columns to create a executable expression to check for |
| 146 |
conditional floating for this specific Item. |
146 |
conditional floating for this specific Item. |
| 147 |
|
147 |
|
| 148 |
@PARAM1 {Reference to HASH of koha.items-row} Item to check for conditional floating. |
148 |
@PARAM1 {String koha.floating_matrix.condition_rules} The boolean expression to turn |
| 149 |
@PARAM2 {String koha.floating_matrix.condition_rules} The boolean expression to turn |
|
|
| 150 |
into a Perl code to check the floating condition. |
149 |
into a Perl code to check the floating condition. |
| 151 |
@THROWS Koha::Exceptions::BadParameter, if the conditionRules couldn't be parsed. |
150 |
@THROWS Koha::Exceptions::BadParameter, if the conditionRules couldn't be parsed. |
| 152 |
=cut |
151 |
=cut |
| 153 |
sub ParseConditionRules { |
152 |
sub ParseConditionRules { |
| 154 |
my ($item, $conditionRulesString) = @_; |
153 |
my ($conditionRulesString) = @_; |
| 155 |
my $evalCondition = ''; |
154 |
my $evalCondition = ''; |
| 156 |
if (my @conds = $conditionRulesString =~ /(\w+)\s+(ne|eq|gt|lt|<|>|==|!=)\s+(\w+)\s*(and|or|xor|&&|\|\|)?/ig) { |
155 |
if (my @conds = $conditionRulesString =~ /(\w+)\s+(ne|eq|gt|lt|=~|<|>|==|!=)\s+(\S+)\s*(and|or|xor|&&|\|\|)?/ig) { |
| 157 |
|
|
|
| 158 |
#If we haven't got no Item, simply stop here to aknowledge that the given condition logic is valid (atleast parseable) |
| 159 |
return undef unless $item; |
| 160 |
|
| 161 |
#If we have an Item, then prepare and return an eval-expression to test if the Item should float. |
| 162 |
#Iterate the condition quads, with the fourth index being the logical join operator. |
156 |
#Iterate the condition quads, with the fourth index being the logical join operator. |
| 163 |
for (my $i=0 ; $i<scalar(@conds) ; $i+=4) { |
157 |
for (my $i=0 ; $i<scalar(@conds) ; $i+=4) { |
| 164 |
my $column = $conds[$i]; |
158 |
my $column = $conds[$i]; |
|
Lines 166-181
sub ParseConditionRules {
Link Here
|
| 166 |
my $value = $conds[$i+2]; |
160 |
my $value = $conds[$i+2]; |
| 167 |
my $join = $conds[$i+3] || ''; |
161 |
my $join = $conds[$i+3] || ''; |
| 168 |
|
162 |
|
| 169 |
$evalCondition .= join(' ',"\$item->{'$column'}",$operator,"'$value'",$join,''); |
163 |
if ($operator eq '=~') { |
|
|
164 |
$value = qr($value); |
| 165 |
$evalCondition .= "\$item->$column $operator /$value/ $join "; |
| 166 |
} else { |
| 167 |
$evalCondition .= "\$item->$column $operator '$value' $join "; |
| 168 |
} |
| 170 |
} |
169 |
} |
| 171 |
|
|
|
| 172 |
return $evalCondition; |
| 173 |
} |
170 |
} |
| 174 |
else { |
171 |
else { |
| 175 |
Koha::Exceptions::BadParameter->throw(error => |
172 |
Koha::Exceptions::BadParameter->throw(error => |
| 176 |
"Koha::FloatingMatrix::parseConditionRules():> Bad condition rules '$conditionRulesString' couldn't be parsed\n". |
173 |
"Koha::FloatingMatrix::BranchRule::ParseConditionRules():> Bad condition rules '$conditionRulesString' couldn't be parsed.\n" |
| 177 |
"See 'Help' for more info"); |
174 |
); |
| 178 |
} |
175 |
} |
|
|
176 |
return $evalCondition; |
| 179 |
} |
177 |
} |
| 180 |
|
178 |
|
| 181 |
=head replace |
179 |
=head replace |
|
Lines 301-313
See parseConditionRules()
Link Here
|
| 301 |
sub setConditionRules { |
299 |
sub setConditionRules { |
| 302 |
my ($self, $val) = @_; |
300 |
my ($self, $val) = @_; |
| 303 |
#Validate the conditinal rules. |
301 |
#Validate the conditinal rules. |
| 304 |
ParseConditionRules(undef, $val); |
302 |
$self->{conditionRulesParsed} = ParseConditionRules($val); |
| 305 |
$self->{conditionRules} = $val; |
303 |
$self->{conditionRules} = $val; |
| 306 |
} |
304 |
} |
| 307 |
sub getConditionRules { |
305 |
sub getConditionRules { return shift->{conditionRules}; } |
| 308 |
my ($self) = @_; |
306 |
sub getConditionRulesParsed { return shift->{conditionRulesParsed}; } |
| 309 |
return $self->{conditionRules}; |
|
|
| 310 |
} |
| 311 |
|
307 |
|
| 312 |
=head toString |
308 |
=head toString |
| 313 |
|
309 |
|
|
Lines 339-342
sub TO_JSON {
Link Here
|
| 339 |
return $json; |
335 |
return $json; |
| 340 |
} |
336 |
} |
| 341 |
|
337 |
|
| 342 |
1; #Satisfy the compiler |
338 |
1; #Satisfy the compiler |