でアプリケーションを扱う、メンバーとして考えられている 。他のユーザーはゲストです。基本的にはZend Frameworkの - 私はすべての登録ユーザーが<strong>ユーザー</strong>、そしてチームを持つユーザーとして考えられているアプリケーションで個別のユーザーとメンバーの扱い方を思っていたユーザーやメンバー
、シンプルなユーザーチームの要求を受け、チームを見つけることができる、などのメンバーは、彼のチームのプロフィールを参照してください他のメンバーを見て、メンバーと彼のチームに比べて、より多くのことを行うことができます。
現在、ユーザー、メンバーとチームは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.
..........
}
あなたが見ることができるように、このクラスを以下のように
は、だから、私は、データベース内の3つのテーブルを持っています私のデータベースのフィールドに非常に "スティック"ですが、私はそれがそれを行うための最善の方法かどうかわかりません。
マイメンバーモデルは、それが「team_users」テーブルを表し、それはセット/ getMembersメソッドを持っていますが、メンバーに対するメソッドを持っていないことを除いて、基本的には同じものです。
このようなことを管理するのがどれほど難しいか理解しています。メンバーを取得するたびに、ユーザーがチームを持っているかどうかを確認する必要があります。もしそうなら、getMember()
などを使用してメンバーインスタンスを作成します。 。
first_name
のようなメンバーについての情報を得ることは難しいですが、私はいつもuser_id
をチェックし、ユーザーインスタンスを作成して彼のfirst_name
を取得する必要があります。
どのように私はこの種のものを扱うことができますか?メンバーはユーザーでもあるため、メンバーモデルはユーザーモデルを拡張する必要がありますか?いいアイデアですか?どうしますか?
ありがとうございます。
関連性のない - 作成したモデリングソフトウェアとは何ですか? –
MySQL Workbench;) –
ああ、それは試したことはありません。今すぐダウンロードしてください。ありがとう! –