/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/Career/CareerResource.php
<?php
namespace App\Http\Resources\Pages\Career;
use App\Helpers\ResourceHelper;
use App\Http\Resources\Pages\Cards\MissionCardCollection;
use App\Models\Vacancy;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
/**
* @OA\Schema(title="CareerResource", description="Career resource",
* @OA\Xml(name="CareerResource")
* )
*/
class CareerResource extends JsonResource
{
/**
* @OA\Property(property="fs_title", type="string", example="We’re always looking people to help us become better"),
* @OA\Property(property="fs_title_background", type="string", example="https://uniferx-backend.test/image.png"),
* @OA\Property(property="fs_view_button", type="string", example="View open jobs"),
* @OA\Property(property="about_tag", type="string", example="Career opportunities"),
* @OA\Property(property="about_title", type="string", example="<p>Unifer as a medium-sized international company offers great opportunities for career growth<p>"),
* @OA\Property(property="about_description", type="string", example="We are not saying that we are unique, but believe us, companies like ours are not that common."),
* @OA\Property(property="mission_text", type="string", example="What makes us different"),
* @OA\Property(property="mission_small_background", type="string", example="https://uniferx-backend.test/image.png"),
* @OA\Property(property="mission_large_background", type="string", example="https://uniferx-backend.test/image.png"),
* @OA\Property(property="mission_cards", type="array",
* @OA\Items(type="object",ref="#/components/schemas/MissionCardResource"),
* )
* @OA\Property(property="open_jobs_tag", type="string", example="open jobs"),
* @OA\Property(property="open_jobs_title", type="string", example="<p>Join our team and be part of the future of agricultural success</p>"),
* @OA\Property(property="team_title", type="string", example="Our team"),
* @OA\Property(property="git_tag", type="string", example="Get in touch"),
* @OA\Property(property="git_title", type="string", example="<p>If you would like to learn more about career opportunities at our company, please contact us!</p>"),
* @OA\Property(property="git_text", type="string", example="Even if you haven't found your dream job on this page, we may still be able to offer you an internship with us."),
* @OA\Property(property="vacancies", type="array",
* @OA\Items(type="object",ref="#/components/schemas/VacancyResource"),
* )
*/
public string|null $name;
public string|null $language;
public string|null $country;
public array|null $attributes;
public function __construct($resource, $language, $country)
{
parent::__construct($resource);
$this->name = $resource->name;
$this->language = $language;
$this->country = $country;
// dd($resource);
$this->attributes = $resource->data ?? [];
}
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
// $vacancies = Vacancy::query()->where('is_enabled', true)->limit(6)->get();
//dd($this->attributes['mission_cards']);
return [
'fs_title' => ResourceHelper::getValue($this->attributes['fs_title'] ?? null, $this->country, $this->language),
'fs_title_background' => ResourceHelper::getImage($this->attributes['fs_title_background'] ?? null),
'fs_view_button' => ResourceHelper::getValue($this->attributes['fs_view_button'] ?? null, $this->country, $this->language),
'about_tag' => ResourceHelper::getValue($this->attributes['about_tag'] ?? null, $this->country, $this->language),
'about_title' => ResourceHelper::getValue($this->attributes['about_title'] ?? null, $this->country, $this->language),
'about_description' => ResourceHelper::getValue($this->attributes['about_description'] ?? null, $this->country, $this->language),
'mission_text' => ResourceHelper::getValue($this->attributes['mission_text'] ?? null, $this->country, $this->language),
// 'mission_small_background' => ResourceHelper::getImage($this->attributes['mission_small_background'] ?? null),
'mission_large_background' => ResourceHelper::getImage($this->attributes['mission_large_background'] ?? null),
'mission_cards' => isset($this->attributes['mission_cards']) ? MissionCardCollection::make( is_array($this->attributes['mission_cards']) ?$this->attributes['mission_cards'] : json_decode($this->attributes['mission_cards']))->country($this->country)->language($this->language) : null,
// 'mission_card_1' => ResourceHelper::getValue($this->attributes['mission_card_1'] ?? null, $this->country, $this->language),
// 'mission_card_2' => ResourceHelper::getValue($this->attributes['mission_card_2'] ?? null, $this->country, $this->language),
// 'mission_card_3' => ResourceHelper::getValue($this->attributes['mission_card_3'] ?? null, $this->country, $this->language),
'open_jobs_tag' => ResourceHelper::getValue($this->attributes['open_jobs_tag'] ?? null, $this->country, $this->language),
'open_jobs_title' => ResourceHelper::getValue($this->attributes['open_jobs_title'] ?? null, $this->country, $this->language),
'team_title' => ResourceHelper::getValue($this->attributes['team_title'] ?? null, $this->country, $this->language),
'team_gallery' => isset($this->attributes['team_gallery']) ? ImageCollection::make($this->attributes['team_gallery'])->country($this->country)->language($this->language) : null,
'git_tag' => ResourceHelper::getValue($this->attributes['git_tag'] ?? null, $this->country, $this->language),
'git_title' => ResourceHelper::getValue($this->attributes['git_title'] ?? null, $this->country, $this->language),
'git_text' => ResourceHelper::getValue($this->attributes['git_text'] ?? null, $this->country, $this->language),
// 'vacancies' => $vacancies ? VacancyCollection::make($vacancies->collect())->country($this->country)->language($this->language)->full(false) : null,
];
}
}