Sponsored Content
Top Forums Web Development Notes with Ravinder on Badging System Development Part II Post 303028315 by RavinderSingh13 on Friday 4th of January 2019 09:01:03 AM
Old 01-04-2019
Quote:
Originally Posted by Neo
Note, I'm jumping on a plane in a few hours, so I don't have time to check this properly, but I'm thinking:
Code:
<?php
$day = 60 * 60 * 24;
$dayago = time() - $day;
$incrementseq = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  daysinsequence +1 WHERE userid =" . $uid;
$selectday = "SELECT lastdayactive AS lastactive FROM user WHERE userid =" . $uid;
$resetday = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  1 WHERE userid =" . $uid;

$day = $vbulletin->db->query_first($selectday);

if ($day['lastactive'] > $dayago && $day['lastactive'] <= $dayago * 2) {
    $status = $vbulletin->db->query_write($incrementseq);
} elseif ($day['lastactive'] > $dayago * 2) {
    $status = $vbulletin->db->query_write($resetday);
}

$getseq = "SELECT daysinsequence AS daysactive FROM user WHERE userid =" . $uid;
$days = $vbulletin->db->query_first($getseq);
if ($days['daysactive'] > 14) {
    $color['fahistory'] == 'black';
} elseif ($days['daysactive'] > 7) {
    $color['fahistory'] == 'indigo';
} elseif ($days['daysactive'] > 3) {
    $color['fahistory'] == 'blue';
} elseif ($days['daysactive'] > 1) {
    $color['fahistory'] == 'limegreen';
} else {
    $color['fahistory'] == 'lightgray';
}
$badgejs .= 'badge["fahistory"] = "' . $color['fahistory'] . '";';
$badgejs .= 'badge["fahistoryval"] = "' . number_format($days['daysactive']) . '";';

Please take a look and let me know what you think Ravinder!

Thanks

PS: I have not debugged that code above yet and realize that we need to add logic to not query the DB after we reset; because we already have the value (1) so no reason to do the extra query, etc.
Hello Neo,

Thank you for writing this one(I apologies that I am not at all getting time to write anything as of now). I have gone through code and it looks great, for my and everyone's understanding I have added explanation too in code(you could let me know if I missed or wrongly mentioned anything here).
Code:
<?php
$day = 60 * 60 * 24;
##Creating day variabale whose value is 1 day's seconds.
$dayago = time() - $day;
##Creating variable dayago whose value is current time - 86400 seconds(day variable) value.
$incrementseq = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  daysinsequence +1 WHERE userid =" . $uid;
##Creating variable incrementseq which will have update query to update lastactivity day and daysinsequence incremented by 1 here.
$selectday = "SELECT lastdayactive AS lastactive FROM user WHERE userid =" . $uid;
##Creating selectday variable in which we are selecting lastdayactive fiedl value from user table as lasactive.
$resetday = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  1 WHERE userid =" . $uid;
##Creating restday(which will RESET values of lastdayactive and daysinsequence value to 1 like restarting count of logging of users.)

$day = $vbulletin->db->query_first($selectday);
##Creating day variable where we are running selectday query to get user's lastactiveday from DB.

##Checking condition if lasactive value is greater than yesterday and less than or equal to dayago * 2 value then run incrementseq query.
if ($day['lastactive'] > $dayago && $day['lastactive'] <= $dayago * 2) {
    $status = $vbulletin->db->query_write($incrementseq);
} 
##If lasactiveday value is greater than dayago * 2 value then call reset value for user's day's login.
elseif ($day['lastactive'] > $dayago * 2) {
    $status = $vbulletin->db->query_write($resetday);
}

##Creating variable getseq by select query to get user's updated daysactive value from user table.
$getseq = "SELECT daysinsequence AS daysactive FROM user WHERE userid =" . $uid;
##Run query to get user's active days value here.
$days = $vbulletin->db->query_first($getseq);

##checking conditions to assig badge color as per user's continous logging here.
if ($days['daysactive'] > 14) {
    $color['fahistory'] == 'black';
} elseif ($days['daysactive'] > 7) {
    $color['fahistory'] == 'indigo';
} elseif ($days['daysactive'] > 3) {
    $color['fahistory'] == 'blue';
} elseif ($days['daysactive'] > 1) {
    $color['fahistory'] == 'limegreen';
} else {
    $color['fahistory'] == 'lightgray';
}
$badgejs .= 'badge["fahistory"] = "' . $color['fahistory'] . '";';
$badgejs .= 'badge["fahistoryval"] = "' . number_format($days['daysactive']) . '";';

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

3 More Discussions You Might Find Interesting

1. What is on Your Mind?

New Badging System - Badges Prototype Beta 1 (Badges Only)

Today I mapped out the new badging system using FA icons, Beta 1 in no particular order except a 6 x 8 grid: https://www.unix.com/members/1-albums215-picture991.png The prototype HTML code for this layout: <style> .fa-badge-grid { font-size: 1.5em; } .row { ... (38 Replies)
Discussion started by: Neo
38 Replies

2. What is on Your Mind?

Status of Badging System - Beta 1

Dear All, Here is the current status of the badging system: The Beta 1 phase of the new badging system is close to completion. 42 prototype badges have been "allocated" 6 prototype badge slots are held in reserve The "alert you have new badges" prototype is running and is currently... (4 Replies)
Discussion started by: Neo
4 Replies

3. What is on Your Mind?

Badging System: UNIX.COM Bug Hunter Badge (New)

I have moved the bug badge out of reserve and into the main stream. Basically, I will assign a color level like the others, based on who has made a good actionable bug report for UNIX.COM. "Good" means screenshots, links, and even details from web dev tools our the HTML source code. So far,... (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 07:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy