#90 - user profile (#125)

* fix css focuses

* #90 - wip

* #90 - fix to generate PDF

* #90 - wip

* #90 - wip

* #90 - wip

* #90 - wip

* #90 - fix to calendar

* #90 - wip

* #90 - fix

* #90 - fix lint

* #90 - fix

* Apply suggestions from code review

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* #90 - cr fixes

* #90 - fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
Adrian Hopek
2022-04-14 11:58:45 +02:00
committed by GitHub
parent 459b62500e
commit cc981b02b4
62 changed files with 765 additions and 251 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\ProfileFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Rackbeat\UIAvatars\HasAvatar;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Eloquent\Helpers\ColorGenerator;
/**
* @property string $first_name
* @property string $last_name
* @property string $position
* @property EmploymentForm $employment_form
* @property Carbon $employment_date
*/
class Profile extends Model
{
use HasFactory;
use HasAvatar;
protected $primaryKey = "user_id";
protected $guarded = [];
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function getAvatar(): string
{
return $this->getAvatarGenerator()
->backgroundColor(ColorGenerator::generate($this->full_name))
->image();
}
public function getfullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}
protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
}
protected static function newFactory(): ProfileFactory
{
return ProfileFactory::new();
}
}

View File

@@ -8,27 +8,20 @@ use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Rackbeat\UIAvatars\HasAvatar;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role;
use Toby\Eloquent\Helpers\ColorGenerator;
/**
* @property int $id
* @property string $first_name
* @property string $last_name
* @property string $email
* @property string $password
* @property string $avatar
* @property string $position
* @property Role $role
* @property EmploymentForm $employment_form
* @property Carbon $employment_date
* @property Profile $profile
* @property Collection $vacationLimits
* @property Collection $vacationRequests
* @property Collection $vacations
@@ -38,12 +31,12 @@ class User extends Authenticatable
use HasFactory;
use Notifiable;
use SoftDeletes;
use HasAvatar;
protected $guarded = [];
protected $casts = [
"role" => Role::class,
"last_active_at" => "datetime",
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
];
@@ -52,6 +45,15 @@ class User extends Authenticatable
"remember_token",
];
protected $with = [
"profile",
];
public function profile(): HasOne
{
return $this->hasOne(Profile::class);
}
public function vacationLimits(): HasMany
{
return $this->hasMany(VacationLimit::class);
@@ -72,18 +74,6 @@ class User extends Authenticatable
return $this->hasMany(Vacation::class);
}
public function getAvatar(): string
{
return $this->getAvatarGenerator()
->backgroundColor(ColorGenerator::generate($this->fullName))
->image();
}
public function getFullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}
public function hasRole(Role $role): bool
{
return $this->role === $role;
@@ -104,9 +94,20 @@ class User extends Authenticatable
}
return $query
->where("first_name", "ILIKE", "%{$text}%")
->orWhere("last_name", "ILIKE", "%{$text}%")
->orWhere("email", "ILIKE", "%{$text}%");
->where("email", "ILIKE", "%{$text}%")
->orWhereRelation(
"profile",
fn(Builder $query) => $query
->where("first_name", "ILIKE", "%{$text}%")
->orWhere("last_name", "ILIKE", "%{$text}%"),
);
}
public function scopeOrderByProfileField(Builder $query, string $field): Builder
{
$profileQuery = Profile::query()->select($field)->whereColumn("users.id", "profiles.user_id");
return $query->orderBy($profileQuery);
}
public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder
@@ -119,11 +120,6 @@ class User extends Authenticatable
);
}
protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
}
protected static function newFactory(): UserFactory
{
return UserFactory::new();

View File

@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\VacationLimitFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -37,13 +36,6 @@ class VacationLimit extends Model
return $this->belongsTo(YearPeriod::class);
}
public function scopeOrderByUserField(Builder $query, string $field): Builder
{
$userQuery = User::query()->select($field)->whereColumn("vacation_limits.user_id", "users.id");
return $query->orderBy($userQuery);
}
protected static function newFactory(): VacationLimitFactory
{
return VacationLimitFactory::new();