Next4Me
 All Classes Files Functions Variables
Region.php
Go to the documentation of this file.
1 <?php
2 
13 class Application_Model_Region extends Zend_Db_Table_Abstract {
14  //put your code here
15  protected $_name="Region";
16  protected $_primary="IdRegion";
17 
18  //==== Start addEditRegion =========================================================================
32  function addEditRegion($entity){
33  $resultId = 0;
34  $page="region.php";
35  $method="addEditRegion";
36  $result=json_encode($entity);
37  $message="";
38  $type="1";
39  $this->ErrorCode = new Application_Model_ErrorCode;
40  $this->Log = new Application_Model_Log;
41 
42  try{
43  unset($entity['IdUserAccount']);
44  unset($entity['UserAccountType']);
45  if ($entity['IdRegion']=="0"){
46  $this->insert($entity);
47  $k=$this->getAdapter()->lastInsertId();
48  $resultCode=$k;
49  }else{
50  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
51  ->from("Region","*")
52  ->where("IdRegion=?",$entity['IdRegion'])
53  );
54  if($sql!=null){
55  $k=$this->update(array(
56  "Value"=>$entity['Value'],
57  "IdParent" => $entity['IdParent'],
58  "Type" => $entity['Type'],
59  ),$this->getAdapter()->quoteInto('IdRegion=?',$entity['IdRegion']));
60  $k=$entity['IdRegion'];
61  $resultCode=$k;
62  }else{
63  $resultId = 3086;
64  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
65  $resultCode=$r['Message'];
66  $message=$r['Message'];
67  $type=3;
68  }
69  }
70 
71 
72  }
73  catch(Exception $e){
74  $resultCode=$e->getMessage();
75  $resultId=101;
76  $type=3;
77  }
78  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
79  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
80  return $response;
81 
82  }
83 
84  //==== End addEditRegion =========================================================================
85 
86  //==== Start getRegionById =========================================================================
96  function getRegionById($entity){
97  $resultId = 0;
98  $page="region.php";
99  $method="getRegionById";
100  $result=json_encode($entity);
101  $message="";
102  $type="1";
103  $this->ErrorCode = new Application_Model_ErrorCode;
104  $this->Log = new Application_Model_Log;
105 
106  try{
107 
108  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
109  ->from("Region","*")
110  ->where("IdRegion=?",$entity['IdRegion'])
111  );
112  if($sql!=null){
113  $result = array("IdRegion"=>$sql->IdRegion,"Value"=>$sql->Value,"IdParent"=>$sql->IdParent, "Type"=>$sql->Type);
114  $resultCode=$result;
115  }else{
116  $resultId = 3170;
117  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
118  $resultCode=$r['Message'];
119  $message=$r['Message'];
120  $type=3;
121  }
122  }
123  catch(Exception $e){
124  $resultCode=$e->getMessage();
125  $resultId=101;
126  $type=3;
127  }
128  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
129  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
130  return $response;
131 
132  }
133  //==== End getRegionById =========================================================================
134 
135  //==== Start getRegionByType =========================================================================
144  function getRegionByType($entity){
145  $resultId = 0;
146  $page="region.php";
147  $method="getRegionByType";
148  $result=json_encode($entity);
149  $message="";
150  $type="1";
151  $this->ErrorCode = new Application_Model_ErrorCode;
152  $this->Log = new Application_Model_Log;
153  $this->Paging = new Application_Model_Paging;
154 
155  try{
156  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
157  ->from("Region","*")
158  ->where("Type=?",$entity['Type'])
159  );
160  if(count($rows)>0){
161  foreach($rows as $row){
162  $res[] = array("IdRegion"=>$row->IdRegion,"Value"=>$row->Value,"IdParent"=>$row->IdParent, "Type"=>$row->Type);
163  }
164  $resultCode=$res;
165  }else{
166  $resultId = 3171;
167  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
168  $resultCode=$r['Message'];
169  $message=$r['Message'];
170  $type=3;
171  }
172  }
173  catch(Exception $e){
174  $resultCode=$e->getMessage();
175  $resultId=101;
176  $type=3;
177  }
178  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
179  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
180  return $response;
181 
182  }
183  //==== End getRegionByType =========================================================================
184 
185  //==== Start getRegionByParent =========================================================================
195  function getRegionByParent($entity){
196  $resultId = 0;
197  $page="region.php";
198  $method="getRegionByParent";
199  $result=json_encode($entity);
200  $message="";
201  $type="1";
202  $this->ErrorCode = new Application_Model_ErrorCode;
203  $this->Log = new Application_Model_Log;
204 
205  try{
206  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
207  ->from("Region","*")
208  ->where("IdParent=?",$entity['IdParent'])
209  );
210  if(count($rows)>0){
211  foreach($rows as $row){
212  $res[] = array("IdRegion"=>$row->IdRegion,"Value"=>$row->Value,"IdParent"=>$row->IdParent, "Type"=>$row->Type);
213  }
214  $resultCode=$res;
215  }else{
216  $resultId = 3172;
217  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
218  $resultCode=$r['Message'];
219  $message=$r['Message'];
220  $type=3;
221  }
222  }
223  catch(Exception $e){
224  $resultCode=$e->getMessage();
225  $resultId=101;
226  $type=3;
227  }
228  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
229  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
230  return $response;
231  }
232 
233  //==== End getRegionByParent =========================================================================
234 
235  //==== Start getRegionRecursiveByParentId =========================================================================
243  function getRegionRecursiveByParentId($parent_id=0,$array_by_parent=array(),$array_by_id=array()){
244  if(empty($array_by_id) && empty($array_by_parent))
245  {
246  $array_by_parent = $array_by_id = array();
247 
248  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
249  ->from("Region","*")
250  ->order(array('IdParent','IdRegion')));
251 
252  foreach($rows as $row){
253  $array_by_parent[$row['IdParent']][]=$row->toArray();
254  $array_by_id[$row['IdRegion']]=$row->toArray();
255  }
256 
257  }
258 
259  $array_de_returnat = array();
260 
261  if(!empty($array_by_parent[$parent_id]))
262  {
263  foreach ($array_by_parent[$parent_id] as $key=>$value)
264  {
265  $count=count($array_de_returnat);
266  $array_de_returnat[$count] = $value;
267  $array_de_returnat[$count]['childs'] =$this->getRegionRecursiveByParentId($value['IdRegion'],$array_by_parent,$array_by_id);
268 
269  }
270  }
271 
272  return $array_de_returnat;
273  }
274 
275  //==== End getRegionRecursiveByParentId =========================================================================
276 
277  //==== Start deleteRegion =========================================================================
285  function deleteRegion($entity){
286  $resultId = 0;
287  $page="region.php";
288  $method="deleteRegion";
289  $result=json_encode($entity);
290  $message="";
291  $type="1";
292  $this->ErrorCode = new Application_Model_ErrorCode;
293  $this->Log = new Application_Model_Log;
294 
295  try{
296  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
297  ->from("Region","*")
298  ->where("IdRegion=?",$entity['IdRegion'])
299  );
300  if($sql!=null){
301  $this->delete($this->getAdapter()->quoteInto("IdRegion=?",$entity['IdRegion']));
302  $resultCode="Date sterse";
303  }else{
304  $resultId = 3173;
305  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
306  $resultCode=$r['Message'];
307  $message=$r['Message'];
308  $type=3;
309  }
310  }
311  catch(Exception $e){
312  $resultCode=$e->getMessage();
313  $resultId=101;
314  $type=3;
315  }
316  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
317  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
318  return $response;
319  }
320  //==== End deleteRegion =========================================================================
321 }
322 
323 ?>