D
D
dobriykot2010-11-28 16:06:50
Programming
dobriykot, 2010-11-28 16:06:50

How to program a set of conditions for an event to occur?

Suppose I need an event to fire when certain conditions are met. For example, “if A > 2000 and B = 1, then [an event occurred]” or something else.
The bottom line is that the user should be able to create such a condition himself by dynamically selecting the parameters (if, and, or, more, less, how many times, at what time, etc.). It also makes the task easier for the programmer, who does not have to hardcode the conditions in the algorithm every time. I could not find a description of such an algorithm on the Internet, but I remember that it was in some kind of cms. For now, I'm thinking about a variant of the form that will post rows into a table with the necessary columns, from which this condition is collected in the future. But this is not a labor-out, it seems to me.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
schursin, 2010-11-28
@schursin

>but I remember that it was in some kind of cms
It seems it was Bitrix...

O
OlegTar, 2010-11-28
@OlegTar

I will help you to understand your question. If I misunderstood, I apologize.
===
The user creates the desired condition.
The condition is put into an array.
It is also possible to foresee what should be fulfilled according to this condition.
Get, for example, the "Condition" object:
{
condition: 'condition text',
list of events: [function1, function2];
}
And put this object in the array of conditions.
("list of events" can also be set by the user)
When some actions occur, we run through the array and check whether the conditions are met.
If they are, then we go over the functions inside the “Condition” object and execute them.
There is also this design patternObserver

V
Vladimir Chernyshev, 2010-11-28
@VolCh

Once (but it was a long time ago and not true) I solved a similar subtask like this: a query was formed in the GUI (a tree with leaves “parameter, operation, value[, value2[, value3[ ...]]]]”, or subtrees with the “root” “AND” / “OR”, after pressing the “Save” or “Run” button, it was saved as a tree for subsequent editing and additionally recursively converted into an SQL expression (the subtask was to make a report designer for a fairly extensive database of questionnaires, hiding from SQL users and the tabular nature of the database in general). , and most importantly, generate an expression on your PL, and then execute it through a function,called eval() in many languages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question