misc_pterodactyl-panel/app/Models/Task.php

126 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2016-12-07 22:46:38 +00:00
namespace Pterodactyl\Models;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
2017-09-17 04:10:00 +00:00
use Znck\Eloquent\Traits\BelongsToThrough;
use Sofa\Eloquence\Contracts\CleansAttributes;
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
class Task extends Model implements CleansAttributes, ValidableContract
{
2017-09-17 04:10:00 +00:00
use BelongsToThrough, Eloquence, Validable;
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
const RESOURCE_NAME = 'schedule_task';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'tasks';
/**
* Relationships to be updated when this model is updated.
*
* @var array
*/
protected $touches = ['schedule'];
/**
* Fields that are mass assignable.
*
* @var array
*/
protected $fillable = [
'schedule_id',
2017-09-14 02:46:43 +00:00
'sequence_id',
'action',
'payload',
'time_offset',
'is_queued',
];
2017-03-19 23:36:50 +00:00
/**
* Cast values to correct type.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'schedule_id' => 'integer',
2017-09-14 02:46:43 +00:00
'sequence_id' => 'integer',
'time_offset' => 'integer',
'is_queued' => 'boolean',
2017-03-19 23:36:50 +00:00
];
/**
* Default attributes when creating a new model.
*
* @var array
*/
protected $attributes = [
'is_queued' => false,
];
/**
* @var array
*/
protected static $applicationRules = [
'schedule_id' => 'required',
2017-09-14 02:46:43 +00:00
'sequence_id' => 'required',
'action' => 'required',
'payload' => 'required',
'time_offset' => 'required',
];
/**
* @var array
*/
protected static $dataIntegrityRules = [
'schedule_id' => 'numeric|exists:schedules,id',
2017-09-14 02:46:43 +00:00
'sequence_id' => 'numeric|min:1',
'action' => 'string',
'payload' => 'string',
'time_offset' => 'numeric|between:0,900',
'is_queued' => 'boolean',
];
/**
* Return a hashid encoded string to represent the ID of the task.
*
* @return string
*/
public function getHashidAttribute()
{
return app()->make('hashids')->encode($this->id);
}
2017-04-15 17:52:43 +00:00
/**
* Return the schedule that a task belongs to.
2017-04-15 17:52:43 +00:00
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function schedule()
2017-04-15 17:52:43 +00:00
{
return $this->belongsTo(Schedule::class);
2017-04-15 17:52:43 +00:00
}
/**
* Return the server a task is assigned to, acts as a belongsToThrough.
2017-04-15 17:52:43 +00:00
*
2017-09-17 04:10:00 +00:00
* @return \Znck\Eloquent\Relations\BelongsToThrough
* @throws \Exception
2017-04-15 17:52:43 +00:00
*/
public function server()
{
2017-09-17 04:10:00 +00:00
return $this->belongsToThrough(Server::class, Schedule::class);
}
}