一些背景:
Agame
属于 a round
,
Around
属于 a season
,
Aseason
属于 a competition
Acompetition
是无主的。
我们有八张桌子
名称 => 列
`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)
- 可以
direct
访问游戏 1 - 可以
parent
访问第 1 轮 - 可以
parent
在第 1 季访问 - 可以
parent
参加比赛 1
- 仅与游戏 1 相关联:
- 用户 2
- 与第一轮相关:
user_round (user_id:2, round_id:1)
- 可以
child
访问游戏 1,2 - 可以
direct
访问第 1 轮 - 可以
parent
在第 1 季访问 - 可以
parent
参加比赛 1
- 与第一轮相关:
- 用户 3
- 与第一轮相关:
user_round (user_id:3, round_id:1)
- 拥有用户 2的所有访问权限
- 链接到游戏 2:
`user_game (user_id:3, game_id:2)。 - 可以
direct
访问游戏 2 - 还与第 13 场比赛有关:
user_game (user_id:3, game_id:13)
- 可以
direct
访问游戏 13 - 可以
parent
进入第 7 轮 - 可以
parent
访问第 3 季 - 可以
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
)
)
);