-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.php
181 lines (150 loc) · 7.52 KB
/
Helper.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
<?php
class Helper {
// Create 1 button thao tác
public static function createActionBtn($class, $classIcon, $link = '#' ,$title = '', $type = 'new', $style = ''){
$xhtml = '<li>';
switch ($type){
case 'new':
$xhtml .= '<a class="'.$class.'" href="'.$link.'" title="'.$title.'">
<i class="'.$classIcon.'"></i>
</a>';
break;
case 'submit':
$xhtml .= '<a class="'.$class.'" href="javascript:submitForm(\''.$link.'\');" title="'.$title.'">
<i class="'.$classIcon.'"></i>
</a>';
break;
}
$xhtml .= '</li>';
return $xhtml;
}
// Create input
public static function createInput($type, $name, $id, $class, $value = '', $placeholder = '', $disabled = false){
$strDisabled = '';
if($disabled == true){
$strDisabled = 'disabled';
}
return '<input type="'.$type.'" name="'.$name.'" id="'.$id.'" class="'.$class.'" value="'.$value.'" placeholder="'.$placeholder.'" '.$strDisabled.'>';
}
// Create select box
/* <select name="select" class="form-control">
<option value="opt1">Select One Value Only</option>
<option value="opt2">Type 2</option>
</select> */
public static function CreateSelectBox($arrValue, $name, $id, $class, $keySelected, $dataId = ''){
$strDataid = '';
if($dataId != ''){
$strDataid = 'data-id='.$dataId;
}
$xhtml = '<select '.$strDataid.' name="'.$name.'" id="'.$id.'" class="'.$class.'">';
if(!empty($arrValue)){
foreach($arrValue as $key => $value){
if($key == $keySelected){
$xhtml .= '<option value="'.$key.'" selected="selected" >'.$value.'</option>';
}
else{
$xhtml .= '<option value="'.$key.'">'.$value.'</option>';
}
}
}
$xhtml .= '</select>';
return $xhtml;
}
// Create alert
public static function createAlert($class, $message){
$xhtml = '';
if(!empty($message)){
$xhtml = '<div class="'.$class.'">
<strong>'.$message.'</strong>
</div>';
}
return $xhtml;
}
// Create status
/* <a class="mytooltip tooltip-effect-7" id="status-'.$id.'" href="javascript:changeStatus(\''.$link.'\');" title="Publish">
<i class="fa fa-check-circle"></i>
</a> */
public static function createStatus($value, $link, $id){
$classStatus = ($value == 1) ? 'fa-check-circle' : 'fa-times-circle';
$xhtml = '<a class="status" id="status-'.$id.'" href="javascript:changeStatus(\''.$link.'\');">
<i class="fa '.$classStatus.'"></i>
</a>';
return $xhtml;
}
// Create status group ACP
public static function createGroupACP($value, $link, $id){
$classStatus = ($value == 1) ? 'fa-check-circle' : 'fa-times-circle';
$xhtml = '<a class="status" id="group-acp-'.$id.'" href="javascript:changeGroupACP(\''.$link.'\');">
<i class="fa '.$classStatus.'"></i>
</a>';
return $xhtml;
}
// Create status special
public static function createSpecial($value, $link, $id){
$classStatus = ($value == 1) ? 'fa-check-circle' : 'fa-times-circle';
$xhtml = '<a class="status" id="special-'.$id.'" href="javascript:changeSpecial(\''.$link.'\');">
<i class="fa '.$classStatus.'"></i>
</a>';
return $xhtml;
}
//Rút ngắn văn bản
public static function shortenText($text, $wordCount){
if($text == null){
return '';
}
if(!empty($text) || trim($text) != null){
if(str_word_count($text) > $wordCount){
$arrWord = array_slice(explode(' ', $text), 0, $wordCount);
return implode(' ', $arrWord) . '...';
}
return $text;
}
}
public static function ramdomString($length = 5){
$arrChar = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
$strChar = implode("", $arrChar);
// random chuỗi
$strChar = str_shuffle($strChar);
$nameFile = substr($strChar, 0, $length);
return $nameFile;
}
public static function createImage($folderImg, $nameImg, $attribute = null){
$strAttribute = '';
if(!empty($attribute)){
foreach($attribute as $key => $value){
$strAttribute .= ' ' . $key . '="' . $value . '"';
}
}
$picturePath = PUBLIC_PATH . 'upload/images/' . $folderImg . '/' . $nameImg;
if(file_exists($picturePath) == true){
$picture = '<img '.$strAttribute.' src="'.PUBLIC_URL . 'upload/images/' . $folderImg . '/' . $nameImg.'" alt="" title="" border="0" />';
}
else{
echo 'huhu';
$picture = '<img '.$strAttribute.' src="'.PUBLIC_URL . 'upload/images/' . $folderImg . '/' . '-default.jpg'.'" alt="" title="" border="0" />';
}
return $picture;
}
// Chuyển thành chuỗi không dấu
public static function unsignedStr($str){
$str = preg_replace("/\(|\./", ' ', $str);
$str = preg_replace("/\)/", ' ', $str);
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
$str = preg_replace("/(đ)/", 'd', $str);
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
$str = preg_replace("/(Đ)/", 'D', $str);
$str = preg_replace("/-/", '', $str);
return str_replace(' ', '-', trim(strtolower($str)));
}
}
?>