forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootGrid.php
47 lines (40 loc) · 1.49 KB
/
bootGrid.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
<?php
class BootGrid {
static function getSqlFromPost($searchFieldsNames = array(), $keyPrefix = "", $alternativeOrderBy = "") {
$sql = self::getSqlSearchFromPost($searchFieldsNames);
if (!empty($_POST['sort'])) {
$orderBy = array();
foreach ($_POST['sort'] as $key => $value) {
$orderBy[] = " {$keyPrefix}{$key} {$value} ";
}
$sql .= " ORDER BY ".implode(",", $orderBy);
} else {
$sql .= $alternativeOrderBy;
}
if(!empty($_POST['rowCount']) && !empty($_POST['current']) && $_POST['rowCount']>0){
$current = ($_POST['current']-1)*$_POST['rowCount'];
$sql .= " LIMIT $current, {$_POST['rowCount']} ";
}else{
$_POST['current'] = 0;
$_POST['rowCount'] = 0;
}
return $sql;
}
static function getSqlSearchFromPost($searchFieldsNames = array()) {
$sql = "";
if(!empty($_POST['searchPhrase'])){
global $global;
$search = $global['mysqli']->real_escape_string($_POST['searchPhrase']);
$like = array();
foreach ($searchFieldsNames as $value) {
$like[] = " {$value} LIKE '%{$search}%' ";
}
if(!empty($like)){
$sql .= " AND (". implode(" OR ", $like).")";
}else{
$sql .= " AND 1=1 ";
}
}
return $sql;
}
}