This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDocument.php
More file actions
141 lines (128 loc) · 3.88 KB
/
Document.php
File metadata and controls
141 lines (128 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @author Evgeniy Tkachenko <[email protected]>
*/
namespace tracker\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "{{%document}}".
*
* @property integer $id
* @property string $name
* @property string $description
* @property string $number
* @property string $from
* @property string $to
* @property null|integer $type id from tracker\models\DocumentType
* @property null|integer $category id from tracker\models\DocumentCategory
* @property integer $registered_at
* @property integer $created_at
* @property string $created_by
* @property bool|int $access_for_all
* @property DocumentReceiver[] $receivers
* @property Issue[] $issues
* @property DocumentType|null $typeModel
* @property DocumentCategory|null $categoryModel
* @property DocumentFile $file
*/
class Document extends yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%tracker_document}}';
}
/**
* Returns List of DocumentType models
*
* @return DocumentType[]
*/
public static function types()
{
return DocumentType::findByType(DocumentType::class)->all();
}
/**
* Returns List of DocumentCategory models
*
* @return DocumentCategory[]
*/
public static function categories()
{
return DocumentCategory::findByType(DocumentCategory::class)->all();
}
/**
* @inheritdoc
* @return DocumentQuery the active query used by this AR class.
*/
public static function find()
{
return new DocumentQuery(get_called_class());
}
/**
* @inheritdoc
*/
public function rules()
{
return [
['access_for_all', 'default', 'value' => false],
[['name', 'created_by', 'registered_at', 'created_at', 'access_for_all'], 'required'],
[['registered_at', 'created_at', 'created_by'], 'integer'],
[['description'], 'string'],
[['type', 'category'], 'integer'],
[['number'], 'string', 'max' => 15],
[['name', 'from', 'to'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'name' => Yii::t('TrackerIssuesModule.views', 'Name'),
'file' => Yii::t('TrackerIssuesModule.views', 'File'),
'description' => Yii::t('TrackerIssuesModule.views', 'Resolution, description'),
'number' => Yii::t('TrackerIssuesModule.views', 'Number'),
'from' => Yii::t('TrackerIssuesModule.views', 'From'),
'to' => Yii::t('TrackerIssuesModule.views', 'To'),
'type' => Yii::t('TrackerIssuesModule.views', 'Type'),
'category' => Yii::t('TrackerIssuesModule.views', 'Category'),
'registered_at' => Yii::t('TrackerIssuesModule.views', 'Registered at'),
'access_for_all' => Yii::t('TrackerIssuesModule.views', 'Accessible to all'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getReceivers()
{
return $this->hasMany(DocumentReceiver::className(), ['document_id' => 'id'])->inverseOf('document');
}
/**
* @return ActiveQuery
*/
public function getTypeModel()
{
return $this->hasOne(DocumentType::class, ['id' => 'type']);
}
/**
* @return ActiveQuery
*/
public function getCategoryModel()
{
return $this->hasOne(DocumentCategory::class, ['id' => 'category']);
}
/** @return IssueQuery|ActiveQuery */
public function getIssues()
{
return $this->hasMany(Issue::class, ['id' => 'issue_id'])
->viaTable(DocumentIssue::tableName(), ['document_id' => 'id']);
}
public function getFile()
{
return $this->hasOne(DocumentFile::class, ['document_id' => 'id'])->andWhere(['is_show' => true]);
}
}