Sponsored Content
Top Forums Web Development Notes with Ravinder on Badging System Development Part II Post 303028185 by RavinderSingh13 on Tuesday 1st of January 2019 11:53:40 AM
Old 01-01-2019
Hello Neo,

I have created code snippet for badge for a user completing anniversary on forums. I have put a condition here which validates that if a user is NOT ACTIVE from last 1 year OR user has NOT completed a year itself, then only he should be other than RED badge. Also I have made use of your previously used variable named $time_inactive along with $year here too.

Code:
<?php
$query = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), FROM_UNIXTIME('jointime')))/(3600*24) AS 'join_time' FROM users WHERE userid =" . $uid;
$results = $db->query_first_slave($query);
if ($time_inactive < $year){
  if ($results['join_time'] > 0 && $results['join_time']<1) { 
        $color['fajoin_time'] = 'orangered'; 
  } elseif ($results['join_time']<2 && $results['join_time']>=1) {
        $color['fajoin_time'] = 'darkorange';
  } elseif ($results['join_time']<3 && $results['join_time']>=2) {
        $color['fajoin_time'] = 'lightgray';
  } elseif ($results['join_time']<4 && $results['join_time']>=3) {
        $color['fajoin_time'] = 'limegreen';
  }
    elseif ($results['join_time']<5 && $results['join_time']>=4) {
        $color['fajoin_time'] = 'blue';
  }
    elseif ($results['join_time']<10 && $results['join_time']>=5) {
        $color['fajoin_time'] = 'indigo';
  }
    elseif ($results['join_time']>=10) {
        $color['fajoin_time'] = 'black';
  }
  else  { 
    $color['fajoin_time'] = 'red'; 
  }
}
else  { 
    $color['fajoin_time'] = 'red'; 
}


$badgejs .= 'badge["fajoin_time"] = "' . $color['fajoin_time'] . '";';  
$badgejs .= 'badge["fajoin_timeval"] = "' . number_format($results['join_time']) . '";';

jQuery: I haven't changed "chess-rook" name here, you could please select it as per availability of icons.

$('.fa-chess-rook').css("color",badge["fajoin_time"]);
$('.fa-chess-rook').css("cursor","pointer").attr("title", badge["fajoin_time"] + " Days in UNIX.com forums");
$('.fa-chess-rook').closest('div').find('.fa-circle').css("color",badge["fajoin_time]);

I have checked php code's syntax on online syntax checker in link PHP Code Checker - Syntax Check for Common PHP Mistakes and it didn't find ay issues in it.

NOTE: To validate query stuff I created a dummy schema and table in my vmware test machine and filled some dummy data entry in it to check query mentioned and looked ok there.

Thanks,
R. Singh
 

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
cal(1)							      General Commands Manual							    cal(1)

NAME
cal - Displays a calendar SYNOPSIS
cal [month [year]] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: cal: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
Names the month for which you want the calendar. It can be a number between 1 and 12 for January through December, respectively. If month is not specified, cal displays a calendar for the entire year, unless year is also omitted. Names the year for which you want the calen- dar. Because cal can display a calendar for any year from 1 to 9999, enter the full year rather than just the last two digits. If year is not specified, cal uses the current year. If no operands are specified, cal displays a calendar for the current month. DESCRIPTION
The cal command writes to standard output a Gregorian calendar for the specified year or month. For historical reasons, the cal command's Gregorian calendar is discontinuous. The display for September 1752 (cal 9 1752) jumps from Wednesday the 2nd to Thursday the 14th. The cal command checks the LC_TIME environment variable and uses the correct headers for the current locale. If LC_TIME is not set, cal checks the value of LANG. If neither variable is set, you receive English headers. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To display a calendar for February 1990, enter: cal 2 1990 To display a calendar for the year 84 A.D., enter: cal 84 To display a calendar for the current month, enter: cal ENVIRONMENT VARIABLES
The following environment variables affect the execution of *cmd*: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the format and contents of the calendar. Determines the location of message catalogues for the processing of LC_MESSAGES. Determines the time zone used to calculate the value of the current month. SEE ALSO
Commands: date(1) Files: locale(4) Standards: standards(5) Command and Shell User's Guide cal(1)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy