1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NovaAdDirector\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use NovaAdDirector\Factories\AdConfigurationFactory; |
8
|
|
|
use NovaFlexibleContent\Concerns\HasFlexible; |
9
|
|
|
|
10
|
|
|
class AdConfiguration extends Model |
11
|
|
|
{ |
12
|
|
|
use HasFactory, HasFlexible; |
13
|
|
|
|
14
|
|
|
protected $guarded = []; |
15
|
|
|
|
16
|
|
|
public function getTable() |
17
|
|
|
{ |
18
|
|
|
return config('nova-ad-director.tables.ad_configurations'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected static function newFactory() |
22
|
|
|
{ |
23
|
|
|
return new AdConfigurationFactory(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getNameAttribute() |
27
|
|
|
{ |
28
|
|
|
return "{$this->key} ({$this->location})"; |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getFlexibleConfigurationAttribute() |
32
|
|
|
{ |
33
|
|
|
return $this->flexible('configuration', collect(config('nova-ad-director.flexible.configuration.layouts'))->mapWithKeys(fn ($i) => [(new $i)->name() => $i])->toArray()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function active(): bool |
37
|
|
|
{ |
38
|
|
|
return $this->status === 'active'; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function scopeActive($query) |
42
|
|
|
{ |
43
|
|
|
return $query->where('status', '=', 'active'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function disabled(): bool |
47
|
|
|
{ |
48
|
|
|
return $this->status === 'disabled'; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function scopeDisabled($query) |
52
|
|
|
{ |
53
|
|
|
return $query->where('status', '=', 'disabled'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function scopeLocatedKey($query, string $location, string $key) |
57
|
|
|
{ |
58
|
|
|
return $query->where('key', '=', $key) |
59
|
|
|
->where('location', '=', $location); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function scopeLocatedPossibleKeys($query, string $location, array $keys) |
63
|
|
|
{ |
64
|
|
|
return $query->where('location', '=', $location) |
65
|
|
|
->whereIn('key', $keys) |
66
|
|
|
->orderByRaw("FIELD(`key`, '".implode(',', $keys)."')"); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.