DDDBL 2.0
 All Classes Namespaces Files Functions Variables
register_result_handler.inc.php
Go to the documentation of this file.
1 <?php
2 
3 namespace DDDBL;
4 
5 $objDataObjectPool = new DataObjectPool('Result-Handler');
6 
7 #################################
8 ### handler for: SINGLE_VALUE ###
9 #################################
10 
12 
13  $arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
14  $objQueue->getState()->update(array('result' => (empty($arrResult)) ? null : reset($arrResult)));
15 
16 };
17 
18 $objDataObjectPool->add('SINGLE_VALUE', array('HANDLER' => $cloSingleValueHandler));
19 
20 ###########################
21 ### handler for: SINGLE ###
22 ###########################
23 
25 
26  $arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
27  $objQueue->getState()->update(array('result' => (empty($arrResult)) ? null : $arrResult));
28 
29 };
30 
31 $objDataObjectPool->add('SINGLE', array('HANDLER' => $cloSingleHandler));
32 
33 ##########################
34 ### handler for: MULTI ###
35 ##########################
36 
38 
39  $arrResult = $objQueue->getState()->get('PDOStatement')->fetchAll();
40  $objQueue->getState()->update(array('result' => (empty($arrResult)) ? array() : $arrResult));
41 
42 };
43 
44 $objDataObjectPool->add('MULTI', array('HANDLER' => $cloMultiHandler));
45 
46 #########################
47 ### handler for: LIST ###
48 #########################
49 
51 
52  $objResultCursor = $objQueue->getState()->get('PDOStatement');
53 
54  $arrResult = array();
55 
56  while($arrRow = $objResultCursor->fetch())
57  array_push($arrResult, current($arrRow));
58 
59  $objQueue->getState()->update(array('result' => $arrResult));
60 
61 };
62 
63 $objDataObjectPool->add('LIST', array('HANDLER' => $cloListHandler));
64 
65 #############################
66 ### handler for: GROUP_BY ###
67 #############################
68 
69 $cloGroupedByHandler = function(\DDDBL\Queue $objQueue, $strGroupColumn) {
70 
71  $objResultCursor = $objQueue->getState()->get('PDOStatement');
72 
73  $arrResult = array();
74 
75  while($arrRow = $objResultCursor->fetch()) {
76 
77  if(!isset($arrRow[$strGroupColumn]))
78  throw new \Exception ("could not group result by non-existing column: $strGroupColumn");
79 
80  $arrResult[$arrRow[$strGroupColumn]][] = $arrRow;
81 
82  }
83 
84  $objQueue->getState()->update(array('result' => $arrResult));
85 
86 };
87 
88 $objDataObjectPool->add('GROUP_BY', array('HANDLER' => $cloGroupedByHandler));
89 
90 #############################
91 ### handler for: NOT_NULL ###
92 #############################
93 
95 
96  $arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
97 
98  $objQueue->getState()->update(array('result' => (empty($arrResult)) ? false : true));
99 
100 };
101 
102 $objDataObjectPool->add('NOT_NULL', array('HANDLER' => $cloNotNullHandler));