我想知道如何分别处理用户和会员在所有注册用户都视为用户,谁拥有一批用户应用的应用,被认为是成员 。其他用户是嘉宾。Zend框架 - 处理与用户和会员
基本上,一个简单的用户可以找到一个团队,接受团队请求等的成员都可以看到他的团队的个人资料,看到其他成员,并做了很多相对于成员和他的团队更多的事情。
目前,用户,成员和团队在三个不同的类中处理,它们都代表它们的数据库表结构。
所以,我在我的数据库3个表如下:
我有例如这个类来表示用户:
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.
..........
}
正如你所看到的,这个类是非常“坚持”我的数据库领域,我不知道这是否是最好的方式来做到这一点。
我的会员模式基本一样,只不过它代表的“team_users”表中,并没有设置/ getMembers方法,但具有相对于成员的方法。
现在,你明白管理这样的事情有多难,每次我想要一个成员,我需要检查一个用户是否有团队,如果是的话,我使用getMember()
等创建一个成员实例
从会员方面来说,很难得到关于会员的信息,例如他的first_name
,我总是需要检查user_id
,创建一个用户实例并获得他的first_name
。
我该如何处理这种事情?我在想也许我的会员模式应该扩展用户模式,因为成员也是用户?这是个好主意吗?你会怎么做?
谢谢。
无关 - 您创建的建模软件的截图与? – 2012-03-27 17:10:37
MySQL Workbench;) – 2012-03-27 17:23:04
好啊,从来没有尝试过。现在下载。谢谢! – 2012-03-27 17:31:08