I'm writing a customer portal plugin that will have 3 types of users.
- Organization members
I would like to use Craft's built in UserRecord for front end login, backend management, ..?, and extend it to handle these three user types.
The way I have it set up so far, is that I have a proxy user record, which handles the relations to the organization profile and user profile records. Below I have listed the relevant attributes/keys and relations for each of the records:
Acts as a middle man between the Craft UserRecord and the two records further below.
id craft_user_id organization_id (# | null if private user) user_id (# | null if organization) 'craft_user' => array(static::BELONGS_TO, 'UserRecord', 'craft_user_id'), 'organization_profile' => array(static::HAS_ONE, 'MyPortal_OrganizationProfileRecord', 'proxy_user_id'), 'user_profile' => array(static::HAS_ONE, 'MyPortal_UserProfileRecord', 'proxy_user_id'),
id proxy_user_id contact_user_id 'proxy_user' => array(static::BELONGS_TO, 'MyPortal_ProxyUserRecord', 'proxy_user_id'), // Organization members: 'user_profiles' => array(static::HAS_MANY, 'MyPortal_UserProfileRecord', 'organization_id'), // Contact user: 'contact_user' => array(static::HAS_ONE, 'MyPortal_UserProfileRecord', 'organization_id'),
Handles both private users and organization members.
id proxy_user_id organization_id (# | null if private user) 'proxy_user' => array(static::BELONGS_TO, 'MyPortal_ProxyUserRecord', 'proxy_user_id'), 'organization' => array(static::BELONGS_TO, 'MyPortal_OrganizationProfileRecord', 'organization_id'),
- Is it possible to extend the Craft UserRecord itself with the necessary attributes and relations to handle the OrganizationProfileRecord and the UserProfileRecord, and ditch the proxy user record? If so, how do I do that?
- If not possible, should I structure my records and relations differently than I have done so far?
- Are there any pitfalls I should be vary of?
Please let me know if I should provide any further information! :)
Many thanks in advance for any help you can provide! bowing