Ownerships of objects

Hi there,

I'm using certain objects as a "base" for other objects ("instances"). Let's say the object is a book, and the instances are reviews to this book. The base-objects I retrieve from an API when a user is searching for this book on my site.

To keep the title of the book up-to-date (object->description) I want to auto-update the title with the new information from the API-call each time a user opens this base-object.

But how can I do this? Usually each object has it's owner, but in my case for other users changing the description should be possible as well. Is it possible to have a "global"-owner (the site-guid, '0') for such base-objects?

Thanks for your ideas!

  • Two possibilities:

    • Usage of container_guid: the container_guid of the review is set to the guid of the book object.
    • Relationship: created a relationship between the two entities (you could call it "review of") between review and book.
  • Thanks for the reply. Of course, to get the "connection" between book and review it is possible to deal with containers or relationships. But I want to change the description of the book (not the review), even if I'm not the owner of it (and as "a" user I'm an admin neither)...

  • You can disable the access control on the book entity temporarily within the review add/edit action:

    $access = elgg_set_ignore_access(true);

    $book->description = "Updated description";

    elgg_set_ignore_access($access);

    You have to assign the correct book entity to $books depending on how you implement the connection between book and review before these lines of codes. If the permission to change the book description depends on some condition, you should include these lines within an if-clause that checks this conditions.

  • Yeah, that looks good and should work for my purposes.

    Danke :)

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking