By Fagault Eric on Friday, 16 February 2018
Posted in General
Replies 18
Likes 0
Views 345
Votes 0
Hello,
I need to list the id of the connected user's friends.

I can put a request on the table "_social_friends"
But is there a simpler method?

Best regards.

Eric
You can get a list of friends using the following method,

[gist]
$my = ES::user();
$model = ES::model('Friends');
$friends = $model->getFriends($my->id);
[/gist]
·
Friday, 16 February 2018 18:12
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Mark,
Thank you very much.

Where is the id of the connected member indicated?


$ idUser = JFactory :: getUser () -> id;

$ my = ES :: user ();
$ model = ES :: model ('Friends');
$ friends = $ model-> getFriends ($ my-> id);

echo $ friends;


echo displays: array

My final need is to list friends (id of friends) whose birthday is today.

Best regards.

Eric
·
Friday, 16 February 2018 18:27
·
0 Likes
·
0 Votes
·
0 Comments
·
You need to iterate through each of the items. You can debug it by running

[gist]
var_dump($friends);
[/gist]
·
Friday, 16 February 2018 18:29
·
0 Likes
·
0 Votes
·
0 Comments
·
var_dump causes me a 500 error

$ my = ES :: user ();
$ model = ES :: model ('Friends');
$ friends = $ model-> getFriends ($ my-> id);
var_dump ($ friends);
·
Friday, 16 February 2018 18:41
·
0 Likes
·
0 Votes
·
0 Comments
·
It is definitely something wrong with your code
·
Friday, 16 February 2018 18:48
·
0 Likes
·
0 Votes
·
0 Comments
·
Indeed, I think so too.

At the beginning of the file I put:

require_once (JPATH_ADMINISTRATOR. '/components/com_easysocial/includes/easysocial.php');

Is it correct ?
·
Friday, 16 February 2018 19:00
·
0 Likes
·
0 Votes
·
0 Comments
·
Yes, that is correct. Try this:

[gist]
$my = ES::user();
$model = ES::model('Friends');
$friends = $model->getFriends($my->id);

echo "<pre>";
var_dump($friends);
echo "</pre>";
exit;

[/gist]
·
Friday, 16 February 2018 21:35
·
0 Likes
·
0 Votes
·
0 Comments
·
Merci beaucoup pour votre aide, Mark, mais quand le mets :

echo "<pre>";
var_dump($friends);
echo "</pre>";
exit;

le site perd toutes ces CSS

Quand je fais : echo $my;
Cela affiche: SocialUser
·
Friday, 16 February 2018 21:54
·
0 Likes
·
0 Votes
·
0 Comments
·
Thank you very much for your help, Mark, but when the dish:

echo "<pre>";
var_dump ($ friends);
echo "</ pre>";
exit;

the site loses all these CSS

When I do: echo $ my;
This poster: SocialUser

That's what I did:
·
Friday, 16 February 2018 21:56
·
0 Likes
·
0 Votes
·
0 Comments
·
That's what I did:

<?php
// No direct access
defined('_JEXEC') or die;
JHtml::_('jquery.framework');
$document =& JFactory::getDocument();
$document->addStyleSheet("/modules/mod_esbirthday/esbirthday.css");

$app = JFactory::getApplication();
$idUser = JFactory::getUser()->id;
$nameUser = JFactory::getUser()->username;
//echo $idUser;

$date_du_jour = JFactory::getDate();
$date =JFactory::getDate()->format('d m Y');

$StateFriend = 1;

// Charger Easysocial
require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');
$my = ES::user();
$model = ES::model('Friends');
$friends = $model->getFriends($my->id);

echo $my;
/*
echo "<pre>";
var_dump($friends);
echo "</pre>";
exit;
*/

?>
·
Friday, 16 February 2018 22:00
·
0 Likes
·
0 Votes
·
0 Comments
·
Thank you very much for your help, Mark, but when the dish:

echo "<pre>";
var_dump ($ friends);
echo "</ pre>";
exit;

the site loses all these CSS

When I do: echo $ my;
This poster: SocialUser
·
Friday, 16 February 2018 22:00
·
0 Likes
·
0 Votes
·
0 Comments
·
That is because this is for you to review the result of the $friends . When you execute the codes to get the list of friends, it returns you a list of user items. You need to iterate through them.

I am sorry but this is no longer questions related to EasySocial but it seems to be more about the usage of php
·
Saturday, 17 February 2018 02:07
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post