I have an item with a referenced field to another app. A call has an assigned client.
I use this library: http://podio.github.io/podio-php/
I followed this article: http://podio.github.io/podio-php/fields/
I want to update an existing item by changing the item_id of its field that's referencing another app. The item_id already exists in the other app.
Here's what I tried (this happens when a Webhook is triggered):
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
AND
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array('item_id' => $id_client);
$item->save(array(
'hook' => false,
'silent' => true
));
Where 'client' is the external id of the field and $id_client is an integer number.
Here's the error I get:
[18-Aug-2014 17:33:30 UTC] PHP Notice: Indirect modification of overloaded property PodioItem::$field has no effect in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
[18-Aug-2014 17:33:30 UTC] PHP Warning: Creating default object from empty value in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
If anyone could explain to me why this isn't working I'd be really grateful. The provided documentation is not clear on that subject.
Thank you!
SOLUTION
I got it to work this way, credits to Andreas:
if(!isset($item->fields['client']->values[0]->item_id)){
$item->fields['client'] = new PodioAppItemField();
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
}
You're getting this error because the client field doesn't exist on your item yet. So you're trying to set values for something that doesn't exist.
You need to do something like (untested, but should work):
$item = PodioItem::get($_POST['item_id']);
if (!isset($item->fields['client'])) {
$item->fields['client'] = new PodioAppItemField();
}
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
When you get an item from Podio you won't get all fields in the app, only that ones that have values for that particular item. So you have to check if your particular field is present before trying to set values on it.
Related
Podio's API documentation differs from podio-php's when it comes to creating new Items.
Based on Podio's tutorial, I would have to format each value according to its type, whereas podio-php describes using PodioItemFieldCollection to handle that for you. I prefer the latter option, but I keep getting this error:
Invalid value "1" (string): Not a valid option
I don't see much difference in my code versus the example given by podio-php. What's causing this error?
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "my-text-field", "values" => "FooBar")),
new PodioProgressItemField(array("external_id" => "my-number-field", "values" => 75))
));
$atts = array(
'app' => new PodioApp($app_id),
'fields' => $fields
);
$item = new PodioItem($atts);
No errors caught up to here. But when I try to save...
$response = $item->save();
Invalid value "1" (string): Not a valid option
The $app_id was being passed in as a string. I've had this issue now with a few different ID values returned in an API response. I explicitly cast the value as an integer and the error went away:
$atts = array(
'app' => new PodioApp((int)$app_id),
'fields' => $fields
);
I'm using PHP and the following call to retrieve the top-level TeamDrive folders.
$service->teamdrives->listTeamdrives()->getTeamDrives();
Results
TeamDrive1 --- let's say the ID is XXXXXX
TeamDrive2 --- let's say the ID is YYYYYY
TeamDrive1 has a sub-folder called TeamDrive1Sub1 (ID is SSSSS)
then TeamDrive1Sub1 (ID PPPPP) also has a sub-folder etc
I've tried to use the Drive REST API files:List - but this does not seem to work...
I need to find the children "x" levels deep, how do I do that? Maybe some other interface call such as the one I'm using above $service->teamdrives->listTeamdrives()->getTeamDrives(); which allows me to start at the ID XXXXXX and retrieve it's children
Found my own answer, but there's probably a better way... if you have the ID of a teamdrive folder and want to get the sub-folders - here's what I have for the PHP code
//- first we need to get the $teamDriveId - using the /files/get & the $folderId we passed in
$folderId = "XXXXXX" // from above
$optParams = array(
'supportsTeamDrives' => true,
);
$results = $service->files->get($folderId, $optParams);
$teamDriveId = $results["teamDriveId"];
// now we can get the sub-folders (if there are any)
$params = [
'q' => "'{$folderId}' in parents and trashed = false and mimeType = 'application/vnd.google-apps.folder'",
'pageSize' => $pageSize,
'corpora' => 'teamDrive',
'includeTeamDriveItems' => true,
'supportsTeamDrives' => true,
'teamDriveId' => $teamDriveId, // this must be the parent Id
'orderBy' => 'name',
];
$results = $service->files->listFiles($params);
Hope this helps someone
I added some custom field so that i can get more information when someone registers into the website but i want to alter one field on the form. I created a module which has a hook_form_alter function so that i can alter the field_first_name of the registration form. here is the code
function user_registration_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'user_register_form'){
$form['field_first_name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#description' => t('Enter your first name.'),
'#maxlength' => 255,
'#required' => TRUE,
);
}
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#submit'][] ='user_registration_form_submit';
}
}
I also created a the function which handles the form submission.
function user_registration_form_submit(&$form, &$form_state)
{
$fe_id = db_insert('field_revision_field_first_name')
->fields(array(
'field_first_name_value' => $form_state['value']['field_first_name'],
))->execute();
drupal_set_message(t('your form entry has been added'));
}
My problem is that when i submit the form and i check the user details. i find that the first name details does not exist in the database or when i login as the administrator and click on the 'people' link. i find that all information is are submitted except the first name field which i am trying to alter. I also tried to submit the form without the form submit function but it still doesn't work.
and i get the following error message if i add the form_submit function
Notice: Undefined index: value in user_registration_form_submit() (line 37 of /var/www/html/lite/sites/all/modules/user_regestration/user_registration.module).
PDOException: SQLSTATE[HY000]: General error: 1364 Field 'entity_id'
doesn't have a default value: INSERT INTO
{field_revision_field_first_name} (field_first_name_value) VALUES
(:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in
user_registration_form_submit() (line 38 of
/var/www/html/lite/sites/all/modules/user_regestration/user_registration.module).
THIS IS LINE 37 AND 38 OF MY CODE
'field_first_name_value' => $form_state['value']['field_first_name'],
))->execute();
I am creating the module on localhost first before i push it to the live website
First, it's values not value.
Why don't you use a module providing this functionality, like profile2 ?
The user is not created in your submithandler, so either you save it:
function foo_user_register_form_submit($form, &$form_state){
$edit = array(
'name' => $form_state['values']['name'],
'pass' => user_password(),
'mail' => $form_state['values']['mail'],
'init' => $form_state['values']['mail'],
'status' => 1,
'access' => REQUEST_TIME,
'field_first_name' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_first_name']))),
);
user_save(drupal_anonymous_user(), $edit);
}
For more details see the docs.
Or you could try to add a custom submit handler, which would be fired after the user is created, in form_alter:
$form['#submit'][] = 'your_custom_submit_handler_function';
In there the user should already be created. so:
function your_custom_submit_handler_function(&$form, &$form_state)
{
$fe_id = db_insert('field_revision_field_first_name')
->fields(array(
'field_first_name_value' => $form_state['values']['field_first_name'],
))->execute();
drupal_set_message(t('your form entry has been added'));
}
But keep in mind, that this custom inserting maybe needs some more
code, here you only add the revision entry ..
You're not passing in an entity_id, and your database schema isn't defining a default one. The database expects one, and so it is failing, and it is failing on insert - which is your lines 37 and 38. It has absolutely nothing to do with your first name part.
Basically, Drupal (technically MySQL, or whatever your database backend is) doesn't know what entity you're trying to associate that field with.
Please look at the table that you're actually putting the information into and ensure that the schema either has a default set
Something like:
db_insert('field_revision_field_first_name')
->fields(array(
'field_first_name_value' => $form_state['values']['field_first_name'],
'entity_id' => 1,
))->execute();
Would probably work better for you. There may be other required fields. I recommend taking a look at your database schema.
You also shouldn't have to define a custom form for this - you can add fields to users, and also there is profile2 as another poster mentioned.
I am using this LinkedIn plugins for CakePHP 2.0.4: https://github.com/ProLoser/CakePHP-LinkedIn
I setup everything to work fine with login and get user's profiles like first name, last name,... using this syntax: $this->Linkedin->find("all",...). I renamed the default name,"Linkedin", of Linkedin datasource to "LinkedinSource", hence I can call my model "Linkedin" just for my convenience.
I followed the file /Plugin/Linkedin/Model/LinkedinMessage.php to create this function in my Linkedin model:
function updateStatus($message) {
$request = $this->request;
$request['uri']['path'] = 'people/~/shares';
$this->request = $request;
//Above 3 lines are used to bypass the error "changing value of overloaded object property has no effect if I use $this->request["uri"]["path"] = "..."
$data = array(
'comment' => $message
, 'visibility' => array('code' => 'anyone')
);
//Above settings follow this: https://developer.linkedin.com/documents/share-api
$saved = $this->save($data);
}
When I run above code using my own LinkedIn account (connected & authorized), the value of $saved is just TRUE but NO status/share is posted to my LinkedIn account when I open my account on a browser (Google Chrome)
I tried to change the URI Path to
$request['uri']['path'] = 'people/~/person-activities';
and request data to:
$data = array(
'content-type' => "linkedin-html"
, 'body' => $message
);
as in https://developer.linkedin.com/documents/post-network-update but still no better result.
I also change these lines in /Plugin/Linkedin/Config/LinkedinSource.php:
$config['Apis']['LinkedinSource']['write'] = array(
// http://developer.linkedin.com/docs/DOC-1044
'mailbox' => array(
'people/~/mailbox' => array(
'subject',
'body',
'recipients',
),
),
);
to
$config['Apis']['LinkedinSource']['write'] = array(
// http://developer.linkedin.com/docs/DOC-1044
'mailbox' => array(
'people/~/mailbox' => array(
'subject',
'body',
'recipients',
),
),
//https://developer.linkedin.com/documents/share-api
'shares' => array(
'people/~/shares' => array(
'comment',
'content',
'visibility',
),
),
);
but still no better result.
Just be noted I added these lines in /Plugin/Linkedin/Model/LinkedinMessage.php
public $startQuote;
public $endQuote;
to avoid these errors:
Undefined property: LinkedinSource::$startQuote [CORE/Cake/Model/Model.php, line 1269]
Undefined property: LinkedinSource::$endQuote [CORE/Cake/Model/Model.php, line 1269]
I dont know if that can cause my problem or not but I want to list all details here.
Please help as I spent almost one day to make this work but still can not :(
Found the problem! The Content-Type MUST be application/json in order to work! I thought x-li-format: json is enough but it is NOT.
I have tried every tutorial on the internet , I have asked questions here and got some good answers which I have accepted and followed. I have created modules, altered core files , installed various versions of magento , but it doesn't matter what I do I cant get anything I DO TO STORE IN THE DATABASE!
I just want to be able to created a custom field on the new account form and store it in the database, I don't care where ?
I had same problem and it is being caused by using uppercase letter in your attribute name.
If you use only lowercase letters everything gets saved just fine.
Make a setup script like this:
<?php
$installer = $this;
$installer->startSetup();
$eav = new Mage_Eav_Model_Entity_Setup('core_setup');
$eav->addAttribute('customer', 'my_property', array(
'label' => 'My Property',
'type' => 'varchar',
'input' => 'text',
'visible' => true,
'required' => true,
'position' => 1,
));
$installer->endSetup();
Then you should be able to add the my_property as an input on the New Customer form.
More on EAV at Alan Storm's Blog
Check these MySQL tables to make sure you're new EAV attribute has been inserted properly.
The attribute name should be in eav_attribute with all the atrribute settings and a new attribute_id. The new attribute_id should be in new records in these 3 tables: customer_eav_attribute, customer_eav_attribute_website, customer_form_attribute.
In customer_eav_attribute,customer_eav_attribute_website make sure the is_visible field is set to 1.
If all this checks out, report back with dumps of the 4 new rows I just mentioned so we can check for anything else that might be wrong in the DB. I just recently added new attributes on Magento 1.6.1 and I was nearly tearing my hair out but got it working in the end.
When I haved this problem was becaus was missing code like this
$installer->addAttribute("empresas", "email", array(
"type" => "varchar",
"backend" => "",
"label" => "Email",
"input" => "text",
"source" => "",
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("empresas", "email");
$used_in_forms = array();
$used_in_forms[] = "adminhtml_empresas";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", false)
->setData("is_system", 0)
->setData("is_user_defined", 0)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
in my setup script after $installer->installEntities();