Changeset 4491
- Timestamp:
- 06/08/08 19:05:43 (13 months ago)
- Location:
- branches/0.11/lib/Doctrine
- Files:
-
- 2 modified
-
Query.php (modified) (1 diff)
-
Query/Abstract.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/lib/Doctrine/Query.php
r4488 r4491 1204 1204 1205 1205 /** 1206 * Get the dql call back for this query1207 *1208 * @return array $callback1209 */1210 protected function _getDqlCallback()1211 {1212 $callback = false;1213 if ( ! empty($this->_dqlParts['from'])) {1214 switch ($this->_type) {1215 case self::DELETE:1216 $callback = array(1217 'callback' => 'preDqlDelete',1218 'const' => Doctrine_Event::RECORD_DQL_DELETE1219 );1220 break;1221 case self::UPDATE:1222 $callback = array(1223 'callback' => 'preDqlUpdate',1224 'const' => Doctrine_Event::RECORD_DQL_UPDATE1225 );1226 break;1227 case self::SELECT:1228 $callback = array(1229 'callback' => 'preDqlSelect',1230 'const' => Doctrine_Event::RECORD_DQL_SELECT1231 );1232 break;1233 }1234 }1235 1236 return $callback;1237 }1238 1239 /**1240 * Pre query method which invokes the pre*Query() methods on the model instance or any attached1241 * record listeners1242 *1243 * @return void1244 */1245 protected function _preQuery()1246 {1247 $callback = $this->_getDqlCallback();1248 1249 // if there is no callback for the query type, then we can return early1250 if ( ! $callback) {1251 return;1252 }1253 1254 // parse the FROM clause to find all models used in the DQL1255 $from = new Doctrine_Query_From($this);1256 $this->_components = array();1257 foreach ($this->_dqlParts['from'] as $key => $table) {1258 $componentClause = $from->parse($table, true);1259 foreach ($componentClause as $c) {1260 // remove the prefix if there is one (aka "f.Bar" => "Bar")1261 $component = explode('.', $c[0]);1262 $component = array_pop($component);1263 $alias = isset($c[1]) ? $c[1] : $component;1264 $this->_components[$component] = $alias;1265 }1266 }1267 1268 foreach ($this->_components as $component => $alias) {1269 if (class_exists($component)) {1270 $componentObj = Doctrine::getTable($component);1271 $record = $componentObj->getRecordInstance();1272 1273 // check (and call) preDql*() callback on the model class1274 if (method_exists($record, $callback['callback'])) {1275 $record->$callback['callback']($this, $component, $alias);1276 }1277 1278 // trigger preDql*() callback event1279 $params = array('component`' => $component, 'alias' => $alias);1280 $event = new Doctrine_Event($record, $callback['const'], $this, $params);1281 $componentObj->getRecordListener()->$callback['callback']($event);1282 }1283 }1284 1285 // Invoke preQuery() hook on Doctrine_Query for child classes which implement this hook1286 $this->preQuery();1287 }1288 1289 /**1290 * Blank hook methods which can be implemented in Doctrine_Query child classes1291 *1292 * @return void1293 */1294 public function preQuery()1295 {1296 }1297 1298 /**1299 1206 * getLimitSubquery 1300 1207 * this is method is used by the record limit algorithm -
branches/0.11/lib/Doctrine/Query/Abstract.php
r4488 r4491 244 244 245 245 /** 246 * @var bool Boolean variable for whether or not the preQuery process has been executed 247 */ 248 protected $_preQueried = false; 249 250 /** 246 251 * Constructor. 247 252 * … … 983 988 public function execute($params = array(), $hydrationMode = null) 984 989 { 990 $this->_preQuery(); 991 985 992 if ($hydrationMode !== null) { 986 993 $this->_hydrator->setHydrationMode($hydrationMode); … … 1021 1028 1022 1029 return $result; 1030 } 1031 1032 1033 /** 1034 * Get the dql call back for this query 1035 * 1036 * @return array $callback 1037 */ 1038 protected function _getDqlCallback() 1039 { 1040 $callback = false; 1041 if ( ! empty($this->_dqlParts['from'])) { 1042 switch ($this->_type) { 1043 case self::DELETE: 1044 $callback = array( 1045 'callback' => 'preDqlDelete', 1046 'const' => Doctrine_Event::RECORD_DQL_DELETE 1047 ); 1048 break; 1049 case self::UPDATE: 1050 $callback = array( 1051 'callback' => 'preDqlUpdate', 1052 'const' => Doctrine_Event::RECORD_DQL_UPDATE 1053 ); 1054 break; 1055 case self::SELECT: 1056 $callback = array( 1057 'callback' => 'preDqlSelect', 1058 'const' => Doctrine_Event::RECORD_DQL_SELECT 1059 ); 1060 break; 1061 } 1062 } 1063 1064 return $callback; 1065 } 1066 1067 /** 1068 * Pre query method which invokes the pre*Query() methods on the model instance or any attached 1069 * record listeners 1070 * 1071 * @return void 1072 */ 1073 protected function _preQuery() 1074 { 1075 if ($this->_preQueried) { 1076 return; 1077 } 1078 1079 $this->_preQueried = true; 1080 1081 $callback = $this->_getDqlCallback(); 1082 1083 // if there is no callback for the query type, then we can return early 1084 if ( ! $callback) { 1085 return; 1086 } 1087 1088 // parse the FROM clause to find all models used in the DQL 1089 $from = new Doctrine_Query_From($this); 1090 $this->_components = array(); 1091 foreach ($this->_dqlParts['from'] as $key => $table) { 1092 $componentClause = $from->parse($table, true); 1093 foreach ($componentClause as $c) { 1094 // remove the prefix if there is one (aka "f.Bar" => "Bar") 1095 $component = explode('.', $c[0]); 1096 $component = array_pop($component); 1097 $alias = isset($c[1]) ? $c[1] : $component; 1098 $this->_components[$component] = $alias; 1099 } 1100 } 1101 1102 foreach ($this->_components as $component => $alias) { 1103 if (class_exists($component)) { 1104 $componentObj = Doctrine::getTable($component); 1105 $record = $componentObj->getRecordInstance(); 1106 1107 // check (and call) preDql*() callback on the model class 1108 if (method_exists($record, $callback['callback'])) { 1109 $record->$callback['callback']($this, $component, $alias); 1110 } 1111 1112 // trigger preDql*() callback event 1113 $params = array('component`' => $component, 'alias' => $alias); 1114 $event = new Doctrine_Event($record, $callback['const'], $this, $params); 1115 $componentObj->getRecordListener()->$callback['callback']($event); 1116 } 1117 } 1118 1119 // Invoke preQuery() hook on Doctrine_Query for child classes which implement this hook 1120 $this->preQuery(); 1121 } 1122 1123 /** 1124 * Blank hook methods which can be implemented in Doctrine_Query child classes 1125 * 1126 * @return void 1127 */ 1128 public function preQuery() 1129 { 1023 1130 } 1024 1131