I have a number of values that I need to run a bit of logic on to get a value for a views math expression further down the chain. Im going to provide a much simpler example of what I am actually doing...
Variables set on custom module admin page...
- twoyr_a = 5.4
- twoyr_b = 12.4
- threeyr_a = 5.6
- threeyr_b = 12.7
- fouryr_a = 5.8
- fouryr_b = 13.3
Contract term (Factor A) - Overidden with views-views-field--factor--a.tpl.php
if ($output == '24') {
print variable_get('twoyr_a');
} elseif ($output == '36') {
print variable_get('threeyr_a');
} elseif ($output == '48') {
print variable_get('fouryr_a');
} else {
print '0';
}
Contract term (Factor B) - Overidden with views-views-field--factor--b.tpl.php
if ($output == '24') {
print variable_get('twoyr_b');
} elseif ($output == '36') {
print variable_get('threeyr_b');
} elseif ($output == '48') {
print variable_get('fouryr_b');
} else {
print '0';
}
Views Global:Math Expression
[factor_a] + [factor_b] = result
However, the result is always wrong. Instead of using the result from the PHP template, it is adding the Contract terms (24 + 24 = 48).
Im guessing this is because the math expression runs before the template files do.
So my question is, is there anyway to avoid using Views PHP for this? Or is there a fix for my current solution?
Note: $output
is already defined in the database as 24, 36, or 48 in a "Contract Term" column. It relates to just a normal field in an ECK entity type called "Deal". It's an integer value to define the length of a contract for that deal. Each contract term has its own A and B factors to calculate my clients profit percentage when borrowing from a loan company.