Next4Me
 All Classes Files Functions Variables
EntityType.php
Go to the documentation of this file.
1 <?php
15 class Application_Model_EntityType extends Zend_Db_Table_Abstract {
16  //put your code here
17  protected $_name="EntityType";
18  protected $_primary="IdEntityType";
19 
20  //==== Start addEditEntityType =========================================================================
33  function addEditEntityType($entity){
34  $resultId = 0;
35  $page="EntityType.php";
36  $method="addEditEntityType";
37  $result=json_encode($entity);
38  $message="";
39  $type="1";
40  $this->ErrorCode = new Application_Model_ErrorCode;
41  $this->Log = new Application_Model_Log;
42 
43  try{
44  unset($entity['IdUserAccount']);
45  unset($entity['UserAccountType']);
46  if ($entity['IdEntityType']=="0"){
47  $k=$this->insert($entity);
48  $k=$this->getAdapter()->lastInsertId();
49  $resultCode=$k;
50  }else{
51  $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
52  ->from("EntityType","*")
53  ->where("IdEntityType=?",$entity['IdEntityType'])
54  );
55  if($rows!=null){
56  $this->update(array(
57  "Type" => $entity['Type'],
58  "IdParent" => $entity['IdParent'],
59  ),$this->getAdapter()->quoteInto('IdEntityType=?',$entity['IdEntityType']));
60  $k=$entity['IdEntityType'];
61  }else{
62  $resultId = 3174;
63  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
64  $resultCode=$r['Message'];
65  $message=$r['Message'];
66  $type=3;
67  }
68  }
69 
70 
71  }
72  catch(Exception $e){
73 
74  $resultCode=$e->getMessage();
75  $resultId=101;
76  $type=3;
77 
78  }
79  $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
80  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
81  return $response;
82  return $response;
83  }
84  //==== End addEditEntityType =========================================================================
85 
86  //==== Start getEntityTypeById =========================================================================
95  function getEntityTypeById($Entity){
96  $resultId = 0;
97  $page="EntityType.php";
98  $method="getEntityTypeById";
99  $result=json_encode($Entity);
100  $message="";
101  $type="1";
102  $this->ErrorCode = new Application_Model_ErrorCode;
103  $this->Log = new Application_Model_Log;
104 
105  try{
106  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
107  ->from("EntityType","*")
108  ->where("IdEntityType=?",$Entity['IdEntityType'])
109  );
110  if($sql!=null){
111  $resultCode = array("IdEntityType"=>$sql->IdEntityType,"Type"=>$sql->Type,"IdParent"=>$sql->IdParent);
112  }else{
113  $resultId = 3175;
114  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
115  $resultCode=$r['Message'];
116  $message=$r['Message'];
117  $type=3;
118  }
119 
120 
121 
122 
123  }
124  catch(Exception $e){
125  $resultCode=$e->getMessage();
126  $resultId=101;
127  $type=3;
128  }
129  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
130  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
131  return $response;
132 
133  }
134  //==== End getEntityTypeById =========================================================================
135 
136  //==== Start getEntityTypeByType =========================================================================
145  function getEntityTypeByType($Entity){
146  $resultId = 0;
147  $page="EntityType.php";
148  $method="getEntityTypeByType";
149  $result=json_encode($Entity);
150  $message="";
151  $type="1";
152  $this->ErrorCode = new Application_Model_ErrorCode;
153  $this->Log = new Application_Model_Log;
154 
155  try{
156  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
157  ->from("EntityType","*")
158  ->where("Type=?",$Entity['Type'])
159  );
160  if($sql!=null){
161  $resultCode = array("IdEntityType"=>$sql->IdEntityType,"Type"=>$sql->Type,"IdParent"=>$sql->IdParent);
162  }else{
163  $resultId = 3176;
164  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
165  $resultCode=$r['Message'];
166  $message=$r['Message'];
167  $type=3;
168  }
169 
170  }
171  catch(Exception $e){
172  $resultCode=$e->getMessage();
173  $resultId=101;
174  $type=3;
175  }
176  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
177  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
178  return $response;
179  }
180  //==== End getEntityTypeByType =========================================================================
181 
182  //==== Start getEntityTypeByIdParent =========================================================================
192  function getEntityTypeByIdParent($Entity){
193  $resultId = 0;
194  $page="EntityType.php";
195  $method="getEntityTypeByIdParent";
196  $result=json_encode($Entity);
197  $message="";
198  $type="1";
199  $this->ErrorCode = new Application_Model_ErrorCode;
200  $this->Log = new Application_Model_Log;
201 
202  try{
203  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
204  ->from("EntityType","*")
205  ->where("IdParent=?",$Entity['IdParent'])
206  );
207  //$response =array();
208  if(count($rows)>0){
209  foreach($rows as $row){
210 
211  $resultCode[]=array("IdEntityType"=>$row->IdEntityType, "Type"=>$row->Type, "IdParent"=>$row->IdParent);
212 
213  }
214  }else{
215  $resultId = 3177;
216  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
217  $resultCode=$r['Message'];
218  $message=$r['Message'];
219  $type=3;
220  }
221  }
222  catch(Exception $e){
223  $resultCode=$e->getMessage();
224  $resultId=101;
225  $type=3;
226  }
227  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
228  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
229  return $response;
230  }
231  //==== End getEntityTypeByIdParent =========================================================================
232 
233  //==== Start getEntityTypeByParentType =========================================================================
244  function getEntityTypeByParentType($Entity){
245  $resultId = 0;
246  $page="EntityType.php";
247  $method="getEntityTypeByParentType";
248  $result=json_encode($Entity);
249  $message="";
250  $type="1";
251  $this->ErrorCode = new Application_Model_ErrorCode;
252  $this->Log = new Application_Model_Log;
253 
254  try{
255  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
256  ->from("EntityType","*")
257  ->where("Type=?",$Entity['Type'])
258  );
259  if($sql==null){
260  $resultId = 3179;
261  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
262  $resultCode=$r['Message'];
263  $message=$r['Message'];
264  $type=3;
265  }else{
266  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
267  ->from("EntityType","*")
268  ->where("IdParent=?",$sql->IdEntityType)
269  );
270 
271  if(count($rows)>0){
272  $resultId = 3178;
273  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
274  $resultCode=$r['Message'];
275  $message=$r['Message'];
276  $type=3;
277  }else{
278  foreach($rows as $row){
279  $resultCode[] = array("IdEntityType"=>$row->IdEntityType,"Type"=>$row->Type,"IdParent"=>$row->IdParent);
280  }
281 
282  }
283  }
284 
285 
286  }
287  catch(Exception $e){
288  $resultCode=$e->getMessage();
289  $resultId=101;
290  $type=3;
291  }
292  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
293  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
294  return $response;
295  }
296  //==== End getEntityTypeByParentType =========================================================================
297 
298  //==== Start getEntityTypeTree =========================================================================
307  function getEntityTypeTree($parent_id=0,$array_by_parent=array(),$array_by_id=array()){
308  if(empty($array_by_id) && empty($array_by_parent))
309  {
310  $array_by_parent = $array_by_id = array();
311 
312  $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
313  ->from("EntityType","*")
314  ->order(array('IdParent','IdEntityType')));
315  foreach($rows as $row){
316  $array_by_parent[$row['IdParent']][]=$row->toArray();
317  $array_by_id[$row['IdEntityType']]=$row->toArray();
318  }
319 
320  }
321  $array_de_returnat = array();
322 
323  if(!empty($array_by_parent[$parent_id]))
324  {
325  foreach ($array_by_parent[$parent_id] as $key=>$value)
326  {
327  $count=count($array_de_returnat);
328  $array_de_returnat[$count] = $value;
329  $array_de_returnat[$count]['childs'] =$this->getEntityTypeTree($value['IdEntityType'],$array_by_parent,$array_by_id);
330  }
331  }
332 
333 
334  return $array_de_returnat;
335  }
336  //==== End getEntityTypeTree =========================================================================
337 
338  //==== Start deleteEntityType =========================================================================
348  function deleteEntityType($entity){
349  $resultId = 0;
350  $page="EntityType.php";
351  $method="deleteEntityType";
352  $result=json_encode($entity);
353  $message="";
354  $type="1";
355  $this->ErrorCode = new Application_Model_ErrorCode;
356  $this->Log = new Application_Model_Log;
357 
358  try{
359  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
360  ->from("EntityType","*")
361  ->where("IdEntityType=?",$entity['IdEntityType'])
362  );
363  if($sql==null){
364  $resultId = 3180;
365  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
366  $resultCode=$r['Message'];
367  $message=$r['Message'];
368  $type=3;
369  }
370  if($resultId=="0"){
371  $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
372  ->from("EntityType","*")
373  ->where("IdParent=?",$entity['IdEntityType'])
374  );
375  if($sql!=null){
376  $resultId = 3181;
377  $r=$this->ErrorCode->getErrorCode($resultId,Zend_Registry::get('language'));
378  $resultCode=$r['Message'];
379  $message=$r['Message'];
380  $type=3;
381  }
382  }
383  if($resultId=="0"){
384  $k=$this->delete($this->getAdapter()->quoteInto("IdEntityType=?",$entity['IdEntityType']));
385  $resultCode="Date sterse";
386  }
387  }
388  catch(Exception $e){
389  $resultCode=$e->getMessage();
390  $resultId=101;
391  $type=3;
392  }
393  $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
394  $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
395  return $response;
396  }
397 
398  //==== End deleteEntityType =========================================================================
399 }
400 
401 ?>