MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mbusiness.class
Ir para a documentação deste ficheiro.
1<?php
3{
4 var $_bmodule; // the module of this class
5 var $_bclass; // the name of this class
8 var $_db;
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
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
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?>
objQuery($sql, $parameters=NULL, $maxrows=0)
ExecuteSP($sql, $parameters=null)
SetData($data=NULL)
Definição mbusiness.class:76
__construct($database=NULL, $data=NULL)
Definição mbusiness.class:12
Query($sql, $parameters=NULL, $maxrows=0)
OnCreate($data=NULL)
Definição mbusiness.class:21
Log($operacao, $descricao)
AddError($err)
Definição mbusiness.class:56
GetBusiness($module, $name='main', $data=NULL)
Execute($sql, $parameters=NULL)
GetById($data=NULL)
Definição mbusiness.class:37
GetDatabase($database=NULL)
Definição mbusiness.class:92
ExecuteBatch($cmds)
beginTransaction()
setTransaction(MTransaction $transaction)
objQueryRange($sql, &$range)
static getInstance()
Definição miolo.class:134