1

I've just created a module that concerns books (add book, edit books, etc). Of course the administrator can use it, but I want to allow users that are connected to use it as well. But with condition on uid like so:

  • User1: add book 1, book 5, book 7
  • User2: add book 3
  • ...

The administrator can see all books (1,3,5,7) (that's done). But user1 (which is not superuser user/1 ...) has to only see his/her books (1,5,7), and similar for user2.

I'm sure I have to add a condition on my current module like:

if (uid = current user id) then show only user1's books)

But how to do that?

I know that the table "node" contains both informations of user id and nid (all books).

Note: I want to do that without using the Views module.

  • please show some code so we know what and where code might be appropriate – Geoff Jun 29 '15 at 19:51
1

Have a look at the Node access user reference modules (with about 4,3K reported installs ...), available for both D6 and D7.

Some details from its project page:

Gives content access permissions to users for content that references the users with User reference or Entity reference.

This is great if you want your content authors to be able to choose additional authors, or choose who can view their content, as well as being able to display the list of authors or viewers within your content, or in views displays.

The above details seem to me like a perfect solution to answer your question. So either just use this contributed module in combination with your own module, or use it a inspiration about how you should enhance your own module in combination with User reference or Entity reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.