I fetch data from podio CRM using PHP language and I fetch data for each element via its id as it is found in this function:
public function getContacts($item_id) {
$this->contactAuth();
$item = \PodioItem::get_by_app_item_id($podio_contact_app_id,$item_id);
return $item;
}
For example we have the 'Status' we show it like this:
$status = $item->fields[6]->values;
Not all elements get it right though it is the same function.
Sometimes :
$status = $item->fields[6]->values;
and sometimes :
$status = $item->fields[8]->values;
Can we know what caused the problem?
If some fields are empty they will not be presented in the PodioItem object, that is why the position of a particular field in the array may vary (like a Status field in your example).
So instead of using a field index (which may vary), you should get the value from a field by field's External ID (a human readable name like 'title', 'status' etc) or Field ID (a numeric code):
$item->fields['title']->values // 'title' is an External ID
$item->fields->get(123456789)->values // 123456789 is a Field ID
To know what External ID and Field ID are for a particular field you can list all fields like this:
// Iterate over the field collection
foreach ($item->fields as $field) {
// You can now work on each individual field object:
print "This field has the id: ".$field->field_id;
print "This field has the external_id: ".$field->external_id;
}
Or you can see developer's info on all fields right in Podio in App menu → Developer
And anyways, check the Podio PHP wrapper documentation at https://podio-community.github.io/podio-php/items/ it is pretty useful:)
Related
I am asking for following details from user in form:
Product name:
product Price:
Product URL:
The user can add multiple items in cart. During checkout, I want to filter URL like if user enter below multiple URL in the form and these multiple url's will be inserted in products table.
aliexpress.com/product/phone_cover
aliexpress.com/product/phone_battery
nike.com/cat/shoes
In this case I want to get host (Domain) of URL like:
aliexpress.com
nike.com
and add once in the database store table.
For example, user added 2 URLs from aliexpress and one for nike so I want to store one time aliexpress and one time nike in store_url column of store table in database.
I am getting host URL by the code below:
foreach ($data as $show)
{
$var= parse_url($show->produst_url);
echo $var['host'];
}
below are database tables
-------- -------
products store
-------- -------
id id
product name products_id
product url store url
product price
Any help is appreciated. I have tried my best to explain you my problem but if you still need some more detail I will be happy to explain you more. Thanks
Well there are many ways to do this and this is just one of them...
Your primary question is - how do you save unique entries?
This is just some sample code, based upon what you provided with debug so I could see how it was working as I developed it. There is NO Database "stuff" as you haven't provided any information regarding it, so it's just a starter to get you going.
// Create some dummy test data as per the provided code.
$data[] = (object)array('produst_url' => 'http://aliexpress.com/product/phone_cover');
$data[] = (object)array('produst_url' => 'http://aliexpress.com/product/phone_battery');
$data[] = (object)array('produst_url' => 'http://nike.com/cat/shoes');
var_dump($data); // Check the test array
$host_array = array(); // Init the array to store the host values
foreach ($data as $show) {
$var = parse_url($show->produst_url);
var_dump($var); // Check the $var array
$host = $var['host'];
// Save the host name in the host_array ONLY if it hasn't already been saved.
if ( ! in_array($host, $host_array)) {
$host_array[] = $host;
}
echo $host; // show the host name
}
// Check the final $host_array
var_dump($host_array); // What does the final answer look like?
The final var_dump ,var_dump($host_array), reveals...
array (size=2)
0 => string 'aliexpress.com' (length=14)
1 => string 'nike.com' (length=8)
Not sure if produst should be product but I kept it as you had it. At least it is consistent.
So now you have an array of unique host names. Next you have to save them into the database IF they are not already there, to prevent duplicates.
As you have not provided any insight into your database/table setup,that part should be another question if you are unsure on how to do that.
I've been searching for this solution but haven't found one! I'm using Novak solution's Infusionsoft API.
What I'm trying to do is to get value of a custom field for specific contact. Lets say, I've a custom fields named _myCustomField with Yes/No value. I've 200 contacts in my list but only 15 contact has value 'Yes' for _myCustomField. Lets say I've another custom field _myCustomField2. If I run following query:
$contacts = Infusionsoft_DataService::query( new Infusionsoft_Contact(), array('_myCustomField' => '1') );
I get an array of 15 records, BUT if I print $contacts array then I don't see _myCustomField or _myCustomField2 there.
So, how do I get value for those two custom field inside my loop? Can someone help me with this?
Thanks!
The second parameter of the query method is only the filter and does not tell Infusionsoft that you also want to return any custom fields.
You will want to add the custom fields first:
$contact = new Infusionsoft_Contact();
$contact->addCustomField('_myCustomField');
$contact->addCustomField('_myCustomField2');
$contacts = Infusionsoft_DataService::query( $contact, array('_myCustomField' => '1') );
I'm creating an autocomplete in Laravel 4 using twitter typeahead, but I'm having problems in the matching process.
The JS code:
$('#autocomplete').typeahead({
limit: 20,
name: 'destinatari',
prefetch: '{{URL::to("alumni/posta/utenti")}}',
remote: '{{URL::to("alumni/posta/utenti")}}'
});
The model populates the array like this:
public static function jsonList($idLogged)
{
$users = DB::table('users_data')
->where('userid', '!=', $idLogged)
->select('nome', 'nome_2', 'cognome', 'cognome_2', 'userid')
->orderBy('cognome', 'asc')
->orderBy('nome','asc')
->get();
$i = 0;
$ordered = array();
foreach($users as $u) {
$ordered[$i]['value'] = $u->nome.' '.$u->nome_2.' '.$u->cognome.' '.$u->cognome_2;
$ordered[$i]['tokens'] = array($u->nome, $u->cognome);
$ordered[$i]['userid'] = $u->userid;
$i++;
}
return $ordered;
}
And my controller simply:
return Response::json( Users::jsonList($this->userdata->id) );
The returned json (I see it in Firebug) looks like:
[{"value":"Silvia Miriam Abeyta Carretero","tokens":["Silvia","Abeyta"],"userid":"246"},
{"value":"Malak Julia Abreu Garrido","tokens":["Malak","Abreu"],"userid":"198"},{"value":"Aina Aguado ","tokens":["Aina","Aguado"],"userid":"243"},
{"value":"Jordi Alarc\u00f3n ","tokens":["Jordi","Alarc\u00f3n"],"userid":"308"},
{"value":"Aaron Nerea Alejandro ","tokens":["Aaron","Alejandro"],"userid":"49"},
{"value":"Alexia Alem\u00e1n ","tokens":["Alexia","Alem\u00e1n"],"userid":"306"},
{"value":"Salma Almaraz ","tokens":["Salma","Almaraz"],"userid":"54"},
{"value":"Alma Almonte Nev\u00e1rez","tokens":["Alma","Almonte"],"userid":"101"},
{"value":"Daniela Almonte ","tokens":["Daniela","Almonte"],"userid":"184"}
,....other similar results....]
The problem is that any letter I type only the first name in the list gets autocompleted ("Silvia Miriam Abeyta Carretero") in the input field, but when I type out in full any other name (say, "Daniela Almonte") the field isn't completed and the dropdown keeps showing the whole 20 results, without processing of any kind.
I must say, though, that if I click on a name it gets selected correctly (I'm logging the userid property of the datum ), but still the autocompletion isn't working.
What puzzles me is that If I copy/paste the whole list directly in the JS (taken as is from Firebug), as local property of typeahead() (instead of remote), everything works fine as it should.
What could be causing this? Is it a Laravel response problem? Or is it the typeahead processor (I believe it's in "transport.js" source file, uses jQuery $.ajax()) of the remote url?
It seems like the returned JSON is considered as a single entry, i don't know why since it looks correct to me...
From the typeahead documentation:
$('input.twitter-search').typeahead({
name: 'accounts',
prefetch: 'https://twitter.com/network.json',
remote: 'https://twitter.com/accounts?q=%QUERY'
});
As you can see, the remote parameter must contains the URL with the query parameter.
PHP side, you have to test if the parameter "q" is set and then adapt your request (with a LIKE statement by example) to correctly filter the list.
Otherwise, you can try to remove this remote parameter, maybe it would work with only the prefetch attribute.
I'm looking for a simple example of some code showing how to use jquery autocomplete with ids and values, json and php, but I can't find any. Basically I have a list of employee names in a database, they have an id and a name. I would like to display the name, but use the id in a hidden field in my form submission. I would like to provide the list of names via php and json ajax. I would also like to use the feature where you have to enter say 3 characters before it shows the autocomplete, since it is a very long list of employee names. Not sure whether you have to pass the 3 characters to the php as a parameter for this.
I'm a noob so a simple example would really be appreciated.
Thanks
There are great examples here at jQuery UI:
http://jqueryui.com/demos/autocomplete/#remote
Click the view source button below the example to get a look at the Javascript side of things. Note the parameters for "source" (this is the path to your PHP script delivering results) and "minLength." Setting the minLength property to 3 will take care of the second part of your question.
As far as the remote side the results need to be in JSON format so you can query your data from the database, get it as a PHP associative array and then use the json_encode() method to put it into a format that the autocomplete plugin can read. The autocomplete implementation in their example sends a querystring variable, "term", to the source file containing the search string input by the user.
This example expects JSON results from the server to be in this format:
[ { "id": "Branta hrota", "label": "Pale-bellied Brent Goose", "value": "Pale-bellied Brent Goose" }, ...]
So the PHP source page could deliver results by using code like this:
// source.php (or whatever path you used for the autocomplete "source" setting)
// Sanitize your input!
$term = mysql_real_escape_string( $_GET['term'] );
$results = mysql_query( "SELECT * FROM employees WHERE name LIKE '%{$term}%' "); // Grab your data
$output_array = new array();
while ( $row = mysql_fetch_assoc( $results ) ) {
$output_array[] = array(
'id' => $row['id']
, 'label' => $row['name']
, 'value' => $row['name']
);
}
// Print out JSON response
echo json_encode( $output_array );
So that's all untested pseudocode, but it should point you in the right direction.
I am working with a CMS like system, phpBMS, which defines a certain way of making forms, and defines the form elements to be used in such forms.
This is an example of the form template, and these are the fields that are defined.
Generally, it is pretty simple. If you have an inputField with the id of say, 'name', the content of that field will be saved to the name field in the table the form is assigned to.
Currently, I am using a different input field, inputSmartSearch, which works a bit like google suggest as it can search and automatically display results as you type.
I want to use the content of this field to go into a 'product' table, but I am unsure of how to set this up.
I am calling my smartsearch like so:
$theinput = new inputSmartSearch($db, "chooseproducts", "Choose Product",$therecord["product"], "Choose Product", TRUE, NULL, NULL, TRUE, $required=true);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
When I look what is returned by _POST, I see:
Array ( [chooseproducts] => 75c72a6a-83d9-11df-951a-fa9c1ec271f2 [ds-chooseproducts] => Corona [quantity] => 2 [type] => cash)
I have setup the quantity and type fields like so
$theinput = new inputField("quantity",$therecord["quantity"],"Quantity",true, NULL, 1);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$theinput = new inputBasicList("type",$therecord["paymenttype"],array("Cash"=>"cash","Credit"=>"credit"), "Payment Type");
$theinput->setAttribute("class","important");
$theform->addField($theinput);
The content of the type and quanitity fields get insert into the database perfectly, but absolutely nothing gets inserted from the smartsearch field.
Why? How would I start to troubleshoot this?
I think in this case you would need to manually add this value to the array that is persisted to the database. So:
$variables["product"] = the value you want
So if you san. To persist the name assign Ds-chooseproducts. If you want to persist the id then use chooseproducts from the array.