Search code examples
phpemaillogicclass-design

PHP - Alternating email selection based on a set schedule


Ok, Here is the situation, I am looking for some general input on the logic of this class. The purpose of this class is to: query a schedule database for employees that are currently working, and select the email address of one person who is currently working.

This class gets called by procmail every time an email is received, and serves procmail one email to forward to.

When there is more than one person working, the 2nd email received should go to the next person, the third email to the next, and loop over them as such - Delivering them equally. If nobody is working at a specific time, the list of active workers is set to everybody working the next day, or the same day respectively.

I have this class half-made, and I'm having a hard time coming up with the logic of equal delivery. I figure I would log each email sent in a database table, limit it to about 10 entries and just email it to the person who shows up the least. However, this will not be exactly equal. Neither would just selecting a random email.

I'm not looking for someone to code this for me, just looking for some input on a better logic method; maybe someone has run into this kind of situation before?

The table design is extremely simple, it goes like:

date | name | email | time_in | time_out

Of course there are other tables that handle manual overrides, and the table I mentioned about logging sent emails. I can post the current class I have, but like I said it is half-made, and the class logic is pretty simple - other than this specific part.

Any Idea, or input is welcome!


Solution

  • How about -- keep a counter of how many emails each person got, sort by least to determine who gets the next, then reset all the counters to zero at the start of each shift.