Please explain how to use the Database Class to return the id value when a row is inserted

Peter Lane Posted in Component Development 1 year ago

I am getting Error: Object of class OssnUser could not be converted to string in /var/www/vhosts/localapp.live/prod.localapp.live/components/RecordMaint/ossn_com.php:181

$user = ossn_loggedin_user();
$database = new OssnDatabase();

$params = array();
$params['from'] = "ossn_object";
$params['params'] = array("guid","title");
$params['wheres'] = array("guid = ".$params_in['group_guid']);
$data = $database->select($params);

$abc = "";
$chars = '23456791xTHCMYGREtheuckmyrbrwnfxjumpsivertheazymyrd-RWNFXMT12345679PZSVXEWRTHAZYMYGRD2345679';
for( $i = 0; $i < 12; $i++ )
{ $abc .= $chars[ mt_rand(0, 31 ) ]; }

$params['into']   = 'mgr_calendars';
$params['names']  = array(
    'cal_id',
    'cal_owner',
    'cal_group_id',
    'cal_name',
    'cal_link'
);
$params['values'] = array(
    0,
    $user->guid,
    $data->guid,
    $data->title,
    '$abc'
);
$calid = $database->getLastEntry();

Line 181 folllows

$query = "INSERT INTO mgr_calusers (cu_id, cu_cal_id, cu_user_id, cu_group_id, cu_admin, cu_active) VALUES (0, $calid, $user, ".$data->guid.", 1, 1)";
$database->statement($query);
$database->execute();
Replies
Indonesian Arsalan Shah Replied 1 year ago

You are welcome, just for reference sharing the callback https://www.opensource-socialnetwork.org/documentation/view/5605/group-deleted

gb Peter Lane Replied 1 year ago

Great! Got it now, thanks again!

Indonesian Arsalan Shah Replied 1 year ago

When you delete a group you get a instance of it already in $params["entity"] callback.

gb Peter Lane Replied 1 year ago

Thank you, Arsalan. That worked,

I am testing my callbacks and find I do not understand how to reference the OssnGroup instance to get the group id when I delete a group. Please advise.

Indonesian Arsalan Shah Replied 1 year ago

Well here you have two problems

  1. Where you are doing insert? $database->getLastEntry(); will show after insert operation
  2. Second the error is causing due to you are passing $user object into the cu_user_id you need to pass user ID not user object.