File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Vacancies/Models/Vacancy.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Vacancies\Models;
use App\KommaApp\Categories\Models\Category;
use App\KommaApp\Documents\DocumentsTrait;
use App\KommaApp\Documents\Kms\DocumentableInterface;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\NestedSets\Nodes\TranslatableEloquentNode;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Sites\Models\Site;
use App\KommaApp\Users\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Page
*
* @package App\KommaApp\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Sites\Models\Site[] $sites
* @property \App\KommaApp\Vacancies\Models\VacancyTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Vacancies\Models\VacancyTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Vacancies\Models\Vacancy whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Vacancies\Models\Vacancy whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Vacancies\Models\Vacancy whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Vacancies\Models\Vacancy whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Vacancies\Models\Vacancy whereUpdatedAt($value)
*/
class Vacancy extends TranslatableEloquentNode implements DocumentableInterface
{
use DocumentsTrait;
protected $table = 'vacancies';
protected $class = Vacancy::class;
static public $amountOfBenefits = 9;
static public $amountOfPersonalityMarks = 5;
static public $amountOfSkills = 12;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
public $blocks = false;
protected $fillable = ['active', 'site_id', 'lft', 'rgt', 'tree'];
public function site(): BelongsTo
{
return $this->belongsTo(Site::class);
}
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(VacancyTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'vacancy_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
/**
* Get the images from the current user
*
* @return \Illuminate\Database\Eloquent\Relations\hasMany
*/
public function images(): HasMany
{
/**
*
* On the Image model is an MorphTo relation
* By using a hasMany relation:
* where the imageable_type is filled in with the KmsClass
* And the imageable_id is set as the foreign_id,
* we can collect the images of the given model directly.
*
*/
return $this->hasMany(Image::class, 'imageable_id')
->where('imageable_type', '=', $this->class);
}
public function __get($key)
{
if($key == "title") {
if($this->translation) {
return $this->translation->name;
}
}
return parent::__get($key);
}
public function structuredData()
{
$description = "<p>" . $this->translation->intro_description . "</p><p>Jij bent</p><ul>";
for($i = 1; $i < 5; $i++) if(!empty($this->translation->{'personality_title_' . $i}) && !empty($this->translation->{'personality_description_' . $i})) $description .= '<li>' . $this->translation->{'personality_title_' . $i} . ' - ' . $this->translation->{'personality_description_' . $i} . '</li>';
$description .= "</ul><p>Skills</p><ul>";
for($i = 1; $i < 12; $i++) if(!empty($this->translation->{'skill_' . $i})) $description .= '<li>' . $this->translation->{'skill_' . $i} . '</li>';
$description .= "</ul>";
return '{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"jobLocation": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"streetAddress": "Clement van Maasdijkstraat 3",
"addressLocality": "Budel",
"postalCode": "6021PJ",
"addressCountry": "NL"
}
},
"employmentType": "FULL_TIME",
"datePosted": "' . $this->created_at . '",
"title": "' . $this->translation->name . '",
"description": "' . $description . '",
"hiringOrganization": {
"@type": "Organization",
"name": "Komma",
"sameAs": "https://komma.nl",
"logo": "https://komma.nl/img/kms/logo_blue.svg"
},
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "EUR",
"value": {
"@type": "QuantitativeValue",
"minValue": ' . $this->min_salary .',
"maxValue": ' . $this->max_salary .',
"unitText": "MONTH"
}
}
}';
}
}