-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.php
61 lines (56 loc) · 2.21 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
<?php
/**
* Created by PhpStorm.
* User: thijs
* Date: 30-5-2016
* Time: 15:08
*/
class Helper {
public static function getDropDown(string $name, array $array, string $selected='') {
if(!empty($array)) {
$selectBox = '<select name="'.$name.'" id="'.$name.'"><option></option>';
foreach ($array as $id => $value) {
$selectBox.='<option value="'.$id.'" ';
$selectBox.=($id == $selected)?'selected':'';
$selectBox.='>'.$value.'</option>';
}
return $selectBox.='</select>';
} else {
return '';
}
}
public static function getPagination(string $name, int $max, int $current, int $size) {
$pagination ='<ul class="pagination">';
$min = ceil($current-$size/2);
if($min < 0) {
$min = 0;
}
$tempMax = $min+$size;
if( $tempMax > $max) {
$tempMax = $max;
}
if($current!=0) {
$pagination.='<li><a href="'.$name.'0"><<<</a></li>';
$pagination.='<li><a href="'.$name.($current-1).'"><<</a></li>';
}
for ($index = $min; $index <$current; $index++) {
$pagination.='<li><a href="'.$name.$index.'">'.$index.'</a></li>';
}
$pagination.='<li><a href="'.$name.$current.'" class="active">'.$index.'</a></li>';
for ($index = $current+1; $index<$tempMax; $index++) {
$pagination.='<li><a href="'.$name.$index.'">'.$index.'</a></li>';
}
if($current!=$max) {
$pagination.='<li><a href="'.$name.($current+1).'">>></a></li>';
$pagination.='<li><a href="'.$name.($max).'">>>></a></li>';
}
return $pagination.'</ul>';
}
public static function getHiddenInput(string $name, string $value) {
return '<input type="hidden" name="'.$name.'" value="'.$value.'"/>';
}
public static function getCheckBox(string $name, string $checkedValue, string $uncheckedValue='') {
return (($uncheckedValue=='')?'':'<input type="hidden" name="'.$name.'" value="'.$uncheckedValue.'" id="'.$name.'"/>').
'<input type="checkbox" name="'.$name.'" value="'.$checkedValue.'"/>';
}
}