Training_Resource::pare()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php namespace App;
2
3
use SleepingOwl\Models\Interfaces\ModelWithImageFieldsInterface;
4
use SleepingOwl\Models\SleepingOwlModel;
5
use SleepingOwl\Models\Traits\ModelWithImageOrFileFieldsTrait;
6
use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8
class Training_Resource extends SleepingOwlModel implements ModelWithImageFieldsInterface
9
{
10
    use ModelWithImageOrFileFieldsTrait;
11
12
    public $timestamps = true;
13
14
15
    /**
16
     * The database table used by the model.
17
     *
18
     * @var string
19
     */
20
    protected $table = 'training_resource';
21
22
23
    /**
24
     * Primary key of the table
25
     * @var string
26
     */
27
    protected $primaryKey = 'training_resource_id';
28
29
30
    /**
31
     * The name of the "created at" column.
32
     *
33
     * @var string
34
     */
35
    const CREATED_AT = 'training_resource_entryDate';
36
37
38
    /**
39
     * The name of the "updated at" column.
40
     *
41
     * @var string
42
     */
43
    const UPDATED_AT = 'training_resource_last_update';
44
45
46
    protected $fillable = [
47
        'training_resource_name',
48
        'training_resource_short_name',
49
        'training_resource_description',
50
        'training_resource_thumbnail',
51
        'training_resource_external_url',
52
        'training_resource_softDeleted',
53
        'training_resource_parentResourceId'
54
    ];
55
56
57
    protected $hidden = [
58
        'training_resource_entryDate',
59
        'training_resource_last_update'
60
    ];
61
62
63
    /**
64
     * Get array of image field names and its directories within images folder
65
     *
66
     * Keys of array is image field names
67
     * Values is their directories
68
     *
69
     * @return string[]
70
     */
71
72
    public function getImageFields()
73
    {
74
        return [
75
            'training_resource_thumbnail' => '/'
76
        ];
77
    }
78
79
    public function parent()
80
    {
81
        return $this->belongsTo('\App\Training_Resource', 'training_resource_parentResourceId');
82
    }
83
84
    public function children()
85
    {
86
        return $this->hasMany('\App\Training_Resource', 'training_resource_id');
87
    }
88
    public static function getList()
89
    {
90
        return static::lists('training_resource_name', 'training_resource_id');
91
    }
92
93
    public function getDates()
94
    {
95
        return array_merge(parent::getDates(), ['training_resource_entryDate','training_resource_last_update']);
96
    }
97
    public function pare($pare)
98
    {
99
        $this->training_resource()->detach();
100
        if ( ! $pare) return;
101
        if ( ! $this->exists) $this->save();
102
        $this->training_resource()->attach($pare);
103
    }
104
105
}