0

I have a blog with pages of two types:

  1. Opened pages - everyone can view the page
  2. Closed pages - only followers of the page can view the posts

A follower of a page can be a single user or a group of users. A group can contain single users or a group of users.

How can I query my database in a way that I know if user X can view post Y?


My database is a MySql DB, and I have these tables:

1 entities

  id : type : time_created
  1       1            ...
  2       1            ...
  3       2            ...
  4       2            ...
  5       3            ...
  6       3            ...
  7       4            ...
  8       4            ...
  9       3            ...

2 types

 id : value
  1   post
  2   user
  3   group
  4   page

3 pages

 id : page_id : is_closed : title
  1         7   false       "mordi"
  1         8   true        "cool"

4 entity_relationships

  id : id_one : relationship : id_two
   1        1   "part_of"          7
   2        2   "part_of"          8
   3        3   "member_of"        5
   4         5  "member_of"        6
   5         6  "member_of"        9
   6         9  "follower_of"      8

I need to find that user with entity id 3 can view post with entity id 2 because 3 if a member of group 5 which is a member of 6 which is a member of 6 which is a member of 9 which is a follower of page 8 (a closed page) which post 2 is part of..

Thank you!

Strawberry
  • 33,750
  • 13
  • 40
  • 57
mordicool
  • 29
  • 5

0 Answers0