I am trying to add a new option to PodioCategoryItemField using the podio php api
$field = new \PodioCategoryItemField('test');
$field->add_value( array(
'value'=>array( 'status'=>'active','text' =>'some label','color'=>'#FFF' )
));
I can't get it to work. I have to set an id in the array, but if I do, I get an error that the option is not valid ( offcourse, I try to create a new one )
Any ideas on this?
Related
I'm trying to update firebase realtime database using kreait/firebase-php package.
Here's my tree:
I need to update the child of /detail/pesan/1/<unique ID> which have is_read value of false and update it to true.
Here's part of my code:
$database = $firebase->getDatabase();
$id_pesan=1;
/*
Update Firebase is_read
*/
$update = ['/is_read' => "true"];
$updatePesan_1 = $database
->getReference('chat/detail/'. $id_pesan)
->orderByChild('is_read')
->equalTo('false')
->update($update);
But i get this error :
Call to undefined method Kreait\Firebase\Database\Query::update()
when I change it to get the value first then update / set it :
$updatePesan_1 = $database
->getReference('chat/detail/'. $id_pesan)
->orderByChild('is_read')
->equalTo('false')
->getValue()
->set($update);
I get this error :
{"status":"error","error":400,"message":"Index not defined, add \".indexOn\": \"is_read\", for path \"/chat/detail/1\", to the rules"}
What I'm trying to do is filter / query database first to find child of specific tree which have is_read = false and update the value from "false" to "true".
Is it possible to do query of firebase database then updating it?
If yes how do I fix my code to achieve that?
Here's my solution
Okay so after many research and trial and error.
I did a couple of things :
Change the new rule to enable editing specific field on firebase database
Change the PHP code since I am unable to do filter / query then update. so I had to do it without filter / query and then updating data
1. Changes to Firebase database Rule
I change the rule to this :
{
"rules": {
".read": true,
".write": true,
"chat": {
"detail": {
"$id_pesan" :{
".indexOn": ["is_read"]
}
}
}
}
}
Some short explaination :
The data is stored in chat/detail///
since I need to be able to change what's inside I added ".indexOn" : ["is_read"] I change the rule and put indexing inside chat/detail/.
2. Change PHP code
At first what I want to do is this :
Initialize Firebase
Set references
Do Update call while query-ing field (in 1 call)
But it seems the package doesn't support what I wanted to do. so instead what I had to do is I have to query the field and get the unique ID value first. Then I made it into an Associative Array, then use it to update Database
here's the new code
//initialize
$database = $firebase->getDatabase();
//get value of all the unique ID
$getValue = $database
->getReference('chat/detail/'. $id_pesan)
->orderByChild('is_read')
->equalTo('false')
->getValue();
//initialize Array
$update = [];
//make the array necessary to update the firebase database
/*
What the Array should looks like
<Unique ID>/<variable I wanted to change> => "<new Value>"
Example :
"-IUAYS678/is_read" => "true"
"-JVHBY817/is_read" => "true"
*/
foreach($updatePesan_1 as $k => $v)
{
$update[$k. "/is_read"]="true";
}
//Update the Firebase Database
$updatePesan_1_process=$database->getReference('chat/detail/'. $id_pesan)
->update($update);
I hope this helps
I am trying to update an existing sale.order by linking an existing invoice to it. I have tried several things to add the invoice id to the invoice_ids array of the sales order, but nothing is working.
Here is my code:
$link = $models->execute_kw($db, $uid, $password, 'sale.order', 'write',
array(array($order_id),
array('invoice_ids'=>$invoice_id)));
This returns 1 but it does not change anything. I also tried this method but without success: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write
I think there is something wrong with my syntax.
Try with this code:
#general syntax for many2many field
$many2many_field = array(
new xmlrpcval(
array(
new xmlrpcval(6,"int"),
new xmlrpcval(0,"int"),
new xmlrpcval(array(new xmlrpcval($order_id,"int")),"array")
), "array")
);
array('invoice_ids'=> new xmlrpcval($many2many_field, "array"))
Generally we need to give format like [(6,0,[id1,id2,etc.])]
I'm developing a custom Moodle authentification plugin for Moodle 2.7.
When a user is authenticated I want them to be added to a specific cohort. If that cohort does not exist I need it to be created automatically. I use the user_authenticated_hook() function in my authentification plugin to achieve this.
My code for creating the cohort is this
$data = new stdClass();
$data->name = 'Name string';
$data->idnumber = 'ID string';
$data->description = 'Description string';
$cohortId = cohort_add_cohort($data);
I have included cohort/lib.php in the auth.php file and I have declared the global variables $DB, $CFG and $SESSION at the first line of the user_authenticated_hook() function.
The authentification works without the part about cohorts. But with the cohort part in place authentication fails and I am redirected to the login page.
The page title is changed to "Error" but that is the only error message I get.
What Am I doing wrong? I hope somebody will be able to help me create cohorts and add members.
It might be because the global $USER object doesn't exist yet or hasn't been populated.
Do you have debug switched on in your config.php?
$CFG->debug = 32767;
$CFG->debugdisplay = 1;
It might be better to respond to the user_created event. So if a user is created by another method, they will still be added to the cohort. eg:
Create a local plugin eg:
/local/add_cohorts
Create an events.php
/local/add_cohorts/db/events.php
Which has something like this
$handlers = array (
'user_created' => array (
'handlerfile' => '/local/add_cohorts/lib.php',
'handlerfunction' => 'local_add_cohorts_user_created',
'schedule' => 'instant',
'internal' => 1,
),
);
Then in /local/add_cohorts/lib.php have
function local_add_cohorts_user_created($user) {
// Do your cohort processing here and add the user
// Use $user->id to add to the cohort members
}
Then create a version.php and install the plugin, then the event handler will be registered.
Events api - https://docs.moodle.org/dev/Events_API
I want to create couple lists in mailchimp, and I need to have some users in couple lists. I successfully added user to first list, but can't add to second, because I get an error "This user is already subscribed".
I read about segmentation but this doesn't resolve issue, also I see that there is a posibility to copy user from one list to another via mailchimp admin panel, but I can't find which method can do this is in API v2.0
function cog_add_user_email_mailchimp( $user_id ) {
$user_data = get_userdata( $user_id );
if ( is_object( $user_data ) && ! empty( $user_data->user_email ) ) {
$mailchimp_obj = new COG_Mailchimp_Newsletters( MAILCHIMP_APIKEY );
$mailchimp_obj->user_id = $user_id;
$result = $mailchimp_obj->subscibe_user( $mailchimp_obj->lists_id['all_user_list'], array( 'email' => $user_data->user_email ) );
if ( $mailchimp_obj->check_user_subscribe_meta( $result ) ) {
$mailchimp_obj->subscibe_user( $mailchimp_obj->lists_id['just_registered'], array( 'euid' => $result['euid'] ) );
$mailchimp_obj->init_compaing_object( $mailchimp_obj );
$response = $mailchimp_obj->send_mail( $mailchimp_obj->lists_id['just_registered'] );
}
}
}
Where:
$mailchimp_obj->lists_id - array with lists id
$mailchimp_obj->subscibe_user - wrapper for subscribe method of mailchimp API
So I successfully add user into this list $mailchimp_obj->lists_id['all_user_list'], but when I try to subscribe into this list $mailchimp_obj->lists_id['just_registered'] I get an error.
Yes, you can. You'd better use segments inside the same list, though, as using separate lists count your subscribers twice (and, thus, increase the monthly bill).
Now, what have you tried so far? It is good practice to tell the community what code you have tried and didnt work. Or what did you google that yield no desired results but failed ones, etc.
The MailChimp API is a boon to work with. Read the docs.
http://apidocs.mailchimp.com/
The documentation for Netsuite is quite lacking, they cover the basics and then let you loose to explore. Anyone without a vast knowledge of PHP trying to use their php toolkit would be on their knees begging for mercy.
At any point throughout this whole project it's been trail and error and trying to make sense out of everything until stuff started to work.
I'm stumped on assigning custom fields to sales orders, I know it has to be an object of an object of an object in order for it to tier down the xml for the soap to take over but what with what with what?
I have some code I worked that is getting somewhere but it is complaining it's not the right RecordRef type. If anyone worked with Netsuite and feels my pain please lend me your knowledge before I pull out all my hair.
Thanks in advance.
Code:
$customFields = array('internalId' => 'custbody_new_die_yn','value' => array('name' => 'custbody_new_die_yn','internalId' => 'NO'));
$customObject = new nsComplexObject("SelectCustomFieldRef");
$customObject->setFields($customFields);
$salesOrderFields = array(
'entity' => new nsRecordRef(array('internalId' => $userId)),
'paymentMethod' => array('internalId' => 8),
'ccNumber' => 4111111111111111,
'ccExpireDate' => date("c", mktime(0,0,0,11,1,2011)),
'ccName' => 'Test Testerson',
'itemList' => array(
'item' => array(
'item' => array('internalId' => 5963),
'quantity' => 5
)
),
'department' => new nsRecordRef(array('internalId' => 1)),
'class' => new nsRecordRef(array('internalId' => 47)),
'customFieldList' => $customObject
);
I am not familiar using PHP with Netsuite but I have done a good amount of c#/.net Netsuite work. As Craig mentioned I find it much easier using a language such c#/.net with a Visual Studio generated interface to figure out what is available in the Netsuite SuiteTalk web service API.
There is a fair amount of documentation around this stuff in the NetSuite Help Center - by no means everythign you will need but a good start. Netsuite Help Center
Check out the SuiteFlex/SuiteTalk (Web Services) section specifically this page on Ids & References.
Using Internal Ids, External Ids, and References
With that said I will try to help with a .net example & explanation of adding a custom field to a Sales Order.
Here are a few examples of adding different CustomFieldRefs:
//A list object to store all the customFieldRefs
List<CustomFieldRef> oCustomFieldRefList = new List<CustomFieldRef>();
//List or Record Type reference
SelectCustomFieldRef custbody_XXX_freight_terms = new SelectCustomFieldRef();
custbody_XXX_freight_terms.internalId = "custbody_XXX_freight_terms";
ListOrRecordRef oFreightTermsRecordRef = new ListOrRecordRef();
oFreightTermsRecordRef.internalId = <internalId of specific record in Netsuite>;
//See the References link above for more info on this - trying to figure out typeId caused me a lot of pain.
oFreightTermsRecordRef.typeId = <internalId of the List Record Type in Netsuite>;
custbody_XXX_freight_terms.value = oFreightTermsRecordRef;
oCustomFieldRefList.Add(custbody_XXX_freight_terms);
//Freeform text sorta field
StringCustomFieldRef objStringCustomFieldRef = new StringCustomFieldRef();
objStringCustomFieldRef.internalId = "custbody_XXX_tracking_link";
objStringCustomFieldRef.value = "StringValue";
oCustomFieldRefList.Add(objStringCustomFieldRef);
//Checkbox field type
BooleanCustomFieldRef custbody_XXX_if_fulfilled = new BooleanCustomFieldRef();
custbody_XXX_if_fulfilled.internalId = "custbody_XXX_if_fulfilled";
custbody_XXX_if_fulfilled.value = true;
oCustomFieldRefList.Add(custbody_XXX_if_fulfilled);
//By far the most complicated example a multi-select list referencing other records in Netsuite
MultiSelectCustomFieldRef custrecord_XXX_transaction_link = new MultiSelectCustomFieldRef();
//internal id of field you are updating
custrecord_XXX_transaction_link.internalId = "custrecord_XXX_transaction_link";
List<ListOrRecordRef> oListOrRecordRefList = new List<ListOrRecordRef>();
ListOrRecordRef oListOrRecordRefItemFulfillment = new ListOrRecordRef();
oListOrRecordRefItemFulfillment.name = "Item Fulfillment";
oListOrRecordRefItemFulfillment.internalId = <ItemFulfillmentInternalId>;
//Item Fulfillment is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefItemFulfillment.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefItemFulfillment);
ListOrRecordRef oListOrRecordRefSalesOrder = new ListOrRecordRef();
oListOrRecordRefSalesOrder.name = "Sales Order";
oListOrRecordRefSalesOrder.internalId = <SalesOrderInternalId>;
//Sales Order is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefSalesOrder.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefSalesOrder);
//Add array of all the ListOrRecordRefs to the MultiSelectCustomFieldRef
custrecord_XXX_transaction_link.value = oListOrRecordRefList.ToArray();
oCustomFieldRefList.Add(custrecord_XXX_transaction_link);
//And then add all these to the Custom Record List (Array) on the Sales Order Record
objSalesOrder.customFieldList = oCustomFieldRefList.ToArray();
From what I can tell in your above example I think your issue is with the ListOrRecordRef typeId. Its hard to tell from your example what typeId you are referencing but if you can figure that out and set the TypeId on your SelectCustomFieldRef I think that should fix your issue.
The Custom Field Ref Internal ID is the reference ID on the record you are trying to update. This can be found in the Transaction Body fields for that record within Netsuite.
The Internal ID for the ListOrRecordRef is the internal ID for the actual list item or record that you want to attach to the previously mentioned record
The typeID for the ListOrRecordRef is the internal ID for the custom list/record. This is the parent ID for the previous internal ID, and is not inherently tied to the original record.