K
K
Kekoc2015-11-18 10:03:04
Yii
Kekoc, 2015-11-18 10:03:04

How to automatically change the status of an object depending on the date?

Hello.
The object has "start" and "end" variables (dates), it is also necessary for this object to have statuses:

  1. Active (after creation)
  2. Open (set automatically after reaching the start date);
  3. Closed (set automatically after reaching the end date);
  4. Completed (after setting this status by the user);
  5. Frozen (after setting this status by the user);

What is the actual question. How to implement automatic status change depending on the date?
My ideas:
  1. Statuses open and closed, as such, do not store in the model (and therefore in the database), but simply calculate these statuses for each object, by comparing whether the current date on the server falls within the start and end interval, if there is 1 status. And every time the user is shown on the page a list of objects with a status.
    The disadvantage of such an action is that with a large number of objects and frequent requests, you will have to calculate all this with dates, although not such a complicated action, but still.
  2. Idea number 2 is to run through all objects in Cron daily and change their statuses depending on whether the start or end date for this object has come. The advantage is that the statuses will be directly stored in the object itself and this saves us from unnecessary operations.

Please critique my decisions. And I will look at yours with pleasure)
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question