-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATingExt.class.php
144 lines (127 loc) · 4.27 KB
/
ATingExt.class.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
<?php
/***************************************************************************
*
* Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
*
**************************************************************************/
/**
* @file ATingExt.class.php
* @brief 对Ating 进行了简单的扩展 简化了一些CURD 初始化方法等
* @author sunhuai([email protected])
* @version
* @date 2012-10-25 14:48:43
*/
class ATingExt extends ATing {
//操作的table 名称
protected $_table = '';
/**
* @brief 继承基类的初始化方法 并定义一个init
*
* @returns
*/
public function __construct() {
parent::__construct();
$this->init();
}
public function tingQuery($condition) {
}
/**
* @brief 自定义初始化方法
*
* @returns
*/
public function init() {
}
public function _i($row, $options = NULL, $onUup = NULL) {
return $this->i($this->_table, $row, $options, $onUup);
}
public function _u($row, $conds = NULL, $options = NULL, $appends = NULL)
{
return $this->u($this->_table, $row, $conds, $options, $appends);
}
public function _selectCount($conds = NULL) {
return $this->selectCount($this->_table, $conds);
}
public function _select($columnList = array(), $where = array(), $orderBy = '', $offset, $num) {
$sql = '';
$columns = '*';
$conditionList = array();
if (!is_array($columnList) || !is_array($where)) {
return FALSE;
}
if (!empty($columnList)) {
$columns = join(',', $columnList);
}
$sql .= 'SELECT ' . $columns . ' FROM ' . $this->_table;
if (!empty($where)) {
foreach ($where as $columnStr => $value) {
$columnAttr = explode(" ", trim($columnStr));
$column = $columnAttr[0];
if (count($columnAttr) == 1) {
if (is_string($value)) {
$conditionList[] = $column . ' = ' . "'" . $value . "'";
} else {
$conditionList[] = $column . ' = ' . $value;
}
} else {
$operator = ' ' . $columnAttr[1] . ' ';
if ($columnAttr[1] != 'in') {
if (is_string($value)) {
$conditionList[] = $column . $operator . "'" . $value . "'";
} else {
$conditionList[] = $column . $operator . $value;
}
} else {
$inCondition = array();
foreach ($value as $inVal) {
if (is_string($inVal)) {
$inCondition[] = "'" . $inVal . "'";
} else {
$inCondition[] = $inVal;
}
}
$conditionList[] = $column . $operator . "(" . join(',', $inCondition) . ")";
}
}
}
$sql .= ' WHERE ' . join(' AND ', $conditionList);
}
if ($orderBy) {
$sql .= ' ORDER BY ' . $orderBy;
}
if (isset($offset, $num)) {
$sql .= ' LIMIT ' . $offset . ',' . $num;
}
echo $sql;
exit();
return $this->q($sql);
}
public function _d($conds = NULL, $options = NULL, $appends = NULL) {
return $this->d($this->_table, $conds, $options, $appends);
}
/**
* @brief 简化GET获取参数
*
* @param $name
* @param $default
*
* @returns
*/
public function _getParam($name, $default) {
return TingExtHttpRequest::_getParam($name, $default);
}
/**
* @brief 简化POST获取参数
*
* @param $name
* @param $default
*
* @returns
*/
public function _postParam($name, $default) {
return TingExtHttpRequest::_postParam($name, $default);
}
public function _getFields($filterFields = array(), $requestMethod = 'GET') {
return TingExtHttpRequest::_getFields($filterFields, $requestMethod);
}
}