Search code examples
doctrine-ormtreesiblingsmultiple-users

Doctrine2 - parent, children and sibling users like


after some research i'm still stuck finding a solution to my little problem! I would like to have a kind of pyramidal hirarchical structure for my users, but with a notion of 'sibling users', let me explain.

I have users like that:

the tree means only who created who, in fact both building-admin manage the same building and must see what the other have created.

legend:

b=> building, s=>service, r=>room, a=> admin (with his id)

  • b1-a1
    • b1-s1-a2
      • b1-s1-r1-a2
      • b1-s1-r2-a3
    • b1-s1-a4
      • b1-s1-r1-a5
      • b1-s1-r2-a6
    • b1-s2-a7
  • b1-a8
    • b1-s1-a9
    • b1-s2-a10
      • b1-s2-r1-a11

And my question is, how could i achieve an access on different items depending of which user i am?

Exemple:

'b1-s2-a7' should be able to see the b1-s2-r1-a11 because he's below him even if he's not in his direct tree.

also, 'b1-s1-a9' should see what was created by his 'siblings' 'b1-s1-a2' and 'b1-s1-a4'.

I have started to try with the path structure, but i would like your opinions and advices for not going in the wrong way !

Thanks by advance ;)


Solution

  • I would read the doctrine docs on hierarchical data. I used the extensions bundle and a nested set for something similar.

    Now, regarding certain users being able to see nodes. I don't think that sounds like an issue for your database manager. I think it sounds more like business logic that you can put in your code. The extensions bundle provides some nice functions for only fetching child nodes which I think you could wrap in some convenient service for your purposes.