diff --git a/include/class-User.php b/include/class-User.php index eeb75b3..5dd1008 100644 --- a/include/class-User.php +++ b/include/class-User.php @@ -1,90 +1,107 @@ . /** - * Class that can wrap an User retrieved from the database + * Methods for a User class */ -class User extends Sessionuser { - - /** - * Constructor - */ - public function __construct() { - parent::__construct(); - } +trait UserTrait { /** * Get the User name * * @return string */ public function getUserName() { return $this->get( 'user_name' ); } /** * Get the User ID * * @return int */ public function getUserID() { return $this->getSessionuserID(); } /** * Get the User UID * * @return string */ public function getUserUID() { return $this->getSessionuserUID(); } /** * Get the User role * * @return string */ public function getUserRole() { return $this->getSessionuserRole(); } /** * Check if the User is active * * @return boolean */ public function isUserActive() { return $this->isSessionuserActive(); } /** * Check if the user is me * * @return boolean */ public function isUserMe() { // if I'm logged, compare the IDs if( is_logged() ) { return $this->getUserID() === get_user()->getUserID(); } return false; } + /** + * Normalize an User class + * + */ + protected function normalizeUser() { + $this->integers( 'user_ID' ); + $this->booleans( 'user_active' ); + } + +} + +/** + * Class that can wrap an User retrieved from the database + */ +class User extends Sessionuser { + + use UserTrait; + + /** + * Constructor + */ + public function __construct() { + $this->normalizeUser(); + } }