MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mbusiness.class
Ir para a documentação deste ficheiro.
1
<?php
2
class
MBusiness
extends
PersistentObject
3
{
4
var
$_bmodule
;
// the module of this class
5
var
$_bclass
;
// the name of this class
6
var
$_errors
;
7
var
$_database
;
8
var
$_db
;
9
var
$_transaction
;
10
var
$_miolo
;
11
12
function
__construct
($database = NULL, $data = NULL)
13
{
14
parent::__construct();
15
$this->_miolo =
MIOLO::getInstance
();
16
$this->_errors = array();
17
$this->
GetDatabase
($database);
18
$this->_transaction = NULL;
19
}
20
21
function
OnCreate
($data = NULL)
22
{
23
if
(is_null($data))
24
{
25
return
;
26
}
27
elseif (is_object($data))
28
{
29
$this->
SetData
($data);
30
}
31
else
32
{
33
$this->
GetById
($data);
34
}
35
}
36
37
public
function
GetById
($data=NULL)
38
{
39
}
40
41
function
CheckError
()
42
{
43
$err = $this->_db->GetError();
44
if
($err)
45
{
46
$this->_errors[] = $err;
47
}
48
return
(count($this->_errors) > 0);
49
}
50
51
function
GetErrors
()
52
{
53
return
$this->_errors
;
54
}
55
56
function
AddError
($err)
57
{
58
if
($err)
59
{
60
if
(is_array($err))
61
{
62
$this->_errors = array_merge($this->_errors, $err);
63
}
64
else
65
{
66
$this->_errors[] = $err;
67
}
68
}
69
}
70
71
function
GetData
()
72
{
73
return
$this;
74
}
75
76
public
function
SetData
($data = NULL)
77
{
78
if
(is_null($data))
79
{
80
return
;
81
}
82
foreach
($this as $attr=>$value)
83
{
84
$a = strtolower($attr);
85
if
($data->$a)
86
$this->$attr = $data->$a;
87
elseif ($data->$attr)
88
$this->$attr = $data->$attr;
89
}
90
}
91
92
function
GetDatabase
($database = NULL)
93
{
94
if
(is_null($database))
95
{
96
return
;
97
}
98
$this->_database = $database;
99
$this->_db = $this->_miolo->GetDatabase($this->_database);
100
}
101
102
function
GetDb
()
103
{
104
if
(is_null($this->_db))
105
{
106
throw
new
EBusinessException
( _M(
'Error in Business: _db undefined! '
) .
"Class: {$this->_bclass} - Module: {$this->_bmodule}"
);
107
}
108
return
$this->_db
;
109
}
110
111
function
Query
($sql, $parameters = NULL, $maxrows = 0)
112
{
113
if
($db = $this->
GetDb
())
114
{
115
if
($parameters)
116
{
117
$sql->SetParameters($parameters);
118
}
119
120
$result = $db->GetQuery($sql, $maxrows);
121
$this->
CheckError
();
122
return
$result;
123
}
124
}
125
126
// backward compatibility
127
function
objQuery
($sql, $parameters = NULL, $maxrows = 0)
128
{
129
if
($db = $this->
GetDb
())
130
{
131
if
($parameters)
132
{
133
$sql->SetParameters($parameters);
134
}
135
136
$result = $db->objQuery($sql, $maxrows);
137
$this->
CheckError
();
138
return
$result;
139
}
140
}
141
149
function
Execute
($sql, $parameters = NULL)
150
{
151
if
($db = $this->
GetDb
())
152
{
153
if
($this->_transaction)
154
{
155
$this->_transaction->addCommand($sql);
156
}
157
else
158
{
159
$result = $db->Execute($sql);
160
$this->
CheckError
();
161
return
$result;
162
}
163
}
164
}
165
166
function
GetAffectedRows
()
167
{
168
return
$this->_db->GetAffectedRows();
169
}
170
171
function
ExecuteBatch
($cmds)
172
{
173
if
($db = $this->
GetDb
())
174
{
175
if
($this->_transaction)
176
{
177
foreach
($cmds as $cmd)
178
{
179
$this->_transaction->addCommand($cmd);
180
}
181
}
182
else
183
{
184
$result = $db->ExecuteBatch($cmds);
185
$this->
CheckError
();
186
return
$result;
187
}
188
}
189
}
190
191
// backward compatibility
192
function
objQueryRange
($sql, &$range)
193
{
194
if
($db = $this->
GetDb
())
195
{
196
$result = $db->QueryRange($sql, $range);
197
$this->
CheckError
($this->_db);
198
return
$result;
199
}
200
}
201
202
function
ExecuteSP
($sql, $parameters =
null
)
203
{
204
if
($db = $this->
GetDb
())
205
{
206
$result = $this->_db->ExecuteSP($sql, $parameters);
207
$this->
CheckError
($this->_db);
208
return
$result;
209
}
210
}
211
212
function
GetBusiness
($module, $name =
'main'
, $data = NULL)
213
{
214
return
$this->_miolo->GetBusiness($module, $name, $data);
215
}
216
217
function
Log
($operacao, $descricao)
218
{
219
$login = $this->_miolo->GetLogin();
220
$objLog = $this->_miolo->GetBusinessMAD(
'log'
);
221
$ok = $objLog->Log($operacao, $descricao, $login->idkey, $this->_bmodule, $this->_bclass);
222
if
(!$ok)
223
{
224
$this->
AddError
($objLog->GetErrors());
225
}
226
return
$ok;
227
}
228
229
function
setTransaction
(
MTransaction
$transaction)
230
{
231
$this->_transaction = $transaction;
232
}
233
234
function
getTransaction
()
235
{
236
return
$this->_transaction
;
237
}
238
239
function
beginTransaction
()
240
{
241
if
($db = $this->
GetDb
())
242
{
243
$this->_transaction = $db->getTransaction();
244
}
245
}
246
247
function
endTransaction
()
248
{
249
if
($this->_transaction)
250
{
251
$this->_transaction->process();
252
}
253
}
254
}
255
?>
EBusinessException
Definição
mexception.class:134
MBusiness
Definição
mbusiness.class:3
MBusiness\objQuery
objQuery($sql, $parameters=NULL, $maxrows=0)
Definição
mbusiness.class:127
MBusiness\$_errors
$_errors
Definição
mbusiness.class:6
MBusiness\$_bclass
$_bclass
Definição
mbusiness.class:5
MBusiness\endTransaction
endTransaction()
Definição
mbusiness.class:247
MBusiness\ExecuteSP
ExecuteSP($sql, $parameters=null)
Definição
mbusiness.class:202
MBusiness\$_miolo
$_miolo
Definição
mbusiness.class:10
MBusiness\SetData
SetData($data=NULL)
Definição
mbusiness.class:76
MBusiness\GetDb
GetDb()
Definição
mbusiness.class:102
MBusiness\GetData
GetData()
Definição
mbusiness.class:71
MBusiness\__construct
__construct($database=NULL, $data=NULL)
Definição
mbusiness.class:12
MBusiness\Query
Query($sql, $parameters=NULL, $maxrows=0)
Definição
mbusiness.class:111
MBusiness\GetErrors
GetErrors()
Definição
mbusiness.class:51
MBusiness\OnCreate
OnCreate($data=NULL)
Definição
mbusiness.class:21
MBusiness\$_database
$_database
Definição
mbusiness.class:7
MBusiness\GetAffectedRows
GetAffectedRows()
Definição
mbusiness.class:166
MBusiness\Log
Log($operacao, $descricao)
Definição
mbusiness.class:217
MBusiness\$_transaction
$_transaction
Definição
mbusiness.class:9
MBusiness\AddError
AddError($err)
Definição
mbusiness.class:56
MBusiness\GetBusiness
GetBusiness($module, $name='main', $data=NULL)
Definição
mbusiness.class:212
MBusiness\$_bmodule
$_bmodule
Definição
mbusiness.class:4
MBusiness\CheckError
CheckError()
Definição
mbusiness.class:41
MBusiness\Execute
Execute($sql, $parameters=NULL)
Definição
mbusiness.class:149
MBusiness\GetById
GetById($data=NULL)
Definição
mbusiness.class:37
MBusiness\$_db
$_db
Definição
mbusiness.class:8
MBusiness\getTransaction
getTransaction()
Definição
mbusiness.class:234
MBusiness\GetDatabase
GetDatabase($database=NULL)
Definição
mbusiness.class:92
MBusiness\ExecuteBatch
ExecuteBatch($cmds)
Definição
mbusiness.class:171
MBusiness\beginTransaction
beginTransaction()
Definição
mbusiness.class:239
MBusiness\setTransaction
setTransaction(MTransaction $transaction)
Definição
mbusiness.class:229
MBusiness\objQueryRange
objQueryRange($sql, &$range)
Definição
mbusiness.class:192
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MTransaction
Definição
mtransaction.class:3
PersistentObject
Definição
persistentobject.class:4
classes
model
mbusiness.class
Gerado por
1.10.0