/
setup.php
198 lines (193 loc) · 7.53 KB
/
setup.php
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/**
* @filesource modules/dms/views/setup.php
*
* @copyright 2016 Goragod.com
* @license https://www.kotchasan.com/license/
*
* @see https://www.kotchasan.com/
*/
namespace Dms\Setup;
use Kotchasan\DataTable;
use Kotchasan\Date;
use Kotchasan\Http\Request;
/**
* module=dms-setup
*
* @author Goragod Wiriya <admin@goragod.com>
*
* @since 1.0
*/
class View extends \Gcms\View
{
/**
* แสดงรายการเอกสารส่ง
*
* @param Request $request
* @param array $login
*
* @return string
*/
public function render(Request $request, $login)
{
// ค่าที่ส่งมา
$params = array(
'from' => $request->request('from')->date(),
'to' => $request->request('to')->date()
);
// หมวดหมู่
$category = \Dms\Category\Model::init();
foreach ($category->items() as $k => $label) {
$params[$k] = $request->request($k)->topic();
}
if (!($login['status'] == 1 || empty($login['department']) || empty(self::$cfg->dms_upload_options))) {
$params['department'] = $login['department'];
}
// URL สำหรับส่งให้ตาราง
$uri = $request->createUriWithGlobals(WEB_URL.'index.php');
// ตาราง
$table = new DataTable(array(
/* Uri */
'uri' => $uri,
/* Model */
'model' => \Dms\Setup\Model::toDataTable($params),
/* รายการต่อหน้า */
'perPage' => $request->cookie('dmsSetup_perPage', 30)->toInt(),
/* เรียงลำดับ */
'sort' => $request->cookie('dmsSetup_sort', 'create_date DESC')->toString(),
/* ฟังก์ชั่นจัดรูปแบบการแสดงผลแถวของตาราง */
'onRow' => array($this, 'onRow'),
/* คอลัมน์ที่ไม่ต้องแสดงผล */
'hideColumns' => array('id', 'url'),
/* ตั้งค่าการกระทำของของตัวเลือกต่างๆ ด้านล่างตาราง ซึ่งจะใช้ร่วมกับการขีดถูกเลือกแถว */
'action' => 'index.php/dms/model/setup/action',
'actionCallback' => 'dataTableActionCallback',
'actions' => array(
array(
'id' => 'action',
'class' => 'ok',
'text' => '{LNG_With selected}',
'options' => array(
'delete' => '{LNG_Delete}'
)
)
),
/* คอลัมน์ที่สามารถค้นหาได้ */
'searchColumns' => array('topic', 'document_no'),
/* ตัวเลือกการแสดงผลที่ส่วนหัว */
'filters' => array(
array(
'name' => 'from',
'type' => 'date',
'text' => '{LNG_from}',
'value' => $params['from']
),
array(
'name' => 'to',
'type' => 'date',
'text' => '{LNG_to}',
'value' => $params['to']
)
),
/* ส่วนหัวของตาราง และการเรียงลำดับ (thead) */
'headers' => array(
'create_date' => array(
'text' => '{LNG_Date}',
'sort' => 'create_date'
),
'document_no' => array(
'text' => '{LNG_Document No.}',
'sort' => 'document_no'
),
'topic' => array(
'text' => '{LNG_Document title}',
'sort' => 'topic'
)
),
/* ฟังก์ชั่นตรวจสอบการแสดงผลปุ่มในแถว */
'onCreateButton' => array($this, 'onCreateButton'),
/* ปุ่มแสดงในแต่ละแถว */
'buttons' => array(
'files' => array(
'class' => 'icon-documents button brown',
'href' => $uri->createBackUri(array('module' => 'dms-files', 'id' => ':id')),
'text' => '{LNG_File}'
),
'edit' => array(
'class' => 'icon-edit button green',
'href' => $uri->createBackUri(array('module' => 'dms-write', 'id' => ':id')),
'text' => '{LNG_Edit}'
)
),
/* ปุ่มเพิ่ม */
'addNew' => array(
'class' => 'float_button icon-new',
'href' => $uri->createBackUri(array('module' => 'dms-write')),
'title' => '{LNG_Upload} {LNG_Document}'
)
));
foreach ($category->items() as $k => $label) {
if ($k == 'department' && !($login['status'] == 1 || empty($login['department']) || empty(self::$cfg->dms_upload_options))) {
$categories = [];
foreach ($login['department'] as $department) {
$categories[$department] = $category->get('department', $department);
}
} else {
$categories = $category->toSelect($k);
}
$table->filters[] = array(
'name' => $k,
'text' => $label,
'datalist' => $categories,
'value' => $params[$k]
);
$table->headers[$k] = array(
'text' => $label,
'class' => 'center'
);
$table->cols[$k] = array(
'class' => 'center'
);
}
// save cookie
setcookie('dmsSetup_perPage', $table->perPage, time() + 2592000, '/', HOST, HTTPS, true);
setcookie('dmsSetup_sort', $table->sort, time() + 2592000, '/', HOST, HTTPS, true);
// คืนค่า HTML
return $table->render();
}
/**
* จัดรูปแบบการแสดงผลในแต่ละแถว
*
* @param array $item
*
* @return array
*/
public function onRow($item, $o, $prop)
{
$item['cabinet'] = '<span class="two_lines" title="'.$item['cabinet'].'">'.$item['cabinet'].'</span>';
if (isset($item['department'])) {
$item['department'] = '<span class="two_lines" title="'.$item['department'].'">'.$item['department'].'</span>';
}
$item['create_date'] = Date::format($item['create_date'], 'd M Y');
return $item;
}
/**
* ฟังกชั่นตรวจสอบว่าสามารถสร้างปุ่มได้หรือไม่
*
* @param array $item
*
* @return array
*/
public function onCreateButton($btn, $attributes, $item)
{
if ($btn == 'files') {
if ($item['url'] != '') {
$attributes['href'] = $item['url'];
$attributes['class'] = 'button blue icon-world';
$attributes['text'] = '{LNG_URL}';
$attributes['target'] = '_blank';
}
}
return $attributes;
}
}