How to assign variable when creating PHP array with key and value - php

$data = array(
'uid' => 'key',
'zip' => 'STRING_VARIABLE',
"school" => array(
array("sid" => "STRING_VARIABLE", "qty" => NUMERIC_VARIABLE),
array("strSrchSchool" => array(
"name" => "STRING_VARIABLE",
"address" => "STRING_VARIABLE",
),
"students" => NUMERIC_VARIABLE)
),
"sort" => "default"
);
Above array is a part of API call. I want dynamic values at places where I have mentioned 'STRING_VARIABLE' & 'NUMERIC_VARIABLE'. So I want to write PHP variables there and tried few different things of concatenation but none is working.
When I call API With different tries for above PHP variables, it gives below error.
array(2) { ["status"]=> string(5) "error" ["error"]=> string(62) "Error parsing JSON object, check format and object definition." }
So please let me know what is correct method to write PHP variable directly at above mentioned places when creating PHP array.

You don't have to do anything special.
Just write the name of the variable.
$zip = '252354';
$data = array(
'uid' => 'key',
'zip' => $zip,
"school" => array(
array("sid" => "STRING_VARIABLE", "qty" => NUMERIC_VARIABLE),
array("strSrchSchool" => array(
"name" => "STRING_VARIABLE",
"address" => "STRING_VARIABLE",
),
"students" => NUMERIC_VARIABLE)
),
"sort" => "default"
);
And so on you can write as many variables inside the array as you wish.

Related

How to send action plan to followupboss using rest api in php

I'm trying to send leads and inquiry to followupboss crm, this is the php code i used for connecting to the followupboss rest API https://github.com/FollowUpBoss/fub-api-examples
everything is working correctly, Now I have to add action plan json field to the code. but it is not working,
this is my code:
$data = array(
"source" => $propertyname . "-Landing page",
"type" => "Property Inquiry",
"pageTitle" => $propertyname,
"pageUrl" => $prpurl,
"pageDuration" => "",
"message" => "Viewed: " . $propertyname,
"person" => array(
"firstName" => $fname ,
"lastName" => $lname ,
"emails" => array(array("value" => $email)),
"phones" => array(array("value" => $phone)),
"assignedTo" => "Hossein Shahi",
"addresses" => array(
// Address 1
array(
"street" => "322 S Broadway"
)
// If there are more than 1 address, add here
,array(
"street" => ""
)
),
"tags" => array(),
),
"property" => array(
"street" => $propertyname,
"city" => "",
"state" => "",
"code" => "",
"mlsNumber" => $mlscnm,
"price" => $prpprice,
"forRent" => false,
"url" => $prpurl,
"type" => $prptype,
"bedrooms" => $prpbeds,
"bathrooms" => $prpbaths,
"area" => $prparea,
"lot" => 0
),
"actionPlans" => array(
"status" => "Active",
"name" => "Buyer - Pre Construction",
"id" => ""
)
);
actionPlans isn't a valid field for new leads created via the /events API. That's why it's not working.
Action plans created in the UI are automatically triggered when a new lead comes in. Use the app to associate an action plan with an assignee. That is how you ensure an action plan will be in effect for a lead and the person handling it.
Alternatively, you can make a second API call to /actionPlansPeople to enable an action plan for a specific assignee. New items assigned to that user will use the action plan.

Adding values from a list of flat arrays to a single nested array

