Created
December 31, 2014 07:52
-
-
Save evercode1/10939c513dc0dbe5daca to your computer and use it in GitHub Desktop.
User to UserType Relations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*getUserType | |
*line break to avoid word wrap in PDF | |
* code as single line in your IDE | |
*/ | |
public function getUserType() | |
{ | |
return $this->hasOne(UserType::className(), ['user_type_value' => 'user_type_id']); | |
} | |
/** | |
* get user type name | |
* | |
*/ | |
public function getUserTypeName() | |
{ | |
return $this->userType ? $this->userType->user_type_name : '- no user type -'; | |
} | |
/** | |
* get list of user types for dropdown | |
*/ | |
public static function getUserTypeList() | |
{ | |
$droptions = UserType::find()->asArray()->all(); | |
return ArrayHelper::map($droptions, 'user_type_value', 'user_type_name'); | |
} | |
/** | |
* get user type id | |
* | |
*/ | |
public function getUserTypeId() | |
{ | |
return $this->userType ? $this->userType->id : 'none'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment