ernestolee
Member
I would like to create new usergroup in joomla with customized registration form(juser plugin of fabrik) and assign user to this group(this part is missed, really don`t know how to add it). I have wrote some script which was included in the php plugin of form. but not sure where is a error. It would be helpful to get some info where is a error.
PHP:
// Get a db connection.
$db =JFactory::getDbo();// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('parentid','lft','rgt','title');
$title ='{user_registration_form___companyid}';
$child_query1 ="SELECT max('id') FROM '#__usergroups'";
$newgroupid = $child_query1+1;
$parent_id ='2';
$db->setQuery($child_query1);
$max_rgt = $db->loadResult();
// calculate left and rgt for new entry
$new_lft = $max_rgt;
$new_rgt = $max_rgt +1;
// update lft and rgt of all entries having lft , rgt greater than max_rgt
$upd1 ="UPDATE '#__usergroups' SET 'lft' = 'lft' + 2 WHERE 'lft' >= " $max_rgt;
$upd2 ="UPDATE '#__usergroups' SET 'rgt' = 'rgt' + 2 WHERE 'rgt' >= " $max_rgt;
// Insert values.
$values = array($parent_id, $new_lft, $new_rgt, $title );
// Prepare the insert query.
$query
->insert($db->quoteName('usergroups'))->columns($db->quoteName($columns))->values(implode(',', $db->quote($values)));
// Reset the query using our newly populated query object.
$db->setQuery($query);
try{// Execute the query
$result = $db->execute();//use $db->query() in Joomla2.5}catch(Exception $e){// catch any database errors.}
$newid =(int)$db->insertid();//get new record id