Forums

Expand Registraton-Demo with a field in depend of a other db-table

mznbg 15 Nov, 2015
Hello, need your help!
CF5 have a Registraton-Demo and every one get the rights "registerd".
With this demo I like to expand a further field.
The field is "Invitationcode".

I have a other table in my Database called "dealer".
In this database there are the name of the inviter, the code for the invitationcode and the id of the usergroups.

So when someone make a registration, CF5 should check if the Invitationcode exists and when this is true it should use the usergroups-id for the user rights.

With this I know who was the inviter.
And the users of this inviter have other rights that the other one, depends of usergroups.

Example db _usergroups:
Usergroups-id: 1 / title: public
Usergroups-id: 2 / title: registerd
Usergroups-id: 3 / title: dealer1
Usergroups-id: 4 / title: dealer2
...

db_dealer
inviter-id: 1 / invitername: Georg / invitationcode = Georg2015 / usergroups-id = 3
inviter-id: 2 / invitername: Mike / invitationcode = Mike2015 / usergroups-id = 4
...

So when someone make a reservation and use the invitationcode "Mike2015" he get automaticly the usergroups-id "4".
When he have no invitationcode he get usergoups-id: "2" (registered)
An idea what I have to do?
Thanks in advance !!
GreyHead 16 Nov, 2015
Hi mznbg,

Register the User as normal.

Use an Event Switcher to run a query to check the invitation code. Change the Events List in the Switcher to 'invited'. If an invitation is found return 'invited' otherwise do nothing.

In the 'invited' event of the Event Switcher use the Joomla! User methods to add the user to the extra group(s).

Bob
mznbg 17 Nov, 2015
Hello Bob,

you are great, it sounds easy (but it is it really?), so I will try your solution.😉
Thanks.
mznbg
mznbg 21 Nov, 2015
Hi all,
maybe some will know how I have I solved my problem.
Bob informed me that I can make it with the Event-Switcher, this is my solution, it works
First I have a DB named "Dealer" there are two fields name "Code" = Invitingcode and "Group" = Joomla`s group_id

When the user will registrate he can use an Invitingcode.
In the Event-Switcher I look if the Code exists.

Event-Switcher with Event "invited":
<?php
$db =\ JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__chronoforms_Dealer`
        WHERE `Code` = '{$form->data['Code']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
echo "eventswitcher</br>".$count;
if ( $count > 0 ) {
  return 'invited';
} 
?>

Event: "invited"
<?php

$db =\ JFactory::getDBO();
$query = "
    SELECT Code, Group
        FROM `#__chronoforms_Dealer`
        WHERE `Code` = '{$form->data['Code']}' ;
";

$db->setQuery($query);
$result = $db->loadObjectList();

//Only one Result should be fund, else take the last result as group
foreach ($result as $row) {
    $group = $row->Group;
}

// Get New USER-ID
   $user_id = $form->data['_PLUGINS_']['joomla_registration']['id'];
   $user = JFactory::getUser($user_id);

$db = JFactory::getDbo();
$query = $db->getQuery(true);
 
// Insert columns.
$columns = array('user_id', 'group_id');
 
// Insert values.
$values = array($user_id, $group);
 
// Prepare the insert query.
$query
->insert($db->quoteName('#__user_usergroup_map'))
->columns($db->quoteName($columns))
->values(implode(',', $values)); 
  
$db->setQuery($query);
$db->execute();
 ?>

After then the user have two writings in the "user_usergroup_map", one as "REGISTRATED" and one with the Group in depend of the Invitingcode.

Maybe there are a better solution, but for me it works. 😀

Bye
This topic is locked and no more replies can be posted.