Best way to retrieve a private record

When I try to use get_record_by_id on a private item or file, the function returns null. When I use get_record, I'm getting the first item in my database returned instead of the private item.

What's the best way to retrieve a private record?

get_record_by_id should work. It looks something like this:

$record = get_record_by_id('Item', 14123);

Note that, if you are using this somewhere in a public theme, and you are not logged in or otherwise don't have permissions for the item, returning null is what is expected for a non-public item.

Thanks patrick.

Sorry, I didn't word the question well. Our site uses the Guest User plugin. I don't need to be able to retrieve private records for guest users, but I do need some way to differentiate between private records and records that don't exist. Get_record_by_id returns null in both cases unless logged in as an administrator, so it looks like I can't use it for that purpose.

Is there any way to accomplish this that's built-in to the framework, or is a record's "privateness" always invisible unless logged in as a user with administrator privileges?

Shameless bump.


Will return the binary for whether an item is public or not, but I'm not sure how this would work for a user without permission to view a particular item.

Thanks sheepeeh.

It looks like the metadata function assumes the user has access to the record -- either because it's set as the current record (and it shouldn't be in this case, because it's a private record) or because get_record_by_id/get_record was used to retrieve a reference to the record. Since it doesn't look like there's any way for a user w/out administrator privileges to retrieve a reference to the record, I don't see how the metadata function can be used here.

I appreciate the suggestion, though!

The methods that are built-in to Omeka always filter around the permissions of the user, so anything Omeka offers will not distinguish between permissions and non-existence. That is, not having permissions to view an item will appear the same as the item not existing to the user.

To get at what you want, you'd probably have to write your own direct queries to the database, possibly modeled off of things in the Item Table.

Gotcha. Thanks patrick.