How do you get the value of a "embed"? - podio

I have a link field called lien. When I get it from the API through the Item it belongs to, I receive the following array:
[lien] => Array(
[0] => Array(
[embed] => 49935230
[file] => 129256002
)
)
I have no problem with the file.
How do you get the URL value?
The Embeds documentation: https://developers.podio.com/doc/embeds
A similar issue exists when getting the value of a category field through the Item object. It's an array of the selected option_id, it doesn't hold the option_text. The workaround is to get the corresponding App object and search for the option_text using the provided option_id.

The field's values are returned as a collection of embed objects. You can see documentation at: http://podio.github.io/podio-php/fields/#linkembed-field
E.g.:
$item = PodioItem::get_basic(123);
$field_id = 'embed';
$collection = $item->fields[$field_id]->values;
foreach ($collection as $embed) {
print "Embed id: ".$embed->embed_id;
print "Embed URL: ".$embed->original_url;
}

Related

yii2 name field attribute using variable

I'm trying to create in an activeform a series of controls using a loop for not being to declare the various fields of the model in order to have a generic template to which I pass only the name of the table and it creates the edit form.
So that if I pass the table A and it has 3 fields it creates three fields, the b has 5 fields it creates 5 fields etc etc.
$tfields= Array ( [0] => id [1] => brand_id [2] => group_id)
and i create this code
foreach($tfields as $key => $value) {
if (strlen($value)>0){
echo $form->field($model, $value)->textInput();
}
}
but when i run the code i get this error
Calling unknown method: yii\data\ActiveDataProvider::isAttributeRequired()
any ideas?
tks a lot!
the problem was tha i use an ActiveDataProvider as model, using instead and DynamicModel
in the controller
$model2= new \yii\base\DynamicModel([
]);
in the form
foreach(explode(',',$fields) as $item){
if (strlen($item)<>0){ //to avoid empty
echo $form->field($model2, $item)->textInput();
}
}

Filter Podio Items by Item ID

I'm having a bit of an issue getting a collection of Podio items from an app by item ids.
According to this post, Andreas said that "... you can now filter by item_id (and app_item_id). Just use item_id or app_item_id as the filter key and give it an array of item ids ...".
So I'm trying to get a bunch of items in one shot to reduce API calls with:
$attributes = ["filter" => [
"item_id" => [12345,23456]
]];
$items = PodioItem::filter( $app_id, $attributes );
But I'm always getting all items back from the app, not just the 2 items listed in the filter.
Anyone come across this anomaly before? Workarounds?
You are passing the $attributes array in the wrong format.
You have to pass it in filters array like,
$attributes = ["filters" => [
"item_id" => [12345,23456]
]];
$items = PodioItem::filter( $app_id, $attributes );
You will get back only the mentioned items [12345,23456].

Collecting a referenced app's values

I am trying to cleanup and optimize my come I am running on podio's API. What I am currently doing is using the filter query to return a collection from one app. I then loop over that collection. On each item I use Podio get_field_value to return the value(s) of a field in a referenced app. This creates a lot of API calls. I would like to retrieve everything in one API call Here is a simple version of my current code:
$collection = PodioItem::filter(WHSE_ID, array(
"filters" => array(
WHSE_EQUP_STATUS => array(2),
),
"sort_by" => WHSE_LOAD_IN,
"sort_desc" => false,
"limit" => 50
)
);
foreach ($collection as $item) {
// Table-A ID
$whId = $item->item_id;
// Referenced App Item(s)
$nucId = $item->fields[0]->values[0]->item_id;
// Get Referenced App Item Field
$app_b_value = PodioItem::get_field_value($nucId, NUC_LOAD_OUT);
echo $app_b_value;
}
Is there a more efficient way of doing this? I am thinking inline with the way you would use JOIN in a mysql query.
Thank you for any help you can provide!
if you are trying to get value from each item from filtered collection, you don't need to make podio calls each time.
Podio filter call will give you item with values. you just have to get value from each item.
like following
foreach ($podioFilterData['items'] as $itemData) {
$itemFields = $itemData['fields'];
foreach ($itemFields as $field) {
$value = $field['values'][0];
}
}

send an array variable to formtype in symfony from the controller

I have an sql request in my controller:
$results = $conn->query( " select field 1....fieldn from tableA " );
$row = $results->fetch();
I want to show the returned result $row in twig as dropdown menu list
in other word, how I can send the $row variable to the formtype to use it after that as choice field.
Try it from the other site. Create a "Form Type" and in your "Form Type" you can use an entity field and select data from your database through doctrine for example:
->add('User', 'entity', array(
'required' => true,
'class' => 'Test\TestBundle\Entity\User',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')->where('u.id > 150 and u.id < 160');
}
))
Then you should get an dropdown by default.
The class is here your entity class witch is automatically given to the query builder under that class field and you can use it.

multiple checkbox valiadation for any one in YII frame work for this example

Hi can you please tell how can i validate the multiple checkbox any one is checked in yii framework
array('accept', 'required', 'requiredValue' => 1, 'message' => 'You should select alteast one')
As these value are usually sent as arrays, I wrote an array validator for these cases once: https://github.com/schmunk42/p3extensions/blob/master/validators/P3ArrayValidator.php
Usage example:
array('accept',
'ext.validators.P3ArrayValidator',
'min'=>1,
'allowEmpty'=>false,
'message' => 'You should select at least one'
),
sorry for the late reply.
But, I found a solution without installing any extension.
Take a hidden field with the same name [Checkboxes list field].
<?php echo $form->hiddenField($model,'categories');?>
Display a list of categories with name different from our field name (multiple checkboxes).
But, remember the 'class', and play with the class to save the values.
<?php
echo CHtml::checkBoxList(
'group',
//you can pass the array here which you want to be pre checked
explode(',', trim($model->attributes['categories'], ',')),
CHtml::listData(Category::model()->findAll(),'id','name'),
array('separator'=>'', 'template'=>'<tr><td style="width:5%;">{input}</td><td>{label}</td></tr>', 'class' => 'group')
);
?>
This way validation should work also, you get category ids as comma separated e.g. [,1,2,6,]
<script>
$(function(){
$(".group").click(function(){
var str = $('.group:checked').map(function() {
return this.value;
}).get().join();
var groupCats = (str.length > 0) ? ','+str+',' : '';
$('#ModelNAME_field').val(groupCats);
// Get the 'ModelNAME_field' by viewing source of HTML of hidden field.
});
});
</script>