Simplify user ranks using php enum
This commit is contained in:
parent
98a4a5ae55
commit
7e1a24a2db
|
@ -46,20 +46,4 @@ $config['SQL_db'] = "postgres";
|
||||||
$config['admin_mail'] = "leo@lstronic.com";
|
$config['admin_mail'] = "leo@lstronic.com";
|
||||||
$config['bot_mail'] = "robot@kabano.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")
|
|
||||||
);
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -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
|
class User
|
||||||
{
|
{
|
||||||
private $id = 0;
|
private $id = 0;
|
||||||
|
@ -103,24 +112,9 @@ class User
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
public function get_rank() {
|
public function get_rank() {
|
||||||
if( $this->rank == 'blocked' ) {
|
global $ranks;
|
||||||
return '<span class="userrole" style="color: #aaa;">Membre bloqué</span>';
|
|
||||||
}
|
return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</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>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public function get_avatar() {
|
public function get_avatar() {
|
||||||
if( $this->is_avatar_present == 't')
|
if( $this->is_avatar_present == 't')
|
||||||
|
@ -168,39 +162,9 @@ class User
|
||||||
** Returns true if user permissions are higher than $rank
|
** Returns true if user permissions are higher than $rank
|
||||||
*****/
|
*****/
|
||||||
public function rank_is_higher($rank) {
|
public function rank_is_higher($rank) {
|
||||||
if( $rank == 'blocked' ) {
|
global $ranks;
|
||||||
return true;
|
|
||||||
}
|
return $ranks[$this->rank][0] >= $ranks[$rank][0];
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****
|
/*****
|
||||||
|
|
Loading…
Reference in New Issue