Yamen Nassif
Yamen Nassif

Reputation: 2486

How to achieve a watcher on symfony

Lets assume i have the following entities:

User

class User{
    private $id;
    private $name;
    private $active;
    private $clients;
}

Client

class Client{
    private $id;
    private $name;
    private $active;
    private $subdomain;
    private $users;
}

subdomain

class Subdomain{
    private $id;
    private $name;
    private $active;
}

With all their setters and getters, orm tables and relations. Users and Clients have many-to-many relation while client and subdomain one-to-one relation.

What i want to achieve is not to activate the client till at least one user is active and that client wont be active till its subdomain is active. Now i now that this can be done simply by creating some function and call it whenever an entity is updated and when i have all isActive() is true then i would call setActive on the desired user. But i was searching around for something like an Entity or record watcher so whenever a record is updated automatically check some fields and then update a field on that user. In other words i dont want to manually call the setActive() and checkForClientAndSubdomainActivity() functions. So is there anything like that ready built out there? or should i build it?

Thanks in advance, i cut most of the code just for the ease of read.

Upvotes: 0

Views: 157

Answers (1)

Charlie Lucas
Charlie Lucas

Reputation: 290

You can use Doctrine's events to do your operations everytime you perform an update on a specific entity (there is more events) : doc.

Upvotes: 3

Related Questions