I need some help creating a function that listens for events and then does something everytime an event happens. For example in my application, users can add subscriptions that have due dates.
public function add()
{
$subscription = $this->Subscriptions->newEntity();
if ($this->request->is('post')) {
$subscription = $this->Subscriptions->patchEntity($subscription, $this->request->data);
if ($this->Subscriptions->save($subscription)) {
$this->Flash->success(__('The subscription has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The subscription could not be saved. Please, try again.'));
}
}
$users = $this->Subscriptions->Users->find('list', ['limit' => 200]);
$this->set(compact('subscription', 'users'));
$this->set('_serialize', ['subscription']);
}
Everytime a user adds a subscription, I want my web server to be watching the current date and if there are subscriptions for that due date I want it to fire a function such as echoing out some data. I was thinking of trying and creating an array that holds the subscriptions ID in the database and the due date and iterating over that array over and over again but that would pose some problems it being an infinite loop. Any ideas on how to implement something like this?