-
Notifications
You must be signed in to change notification settings - Fork 24
/
detail.php
130 lines (125 loc) · 4.78 KB
/
detail.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
<?php
/**
* @filesource modules/repair/views/detail.php
*
* @copyright 2016 Goragod.com
* @license https://www.kotchasan.com/license/
*
* @see https://www.kotchasan.com/
*/
namespace Repair\Detail;
use Gcms\Login;
use Kotchasan\DataTable;
use Kotchasan\Date;
use Kotchasan\Template;
/**
* module=repair-detail
*
* @author Goragod Wiriya <admin@goragod.com>
*
* @since 1.0
*/
class View extends \Gcms\View
{
/**
* @var mixed
*/
private $statuses;
/**
* แสดงรายละเอียดการซ่อม
*
* @param object $index
* @param array $login
*
* @return string
*/
public function render($index, $login)
{
// สถานะการซ่อม
$this->statuses = \Repair\Status\Model::create();
// อ่านสถานะการทำรายการทั้งหมด
$statuses = \Repair\Detail\Model::getAllStatus($index->id);
// URL สำหรับส่งให้ตาราง
$uri = self::$request->createUriWithGlobals(WEB_URL.'index.php');
// ตาราง
$table = new DataTable(array(
/* Uri */
'uri' => $uri,
/* array datas */
'datas' => $statuses,
/* ฟังก์ชั่นจัดรูปแบบการแสดงผลแถวของตาราง */
'onRow' => array($this, 'onRow'),
/* คอลัมน์ที่ไม่ต้องแสดงผล */
'hideColumns' => array('id'),
/* ตั้งค่าการกระทำของของตัวเลือกต่างๆ ด้านล่างตาราง ซึ่งจะใช้ร่วมกับการขีดถูกเลือกแถว */
'action' => 'index.php/repair/model/detail/action?repair_id='.$index->id,
'actionCallback' => 'dataTableActionCallback',
/* ส่วนหัวของตาราง และการเรียงลำดับ (thead) */
'headers' => array(
'name' => array(
'text' => '{LNG_Operator}'
),
'status' => array(
'text' => '{LNG_Repair status}',
'class' => 'center'
),
'create_date' => array(
'text' => '{LNG_Transaction date}',
'class' => 'center'
),
'comment' => array(
'text' => '{LNG_Comment}'
)
),
/* รูปแบบการแสดงผลของคอลัมน์ (tbody) */
'cols' => array(
'status' => array(
'class' => 'center'
),
'create_date' => array(
'class' => 'center'
)
)
));
if (Login::checkPermission($login, array('can_manage_repair', 'can_repair'))) {
/* ปุ่มแสดงในแต่ละแถว */
$table->buttons = array(
'delete' => array(
'class' => 'icon-delete button red notext',
'id' => ':id',
'title' => '{LNG_Delete}'
)
);
}
// template
$template = Template::createFromFile(ROOT_PATH.'modules/repair/views/detail.html');
$template->add(array(
'/%NAME%/' => $index->name,
'/%PHONE%/' => $index->phone,
'/%TOPIC%/' => $index->topic,
'/%PRODUCT_NO%/' => base64_encode(\Kotchasan\Barcode::create($index->product_no, 30, 9)->toPng()),
'/%JOB_DESCRIPTION%/' => nl2br($index->job_description),
'/%CREATE_DATE%/' => Date::format($index->create_date, 'd M Y'),
'/%COMMENT%/' => $index->comment,
'/%DETAILS%/' => $table->render()
));
// คืนค่า HTML
return $template->render();
}
/**
* จัดรูปแบบการแสดงผลในแต่ละแถว
*
* @param array $item ข้อมูลแถว
* @param int $o ID ของข้อมูล
* @param object $prop กำหนด properties ของ TR
*
* @return array คืนค่า $item กลับไป
*/
public function onRow($item, $o, $prop)
{
$item['comment'] = nl2br($item['comment']);
$item['create_date'] = Date::format($item['create_date'], 'd M Y H:i');
$item['status'] = '<mark class=term style="background-color:'.$this->statuses->getColor($item['status']).'">'.$this->statuses->get($item['status']).'</mark>';
return $item;
}
}