Post

1 follower Follow
0
Avatar

Best way to get item details? stay in filter_by_view, or jump to get_item?

I am getting a set of items through the filter_by_view method.  Because I have several cross-app references each item in the filter_by_view array is very deep.  For example, I have a product app in another space that I reference, I have individual activities referenced from another app, and 3 fields that reference people, internal contacts, partner contacts, and customer contacts.  Regardless, 5 different reference fields with multiple items, multiple revisions etc. makes the array very complex to parse.  I tried a array_keys, array_search, and array_values to recurse the item but it seems difficult.  

I'm trying to use the item_id from the filter_by_view to jump to the get_item of that item_id but I'm not sure if I'm missing something here.  Getting the item data from a new object call seems inefficient since I already have the items from the filter by view.  It just seems really hard to parse the deep array when there can be multiple instances of referenced items, contacts, products.

Am I missing something easy here? Is there an easy way to get information out of the filter_by_view output?

Roy A. Tokeshi Answered

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Roy,

The filter methods return a collection of PodioItem instances. Have you seen the examples in https://github.com/podio/podio-php/blob/master/examples/items.php and the class files for PodioItem https://github.com/podio/podio-php/blob/master/models/PodioItem.php and PodioItemField https://github.com/podio/podio-php/blob/master/models/PodioItemField.php ?

You shouldn't have to deal with the underlying arrays very much. For example if you have an item and want to grab the title of the first referenced item in the field with the external id of 'app-reference' (this could be written in fewer lines, if you want to chain the method calls):

$item = PodioItem::get($item_id);

$field = $item->field('api-reference'); // Returns PodioItemField instance when given external_id

$references = $field->items(); // Returns list of PodioItem instances

print $references[0]->title;

If you look in class file for PodioItemField you can see that app reference fields are instances of PodioAppItemField and they have a method called 'items' that will return a list of PodioItem instances for the references (similar methods are available for contact fields, image fields etc.).

Does that help?

All the best,

Andreas 

Andreas Haugstrup Pedersen 0 votes