I am not sure you can formally have a 1:1 relation between sf_guard_user and demandeur, or sf_guard_user and entreprise, as it is possible to have 0:1 in each case. However this may not stop it working.
I would add a "type" in sf_guard_user_profile to determine whether a user is a demandeur or an entreprise. Then, in your myUser class, which should extend sfGuardSecurityUser, you can do something like:
- Code: Select all
public function getUserType()
{
return $this->getProfile->getType();
}
In your action you would then do:
- Code: Select all
public function execute($r)
{
switch ($this->getUser()->getUserType())
{
case PROFILE_PEER::TYPE_DEMANDEUR:
// Doctrine code to limit your select by demandeur
break;
case PROFILE_PEER::TYPE_ENTREPRISE:
// Doctrine code to limit your select by entreprise
break;
default:
// Doctrine code to return null result set
}
}
Put in a suitable child Doctrine class for PROFILE_PEER - I am not sure what to put here, as I use Propel not Doctrine! But I am sure you can work that out. They just need to be constants so you can tell the difference between the two items.
You will also need to be able to recall the id_demandeur or id_entreprise for a user at any time. This could be done inside myUser again, with a new function, or do as I do and read it upon logon and store it in a persistent user attribute.