Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:42:29+00:00 2026-06-01T03:42:29+00:00

I was wondering how to handle separately users and members in an application where

  • 0

I was wondering how to handle separately users and members in an application where all registered users are considered as users, and users who have a team, are considered as members. Others users are guest.

Basically, a simple user can find a team, receive a team request, etc. A member can see his team profile, see other members, and do a lot of more things relative to members and his team.

Currently, users, members and teams are handle in three different classes, all of them represent their database table structure.

So I have 3 tables in my database as follows:

MySQL Workbench

And I have for example this class to represent a user:

class Lib_Model_Users_User implements Zend_Auth_Adapter_Interface, Zend_Acl_Role_Interface
{
    protected $_gateway;
    protected $_roleId;

    protected $_member = null;
    protected $_team = null;

    protected $_data = array(
        'user_id'       => null,
        'email'         => null,
        'password'      => null, 
        'first_name'    => null, 
        'last_name'     => null,
        'gender'        => null,
        'address'       => null,
        'city'          => null,
        'country'       => null,
        'postal_code'   => null, 
        'phone_mobile'  => null,
        'phone_home'    => null,
        'date_of_birth' => null,
        'occupation'    => null,
        'active'        => false,
        'created_on'    => null,
        'last_login'    => null,
        'last_update'   => null);

    public function __construct($data, $gateway)
    {
        $this->setGateway($gateway);
        $this->populate($data);

        if (!isset($this->user_id)) {
            if (!isset($this->email)) {
                if (!isset($this->first_name, $this->last_name))
                    throw new Lib_Exception('Initial data must contain an email or a user id or a pair firstname/lastname');
            }
        }
    }

    public function setMember($data)
    {
        $gateway = new Lib_Model_Teams_Gateway();
        $this->_member = $gateway->createMember($data);
    }

    public function getMember($status = 'active')
    {
        if (null === $this->getTeam()) {
            return null;
        }

        if (null === $this->_member) {
            $this->_member = $this->getTeam()->getMember($this->user_id);
        }

        if (is_string($status)) {
            $status = array($status);
        }

        foreach ($status as $state) {
            if ($this->_member->status == $state) {
                return $this->_member;
            }
        }
        return null;
    }

    public function getTeam($active = true)
    {
        if ($this->_team === null) {
            $this->_team = $this->getGateway()->fetchTeam($this->user_id, $active);
        }
        return $this->_team;
    }

    public function save()
    {
        $gateway = $this->getGateway();
        $dbTable = $gateway->getDbTable();
        $row = $dbTable->find($this->user_id)->current();
        if ($row) {
            foreach ($this->_data as $key => $value) {
                $row->$key = $value;
            }
            return $row->save();
        }
        $this->user_id = $dbTable->insert($this->_data);
        return $this->user_id; 
    }

    public function getRoleId()
    {
        if (null === $this->_roleId)
            $this->_roleId = $this->user_id;
        return $this->_roleId;
    }

    ..........
    // etc.
    ..........
}

As you can see, this class is very “stick” to my database fields, I don’t know if it’s the best way to do it though.

My Members model is basically the same thing, except that it represents the “team_users” table and it doesn’t have the set/getMembers methods but have methods relative to members.

Now, you understand how hard is it to manage such a thing, each time I want to get a member, I need to check if a user has a team, if so, I create a member instance using getMember(), etc.

From the member side, it’s hard to get an information about a member such as his first_name, I always need to check the user_id, create a user instance and get his first_name.

How can I handle this kind of thing? I was thinking maybe my Member model should just extends the Users model since a member is also a user? Is it a good idea? How would you do it?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:42:30+00:00Added an answer on June 1, 2026 at 3:42 am

    Model it the way the things are, regardless how your database is structured – that will turn out to work best in most cases.

    • As a member is some type of user, the Member class should extend the User class.
    • Only the Member class should have a method getTeam(), as only members have a team and normal users don’t.

    I don’t think that there really is a beautiful solution to handle your exact situation. But how about something like this?

    $user = new User($data, $gateway);
    if ($user->hasTeam()) {
        $user = Member::fromUser($user); // returns a new instance of 'Member'
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at rearchitecting an existing application and am wondering how best to handle
I'm building a web application, and am wondering how to handle errors with my
I was wondering how to handle errors inside a script that is meant to
I'm new to source control in general and am wondering how to handle the
I'm wondering if Fuel ORM can handle the design described here: http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2/normalizedSchema.gif The following
I'm trying to handle this possible exploit and wondering what is the best way
I'm wondering what are the recommended ways to handle situations where, in memory managed
I'm wondering if it's possible to get a handle on running instances of a
I am wondering if there is a way to handle this more elegantly. After
I was wondering if there was a standard way for backbone models/controllers to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.