- small changes (#98)

* - added some test

* - cr fix

* wip

* wip

* Update resources/js/Shared/MainMenu.vue

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
Adrian Hopek
2022-03-30 10:33:18 +02:00
committed by GitHub
parent ab16af1ca9
commit 08421b8a69
40 changed files with 323 additions and 286 deletions

View File

@@ -30,13 +30,15 @@ class YearPeriodRetriever
public function links(): array
{
$current = $this->selected();
$selected = $this->selected();
$current = $this->current();
$years = YearPeriod::query()->whereIn("year", $this->offset($current->year))->get();
$years = YearPeriod::query()->whereIn("year", $this->offset($selected->year))->get();
$navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod));
return [
"current" => $current->year,
"current" => $this->toNavigation($current),
"selected" => $this->toNavigation($selected),
"navigation" => $navigation->toArray(),
];
}

View File

@@ -71,18 +71,6 @@ class User extends Authenticatable
return $this->hasMany(Vacation::class);
}
public function scopeSearch(Builder $query, ?string $text): Builder
{
if ($text === null) {
return $query;
}
return $query
->where("first_name", "ILIKE", $text)
->orWhere("last_name", "ILIKE", $text)
->orWhere("email", "ILIKE", $text);
}
public function getAvatar(): string
{
return $this->getAvatarGenerator()
@@ -108,6 +96,28 @@ class User extends Authenticatable
->exists();
}
public function scopeSearch(Builder $query, ?string $text): Builder
{
if ($text === null) {
return $query;
}
return $query
->where("first_name", "ILIKE", $text)
->orWhere("last_name", "ILIKE", $text)
->orWhere("email", "ILIKE", $text);
}
public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder
{
return $query->whereRelation(
"vacationlimits",
fn(Builder $query) => $query
->where("year_period_id", $yearPeriod->id)
->whereNotNull("days"),
);
}
protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);

View File

@@ -4,10 +4,12 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Toby\Domain\VacationRequestStatesRetriever;
/**
* @property int $id
@@ -40,4 +42,12 @@ class Vacation extends Model
{
return $this->belongsTo(YearPeriod::class);
}
public function scopeApproved(Builder $query): Builder
{
return $query->whereRelation(
"vacationRequest",
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()),
);
}
}

View File

@@ -7,7 +7,6 @@ namespace Toby\Eloquent\Observers;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Str;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
class UserObserver
{
@@ -23,15 +22,4 @@ class UserObserver
*/
$user->password = $this->hash->make(Str::random(40));
}
public function created(User $user): void
{
$yearPeriods = YearPeriod::all();
foreach ($yearPeriods as $yearPeriod) {
$user->vacationLimits()->create([
"year_period_id" => $yearPeriod->id,
]);
}
}
}

View File

@@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Observers;
use Toby\Domain\PolishHolidaysRetriever;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
class YearPeriodObserver
{
public function __construct(
protected PolishHolidaysRetriever $polishHolidaysRetriever,
) {}
public function created(YearPeriod $yearPeriod): void
{
$this->createVacationLimitsFor($yearPeriod);
$this->createHolidaysFor($yearPeriod);
}
protected function createVacationLimitsFor(YearPeriod $yearPeriod): void
{
$users = User::all();
foreach ($users as $user) {
$yearPeriod->vacationLimits()->create([
"user_id" => $user->id,
]);
}
}
protected function createHolidaysFor(YearPeriod $yearPeriod): void
{
$holidays = $this->polishHolidaysRetriever->getForYearPeriod($yearPeriod);
foreach ($holidays as $holiday) {
$yearPeriod->holidays()->create([
"name" => $holiday["name"],
"date" => $holiday["date"],
]);
}
}
}