【发布时间】:2013-01-30 23:24:08
【问题描述】:
一些背景:
一个game属于一个round,
一个round 属于一个season,season 属于 competitioncompetition 是无主的。
我们有八张桌子
名称 => 列
`games` => `id`, `round_id`,
`rounds` => `id`, `season_id`,
`seasons` => `id`, `competition_id`,
`competitions` => `id`,
----
`user_game` => `user_id`, `game_id`,
`user_round` => `user_id`, `round_id`,
`user_season` => `user_id`, `season_id`,
`user_competition` => `user_id`, `competition_id`
所以,前四个表将不同的部分链接在一起,
后四个表将用户链接到相应的部分。
一些虚拟数据,注意当第二个 id 发生变化时我已经拆分了表格以便于阅读。
前四张表
/--GAMES--------------\ /--ROUNDS-------------\
| id | round_id | | id | season_id |
| 1 | 1 | | 1 | 1 |
| 2 | 1 | | 2 | 1 |
|----|----------------| | 3 | 1 |
| 3 | 2 | |----|----------------|
| 4 | 2 | | 4 | 2 |
|----|----------------| | 5 | 2 |
| 5 | 3 | | 6 | 2 |
| 6 | 3 | |----|----------------|
|----|----------------| | 7 | 3 |
| 7 | 4 | | 8 | 3 |
| 8 | 4 | | 9 | 3 |
|----|----------------| |----|----------------|
| 9 | 5 | | 10 | 4 |
| 10 | 5 | \---------------------/
|----|----------------|
| 11 | 6 | /--SEASONS------------\
| 12 | 6 | | id | competition_id |
|----|----------------| | 1 | 1 |
| 13 | 7 | | 2 | 1 |
| 14 | 7 | |----|----------------|
|----|----------------| | 3 | 2 |
| 15 | 8 | | 4 | 2 |
| 16 | 8 | \---------------------/
|----|----------------|
| 17 | 9 | /--COMPETITIONS-------\
| 18 | 9 | | id |
|----|----------------| | 1 |
| 19 | 10 | | 2 |
| 20 | 10 | \---------------------/
\---------------------/
下面的列表最好地解释了接下来的四个表
用户:
-
用户 1
- 仅与游戏 1 相关联:
user_game (user_id:1, game_id:1) - 在游戏 1 上拥有
direct访问权限 - 在第 1 轮拥有
parent访问权限 - 在第 1 季有
parent访问权限 - 在比赛 1 上有
parent访问权限
- 仅与游戏 1 相关联:
-
用户 2
- 链接到第一轮:
user_round (user_id:2, round_id:1) - 拥有
child游戏 1,2 的访问权限 - 在第 1 轮有
direct访问权限 - 在第 1 季有
parent访问权限 - 在比赛 1 上有
parent访问权限
- 链接到第一轮:
-
用户 3
- 链接到第一轮:
user_round (user_id:3, round_id:1) - 拥有用户 2 的所有访问权限
- 链接到游戏 2:
`user_game (user_id:3, game_id:2)。 - 在游戏 2 上拥有
direct访问权限 - 还链接到第 13 场比赛:
user_game (user_id:3, game_id:13) - 在第 13 场比赛中拥有
direct访问权限 - 在第 7 轮拥有
parent访问权限 - 在第 3 季有
parent访问权限 - 拥有
parent参加比赛 2 的访问权限
- 链接到第一轮:
所以,当获取上述三个用户的访问权限时,我希望得到这三个数组,
请注意:parent_access:用户拥有部分访问权限,就像访问子对象一样(无论是什么对象)direct_access:用户拥有直接授予的完全访问权限child access:用户拥有作为父对象的完全访问权限(无论是什么对象)已被授予直接访问权限
用户 1
$user1 = array(
'games' => array(
[1] => array(
'id' => 1,
'parent_access' => false,
'direct_access' => true,
'child_access' => false
)
),
'rounds' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
)
),
'seasons' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
),
'competitions' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
)
);
用户 2
$user2 = array(
'games' => array(
[1] => array(
'id' => 1,
'parent_access' => false,
'direct_access' => false,
'child_access' => true
),
[2] => array(
'id' => 2,
'parent_access' => false,
'direct_access' => false,
'child_access' => true
)
),
'rounds' => array(
[1] => array(
'id' => 1,
'parent_access' => false,
'direct_access' => true,
'child_access' => false
)
),
'seasons' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
),
'competitions' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
)
);
用户 3
$user3 = array(
'games' => array(
[1] => array(
'id' => 1,
'parent_access' => false,
'direct_access' => false,
'child_access' => true
),
[2] => array(
'id' => 2,
'parent_access' => false,
'direct_access' => true,
'child_access' => true
),
[13] => array(
'id' => 13,
'parent_access' => false,
'direct_access' => true,
'child_access' => false
)
),
'rounds' => array(
[1] => array(
'id' => 1,
'parent_access' => false,
'direct_access' => true,
'child_access' => false
),
[7] => array(
'id' => 7,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
)
),
'seasons' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
[3] => array(
'id' => 3,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
)
),
'competitions' => array(
[1] => array(
'id' => 1,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
),
[2] => array(
'id' => 2,
'parent_access' => true,
'direct_access' => false,
'child_access' => false
)
)
);
【问题讨论】:
-
关于我的尝试,我能想到的任何事情都涉及从所有八个表中获取每一行,并遍历每个
user_*表并构建矩阵,这些表中的每一行不是user_game行循环遍历所有较低对象以将child访问标志添加到该对象,但是我的上帝,这是很多循环!还有很多代码要与我的问题一起发布,因此我没有展示我的尝试! -
另外,看看那些假数据表,我想没有多少人会说我没有在我的问题上付出足够的努力;)
标签: php mysql matrix parent-child access-control