mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			110 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * ImportJob.php
 | |
|  * Copyright (c) 2017 thegrumpydictator@gmail.com
 | |
|  *
 | |
|  * This file is part of Firefly III.
 | |
|  *
 | |
|  * 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
 | |
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
 | |
|  */
 | |
| declare(strict_types=1);
 | |
| 
 | |
| namespace FireflyIII\Models;
 | |
| 
 | |
| use FireflyIII\User;
 | |
| use Illuminate\Database\Eloquent\Model;
 | |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 | |
| 
 | |
| /**
 | |
|  * Class ImportJob.
 | |
|  *
 | |
|  * @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
 | |
|  * @property int    $tag_id
 | |
|  * @property Tag    $tag
 | |
|  */
 | |
| class ImportJob extends Model
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * The attributes that should be casted to native types.
 | |
|      *
 | |
|      * @var array
 | |
|      */
 | |
|     protected $casts
 | |
|         = [
 | |
|             'created_at'      => 'datetime',
 | |
|             'updated_at'      => 'datetime',
 | |
|             'configuration'   => 'array',
 | |
|             'extended_status' => 'array',
 | |
|             'transactions'    => 'array',
 | |
|             'errors'          => 'array',
 | |
|         ];
 | |
|     /** @var array */
 | |
|     protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors'];
 | |
| 
 | |
|     /**
 | |
|      * @param $value
 | |
|      *
 | |
|      * @return mixed
 | |
|      *
 | |
|      * @throws NotFoundHttpException
 | |
|      */
 | |
|     public static function routeBinder(string $value): ImportJob
 | |
|     {
 | |
|         if (auth()->check()) {
 | |
|             $key       = trim($value);
 | |
|             $importJob = auth()->user()->importJobs()->where('key', $key)->first();
 | |
|             if (null !== $importJob) {
 | |
|                 return $importJob;
 | |
|             }
 | |
|         }
 | |
|         throw new NotFoundHttpException;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @codeCoverageIgnore
 | |
|      * @return \Illuminate\Database\Eloquent\Relations\MorphMany
 | |
|      */
 | |
|     public function attachments()
 | |
|     {
 | |
|         return $this->morphMany(Attachment::class, 'attachable');
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @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);
 | |
|     }
 | |
| }
 |