Search code examples
phpzend-frameworkomeka

Omeka: Get all items in Controller


I'm writing an Omeka Plugin and wants to get the list of all public Items with their all elements, in a controller under my plugin.

I've tried get_items() but the function doesn't exists, it looks like the function is only available for the views - not sure how.

another try was to manually fetch the records from database, but that's not a standard way.

So, the question is, is there a predefined function/class or way to get all the items in a controller?


Solution

  • I'm not sure if there is a function that will get you the items along with all of their element texts, but if you want a list of items, inside the controller you should be able to make a call like:

    $items = $this->_helper->db->getTable('Item')->findAll();
    

    The Omeka docs warn against getting all the items at once because it could be memory intensive. So, alternatively, you can loop through items.

    $items = $this->_helper->db->getTable('Item');
    $item = $items->findFirst();
    while($item != NULL){
        // Do something
        $item = $items->findNext($item);
    }
    

    There is a "public" property on an item that tells you if it's public. In order to get the element texts for an item, I think you'd have to make a query on the ElementText table.

    For more information, see the Omeka read the docs page for Table_Item, Omeka_Db_Table and Item:

    http://omeka.readthedocs.io/en/latest/Reference/libraries/Omeka/Db/Table.html http://omeka.readthedocs.io/en/latest/Reference/models/Table/Item.html http://omeka.readthedocs.io/en/latest/Reference/models/Item.html