|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\models; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* This is the model class for table "field_has_content_type". |
|
9
|
|
|
* |
|
10
|
|
|
* @property int $field_id |
|
11
|
|
|
* @property string $content_type_id |
|
12
|
|
|
* @property Field $field |
|
13
|
|
|
* @property ContentType $contentType |
|
14
|
|
|
*/ |
|
15
|
|
View Code Duplication |
class FieldHasContentType extends \yii\db\ActiveRecord |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public static function tableName() |
|
21
|
|
|
{ |
|
22
|
|
|
return 'field_has_content_type'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function rules() |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
[['field_id', 'content_type_id'], 'required'], |
|
32
|
|
|
[['field_id'], 'integer'], |
|
33
|
|
|
[['content_type_id'], 'string', 'max' => 45], |
|
34
|
|
|
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => Field::class, 'targetAttribute' => ['field_id' => 'id']], |
|
35
|
|
|
[['content_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => ContentType::class, 'targetAttribute' => ['content_type_id' => 'id']], |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function attributeLabels() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
'field_id' => Yii::t('app', 'Field ID'), |
|
46
|
|
|
'content_type_id' => Yii::t('app', 'Content Type'), |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return \yii\db\ActiveQuery |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getField() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->hasOne(Field::class, ['id' => 'field_id']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return \yii\db\ActiveQuery |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getContentType() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->hasOne(ContentType::class, ['id' => 'content_type_id']); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.