firefly-iii/app/Models/ImportJob.php

105 lines
2.8 KiB
PHP
Raw Normal View History

2016-06-10 14:00:00 -05:00
<?php
/**
* ImportJob.php
2017-10-21 01:40:00 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-06-10 14:00:00 -05:00
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
2017-10-21 01:40:00 -05: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 07:44:05 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-06-10 14:00:00 -05:00
*/
2017-03-24 09:15:12 -05:00
declare(strict_types=1);
2016-06-10 14:00:00 -05:00
namespace FireflyIII\Models;
2018-03-10 13:25:42 -06:00
use FireflyIII\User;
2016-06-10 14:00:00 -05:00
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2016-11-18 13:06:08 -06:00
/**
2017-11-15 05:25:49 -06:00
* Class ImportJob.
2018-03-10 15:38:20 -06:00
*
* @property array $transactions
* @property array $configuration
* @property User $user
* @property int $user_id
* @property string $status
* @property string $stage
2016-11-18 13:06:08 -06:00
*/
2016-06-10 14:00:00 -05:00
class ImportJob extends Model
{
2017-12-17 07:30:53 -06:00
/**
2017-12-23 10:42:07 -06:00
* The attributes that should be casted to native types.
*
2017-12-17 07:30:53 -06:00
* @var array
*/
2017-12-23 10:42:07 -06:00
protected $casts
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'configuration' => 'array',
'extended_status' => 'array',
'transactions' => 'array',
2018-05-03 10:23:16 -05:00
'errors' => 'array',
];
/** @var array */
2018-05-03 10:23:16 -05:00
protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors'];
2016-06-10 14:00:00 -05:00
/**
* @param $value
*
* @return mixed
2017-11-15 05:25:49 -06:00
*
2016-06-10 14:00:00 -05:00
* @throws NotFoundHttpException
*/
2018-02-09 12:24:15 -06:00
public static function routeBinder(string $value): ImportJob
2016-06-10 14:00:00 -05:00
{
if (auth()->check()) {
$key = trim($value);
$importJob = auth()->user()->importJobs()->where('key', $key)->first();
if (null !== $importJob) {
return $importJob;
2016-06-10 14:00:00 -05:00
}
}
throw new NotFoundHttpException;
}
2016-06-27 08:15:46 -05:00
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
2016-06-27 08:15:46 -05:00
*/
public function attachments()
2016-06-27 08:15:46 -05:00
{
return $this->morphMany(Attachment::class, 'attachable');
2016-06-27 08:15:46 -05:00
}
2018-05-03 10:23:16 -05: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 14:00:00 -05:00
}