By Alexandre Cayer on Tuesday, 17 June 2014
Posted in Technical Issues
Replies 7
Likes 0
Views 1K
Votes 0
Hi Guys,

Mark provide me some explanation on the Friends table to auto add a specific user to each new registration. However, I have looked in the Controller and Template folder, and not sure where is the best lane to push the entry since i would need the Id of that new user as to update the friend table.
Can you point me the best file, line, as to proceed.

Thanks

Alex
Hi.

As mentioned, you actually don't have to temper with the friend controller to do this.

If you are writing your own field or riding on any existing fields (joomla_username for example, would be a good field to ride on since it is a mandatory field), you can do this with the onRegisterAfterSave trigger (since this only happens once after registration).


public function onRegisterAfterSave(&$post, &$user)
{
// Fill in the id of the target user id that you want.
$usertoassign = 0;

$friend = Foundry::table('Friend');

// This will be the user who initiate the friend request
$friend->actor_id = $user->id;

// This will tbe the user who receives the friend request
$friend->target_id = $usertoassign;

// This will set the request as approved.
// Set it to 0 if you want the target to see the request and to manually "approve" the request
$friend->state = 1;

$friend->created = JFactory::getDate()->toSql();

$friend->store();
}
·
Tuesday, 24 June 2014 15:48
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Alexandre,

Which particular field have you activated for registration? You could edit one of the custom fields app to add your codes. For instance, if you are requesting the user for their full name, you could edit /media/com_easysocial/apps/fields/user/joomla_fullname/joomla_fullname.php
·
Wednesday, 18 June 2014 01:20
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mark,

This could be good. However, when one process into registration, does it "freeze" the id number somewhere. I would basicly insert row into the friend table so that i known user ID would be friend with that new registry. Any other solution to achieve the same is welcome

Thanks

Alex
·
Wednesday, 18 June 2014 10:14
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

You would want to use the "onRegisterAfterSave" trigger. In this trigger, you will have the "user id" of the newly registered user from the $user object.
·
Wednesday, 18 June 2014 12:02
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Jason,

I have taken a look at the friend controller and it all use lists.
if I have $newUser=$user-->id;$usertoassign=92;
how could I assign $usertoassign to $newUser without using the list ?!
I'm a bit lost. Could you provide a little bit of code ?

Thanks
·
Tuesday, 24 June 2014 13:31
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Jason,

Created thread: Pull: Custom user field: autoadduser + extend to group JSON error

Could you join in for the group error part or help extend.

Thanks
·
Wednesday, 25 June 2014 12:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Sure thing. I'll reply you on the other thread.
·
Wednesday, 25 June 2014 12:46
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post