forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.php
More file actions
145 lines (128 loc) · 3.63 KB
/
Copy pathTemplate.php
File metadata and controls
145 lines (128 loc) · 3.63 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
142
143
144
145
<?php
namespace app\models;
use Yii;
use yii\data\Pagination;
use app\widgets\LinkPager;
/**
* This is the model class for table "{{%doc_template}}".
*
* @property int $id
* @property string $encode_id 加密id
* @property int $project_id 项目id
* @property string $header_fields header参数,json格式
* @property string $request_fields 请求参数,json格式
* @property string $response_fields 响应参数,json格式
* @property int $status 模板状态
* @property int $creater_id 创建者id
* @property int $updater_id 更新者id
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
*/
class Template extends Model
{
/**
* 绑定数据表
*/
public static function tableName()
{
return '{{%template}}';
}
/**
* 验证规则
*/
public function rules()
{
return [
[['encode_id', 'project_id', 'status'], 'required'],
[['project_id', 'status', 'creater_id', 'updater_id'], 'integer'],
[['header_fields', 'request_fields', 'response_fields'], 'string'],
[['created_at', 'updated_at'], 'safe'],
[['encode_id'], 'string', 'max' => 50],
[['encode_id'], 'unique'],
];
}
/**
* 字段字典
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'encode_id' => '加密id',
'project_id' => '项目id',
'header_fields' => 'header参数,json格式',
'request_fields' => '请求参数,json格式',
'response_fields' => '响应参数,json格式',
'status' => '模板状态',
'creater_id' => '创建者id',
'updater_id' => '更新者id',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* 获取header参数数组
* @return object
*/
public function getHeaderAttributes()
{
return json_decode($this->header_fields);
}
/**
* 获取请求参数数组
* @return object
*/
public function getRequestAttributes()
{
return json_decode($this->request_fields);
}
/**
* 获取响应参数数组
* @return object
*/
public function getResponseAttributes()
{
return json_decode($this->response_fields);
}
/**
* 获取所属项目
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(),['id'=>'project_id']);
}
/** 模板搜索
* @param array $params
* @return $this
* @throws \Exception
*/
public function search($params = [])
{
$this->params = array2object($params);
$query = static::find();
$pagination = new Pagination([
'pageSizeParam' => false,
'totalCount' => $query->count(),
'pageSize' => $this->pageSize,
'validatePage' => false,
]);
$this->models = $query
->offset($pagination->offset)
->limit($pagination->limit)
->orderBy('id DESC')
->all();
$this->count = $query->count();
$this->sql = $query->createCommand()->getRawSql();
$this->pages = LinkPager::widget([
'pagination' => $pagination,
'nextPageLabel' => '下一页',
'prevPageLabel' => '上一页',
'firstPageLabel' => '首页',
'lastPageLabel' => '尾页',
'hideOnSinglePage' => true,
'maxButtonCount' => 5,
]);
return $this;
}
}