By Abi on Saturday, 08 August 2015
Posted in General
Replies 9
Likes 0
Views 0.9K
Votes 0
Hi Mark,

You helped me to develop a ranking system but I now wonder if it can be made more sophisticated.

(1) I want to modify the following code

if ($points > 100 && $points < 200) {
echo '<img src="http://cloud.stackideas.com/path/to/your/badge3.png" />';
}

So that.....
If (points greater than 100 but less than 200) AND (create.comment badge achieved) AND (reply.question badge achieved) AND (followers.follow badge achieved)
THEN echo '<img src="http://cloud.stackideas.com/path/to/your/Celebrity.png" />';

(2) But if the above is not achievable, how about

If (points greater than 100 but less than 200) AND (create.comment points greater than 300) AND (reply.question points greater than 250) AND (followers.follow points greater than 800)
THEN echo '<img src="http://cloud.stackideas.com/path/to/your/superbadge.png" />';
Hi Abi,

Ah I see. You can try to retrieve profile user id when you viewing the profile by using the following code:
// Get the user's id.
$id = $this->input->get('id', 0, 'int');

// The current logged in user might be viewing their own profile.
if ($id == 0) {
$id = FD::user()->id;
}

$userme = FD::user($id);
$db = JFactory::getDBO();
$query = 'select * from jos_social_badges_maps where user_id = ' . $userme->id . ' and (badge_id=20 or badge_id=32)';
$db->setQuery($query);
$result = $db->loadObjectList();

$hasBadges = count($result) == 2;

if ($hasBadges && $userme->getPoints() < 500) {
echo 'hello hello';
}


Hope these help.
·
Tuesday, 18 August 2015 12:45
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Abi,

This requires quite a bit of hack if you want to achieve this but it is do-able, you just need to run a SQL query to see if the user achieved such badges on the site.

The mapping between a badge and the user is stored on the table #__social_badges_maps . If the user earned a badge, a new record will be stored in this table
·
Saturday, 08 August 2015 17:59
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mark,

I can query the table but can't translate that to what I want to achieve.

SELECT *
FROM `xxx_social_badges_maps`
WHERE badge_id =32

(A) Assuming that I want to check if badge id 32 and id 67 are earned by the user and points > 500, then echo "hello hello".

How can I do this - I know this is outside normal support but I need my ranking system to be a bit better that my initial thoughts.

Thanks for all your help.
Abi
·
Friday, 14 August 2015 00:59
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Abi,

The quickest way would be something like this:


$user = FD::user();
$db = JFactory::getDBO();
$query = 'select * from jos_social_badges_maps where user_id = ' . $user->id . ' and (badge_id=67 or badge_id=32)';
$db->setQuery($query);
$result = $db->loadObjectList();

$hasBadges = count($result) == 2;

if ($hasBadges && $user->getPoints() > 500) {
echo 'hello hello';
}
·
Friday, 14 August 2015 02:21
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Mark, but unfortunately it gave various problems and I tried to modify it but had no clear idea of what i was doing. Here is my modification but I used the actual table name. badge IDs 20 & 32 exist and my test user has both. I think that $user was interfering with something in default.header.php so I changed it to $userme. <?php echo $userme; ?> outputs SocialUser


<?php

$userme = FD::user(); ?>
<?php $db = JFactory::getDBO(); ?>
<?php $query = 'select * from XXX_social_badges_maps where user_id = ' . $userme->id . ' and (badge_id=20 or badge_id=32)'; ?>


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

<?php $hasBadges = count($result) == 2; ?>


<?php

if ($hasBadges && $user->getPoints() < 500) {
echo 'hello hello';
}
?>
Abi
·
Friday, 14 August 2015 05:51
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Abi,

May I know what is the error that you are facing with the example code that my colleague Mark shown to you? By the way you should also change all the variable $user to $userme at your last if statement:
if ($hasBadges && $user->getPoints() < 500) {
echo 'hello hello';
}
// change it to
if ($hasBadges && $userme->getPoints() < 500) {
echo 'hello hello';
}
·
Monday, 17 August 2015 16:32
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Ezrul,

It works great except for two things that I noticed.

(1) If userA meets the criteria ( badges id=67 and id=32) AND points <500 logs on to the website, then her profile properly displays "hello hello". But if she views the profile of another user UserB e.g with only one badge with id=20, then the profile display still shows "hello hello". It does not check to see if the other user has requisite badges,


(2) Only a user that is logged on can see the 'hello hello' associated with her account, but I want the public to be a able to see it. In the above example userA can see her 'hello hello' but userB cannot see it nor can the public see it.

I appreciate all the help that I'm getting.
Abi
·
Tuesday, 18 August 2015 09:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks StackIdeas - excellent EasySocial and superb support!!

Abi
·
Tuesday, 18 August 2015 15:29
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome Abi.
·
Tuesday, 18 August 2015 16:39
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post