Files
firefly-iii/app/Models/ImportJob.php

110 lines
2.9 KiB
PHP
Raw Normal View History

2016-06-10 21:00:00 +02:00
<?php
/**
* ImportJob.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-06-10 21:00:00 +02:00
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:44:05 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-06-10 21:00:00 +02:00
*/
2017-03-24 15:15:12 +01:00
declare(strict_types=1);
2016-06-10 21:00:00 +02:00
namespace FireflyIII\Models;
2018-03-10 20:25:42 +01:00
use FireflyIII\User;
2016-06-10 21:00:00 +02:00
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2016-11-18 20:06:08 +01:00
/**
2017-11-15 12:25:49 +01:00
* Class ImportJob.
2018-03-10 22:38:20 +01:00
*
* @property array $transactions
* @property array $configuration
* @property User $user
* @property int $user_id
* @property string $status
* @property string $stage
* @property string $key
* @property string $provider
* @property string $file_type
2018-05-23 12:36:12 +02:00
* @property int $tag_id
* @property Tag $tag
2016-11-18 20:06:08 +01:00
*/
2016-06-10 21:00:00 +02:00
class ImportJob extends Model
{
2017-12-17 14:30:53 +01:00
/**
2017-12-23 17:42:07 +01:00
* The attributes that should be casted to native types.
*
2017-12-17 14:30:53 +01:00
* @var array
*/
2017-12-23 17:42:07 +01:00
protected $casts
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'configuration' => 'array',
'extended_status' => 'array',
'transactions' => 'array',
2018-05-03 17:23:16 +02:00
'errors' => 'array',
];
/** @var array */
2018-05-03 17:23:16 +02:00
protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors'];
2016-06-10 21:00:00 +02:00
/**
* @param $value
*
* @return mixed
2017-11-15 12:25:49 +01:00
*
2016-06-10 21:00:00 +02:00
* @throws NotFoundHttpException
*/
2018-02-09 19:24:15 +01:00
public static function routeBinder(string $value): ImportJob
2016-06-10 21:00:00 +02:00
{
if (auth()->check()) {
$key = trim($value);
$importJob = auth()->user()->importJobs()->where('key', $key)->first();
if (null !== $importJob) {
return $importJob;
2016-06-10 21:00:00 +02:00
}
}
throw new NotFoundHttpException;
}
2016-06-27 15:15:46 +02:00
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
2016-06-27 15:15:46 +02:00
*/
public function attachments()
2016-06-27 15:15:46 +02:00
{
return $this->morphMany(Attachment::class, 'attachable');
2016-06-27 15:15:46 +02:00
}
2018-05-03 17:23:16 +02:00
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function tag()
{
return $this->belongsTo(Tag::class);
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
2016-06-10 21:00:00 +02:00
}