Simplify user ranks using php enum

This commit is contained in:
Léo Serre 2018-10-18 20:08:02 +02:00
parent 98a4a5ae55
commit 7e1a24a2db
2 changed files with 15 additions and 67 deletions

View File

@ -46,20 +46,4 @@ $config['SQL_db'] = "postgres";
$config['admin_mail'] = "leo@lstronic.com";
$config['bot_mail'] = "robot@kabano.com";
/*****
** Locales configuration
*****/
$config['locales'] = array(
"fr" => array("fr","fr_FR.UTF8","french","fr_FR","fr_FR.UTF-8", "Français")
);
$config['roles'] = array(
1000 => array(1000,"Administrateur", "red"),
800 => array(800,"Modérateur", "orangered"),
600 => array(600,"Membre premium", "orange"),
400 => array(400,"Utilisateur", "green"),
200 => array(200,"Membre archivé", "#aaa"),
0 => array(0,"Visiteur", "black")
);
?>

View File

@ -8,6 +8,15 @@
***********************************************************
**********************************************************/
$ranks = array(
"administrator" => array(1000,"Administrateur", "red"),
"moderator" => array(800,"Modérateur", "orangered"),
"premium" => array(600,"Membre premium", "orange"),
"registered" => array(400,"Utilisateur", "green"),
"blocked" => array(200,"Membre archivé", "#aaa"),
"visitor" => array(0,"Visiteur", "black")
);
class User
{
private $id = 0;
@ -103,24 +112,9 @@ class User
return $this->id;
}
public function get_rank() {
if( $this->rank == 'blocked' ) {
return '<span class="userrole" style="color: #aaa;">Membre bloqué</span>';
}
else if( $this->rank == 'visitor' ) {
return '<span class="userrole" style="color: black;">Visiteur</span>';
}
else if( $this->rank == 'registered' ) {
return '<span class="userrole" style="color: green;">Membre</span>';
}
else if( $this->rank == 'premium' ) {
return '<span class="userrole" style="color: orange;">Membre premium</span>';
}
else if( $this->rank == 'moderator' ) {
return '<span class="userrole" style="color: orangered;">Modérateur</span>';
}
else {
return '<span class="userrole" style="color: red;">Administrateur</span>';
}
global $ranks;
return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
}
public function get_avatar() {
if( $this->is_avatar_present == 't')
@ -168,39 +162,9 @@ class User
** Returns true if user permissions are higher than $rank
*****/
public function rank_is_higher($rank) {
if( $rank == 'blocked' ) {
return true;
}
else if( $rank == 'visitor' ) {
if( $this->rank == 'blocked' )
return false;
else
return true;
}
else if( $rank == 'registered' ) {
if( $this->rank == 'blocked' || $this->rank == 'visitor' )
return false;
else
return true;
}
else if( $rank == 'premium' ) {
if( $this->rank == 'premium' || $this->rank == 'moderator' || $this->rank == 'administrator' )
return true;
else
return false;
}
else if( $rank == 'moderator' ) {
if( $this->rank == 'moderator' || $this->rank == 'administrator' )
return true;
else
return false;
}
else {
if( $this->rank == 'administrator' )
return true;
else
return false;
}
global $ranks;
return $ranks[$this->rank][0] >= $ranks[$rank][0];
}
/*****