PHP Noob here, in over my head.
I have a file listing script that's checking through a directory and producing a series of file paths. They look more or less like this:
2014/1Q/ES/PDFs/141QES_01.pdf
I want to iterate through the list (it's a long list) and construct a nested associative array or object from which I can create an organized file tree with download links. The catch is I don't want my method to be specific to the path structure for this particular site, I want to build it dynamically based on the directory structure in the file paths so I can use this on other sites with similar needs.
$results = array(
'2014' => array(
'1Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf',
...
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
...
)
),
...
),
'2Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf',
...
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
...
)
),
...
)...
),
'2015' => array(
...
)
)
What's killing me is I can explode the paths into an array that contains the exact keys and filename I need, but I can't for the life of me figure out how to inject that flat array into the larger associative array. I'm betting it's a lot simpler than I'm making it, so I could use some wisdom. If I'm being stupid, I don't mind hearing it.
Maybe I'm misunderstanding something here but here's how you'd add a value to the PDF's array for the file 2014/1Q/ES/PDFs/141QES_03.pdf
$results = array(
'2014' => array(
'1Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf'
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
)
)
),
'2Q' => array(
'ES' => array(
'PDFs' => array(
'141QES_01.pdf',
'141QES_02.pdf',
)
),
'SE' => array(
'PDFs' => array(
'141QSE_01.pdf',
'141QSE_02.pdf',
)
)
)
));
Insertion code:
//insert value
$tmp = '2014/1Q/ES/PDFs/141QES_03.pdf';
$tmpArr = explode('/',$tmp);
$results[$tmpArr[0]][$tmpArr[1]][$tmpArr[2]][$tmpArr[3]][]=$tmpArr[4];
var_dump($results);
This outputs:
array(1) {
[2014]=>
array(2) {
["1Q"]=>
array(2) {
["ES"]=>
array(1) {
["PDFs"]=>
array(3) {
[0]=>
string(13) "141QES_01.pdf"
[1]=>
string(13) "141QES_02.pdf"
[2]=>
string(13) "141QES_03.pdf"
}
}...

Using REST web services add meetings and meetings_contacts relationship using set_relationship method

i have tried to set a relationship between the Meetings created and assigned contacts using rest ,Following is my code .. meetings are inserted successfully but i have no idea why assigned contacts are not saved into a meetings_contacts table
$login_parameters = array(
"user_auth"=>array(
"user_name"=>'rocks',
"password"=>md5('rocks'),
"version"=>"1"
),
"application_name"=>"VanareClient",
"name_value_list"=>array(),
);
$data = call("login", $login_parameters, $url);
$set_contact_parameters = array (
'session' => $data->id,
'module_name' => 'Meetings',
'name_value_list' => array( array (
"name" => "name",
"value" => "Subject"
),
array (
"name" => "description",
"value" => "description"
),
array (
"name" => "location",
"value" => "Pune"
),
array (
"name" => "duration_hours",
"value" =>"1"
),
) );
$dataMeeting = call ( "set_entry", $set_contact_parameters, $url );
$parameters = array(
'session' => $data->id,
'module_name' => 'Meetings',
'module_id' => $dataMeeting->id,
'link_field_name' => 'meetings_contacts',
'related_ids ' => array('25627846-a8a2-eeb5-3565-532035113842'),
);
$dataContactMeetings = call ( "set_relationship", $parameters, $url );
this is what i was trying .. please help me how to insert the relationship of meetings and contacts into a meetings_contacts mysql table . I am Using Sugarcrm CE 6.5.16 version .
Try with
'link_field_name' => 'contacts',
since the link field name is 'contacts' ( the relationship name is 'meetings_contacts' ).

Assigning a variable inside an array

I am working on a wordpress site and I need to assign the value of a function to a value inside an array but it keeps giving me errors. In the customFields array I need to insert the value of the get_option('contact_email', 'no one') into some helper text. In the code snippet below I need to replace {CONTACT_EMAIL} with the get_option value but can't figure it out.
...
var $customFields = array(
array(
"name" => "ContactPerson-name",
"title" => "Contact Name",
"description" => "Enter the first and last name of the page contact. If left blank, the site default of {CONTACT_PERSON} will be used.",
"type" => "textinput",
"scope" => array( "page" ),
"capability" => "edit_pages"
),
array(
"name" => "ContactPerson-email",
"title" => "Contact Email",
"description" => "Enter the email address of the page contact. If left blank, the site default of {CONTACT_EMAIL} will be used.",
"type" => "textinput",
"scope" => array( "page" ),
"capability" => "edit_pages"
),
array(
"name" => "ContactPerson-phone",
"title" => "Contact Phone (XXX) XXX-XXXX",
"description" => "Enter the phone number of the page contact. If left blank, the site default of {CONTACT_PHONE} will be used.",
"type" => "textinput",
"scope" => array( "page" ),
"capability" => "edit_pages"
),
array(
"name" => "ContactPerson-address",
"title" => "Contact Room Number & Building",
"description" => "Enter the room number and building of the page contact. Click here for building abbreviations. If left blank, the site default of {CONTACT_ADDRESS} will be used.",
"type" => "textinput",
"scope" => array( "page" ),
"capability" => "edit_pages"
),
...
...
I've tried to close the text and concat the function, I've tried to do a string replace and nothing seems to work. Thanks for any help anyone can provide.
Brute force method will work...
$customFields = array(
array(
"name" => "ContactPerson-name",
"title" => "Contact Name",
"description" => "... of {CONTACT_PERSON} will be used...",
"type" => "textinput",
"scope" => array( "page" ),
"capability" => "edit_pages"
)
);
$contact_person = get_option('contact_person');
foreach($customFields as &$field)
{
$field['description'] = str_replace("{CONTACT_PERSON}", $contact_person, $field['description']);
}
unset($field);

Capturing variable in ajaxoptions yii

I want to capture javascript/PHP variable in the ajaxoptions' options. e.g;
CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
'data' => array("id" => $model->id),
'type' => 'POST',
'error' => 'js:function(data){}',
'beforeSend' => 'js:function(request){}',
'success' => 'js:function(data){
alert(jQuery(this).attr("id"));
alert({$model->id});
}',
'complete' => 'js:function(data){}',
//'update'=>'#where_to_put_the_response',
), array(
"confirm" => "Are you sure you want to delete?",
"id" => "linkID",
"href" => "javascript:;",
"title" => "mTitle"
)
);
In the success option I have two alerts to show you guyz how do i want it. Which doesn't display correct data. Is there any way to get the php variables and the jQuery(this) object?
I have extracted the data i wanted from "jQuery(this)". Actually "jQuery(this)" returned me the data in a different format. Below is the code.
CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
'data' => array("id" => $model->id),
'type' => 'POST',
'error' => 'js:function(data){}',
'beforeSend' => 'js:function(request){
mdata=(jQuery(this)[0]["data"]).replace( /^\D+/g, "");
}',
'success' => 'js:function(data){
alert(mdata);
}',
'complete' => 'js:function(data){alert(mdata);}',
//'update'=>'#where_to_put_the_response',
), array(
"confirm" => "Are you sure you want to delete?",
"id" => "linkID",
"href" => "javascript:;",
"title" => "mTitle"
)
);
if alert the "jQuery(this)" like alert(JSON.stringify(jQuery(this))); - you will get the idea of the data returned.

Categories