1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This model represents one translation for a term. |
5
|
|
|
*/ |
6
|
|
|
namespace Rocket\Taxonomy\Model; |
7
|
|
|
|
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
9
|
|
|
use Rocket\Taxonomy\Support\Laravel5\Facade as T; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The translation Data for a term |
13
|
|
|
* |
14
|
|
|
* @property int $id |
15
|
|
|
* @property int $term_id |
16
|
|
|
* @property int $language_id |
17
|
|
|
* @property string $title |
18
|
|
|
* @property string $description |
19
|
|
|
*/ |
20
|
|
|
class TermData extends Model |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var bool Indicates if the model should be timestamped. |
24
|
|
|
*/ |
25
|
|
|
public $timestamps = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string The table associated with the model. |
29
|
|
|
*/ |
30
|
|
|
protected $table = 'taxonomy_terms_data'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* When used in a term, we set this to true or false |
34
|
|
|
*/ |
35
|
|
|
public $translated = true; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array The attributes that are mass assignable. |
39
|
|
|
*/ |
40
|
|
|
protected $fillable = ['term_id', 'language_id', 'title', 'description']; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create a new Eloquent model instance. |
44
|
|
|
* |
45
|
|
|
* @param array $attributes |
46
|
|
|
* @return void |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function __construct(array $attributes = []) |
49
|
|
|
{ |
50
|
|
|
parent::__construct($attributes); |
51
|
|
|
|
52
|
|
|
if (array_key_exists('translated', $attributes)) { |
53
|
|
|
$this->translated = $attributes['translated']; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the term this data is linked to. |
59
|
174 |
|
* |
60
|
|
|
* @codeCoverageIgnore |
61
|
174 |
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
62
|
3 |
|
*/ |
63
|
3 |
|
public function term() |
64
|
|
|
{ |
65
|
174 |
|
return $this->belongsTo(TermContainer::class, 'term_id'); |
66
|
|
|
} |
67
|
174 |
|
|
68
|
174 |
|
/** |
69
|
|
|
* Save the model to the database. |
70
|
|
|
* |
71
|
|
|
* @param array $options |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function save(array $options = []) |
75
|
|
|
{ |
76
|
|
|
if ($this->translated === false) { |
77
|
|
|
$this->translated = true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
T::uncacheTerm($this->term_id); |
81
|
|
|
|
82
|
|
|
parent::save($options); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function toArray() |
86
|
|
|
{ |
87
|
|
|
$array = parent::toArray(); |
88
|
|
|
$array['translated'] = $this->translated; |
89
|
|
|
return $array; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.