Skip to content

Instantly share code, notes, and snippets.

@evercode1
Created December 31, 2014 07:52
Show Gist options
  • Save evercode1/10939c513dc0dbe5daca to your computer and use it in GitHub Desktop.
Save evercode1/10939c513dc0dbe5daca to your computer and use it in GitHub Desktop.
User to UserType Relations
/**
*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