* - 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>
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace Toby\Domain\Actions;
 | 
						|
 | 
						|
use Toby\Domain\PolishHolidaysRetriever;
 | 
						|
use Toby\Eloquent\Models\User;
 | 
						|
use Toby\Eloquent\Models\YearPeriod;
 | 
						|
 | 
						|
class CreateYearPeriodAction
 | 
						|
{
 | 
						|
    public function __construct(
 | 
						|
        protected PolishHolidaysRetriever $polishHolidaysRetriever,
 | 
						|
    ) {}
 | 
						|
 | 
						|
    public function execute(int $year): YearPeriod
 | 
						|
    {
 | 
						|
        $yearPeriod = new YearPeriod([
 | 
						|
            "year" => $year,
 | 
						|
        ]);
 | 
						|
 | 
						|
        $yearPeriod->save();
 | 
						|
 | 
						|
        $this->createVacationLimitsFor($yearPeriod);
 | 
						|
        $this->createHolidaysFor($yearPeriod);
 | 
						|
 | 
						|
        return $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"],
 | 
						|
            ]);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |