Description:

This patch gives you the possibility to have mathematical expressions in (both sides of) your numeric comparison conditions.

How:

Currently both sides of the comparator are cast to a float. Instead we'll evaluate the mathematical expression entered.
Non-allowed characters (anything but mathematical operators and digits) are stripped from the expression, after which it is evaluated.

Example:

If you want a condition to check if a node is e.g. older than one week, you logically would compare the current date with the node date plus one week expressed in seconds.

Text to compare:
[node:site-timestamp]
Greater than:
[node:mod-timestamp] + (7*24*60*60)

After replacing the tokens this (internally) gives us the comparison:

1210764328 > 1204761600 + (7*24*60*60)

Now we'll mathematically evaluate both sides and then do the comparison:

1210764328 > 1205366400

Notes:

Currently, invalid mathematical expressions (such as 2*4+) return zero.

Comments

fago’s picture

Status: Needs review » Needs work

yep, I already thought about this too. This is indeed really useful, however I'd like to see to get it implemented in a more general way:

- a generic php-input filter system, that can be easily attached to any input fields like the token integration, e.g. we could parse everything in between <? ?>. So one could do calculations and so on easily, while the basic usage is the same.

What do you think about this?

Anyway, I think we need to have a nice error reporting system - so that syntax errors are reported immediately. At least for this your patch needs to be improved.

mitchell’s picture

Project: Workflow-ng » Rules
Version: 5.x-2.x-dev » 6.x-1.x-dev
Component: Miscellaneous » Rules Engine

Moving this feature request to Rules.

@folkertdv: Is this still on your radar?

fago’s picture

Status: Needs work » Closed (won't fix)

That's not needed any more, as now there is a PHP input filter that allows you do mathematical expressions easily.