I'm working on a Drupal module to create a Smartsheet when a Drupal node, of a specific type, is published.
The sheet is being created fine but is not using the template I'm specifying with the formId variable.
What am I doing wrong?
Thanks
Code is:
<?php
function smartsheet_node_insert($node) {
if ($node->type == 'oa_space') {
// Initialize URL Variables
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL ."/sheets/";
$columnURL = $baseURL. "/sheet/" . $node->nid . "/columns";
// Insert your Smartsheet API Token here
$accessToken = "[my api token]";
// Create Headers Array for Curl
$headers = array(
"Authorization: Bearer ". $accessToken,
"Content-Type: application/json"
);
// Create new sheet
$theSheet = array(
'name' => $node->title,
'fromId' => '[template id]',
);
$postfields = json_encode($theSheet);
// Connect to Smartsheet API
$curlSession = curl_init($sheetsURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_POST, 1);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$createResponse = curl_exec($curlSession);
// Assign response to PHP object
$createObj = json_decode($createResponse);
if (curl_getinfo($curlSession, CURLINFO_HTTP_CODE) != 200) {
//if (curl_errno($curlSession)) {
drupal_set_message("Oh No! Could not create sheet " . $node->title . "because " . $createObj->message);
} else {
// Tell the user!
drupal_set_message("A Smartsheet has been created for the " . $node->title . " project");
// close curlSession
curl_close($curlSession);
}
}
}
Your code looks good. If the sheet is being created, then the structure of your call is good. It's likely that you just have an incorrect templateId. Where did you get the template Id?
Through the Smartsheet interface, you can find the template Id in the Sheet Properties. This article on the Smartsheet Help section describes where to find the Sheet Properties. In the properties window you'll take the value for Sheet ID, and use it for the fromId value in your Create Sheet call.
#stmcallister. Exactly. The sheet structure is copied but not the content.
Template ID = 2774566423553924, newest sheet ID = 8533387423049604.
Thanks,
Glenn
Related
public function registration_insert($data) {
//$this->db->trans_start();
//echo "<pre>";print_r($_POST);die;
// Query to check whether username already exist or not
$condition = "user_name =" . "'" . $data['user_name'] . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
// Query to insert data in database
$this->db->insert('user_login', $data);
if ($this->db->affected_rows() > 0) {
return true;
}
This is my program. It is not executing this code. I want to store the data in the database. Explicitly, with print_r(), it is posting the data but it is not storing it in the database and it is showing error.
First of all, i want to check your $data variable , if $data is not an object that have the sames attribute name like your database table column that will give you a problem.
I mean, for exemple if your user_login table have tow column (id , user_name), you should have in the $data object the same name of attributes
and to verify if your query work correctly just your code will be like this :
$q = $this->db->insert('user_login', $data);
if ($q) {
return $this->db->insert_id();
} else {
return false;
}
I am using vtiger 6.1.0 version.I want to fetch the user details from the database in the vtiger.
My code:
require_once('include/database/PearDatabase.php');
$db = PearDatabase::getInstance();
$query8 = "SELECT id from vtiger_users where is_admin=?";
$result8 =$db->pquery($query8, array("on"));
echo $num_rows = $db->num_rows($result8);
for($i=0; $i<$num_rows; $i++) {
echo $row = $db->query_result_rowdata($result8, $i,'id');
}
While using this code, the total number of rows is printed, but each id can not be fetched, showing some internal server error. Please help me!
You can pass only two argument in query_result_rowdata function.
Please see function in include/database/PearDatabase.php file.
function raw_query_result_rowdata(&$result, $row=0) {
if (!is_object($result))
throw new Exception("result is not an object");
$result->Move($row);
$rowdata = $this->change_key_case($result->FetchRow());
return $rowdata;
}
So please use like that, it work for me.
$index = 0;
foreach($listViewEntries as $recordId => $record) {
$rawData = $db->query_result_rowdata($listResult, $index++);
}
Hi I have a for that has one field (url) and I want to insert the URL typed in the form to the DB
My function add in my controller looks like this:
public function add(){
if($this->request->is('post')){
// debug($this->Link->find('all'));//this works
$link = $this->Link->findByUrl($this->request->data['link']['url']);
if(empty($link)){
//I will create the link
$this->Link->create($this->request->data, true);//true = ignoring the ID
$this->Link->save(null, true, array('url'));
//null = because I ready wrote "$this->request->data" in create
//true = I want to use VALIDATION
//array = I choose to SAVE this field only
echo "I've created the link";
die($this->Link->id);
}else {
debug($link);
die("The link is already in the database");
//je dois récupérer le lien
}
}
How can I insert into the DB the links entered?
Not sure which version of Cake you're using, but the way this would normally work is:
create() new reference
set() new data
save() reference
Example:
$this->Link->create();
$this->Link->set($this->request->data['link']);
$save = $this->Link->save();
echo $save ? "I've created the link" : "Error creating link!";
die($this->Link->id);
Hi for my custom component I need to set some custom parameters for joomla user for membership for checking if the user ni trial period or not and it can be change from the component admin panel for specific user.
The problem arises while retrieving the parameter. I think it is stored in cookie and it isn^t updated. I wrote the code like that to check it.
$user = JFactory::getUser(JRequest::getVar('id','0'));
echo $user->getParam('trialPeriod','0');
to save the value I am useing JHTML booleanlist.
$user->setParam('trialPeriod',$data['trialPeriod']);
$user->save();
Then is stores the value in joomla users table in the row of that user with column of params as;
{"trialPeriod":"0"}
in this situation it echoes the value as 0. Then I am changin the state of trialPeriod var as 1 and storing in db it updates the db as;
{"trialPeriod":"1"}
After all I am refreshing the page where the value is prompt the the screen the the value remains still the same as 0;
To clarify;
First of all there is no problem with saving the param it is changed properly. The problem is retrieving the changed one. The releated piece of code is following;
$user = JFactory::getUser();
$doc = JFactory::getDocument();
if($user->getParam('trialPeriod',0) == 0){
$ed = JFactory::getDate($obj->expirationDate);//obj is user from custom table and there is no problem with getting it.
$isTrialEnd = FALSE;
}else{
$ed = JFactory::getDate($user->getParam('trialExp',0));
$isTrialEnd = TRUE;
}
if($isTrialEnd){
//do something else
}else{
echo $user->getParam('trialPeriod','0');
}
actually big part of the code is unneccessary to explain it but you will get the idea.
What is the solution for this?
Editted.
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$db = $this->getDbo();
$isNew = empty($data['uid']) ? true : false;
$params = JComponentHelper::getParams('com_dratransport');
if($isNew){
// Initialise the table with JUser.
$user = new JUser;
// Prepare the data for the user object.
$username = self::getCreatedUserName($data['type']);
$data['username'] = !empty($data['username']) ? $data['username'] : $username;
$data['password'] = $data['password1'];
$useractivation = $params->get('useractivation');
// Check if the user needs to activate their account.
if (($useractivation == 1) || ($useractivation == 2)) {
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$data['block'] = 1;
}
}else{
$user = JFactory::getUser($data['uid']);
$data['password'] = $data['password1'];
}
$membership = DraTransportHelperArrays::membershipCFG();
$membership = $membership[$data['membership']];
if($data['membership'] == 4)
$data['groups'] = array($params->get('new_usertype',2),$params->get($membership,2));
else
$data['groups'] = array($params->get($membership,2));
$data['name'] = $data['companyName'];
$user->setParam('trialPeriod',$data['trialPeriod']);
// Bind the data.
if (!$user->bind($data)) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Store the data.
if (!$user->save()) {
$app->enqueuemessage($user->getError());
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
this piece of code is for storing the data releated with the users table.
Turns out this was the fact that Joomla stores the JUser instance in the session that caused the problem.
When changing a user's parameters from the back-end, the changes are not reflected in that user's session, until she logs out and back in again.
We could not find an easy option to modify anther user's active session, so we resorted to the use of a plugin that refreshes the JUser instance in the logged-in users' session, something like the following:
$user = JFactory::getUser();
$session = JFactory::getSession();
if(!$user->guest) {
$session->set('user', new JUser($user->id));
}
(reference: here).
In hook_user_update I'm retrieving a facebook profile pic and saving a record in the file_managed table. That much is going well. But I also want to save a record for a file field attached to the user entity. Normally what I do in these hooks is assign the values to $edit['field_something'], and I think that's the correct way to do this. That has always worked for other field types, but it is not working for the file field. You can see toward the end of the function where I dump the vars to confirm that I have something suitable to assign to $edit['field_something'] -- at least, I think it's suitable. I get no errors, but no record is created in the field_data_field_image table. What am I missing? Thank you!
/**
* Implementation of hook_user_update().
*
*/
function hifb_user_update(&$edit, $account, $category) {
if (empty($account->field_image['und'])) {
$fbid = $edit['field_facebook_id']['und'][0]['value'];
if (!empty($fbid)) {
$url = 'http://graph.facebook.com/' . $fbid . '/picture?type=large';
if ($file_contents = file_get_contents($url)) {
$size = getimagesize($url);
$ext = image_type_to_extension($size[2]);
$filename = 'fb_' . $fbid . '_u_' . $account->uid . $ext;
$uri = file_default_scheme() . '://' . $filename;
// Saves the file to the default files directory and creates the record in files_managed table.
$file = file_save_data($file_contents, $uri, FILE_EXISTS_REPLACE);
//var_dump($file); die;
/* Here's an example from the var_dump: object(stdClass)#120 (8) { ["fid"]=> string(3) "576" ["uri"]=> string(30) "public://fb_767816596_u_1.jpeg" ["filename"]=> string(21) "fb_767816596_u_1.jpeg" ["filemime"]=> string(10) "image/jpeg" ["uid"]=> string(1) "1" ["status"]=> int(1) ["timestamp"]=> int(1339686244) ["filesize"]=> int(2919) } */
// Creates record in field_data_field_image table??
$edit['field_image']['und'][0] = (array)$file;
}
}
}
}
I believe the reason it doesn't work is because in hook_user_update, the update has already occurred. So setting a value for $edit has no effect. The same code that I posted in the question works fine in hook_user_presave.