diff --git a/app/Entities/Users/Event.php b/app/Entities/Users/Event.php index 0e1c1cc..69aae55 100644 --- a/app/Entities/Users/Event.php +++ b/app/Entities/Users/Event.php @@ -6,19 +6,48 @@ use App\Entities\Projects\Project; use Illuminate\Database\Eloquent\Model; /** + * User event model. + * * @author Nafies Luthfi */ class Event extends Model { + /** + * The table associated with the model. + * + * @var string + */ protected $table = 'user_events'; + + /** + * The attributes that aren't mass assignable. + * + * @var array + */ protected $guarded = ['id', 'created_at', 'updated_at']; + + /** + * The attributes that should be cast to native types. + * + * @var array + */ protected $casts = ['is_allday' => 'boolean']; + /** + * Event belongs to User relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function user() { return $this->belongsTo(User::class); } + /** + * Event belongs to Project relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function project() { return $this->belongsTo(Project::class); diff --git a/app/Entities/Users/Role.php b/app/Entities/Users/Role.php index 1f3378f..611aea6 100644 --- a/app/Entities/Users/Role.php +++ b/app/Entities/Users/Role.php @@ -5,25 +5,47 @@ namespace App\Entities\Users; use App\Entities\ReferenceAbstract; /** - * Role Class. + * Role reference class. */ class Role extends ReferenceAbstract { + /** + * List of user role. + * + * @var array + */ protected static $lists = [ 1 => 'admin', 2 => 'worker', ]; + /** + * Get role name by id. + * + * @param int $singleId + * @return string + */ public static function getNameById($roleId) { return trans('user.roles.'.static::$lists[$roleId]); } + /** + * Get role id by name. + * + * @param string $roleName + * @return string + */ public static function getIdByName($roleName) { return array_search($roleName, static::$lists); } + /** + * Get user roles in array format. + * + * @return array + */ public static function toArray() { $lists = []; diff --git a/app/Entities/Users/User.php b/app/Entities/Users/User.php index 1dc40aa..44e81ed 100644 --- a/app/Entities/Users/User.php +++ b/app/Entities/Users/User.php @@ -9,14 +9,35 @@ class User extends Authenticatable { use Notifiable; + /** + * The attributes that are mass assignable. + * + * @var array + */ protected $fillable = ['name', 'email', 'password', 'api_token', 'lang']; + + /** + * The attributes that should be hidden for serialization. + * + * @var array + */ protected $hidden = ['password', 'remember_token', 'api_token']; + /** + * Set user password attribute on save. + * + * @param void + */ public function setPasswordAttribute($value) { $this->attributes['password'] = bcrypt($value); } + /** + * Show user name with link to user detail. + * + * @return Illuminate\Support\HtmlString + */ public function nameLink() { return link_to_route('users.show', $this->name, [$this]); @@ -35,8 +56,7 @@ class User extends Authenticatable /** * Assign the given role to the user. * - * @param string $role - * + * @param string $roleName * @return void */ public function assignRole(string $roleName) @@ -52,8 +72,7 @@ class User extends Authenticatable /** * Remove the given role from the user. * - * @param string $role - * + * @param string $roleName * @return void */ public function removeRole(string $roleName) @@ -69,8 +88,7 @@ class User extends Authenticatable /** * Determine if the user has the given role. * - * @param string $role - * + * @param string $roleName * @return bool */ public function hasRole(string $roleName) @@ -83,8 +101,7 @@ class User extends Authenticatable /** * Determine if the user has the given array of role. * - * @param array $role - * + * @param array $roleNameArray * @return bool */ public function hasRoles(array $roleNameArray) @@ -101,6 +118,13 @@ class User extends Authenticatable }); } + /** + * User query scope based on role names. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $roleNameArray + * @return \Illuminate\Database\Eloquent\Builder + */ public function scopeHasRoles($query, array $roleNameArray) { return $query->whereHas('roles', function ($q) use ($roleNameArray) { @@ -114,6 +138,11 @@ class User extends Authenticatable }); } + /** + * List of user roles in html list items. + * + * @return string + */ public function roleList() { $roleList = '