-
Notifications
You must be signed in to change notification settings - Fork 11
/
vehicles.php
129 lines (125 loc) · 4.97 KB
/
vehicles.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
<?php
/**
* @filesource modules/car/views/vehicles.php
*
* @copyright 2016 Goragod.com
* @license https://www.kotchasan.com/license/
*
* @see https://www.kotchasan.com/
*/
namespace Car\Vehicles;
use Kotchasan\DataTable;
use Kotchasan\Http\Request;
use Kotchasan\Language;
/**
* module=car-vehicles
*
* @author Goragod Wiriya <admin@goragod.com>
*
* @since 1.0
*/
class View extends \Gcms\View
{
/**
* ตารางยานพาหนะ
*
* @param Request $request
*
* @return string
*/
public function render(Request $request)
{
$category = \Car\Category\Model::init();
$filter_sources = Language::get('CAR_SELECT', []);
$filters = [];
$params = [
'published' => 1
];
foreach ($filter_sources as $key => $label) {
$params[$key] = $request->request($key)->topic();
$filters[] = array(
'name' => $key,
'text' => $label,
'options' => array('' => '{LNG_all items}') + $category->toSelect($key),
'value' => $params[$key]
);
}
// URL สำหรับส่งให้ตาราง
$uri = $request->createUriWithGlobals(WEB_URL.'index.php');
// ตาราง
$table = new DataTable(array(
/* Uri */
'uri' => $uri,
/* Model */
'model' => \Car\Vehicles\Model::toDataTable($params),
/* รายการต่อหน้า */
'perPage' => $request->cookie('car_perPage', 30)->toInt(),
/* ฟังก์ชั่นจัดรูปแบบการแสดงผลแถวของตาราง */
'onRow' => array($this, 'onRow'),
/* คอลัมน์ที่ไม่ต้องแสดงผล */
'hideColumns' => array('detail', 'color'),
/* ตั้งค่าการกระทำของของตัวเลือกต่างๆ ด้านล่างตาราง ซึ่งจะใช้ร่วมกับการขีดถูกเลือกแถว */
'action' => 'index.php/car/model/vehicles/action',
'actionCallback' => 'dataTableActionCallback',
/* ตัวเลือกด้านบนของตาราง ใช้จำกัดผลลัพท์การ query */
'filters' => $filters,
/* ส่วนหัวของตาราง และการเรียงลำดับ (thead) */
'headers' => array(
'id' => array(
'text' => ''
),
'number' => array(
'text' => '{LNG_Vehicle}',
'sort' => 'number'
),
'seats' => array(
'text' => '{LNG_Number of seats}',
'class' => 'center',
'sort' => 'seats'
)
),
/* รูปแบบการแสดงผลของคอลัมน์ (tbody) */
'cols' => array(
'number' => array(
'class' => 'top'
),
'seats' => array(
'class' => 'center'
)
),
/* ปุ่มแสดงในแต่ละแถว */
'buttons' => array(
'car' => array(
'class' => 'icon-addtocart button blue',
'id' => ':id',
'text' => '{LNG_Book a vehicle}'
),
'detail' => array(
'class' => 'icon-info button orange',
'id' => ':id',
'text' => '{LNG_Detail}'
)
)
));
// save cookie
setcookie('car_perPage', $table->perPage, time() + 2592000, '/', HOST, HTTPS, true);
// คืนค่า HTML
return $table->render();
}
/**
* จัดรูปแบบการแสดงผลในแต่ละแถว
*
* @param array $item ข้อมูลแถว
* @param int $o ID ของข้อมูล
* @param object $prop กำหนด properties ของ TR
*
* @return array
*/
public function onRow($item, $o, $prop)
{
$item['number'] = '<span class="term" style="background-color:'.$item['color'].'">'.$item['number'].'</span><p class=cuttext>'.strip_tags($item['detail']).'</p>';
$thumb = is_file(ROOT_PATH.DATA_FOLDER.'car/'.$item['id'].'.jpg') ? WEB_URL.DATA_FOLDER.'car/'.$item['id'].'.jpg' : WEB_URL.'modules/car/img/noimage.png';
$item['id'] = '<img src="'.$thumb.'" style="max-height:4em;max-width:8em;" alt=thumbnail>';
return $item;
}
}