PodioItem::Update - updating an Embed Field...

Answered

Comments

10 comments

  • Andreas Haugstrup Pedersen

    Hi Patrick,

    ->set_value() can't actually take a PodioEmbed object as an argument. I should probably make that work...

    Anyway, your problem is that you have to create an embed before you can attach it to an item. Conceptually it works the same as files. You must first upload the file/create the embed to get a file_id/embed_id and then use that id when setting the item field value.

    So in your case:

    // Create the embed:

    $embed = PodioEmbed::create(array('url' => 'http://example.com/'));

    // Pretend $item holds a PodioItem instance

    $item->field('organizationlink')->set_value(array('embed' => $embed->id, 'file' => $embed->files[0]->));

    // I'm not actually sure you can use that shorthand for grabbing the file_id of the first file of the embed, but I'll let you figure that out :)

    It's on my very long list of things to do to create more comprehensive tutorials for working with items and item fields, but there's just been so many other things. I hope you like the new navigation and chat :)

    /Andreas

    0
    Comment actions Permalink
  • Patrick Steil

    Ok, I got this to work finally:

    
    
    
    
    $attributes = array( 'url' => 'http://www.infranet.com' );   
     $embed = PodioEmbed::create( $attributes );  
     $attribute['embed']['embed\_id'] = $embed->embed\_id;  
     $attribute['file']['file\_id'] = $embed->files[0]->file\_id;   
    $this->orgItem->field('organizationlink')->set\_value($attribute);
    
    
    
    
    

    I feel like I just cheated and created my own data structure to meet the needs of the set_value() code... I wish I could have just passed in the $embed object like this:

    
    
    
    
    $attributes = array( 'url' => 'http://www.infranet.com' );   
    $embed = PodioEmbed::create( $attributes );  
    $this->orgItem->field('organizationlink')->set\_value($embed);
    
    
    
    
    

    Can set_value() be enhanced to support this?  Would make a lot more sense... :)  I tried to get it to do that, but didn't understand enough about the PodioItemField class to be able to get it to work... 

    Now my other bigger problem is that the above code ONLY works if the "organizationlink" field ALREADY has an "embed" object specified in the Podio Item...  so in effect my code above works as an "update" to that field, but if I remove the "embed" object from the Item and then run my code I get this error:

    
    
    
    
    **Fatal error**: Call to a member function set\_value() on a non-object in **C:\git\podiohelpdesk\helpdesk\libs\PTOrganization.class.php** on line **292**
    
    
    
    
    **```**
    
    which is pointing to this line of code:
    
    

    $this->orgItem->field('organizationlink')->set_value($attribute);

    
    I think this is something that set\_value() should take care of... ?
    
    Thanks... 
    
    0
    Comment actions Permalink
  • Patrick Steil

    Sorry, was trying to figure out how to use "block quotes" in Zen markdown... according to their site I used the same character they said to use... is it supposed to be a single quote?  I used the angled quote that is on the key next to the "1" key... which is what they showed on their website:  https://support.zendesk.com/entries/21714462

    0
    Comment actions Permalink
  • Patrick Steil

    '''

    last test

    '''

    0
    Comment actions Permalink
  • Patrick Steil

    Oh and the chat system is sweet!    

    ' Great job... 

    0
    Comment actions Permalink
  • Patrick Steil

    Andreas, just a reminder on this one and I also have the same question about how to use set_value for a Contact type field... thanks... 

    Patrick

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Hi Patrick,

    I made some changes to podio-php that should make your life a bit easier. Easy part first: When you have a PodioItem and you want to add a new field to it that didn't previously have a value. You then need to 1) Create a new PodioItemField and 2) add that object to the fields collection. It was a little annoying to write the example so instead I wrote some convenience methods for adding and removing fields. See example at https://github.com/podio/podio-php/blob/master/examples/items.php#L110-L112 (see the highlighted lines)

    Secondly, this sample of yours:

    $attributes = array( 'url' => ' http://www.infranet.com' ); 

    $embed = PodioEmbed::create( $attributes );

    $this->orgItem->field('organizationlink')->set_value($embed);

    Should work now if you pull a fresh copy of podio-php. It's only for embed fields right now but I'll get it done in a similar way for contact, app, image etc. fields as well.

    /Andreas

    0
    Comment actions Permalink
  • Patrick Steil

    Very cool Andreas!  Thanks!  

    I do still need a sample of how to set_value for a contact field, thanks!  :)

    0
    Comment actions Permalink
  • Patrick Steil

    Andreas,

    I have now been able to update the "organizationlink" field as I desired, thanks!

    A side issue that popped up:

    I am not sure if I missed that I was getting this error before ( This code was working before) but now when I do the following:

    $field = new PodioAppItemField($field_id);

    $field->set_value($reference_to_item_id); // The item to add a reference to

    $obj = PodioItemField::update($item_id, $field_id, $field->as_json(false));

     

    on the set_value() call I am getting this error:

    Warning: Cannot use a scalar value as an array in C:\git\podiohelpdesk\helpdesk\libs\PodioApiV3\models\PodioItemField.php on line 79 

    I report it here only because maybe this is a side effect of the changes you made last night?

    I am trying to set an app reference... also, should there be an PodioAppReferenceItemField class?

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Nothing changed in that part of the code so you would have gotten the error before my latest changes as well. You have probably only been passing in blank values so far. Anyway, wrap the argument in an array:

    $field->set_value(array($reference_to_item_id));

    Same for contact fields: Pass in an array of profile ids

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk