This is more like a logic question than coding, I have been in to programming but procedural way, opted for Phalcon to wrap my head around in OOP as well this great framework. Been reading a lot about oop and stuff including design pattterns, fancy programming terminology etc..
So here is a task I need to to , made a small application which needs to send out notification regulary on following basis until its completed.
- Daily
- Weekly
- Monthly
So, a table with lastRun and status of completion is made. Keeping it simple, have plan to check notification those are NOT COMPLETED and on the basis of lastRun , notification will be sent out.
Now need to know correct way to do it in Phalcon.
I made a controller "CronController.php" where indexAction() run query to pull out data of pending notificaitons.
It has following so there is no output when its executed:
$this->view->setRenderLevel(
View::LEVEL_NO_RENDER
);
That data now need following operation: Find type of Run ie. daily , weekly, monthly Check lastRun time, if daily ,then if not sent out in last 24 hours, SEND It. if Weekly, not sent out in last 7 days, days, SEND it. if Monthly, not sent out in last 30 days / month , SEND it.
And then update lastRun time with current time. Ofcourse, it will need some validation if notification was successful , only then update lastRun etc.
I am tempted to use switch / case to carry it out. But I feel that I guess there could be some classy OOP way to do it. If its overkill then still want to know it. Need to know what way to do in Phalcon , should I add another method in CronController.php , but that would be bad as Phalcon associate it with someAction. Should I carry out above logic in another library file and use results here ?