@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function getPHPType() |
| 37 | 37 | { |
| 38 | - $dbtype = strtolower($this->getDbType()); |
|
| 38 | + $dbtype=strtolower($this->getDbType()); |
|
| 39 | 39 | foreach(self::$types as $type => $dbtypes) |
| 40 | 40 | { |
| 41 | 41 | if(in_array($dbtype, $dbtypes)) |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function getSearchExpression($fields, $keywords) |
| 32 | 32 | { |
| 33 | - $columns = array(); |
|
| 33 | + $columns=array(); |
|
| 34 | 34 | foreach($fields as $field) |
| 35 | 35 | { |
| 36 | 36 | if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
| 37 | - $columns[] = $field; |
|
| 37 | + $columns[]=$field; |
|
| 38 | 38 | } |
| 39 | 39 | return parent::getSearchExpression($columns, $keywords); |
| 40 | 40 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected function isSearchableColumn($column) |
| 46 | 46 | { |
| 47 | - $type = strtolower($column->getDbType()); |
|
| 48 | - return $type === 'character varying' || $type === 'varchar' || |
|
| 49 | - $type === 'character' || $type === 'char' || $type === 'text'; |
|
| 47 | + $type=strtolower($column->getDbType()); |
|
| 48 | + return $type==='character varying' || $type==='varchar' || |
|
| 49 | + $type==='character' || $type==='char' || $type==='text'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | $conditions=array(); |
| 61 | 61 | foreach($words as $word) |
| 62 | - $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 62 | + $conditions[]=$column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 63 | 63 | return '('.implode(' AND ', $conditions).')'; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
| 90 | 90 | { |
| 91 | - $limit = $limit!==null ? (int)$limit : -1; |
|
| 92 | - $offset = $offset!==null ? (int)$offset : -1; |
|
| 93 | - $limitStr = $limit >= 0 ? ' LIMIT '.$limit : ''; |
|
| 94 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 91 | + $limit=$limit!==null ? (int) $limit : -1; |
|
| 92 | + $offset=$offset!==null ? (int) $offset : -1; |
|
| 93 | + $limitStr=$limit >= 0 ? ' LIMIT '.$limit : ''; |
|
| 94 | + $offsetStr=$offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 95 | 95 | return $sql.$limitStr.$offsetStr; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -105,18 +105,18 @@ discard block |
||
| 105 | 105 | $orders=array(); |
| 106 | 106 | foreach($ordering as $name => $direction) |
| 107 | 107 | { |
| 108 | - $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC'; |
|
| 109 | - if(false !== strpos($name, '(') && false !== strpos($name, ')')) { |
|
| 108 | + $direction=strtolower($direction)=='desc' ? 'DESC' : 'ASC'; |
|
| 109 | + if(false!==strpos($name, '(') && false!==strpos($name, ')')) { |
|
| 110 | 110 | // key is a function (bad practice, but we need to handle it) |
| 111 | - $key = $name; |
|
| 111 | + $key=$name; |
|
| 112 | 112 | } else { |
| 113 | 113 | // key is a column |
| 114 | - $key = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 114 | + $key=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 115 | 115 | } |
| 116 | - $orders[] = $key.' '.$direction; |
|
| 116 | + $orders[]=$key.' '.$direction; |
|
| 117 | 117 | } |
| 118 | 118 | if(count($orders) > 0) |
| 119 | - $sql .= ' ORDER BY '.implode(', ', $orders); |
|
| 119 | + $sql.=' ORDER BY '.implode(', ', $orders); |
|
| 120 | 120 | return $sql; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function getSearchExpression($fields, $keywords) |
| 132 | 132 | { |
| 133 | - if(strlen(trim($keywords)) == 0) return ''; |
|
| 134 | - $words = preg_split('/\s/u', $keywords); |
|
| 135 | - $conditions = array(); |
|
| 133 | + if(strlen(trim($keywords))==0) return ''; |
|
| 134 | + $words=preg_split('/\s/u', $keywords); |
|
| 135 | + $conditions=array(); |
|
| 136 | 136 | foreach($fields as $field) |
| 137 | 137 | { |
| 138 | - $column = $this->getTableInfo()->getColumn($field)->getColumnName(); |
|
| 139 | - $conditions[] = $this->getSearchCondition($column, $words); |
|
| 138 | + $column=$this->getTableInfo()->getColumn($field)->getColumnName(); |
|
| 139 | + $conditions[]=$this->getSearchCondition($column, $words); |
|
| 140 | 140 | } |
| 141 | 141 | return '('.implode(' OR ', $conditions).')'; |
| 142 | 142 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $conditions=array(); |
| 152 | 152 | foreach($words as $word) |
| 153 | - $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 153 | + $conditions[]=$column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 154 | 154 | return '('.implode(' AND ', $conditions).')'; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -195,102 +195,102 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public function getSelectFieldList($data='*') { |
| 197 | 197 | if(is_scalar($data)) { |
| 198 | - $tmp = explode(',', $data); |
|
| 199 | - $result = array(); |
|
| 198 | + $tmp=explode(',', $data); |
|
| 199 | + $result=array(); |
|
| 200 | 200 | foreach($tmp as $v) |
| 201 | - $result[] = trim($v); |
|
| 201 | + $result[]=trim($v); |
|
| 202 | 202 | return $result; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $bHasWildcard = false; |
|
| 206 | - $result = array(); |
|
| 205 | + $bHasWildcard=false; |
|
| 206 | + $result=array(); |
|
| 207 | 207 | if(is_array($data) || $data instanceof Traversable) { |
| 208 | - $columns = $this->getTableInfo()->getColumns(); |
|
| 208 | + $columns=$this->getTableInfo()->getColumns(); |
|
| 209 | 209 | foreach($data as $key=>$value) { |
| 210 | 210 | if($key==='*' || $value==='*') { |
| 211 | - $bHasWildcard = true; |
|
| 211 | + $bHasWildcard=true; |
|
| 212 | 212 | continue; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | if(strToUpper($key)==='NULL') { |
| 216 | - $result[] = 'NULL'; |
|
| 216 | + $result[]='NULL'; |
|
| 217 | 217 | continue; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | if(strpos($key, '(')!==false && strpos($key, ')')!==false) { |
| 221 | - $result[] = $key; |
|
| 221 | + $result[]=$key; |
|
| 222 | 222 | continue; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | if(stripos($key, 'AS')!==false) { |
| 226 | - $result[] = $key; |
|
| 226 | + $result[]=$key; |
|
| 227 | 227 | continue; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | if(stripos($value, 'AS')!==false) { |
| 231 | - $result[] = $value; |
|
| 231 | + $result[]=$value; |
|
| 232 | 232 | continue; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $v = isset($columns[$value]); |
|
| 236 | - $k = isset($columns[$key]); |
|
| 235 | + $v=isset($columns[$value]); |
|
| 236 | + $k=isset($columns[$key]); |
|
| 237 | 237 | if(is_integer($key) && $v) { |
| 238 | - $key = $value; |
|
| 239 | - $k = $v; |
|
| 238 | + $key=$value; |
|
| 239 | + $k=$v; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | if(strToUpper($value)==='NULL') { |
| 243 | 243 | if($k) |
| 244 | - $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
|
| 244 | + $result[]='NULL AS '.$columns[$key]->getColumnName(); |
|
| 245 | 245 | else |
| 246 | - $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 246 | + $result[]='NULL'.(is_string($key) ? (' AS '.(string) $key) : ''); |
|
| 247 | 247 | continue; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if(strpos($value, '(')!==false && strpos($value, ')')!==false) { |
| 251 | 251 | if($k) |
| 252 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
| 252 | + $result[]=$value.' AS '.$columns[$key]->getColumnName(); |
|
| 253 | 253 | else |
| 254 | - $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 254 | + $result[]=$value.(is_string($key) ? (' AS '.(string) $key) : ''); |
|
| 255 | 255 | continue; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | if($v && $key==$value) { |
| 259 | - $result[] = $columns[$value]->getColumnName(); |
|
| 259 | + $result[]=$columns[$value]->getColumnName(); |
|
| 260 | 260 | continue; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | if($k && $value==null) { |
| 264 | - $result[] = $columns[$key]->getColumnName(); |
|
| 264 | + $result[]=$columns[$key]->getColumnName(); |
|
| 265 | 265 | continue; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | if(is_string($key) && $v) { |
| 269 | - $result[] = $columns[$value]->getColumnName() . ' AS ' . $key; |
|
| 269 | + $result[]=$columns[$value]->getColumnName().' AS '.$key; |
|
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | if(is_numeric($value) && $k) { |
| 274 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
| 274 | + $result[]=$value.' AS '.$columns[$key]->getColumnName(); |
|
| 275 | 275 | continue; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | if(is_string($value) && $k) { |
| 279 | - $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName(); |
|
| 279 | + $result[]=$this->getDbConnection()->quoteString($value).' AS '.$columns[$key]->getColumnName(); |
|
| 280 | 280 | continue; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | if(!$v && !$k && is_integer($key)) { |
| 284 | - $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value); |
|
| 284 | + $result[]=is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value); |
|
| 285 | 285 | continue; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key; |
|
| 288 | + $result[]=(is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value)).' AS '.$key; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if($data===null || count($result) == 0 || $bHasWildcard) |
|
| 293 | - $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
| 292 | + if($data===null || count($result)==0 || $bHasWildcard) |
|
| 293 | + $result=$result=array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
| 294 | 294 | |
| 295 | 295 | return $result; |
| 296 | 296 | } |
@@ -304,21 +304,21 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*') |
| 306 | 306 | { |
| 307 | - $table = $this->getTableInfo()->getTableFullName(); |
|
| 308 | - $fields = implode(', ', $this -> getSelectFieldList($select)); |
|
| 309 | - $sql = "SELECT {$fields} FROM {$table}"; |
|
| 307 | + $table=$this->getTableInfo()->getTableFullName(); |
|
| 308 | + $fields=implode(', ', $this -> getSelectFieldList($select)); |
|
| 309 | + $sql="SELECT {$fields} FROM {$table}"; |
|
| 310 | 310 | if(!empty($where)) |
| 311 | - $sql .= " WHERE {$where}"; |
|
| 311 | + $sql.=" WHERE {$where}"; |
|
| 312 | 312 | return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
| 315 | + public function applyCriterias($sql, $parameters=array(), $ordering=array(), $limit=-1, $offset=-1) |
|
| 316 | 316 | { |
| 317 | 317 | if(count($ordering) > 0) |
| 318 | - $sql = $this->applyOrdering($sql, $ordering); |
|
| 319 | - if($limit>=0 || $offset>=0) |
|
| 320 | - $sql = $this->applyLimitOffset($sql, $limit, $offset); |
|
| 321 | - $command = $this->createCommand($sql); |
|
| 318 | + $sql=$this->applyOrdering($sql, $ordering); |
|
| 319 | + if($limit >= 0 || $offset >= 0) |
|
| 320 | + $sql=$this->applyLimitOffset($sql, $limit, $offset); |
|
| 321 | + $command=$this->createCommand($sql); |
|
| 322 | 322 | $this->bindArrayValues($command, $parameters); |
| 323 | 323 | return $command; |
| 324 | 324 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @param array binding parameters. |
| 330 | 330 | * @return TDbCommand count command. |
| 331 | 331 | */ |
| 332 | - public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
| 332 | + public function createCountCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1) |
|
| 333 | 333 | { |
| 334 | 334 | return $this->createFindCommand($where, $parameters, $ordering, $limit, $offset, 'COUNT(*)'); |
| 335 | 335 | } |
@@ -342,12 +342,12 @@ discard block |
||
| 342 | 342 | * @param array delete parameters. |
| 343 | 343 | * @return TDbCommand delete command. |
| 344 | 344 | */ |
| 345 | - public function createDeleteCommand($where,$parameters=array()) |
|
| 345 | + public function createDeleteCommand($where, $parameters=array()) |
|
| 346 | 346 | { |
| 347 | - $table = $this->getTableInfo()->getTableFullName(); |
|
| 348 | - if (!empty($where)) |
|
| 349 | - $where = ' WHERE '.$where; |
|
| 350 | - $command = $this->createCommand("DELETE FROM {$table}".$where); |
|
| 347 | + $table=$this->getTableInfo()->getTableFullName(); |
|
| 348 | + if(!empty($where)) |
|
| 349 | + $where=' WHERE '.$where; |
|
| 350 | + $command=$this->createCommand("DELETE FROM {$table}".$where); |
|
| 351 | 351 | $this->bindArrayValues($command, $parameters); |
| 352 | 352 | return $command; |
| 353 | 353 | } |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | public function createInsertCommand($data) |
| 364 | 364 | { |
| 365 | - $table = $this->getTableInfo()->getTableFullName(); |
|
| 366 | - list($fields, $bindings) = $this->getInsertFieldBindings($data); |
|
| 367 | - $command = $this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
| 365 | + $table=$this->getTableInfo()->getTableFullName(); |
|
| 366 | + list($fields, $bindings)=$this->getInsertFieldBindings($data); |
|
| 367 | + $command=$this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
| 368 | 368 | $this->bindColumnValues($command, $data); |
| 369 | 369 | return $command; |
| 370 | 370 | } |
@@ -379,15 +379,15 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function createUpdateCommand($data, $where, $parameters=array()) |
| 381 | 381 | { |
| 382 | - $table = $this->getTableInfo()->getTableFullName(); |
|
| 382 | + $table=$this->getTableInfo()->getTableFullName(); |
|
| 383 | 383 | if($this->hasIntegerKey($parameters)) |
| 384 | - $fields = implode(', ', $this->getColumnBindings($data, true)); |
|
| 384 | + $fields=implode(', ', $this->getColumnBindings($data, true)); |
|
| 385 | 385 | else |
| 386 | - $fields = implode(', ', $this->getColumnBindings($data)); |
|
| 386 | + $fields=implode(', ', $this->getColumnBindings($data)); |
|
| 387 | 387 | |
| 388 | - if (!empty($where)) |
|
| 389 | - $where = ' WHERE '.$where; |
|
| 390 | - $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
| 388 | + if(!empty($where)) |
|
| 389 | + $where=' WHERE '.$where; |
|
| 390 | + $command=$this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
| 391 | 391 | $this->bindArrayValues($command, array_merge($data, $parameters)); |
| 392 | 392 | return $command; |
| 393 | 393 | } |
@@ -399,13 +399,13 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | protected function getInsertFieldBindings($values) |
| 401 | 401 | { |
| 402 | - $fields = array(); $bindings=array(); |
|
| 402 | + $fields=array(); $bindings=array(); |
|
| 403 | 403 | foreach(array_keys($values) as $name) |
| 404 | 404 | { |
| 405 | - $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 406 | - $bindings[] = ':'.$name; |
|
| 405 | + $fields[]=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 406 | + $bindings[]=':'.$name; |
|
| 407 | 407 | } |
| 408 | - return array(implode(', ',$fields), implode(', ', $bindings)); |
|
| 408 | + return array(implode(', ', $fields), implode(', ', $bindings)); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | $bindings=array(); |
| 420 | 420 | foreach(array_keys($values) as $name) |
| 421 | 421 | { |
| 422 | - $column = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 423 | - $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name; |
|
| 422 | + $column=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
| 423 | + $bindings[]=$position ? $column.' = ?' : $column.' = :'.$name; |
|
| 424 | 424 | } |
| 425 | 425 | return $bindings; |
| 426 | 426 | } |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | { |
| 445 | 445 | foreach($values as $name=>$value) |
| 446 | 446 | { |
| 447 | - $column = $this->getTableInfo()->getColumn($name); |
|
| 448 | - if($value === null && $column->getAllowNull()) |
|
| 447 | + $column=$this->getTableInfo()->getColumn($name); |
|
| 448 | + if($value===null && $column->getAllowNull()) |
|
| 449 | 449 | $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
| 450 | 450 | else |
| 451 | 451 | $command->bindValue(':'.$name, $value, $column->getPdoType()); |
@@ -460,15 +460,15 @@ discard block |
||
| 460 | 460 | { |
| 461 | 461 | if($this->hasIntegerKey($values)) |
| 462 | 462 | { |
| 463 | - $values = array_values($values); |
|
| 464 | - for($i = 0, $max=count($values); $i<$max; $i++) |
|
| 465 | - $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
|
| 463 | + $values=array_values($values); |
|
| 464 | + for($i=0, $max=count($values); $i < $max; $i++) |
|
| 465 | + $command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i])); |
|
| 466 | 466 | } |
| 467 | 467 | else |
| 468 | 468 | { |
| 469 | 469 | foreach($values as $name=>$value) |
| 470 | 470 | { |
| 471 | - $prop = $name[0]===':' ? $name : ':'.$name; |
|
| 471 | + $prop=$name[0]===':' ? $name : ':'.$name; |
|
| 472 | 472 | $command->bindValue($prop, $value, $this->getPdoType($value)); |
| 473 | 473 | } |
| 474 | 474 | } |
@@ -191,7 +191,6 @@ discard block |
||
| 191 | 191 | * array('col1' => 'NULL', '*') |
| 192 | 192 | * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM... |
| 193 | 193 | * </code> |
| 194 | - * @param mixed $value |
|
| 195 | 194 | * @return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage |
| 196 | 195 | * @since 3.1.7 |
| 197 | 196 | * @todo add support for table aliasing |
@@ -399,7 +398,7 @@ discard block |
||
| 399 | 398 | /** |
| 400 | 399 | * Returns a list of insert field name and a list of binding names. |
| 401 | 400 | * @param object array or object to be inserted. |
| 402 | - * @return array tuple ($fields, $bindings) |
|
| 401 | + * @return string[] tuple ($fields, $bindings) |
|
| 403 | 402 | */ |
| 404 | 403 | protected function getInsertFieldBindings($values) |
| 405 | 404 | { |
@@ -467,8 +467,7 @@ |
||
| 467 | 467 | $values = array_values($values); |
| 468 | 468 | for($i = 0, $max=count($values); $i<$max; $i++) |
| 469 | 469 | $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
| 470 | - } |
|
| 471 | - else |
|
| 470 | + } else |
|
| 472 | 471 | { |
| 473 | 472 | foreach($values as $name=>$value) |
| 474 | 473 | { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | if($column->hasSequence()) |
| 33 | 33 | { |
| 34 | - $command = $this->getDbConnection()->createCommand('SELECT @@Identity'); |
|
| 34 | + $command=$this->getDbConnection()->createCommand('SELECT @@Identity'); |
|
| 35 | 35 | return intval($command->queryScalar()); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
| 81 | 81 | { |
| 82 | - $limit = $limit!==null ? intval($limit) : -1; |
|
| 83 | - $offset = $offset!==null ? intval($offset) : -1; |
|
| 84 | - if ($limit > 0 && $offset <= 0) //just limit |
|
| 85 | - $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql); |
|
| 82 | + $limit=$limit!==null ? intval($limit) : -1; |
|
| 83 | + $offset=$offset!==null ? intval($offset) : -1; |
|
| 84 | + if($limit > 0 && $offset <= 0) //just limit |
|
| 85 | + $sql=preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql); |
|
| 86 | 86 | else if($limit > 0 && $offset > 0) |
| 87 | - $sql = $this->rewriteLimitOffsetSql($sql, $limit,$offset); |
|
| 87 | + $sql=$this->rewriteLimitOffsetSql($sql, $limit, $offset); |
|
| 88 | 88 | return $sql; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected function rewriteLimitOffsetSql($sql, $limit, $offset) |
| 100 | 100 | { |
| 101 | - $fetch = $limit+$offset; |
|
| 102 | - $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $fetch", $sql); |
|
| 103 | - $ordering = $this->findOrdering($sql); |
|
| 101 | + $fetch=$limit + $offset; |
|
| 102 | + $sql=preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $fetch", $sql); |
|
| 103 | + $ordering=$this->findOrdering($sql); |
|
| 104 | 104 | |
| 105 | - $orginalOrdering = $this->joinOrdering($ordering); |
|
| 106 | - $reverseOrdering = $this->joinOrdering($this->reverseDirection($ordering)); |
|
| 107 | - $sql = "SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}"; |
|
| 105 | + $orginalOrdering=$this->joinOrdering($ordering); |
|
| 106 | + $reverseOrdering=$this->joinOrdering($this->reverseDirection($ordering)); |
|
| 107 | + $sql="SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}"; |
|
| 108 | 108 | return $sql; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | $matches=array(); |
| 122 | 122 | $ordering=array(); |
| 123 | 123 | preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches); |
| 124 | - if(count($matches)>1 && count($matches[2]) > 0) |
|
| 124 | + if(count($matches) > 1 && count($matches[2]) > 0) |
|
| 125 | 125 | { |
| 126 | - $parts = explode(',', $matches[2][0]); |
|
| 126 | + $parts=explode(',', $matches[2][0]); |
|
| 127 | 127 | foreach($parts as $part) |
| 128 | 128 | { |
| 129 | 129 | $subs=array(); |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | if(count($subs) > 1 && count($subs[2]) > 0) |
| 133 | 133 | { |
| 134 | - $ordering[$subs[1][0]] = $subs[2][0]; |
|
| 134 | + $ordering[$subs[1][0]]=$subs[2][0]; |
|
| 135 | 135 | } |
| 136 | 136 | //else what? |
| 137 | 137 | } |
| 138 | 138 | else |
| 139 | - $ordering[trim($part)] = 'ASC'; |
|
| 139 | + $ordering[trim($part)]='ASC'; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return $ordering; |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | protected function joinOrdering($orders) |
| 150 | 150 | { |
| 151 | - if(count($orders)>0) |
|
| 151 | + if(count($orders) > 0) |
|
| 152 | 152 | { |
| 153 | 153 | $str=array(); |
| 154 | 154 | foreach($orders as $column => $direction) |
| 155 | - $str[] = $column.' '.$direction; |
|
| 155 | + $str[]=$column.' '.$direction; |
|
| 156 | 156 | return 'ORDER BY '.implode(', ', $str); |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | protected function reverseDirection($orders) |
| 165 | 165 | { |
| 166 | 166 | foreach($orders as $column => $direction) |
| 167 | - $orders[$column] = strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC'; |
|
| 167 | + $orders[$column]=strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC'; |
|
| 168 | 168 | return $orders; |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -138,8 +138,7 @@ |
||
| 138 | 138 | $ordering[$subs[1][0]] = $subs[2][0]; |
| 139 | 139 | } |
| 140 | 140 | //else what? |
| 141 | - } |
|
| 142 | - else |
|
| 141 | + } else |
|
| 143 | 142 | $ordering[trim($part)] = 'ASC'; |
| 144 | 143 | } |
| 145 | 144 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class TMysqlTableColumn extends TDbTableColumn |
| 25 | 25 | { |
| 26 | - private static $types = array( |
|
| 26 | + private static $types=array( |
|
| 27 | 27 | 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'), |
| 28 | 28 | 'boolean' => array('boolean', 'bool'), |
| 29 | 29 | 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed') |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function getPHPType() |
| 37 | 37 | { |
| 38 | - $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType()))); |
|
| 38 | + $dbtype=trim(str_replace(array('unsigned', 'zerofill'), array('', '',), strtolower($this->getDbType()))); |
|
| 39 | 39 | if($dbtype==='tinyint' && $this->getColumnSize()===1) |
| 40 | 40 | return 'boolean'; |
| 41 | 41 | foreach(self::$types as $type => $dbtypes) |
@@ -30,12 +30,12 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
| 32 | 32 | { |
| 33 | - $limit = $limit!==null ? intval($limit) : -1; |
|
| 34 | - $offset = $offset!==null ? intval($offset) : -1; |
|
| 33 | + $limit=$limit!==null ? intval($limit) : -1; |
|
| 34 | + $offset=$offset!==null ? intval($offset) : -1; |
|
| 35 | 35 | if($limit > 0 || $offset > 0) |
| 36 | 36 | { |
| 37 | - $limitStr = ' LIMIT '.$limit; |
|
| 38 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 37 | + $limitStr=' LIMIT '.$limit; |
|
| 38 | + $offsetStr=$offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 39 | 39 | return $sql.$limitStr.$offsetStr; |
| 40 | 40 | } |
| 41 | 41 | else |
@@ -41,8 +41,7 @@ |
||
| 41 | 41 | $limitStr = ' LIMIT '.$limit; |
| 42 | 42 | $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
| 43 | 43 | return $sql.$limitStr.$offsetStr; |
| 44 | - } |
|
| 45 | - else |
|
| 44 | + } else |
|
| 46 | 45 | return $sql; |
| 47 | 46 | } |
| 48 | 47 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @TODO add sqlite types. |
| 28 | 28 | */ |
| 29 | - private static $types = array(); |
|
| 29 | + private static $types=array(); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Overrides parent implementation, returns PHP type from the db type. |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function getPHPType() |
| 36 | 36 | { |
| 37 | - $dbtype = strtolower($this->getDbType()); |
|
| 37 | + $dbtype=strtolower($this->getDbType()); |
|
| 38 | 38 | foreach(self::$types as $type => $dbtypes) |
| 39 | 39 | { |
| 40 | 40 | if(in_array($dbtype, $dbtypes)) |
@@ -425,14 +425,12 @@ discard block |
||
| 425 | 425 | $this->_recordState = self::STATE_LOADED; |
| 426 | 426 | return true; |
| 427 | 427 | } |
| 428 | - } |
|
| 429 | - else if($this->_recordState===self::STATE_LOADED) |
|
| 428 | + } else if($this->_recordState===self::STATE_LOADED) |
|
| 430 | 429 | { |
| 431 | 430 | $this->onUpdate($param); |
| 432 | 431 | if($param->getIsValid() && $gateway->update($this)) |
| 433 | 432 | return true; |
| 434 | - } |
|
| 435 | - else |
|
| 433 | + } else |
|
| 436 | 434 | throw new TActiveRecordException('ar_save_invalid', get_class($this)); |
| 437 | 435 | |
| 438 | 436 | return false; |
@@ -455,8 +453,7 @@ discard block |
||
| 455 | 453 | $this->_recordState=self::STATE_DELETED; |
| 456 | 454 | return true; |
| 457 | 455 | } |
| 458 | - } |
|
| 459 | - else |
|
| 456 | + } else |
|
| 460 | 457 | throw new TActiveRecordException('ar_delete_invalid', get_class($this)); |
| 461 | 458 | |
| 462 | 459 | return false; |
@@ -723,8 +720,7 @@ discard block |
||
| 723 | 720 | { |
| 724 | 721 | $criteria = $this->getRecordCriteria(count($args)>0 ? $args[0] : null, array_slice($args,1)); |
| 725 | 722 | return $context->getRelationHandler($criteria); |
| 726 | - } |
|
| 727 | - else |
|
| 723 | + } else |
|
| 728 | 724 | return null; |
| 729 | 725 | } |
| 730 | 726 | |
@@ -743,8 +739,7 @@ discard block |
||
| 743 | 739 | { |
| 744 | 740 | list($property, $relation) = $definition; |
| 745 | 741 | return new TActiveRecordRelationContext($this,$property,$relation); |
| 746 | - } |
|
| 747 | - else |
|
| 742 | + } else |
|
| 748 | 743 | return null; |
| 749 | 744 | } |
| 750 | 745 | |
@@ -827,8 +822,7 @@ discard block |
||
| 827 | 822 | { |
| 828 | 823 | $property= $method[4]==='_' ? substr($method,5) : substr($method,4); |
| 829 | 824 | return $this->getRelationHandler($property, $args); |
| 830 | - } |
|
| 831 | - else if($findOne=strncasecmp($method,'findby',6)===0) |
|
| 825 | + } else if($findOne=strncasecmp($method,'findby',6)===0) |
|
| 832 | 826 | $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
| 833 | 827 | else if(strncasecmp($method,'findallby',9)===0) |
| 834 | 828 | $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
@@ -894,8 +888,7 @@ discard block |
||
| 894 | 888 | { |
| 895 | 889 | $useArgs = !is_array($parameters) && is_array($args); |
| 896 | 890 | return new TActiveRecordCriteria($criteria,$useArgs ? $args : $parameters); |
| 897 | - } |
|
| 898 | - else if($criteria instanceof TSqlCriteria) |
|
| 891 | + } else if($criteria instanceof TSqlCriteria) |
|
| 899 | 892 | return $criteria; |
| 900 | 893 | else |
| 901 | 894 | return new TActiveRecordCriteria(); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | /** |
| 325 | 325 | * Gets the current Db connection, the connection object is obtained from |
| 326 | 326 | * the TActiveRecordManager if connection is currently null. |
| 327 | - * @return TDbConnection current db connection for this object. |
|
| 327 | + * @return \Prado\Data\TDbConnection current db connection for this object. |
|
| 328 | 328 | */ |
| 329 | 329 | public function getDbConnection() |
| 330 | 330 | { |
@@ -511,6 +511,7 @@ discard block |
||
| 511 | 511 | * Delete multiple records using a criteria. |
| 512 | 512 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
| 513 | 513 | * @param mixed parameter values. |
| 514 | + * @param TSqlCriteria $criteria |
|
| 514 | 515 | * @return int number of records deleted. |
| 515 | 516 | */ |
| 516 | 517 | public function deleteAll($criteria=null, $parameters=array()) |
@@ -577,6 +578,7 @@ discard block |
||
| 577 | 578 | * |
| 578 | 579 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
| 579 | 580 | * @param mixed parameter values. |
| 581 | + * @param TSqlCriteria $criteria |
|
| 580 | 582 | * @return TActiveRecord matching record object. Null if no result is found. |
| 581 | 583 | */ |
| 582 | 584 | public function find($criteria,$parameters=array()) |
@@ -593,6 +595,7 @@ discard block |
||
| 593 | 595 | * |
| 594 | 596 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
| 595 | 597 | * @param mixed parameter values. |
| 598 | + * @param TSqlCriteria $criteria |
|
| 596 | 599 | * @return array matching record objects. Empty array if no result is found. |
| 597 | 600 | */ |
| 598 | 601 | public function findAll($criteria=null,$parameters=array()) |
@@ -706,6 +709,7 @@ discard block |
||
| 706 | 709 | * Find the number of records. |
| 707 | 710 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
| 708 | 711 | * @param mixed parameter values. |
| 712 | + * @param TActiveRecordCriteria $criteria |
|
| 709 | 713 | * @return int number of records. |
| 710 | 714 | */ |
| 711 | 715 | public function count($criteria=null,$parameters=array()) |
@@ -721,6 +725,7 @@ discard block |
||
| 721 | 725 | * value equal to the $property value. |
| 722 | 726 | * @param string relationship/property name corresponding to keys in $RELATION array. |
| 723 | 727 | * @param array method call arguments. |
| 728 | + * @param string $name |
|
| 724 | 729 | * @return TActiveRecordRelation, null if the context or the handler doesn't exist |
| 725 | 730 | */ |
| 726 | 731 | protected function getRelationHandler($name,$args=array()) |
@@ -945,6 +950,7 @@ discard block |
||
| 945 | 950 | * Raised before the record attempt to insert its data into the database. |
| 946 | 951 | * To prevent the insert operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
| 947 | 952 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
| 953 | + * @param TActiveRecordChangeEventParameter $param |
|
| 948 | 954 | */ |
| 949 | 955 | public function onInsert($param) |
| 950 | 956 | { |
@@ -955,6 +961,7 @@ discard block |
||
| 955 | 961 | * Raised before the record attempt to delete its data from the database. |
| 956 | 962 | * To prevent the delete operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
| 957 | 963 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
| 964 | + * @param TActiveRecordChangeEventParameter $param |
|
| 958 | 965 | */ |
| 959 | 966 | public function onDelete($param) |
| 960 | 967 | { |
@@ -965,6 +972,7 @@ discard block |
||
| 965 | 972 | * Raised before the record attempt to update its data in the database. |
| 966 | 973 | * To prevent the update operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
| 967 | 974 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
| 975 | + * @param TActiveRecordChangeEventParameter $param |
|
| 968 | 976 | */ |
| 969 | 977 | public function onUpdate($param) |
| 970 | 978 | { |
@@ -1048,7 +1056,7 @@ discard block |
||
| 1048 | 1056 | |
| 1049 | 1057 | /** |
| 1050 | 1058 | * Return record data as JSON |
| 1051 | - * @return JSON |
|
| 1059 | + * @return string |
|
| 1052 | 1060 | * @since 3.2.4 |
| 1053 | 1061 | */ |
| 1054 | 1062 | public function toJSON(){ |
@@ -1032,26 +1032,26 @@ |
||
| 1032 | 1032 | return isset(self::$_relations[get_class($this)][strtolower($property)]); |
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | - /** |
|
| 1036 | - * Return record data as array |
|
| 1037 | - * @return array of column name and column values |
|
| 1038 | - * @since 3.2.4 |
|
| 1039 | - */ |
|
| 1040 | - public function toArray(){ |
|
| 1041 | - $result=array(); |
|
| 1042 | - foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){ |
|
| 1043 | - $result[$columnName]=$this->getColumnValue($columnName); |
|
| 1044 | - } |
|
| 1035 | + /** |
|
| 1036 | + * Return record data as array |
|
| 1037 | + * @return array of column name and column values |
|
| 1038 | + * @since 3.2.4 |
|
| 1039 | + */ |
|
| 1040 | + public function toArray(){ |
|
| 1041 | + $result=array(); |
|
| 1042 | + foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){ |
|
| 1043 | + $result[$columnName]=$this->getColumnValue($columnName); |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - return $result; |
|
| 1047 | - } |
|
| 1046 | + return $result; |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | - /** |
|
| 1050 | - * Return record data as JSON |
|
| 1051 | - * @return JSON |
|
| 1052 | - * @since 3.2.4 |
|
| 1053 | - */ |
|
| 1054 | - public function toJSON(){ |
|
| 1055 | - return json_encode($this->toArray()); |
|
| 1056 | - } |
|
| 1049 | + /** |
|
| 1050 | + * Return record data as JSON |
|
| 1051 | + * @return JSON |
|
| 1052 | + * @since 3.2.4 |
|
| 1053 | + */ |
|
| 1054 | + public function toJSON(){ |
|
| 1055 | + return json_encode($this->toArray()); |
|
| 1056 | + } |
|
| 1057 | 1057 | } |
| 1058 | 1058 | \ No newline at end of file |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | * @var TActiveRecordInvalidFinderResult |
| 201 | 201 | * @since 3.1.5 |
| 202 | 202 | */ |
| 203 | - protected $_invalidFinderResult = null; // use protected so that serialization is fine |
|
| 203 | + protected $_invalidFinderResult=null; // use protected so that serialization is fine |
|
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * Prevent __call() method creating __sleep() when serializing. |
| 207 | 207 | */ |
| 208 | 208 | public function __sleep() |
| 209 | 209 | { |
| 210 | - return array_diff(parent::__sleep(),array("\0*\0_connection")); |
|
| 210 | + return array_diff(parent::__sleep(), array("\0*\0_connection")); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -262,12 +262,12 @@ discard block |
||
| 262 | 262 | * @param mixed property value. |
| 263 | 263 | * @since 3.1.2 |
| 264 | 264 | */ |
| 265 | - public function __set($name,$value) |
|
| 265 | + public function __set($name, $value) |
|
| 266 | 266 | { |
| 267 | 267 | if($this->hasRecordRelation($name) && !$this->canSetProperty($name)) |
| 268 | 268 | $this->$name=$value; |
| 269 | 269 | else |
| 270 | - parent::__set($name,$value); |
|
| 270 | + parent::__set($name, $value); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | $class=new ReflectionClass($className); |
| 295 | 295 | $relations=array(); |
| 296 | 296 | foreach($class->getStaticPropertyValue('RELATIONS') as $key=>$value) |
| 297 | - $relations[strtolower($key)]=array($key,$value); |
|
| 297 | + $relations[strtolower($key)]=array($key, $value); |
|
| 298 | 298 | self::$_relations[$className]=$relations; |
| 299 | 299 | } |
| 300 | 300 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | if(!is_array($data)) |
| 311 | 311 | throw new TActiveRecordException('ar_data_invalid', get_class($this)); |
| 312 | 312 | foreach($data as $name=>$value) |
| 313 | - $this->setColumnValue($name,$value); |
|
| 313 | + $this->setColumnValue($name, $value); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
@@ -361,16 +361,16 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | if($record===null || get_class($this)!==get_class($record)) |
| 363 | 363 | return false; |
| 364 | - $tableInfo = $this->getRecordTableInfo(); |
|
| 365 | - $pks = $tableInfo->getPrimaryKeys(); |
|
| 366 | - $properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys(); |
|
| 364 | + $tableInfo=$this->getRecordTableInfo(); |
|
| 365 | + $pks=$tableInfo->getPrimaryKeys(); |
|
| 366 | + $properties=count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys(); |
|
| 367 | 367 | $equals=true; |
| 368 | 368 | foreach($properties as $prop) |
| 369 | 369 | { |
| 370 | 370 | if($strict) |
| 371 | - $equals = $equals && $this->getColumnValue($prop) === $record->getColumnValue($prop); |
|
| 371 | + $equals=$equals && $this->getColumnValue($prop)===$record->getColumnValue($prop); |
|
| 372 | 372 | else |
| 373 | - $equals = $equals && $this->getColumnValue($prop) == $record->getColumnValue($prop); |
|
| 373 | + $equals=$equals && $this->getColumnValue($prop)==$record->getColumnValue($prop); |
|
| 374 | 374 | if(!$equals) |
| 375 | 375 | return false; |
| 376 | 376 | } |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | public static function finder($className=__CLASS__) |
| 390 | 390 | { |
| 391 | - static $finders = array(); |
|
| 391 | + static $finders=array(); |
|
| 392 | 392 | if(!isset($finders[$className])) |
| 393 | 393 | { |
| 394 | - $f = Prado::createComponent($className); |
|
| 394 | + $f=Prado::createComponent($className); |
|
| 395 | 395 | $finders[$className]=$f; |
| 396 | 396 | } |
| 397 | 397 | return $finders[$className]; |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | */ |
| 422 | 422 | public function save() |
| 423 | 423 | { |
| 424 | - $gateway = $this->getRecordGateway(); |
|
| 425 | - $param = new TActiveRecordChangeEventParameter(); |
|
| 424 | + $gateway=$this->getRecordGateway(); |
|
| 425 | + $param=new TActiveRecordChangeEventParameter(); |
|
| 426 | 426 | if($this->_recordState===self::STATE_NEW) |
| 427 | 427 | { |
| 428 | 428 | $this->onInsert($param); |
| 429 | 429 | if($param->getIsValid() && $gateway->insert($this)) |
| 430 | 430 | { |
| 431 | - $this->_recordState = self::STATE_LOADED; |
|
| 431 | + $this->_recordState=self::STATE_LOADED; |
|
| 432 | 432 | return true; |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | { |
| 454 | 454 | if($this->_recordState===self::STATE_LOADED) |
| 455 | 455 | { |
| 456 | - $gateway = $this->getRecordGateway(); |
|
| 457 | - $param = new TActiveRecordChangeEventParameter(); |
|
| 456 | + $gateway=$this->getRecordGateway(); |
|
| 457 | + $param=new TActiveRecordChangeEventParameter(); |
|
| 458 | 458 | $this->onDelete($param); |
| 459 | 459 | if($param->getIsValid() && $gateway->delete($this)) |
| 460 | 460 | { |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | public function deleteByPk($keys) |
| 495 | 495 | { |
| 496 | 496 | if(func_num_args() > 1) |
| 497 | - $keys = func_get_args(); |
|
| 498 | - return $this->getRecordGateway()->deleteRecordsByPk($this,(array)$keys); |
|
| 497 | + $keys=func_get_args(); |
|
| 498 | + return $this->getRecordGateway()->deleteRecordsByPk($this, (array) $keys); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | public function deleteAllByPks($keys) |
| 505 | 505 | { |
| 506 | 506 | if(func_num_args() > 1) |
| 507 | - $keys = func_get_args(); |
|
| 507 | + $keys=func_get_args(); |
|
| 508 | 508 | return $this->deleteByPk($keys); |
| 509 | 509 | } |
| 510 | 510 | /** |
@@ -515,8 +515,8 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | public function deleteAll($criteria=null, $parameters=array()) |
| 517 | 517 | { |
| 518 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 519 | - $criteria = $this->getRecordCriteria($criteria,$parameters, $args); |
|
| 518 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 519 | + $criteria=$this->getRecordCriteria($criteria, $parameters, $args); |
|
| 520 | 520 | return $this->getRecordGateway()->deleteRecordsByCriteria($this, $criteria); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | { |
| 541 | 541 | $result=array(); |
| 542 | 542 | foreach($reader as $data) |
| 543 | - $result[] = $this->populateObject($data); |
|
| 543 | + $result[]=$this->populateObject($data); |
|
| 544 | 544 | return $result; |
| 545 | 545 | } |
| 546 | 546 | |
@@ -579,12 +579,12 @@ discard block |
||
| 579 | 579 | * @param mixed parameter values. |
| 580 | 580 | * @return TActiveRecord matching record object. Null if no result is found. |
| 581 | 581 | */ |
| 582 | - public function find($criteria,$parameters=array()) |
|
| 582 | + public function find($criteria, $parameters=array()) |
|
| 583 | 583 | { |
| 584 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 585 | - $criteria = $this->getRecordCriteria($criteria,$parameters, $args); |
|
| 584 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 585 | + $criteria=$this->getRecordCriteria($criteria, $parameters, $args); |
|
| 586 | 586 | $criteria->setLimit(1); |
| 587 | - $data = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria); |
|
| 587 | + $data=$this->getRecordGateway()->findRecordsByCriteria($this, $criteria); |
|
| 588 | 588 | return $this->populateObject($data); |
| 589 | 589 | } |
| 590 | 590 | |
@@ -595,12 +595,12 @@ discard block |
||
| 595 | 595 | * @param mixed parameter values. |
| 596 | 596 | * @return array matching record objects. Empty array if no result is found. |
| 597 | 597 | */ |
| 598 | - public function findAll($criteria=null,$parameters=array()) |
|
| 598 | + public function findAll($criteria=null, $parameters=array()) |
|
| 599 | 599 | { |
| 600 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 600 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 601 | 601 | if($criteria!==null) |
| 602 | - $criteria = $this->getRecordCriteria($criteria,$parameters, $args); |
|
| 603 | - $result = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria,true); |
|
| 602 | + $criteria=$this->getRecordCriteria($criteria, $parameters, $args); |
|
| 603 | + $result=$this->getRecordGateway()->findRecordsByCriteria($this, $criteria, true); |
|
| 604 | 604 | return $this->populateObjects($result); |
| 605 | 605 | } |
| 606 | 606 | |
@@ -618,11 +618,11 @@ discard block |
||
| 618 | 618 | */ |
| 619 | 619 | public function findByPk($keys) |
| 620 | 620 | { |
| 621 | - if($keys === null) |
|
| 621 | + if($keys===null) |
|
| 622 | 622 | return null; |
| 623 | 623 | if(func_num_args() > 1) |
| 624 | - $keys = func_get_args(); |
|
| 625 | - $data = $this->getRecordGateway()->findRecordByPK($this,$keys); |
|
| 624 | + $keys=func_get_args(); |
|
| 625 | + $data=$this->getRecordGateway()->findRecordByPK($this, $keys); |
|
| 626 | 626 | return $this->populateObject($data); |
| 627 | 627 | } |
| 628 | 628 | |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | public function findAllByPks($keys) |
| 647 | 647 | { |
| 648 | 648 | if(func_num_args() > 1) |
| 649 | - $keys = func_get_args(); |
|
| 650 | - $result = $this->getRecordGateway()->findRecordsByPks($this,(array)$keys); |
|
| 649 | + $keys=func_get_args(); |
|
| 650 | + $result=$this->getRecordGateway()->findRecordsByPks($this, (array) $keys); |
|
| 651 | 651 | return $this->populateObjects($result); |
| 652 | 652 | } |
| 653 | 653 | |
@@ -659,12 +659,12 @@ discard block |
||
| 659 | 659 | * @param array $parameters |
| 660 | 660 | * @return TActiveRecord, null if no result is returned. |
| 661 | 661 | */ |
| 662 | - public function findBySql($sql,$parameters=array()) |
|
| 662 | + public function findBySql($sql, $parameters=array()) |
|
| 663 | 663 | { |
| 664 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 665 | - $criteria = $this->getRecordCriteria($sql,$parameters, $args); |
|
| 664 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 665 | + $criteria=$this->getRecordCriteria($sql, $parameters, $args); |
|
| 666 | 666 | $criteria->setLimit(1); |
| 667 | - $data = $this->getRecordGateway()->findRecordBySql($this,$criteria); |
|
| 667 | + $data=$this->getRecordGateway()->findRecordBySql($this, $criteria); |
|
| 668 | 668 | return $this->populateObject($data); |
| 669 | 669 | } |
| 670 | 670 | |
@@ -676,11 +676,11 @@ discard block |
||
| 676 | 676 | * @param array $parameters |
| 677 | 677 | * @return array matching active records. Empty array is returned if no result is found. |
| 678 | 678 | */ |
| 679 | - public function findAllBySql($sql,$parameters=array()) |
|
| 679 | + public function findAllBySql($sql, $parameters=array()) |
|
| 680 | 680 | { |
| 681 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 682 | - $criteria = $this->getRecordCriteria($sql,$parameters, $args); |
|
| 683 | - $result = $this->getRecordGateway()->findRecordsBySql($this,$criteria); |
|
| 681 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 682 | + $criteria=$this->getRecordCriteria($sql, $parameters, $args); |
|
| 683 | + $result=$this->getRecordGateway()->findRecordsBySql($this, $criteria); |
|
| 684 | 684 | return $this->populateObjects($result); |
| 685 | 685 | } |
| 686 | 686 | |
@@ -696,9 +696,9 @@ discard block |
||
| 696 | 696 | * @param array matching field values. |
| 697 | 697 | * @return array matching active records. Empty array is returned if no result is found. |
| 698 | 698 | */ |
| 699 | - public function findAllByIndex($criteria,$fields,$values) |
|
| 699 | + public function findAllByIndex($criteria, $fields, $values) |
|
| 700 | 700 | { |
| 701 | - $result = $this->getRecordGateway()->findRecordsByIndex($this,$criteria,$fields,$values); |
|
| 701 | + $result=$this->getRecordGateway()->findRecordsByIndex($this, $criteria, $fields, $values); |
|
| 702 | 702 | return $this->populateObjects($result); |
| 703 | 703 | } |
| 704 | 704 | |
@@ -708,12 +708,12 @@ discard block |
||
| 708 | 708 | * @param mixed parameter values. |
| 709 | 709 | * @return int number of records. |
| 710 | 710 | */ |
| 711 | - public function count($criteria=null,$parameters=array()) |
|
| 711 | + public function count($criteria=null, $parameters=array()) |
|
| 712 | 712 | { |
| 713 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 713 | + $args=func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 714 | 714 | if($criteria!==null) |
| 715 | - $criteria = $this->getRecordCriteria($criteria,$parameters, $args); |
|
| 716 | - return $this->getRecordGateway()->countRecords($this,$criteria); |
|
| 715 | + $criteria=$this->getRecordCriteria($criteria, $parameters, $args); |
|
| 716 | + return $this->getRecordGateway()->countRecords($this, $criteria); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -723,11 +723,11 @@ discard block |
||
| 723 | 723 | * @param array method call arguments. |
| 724 | 724 | * @return TActiveRecordRelation, null if the context or the handler doesn't exist |
| 725 | 725 | */ |
| 726 | - protected function getRelationHandler($name,$args=array()) |
|
| 726 | + protected function getRelationHandler($name, $args=array()) |
|
| 727 | 727 | { |
| 728 | - if(($context=$this->createRelationContext($name)) !== null) |
|
| 728 | + if(($context=$this->createRelationContext($name))!==null) |
|
| 729 | 729 | { |
| 730 | - $criteria = $this->getRecordCriteria(count($args)>0 ? $args[0] : null, array_slice($args,1)); |
|
| 730 | + $criteria=$this->getRecordCriteria(count($args) > 0 ? $args[0] : null, array_slice($args, 1)); |
|
| 731 | 731 | return $context->getRelationHandler($criteria); |
| 732 | 732 | } |
| 733 | 733 | else |
@@ -747,8 +747,8 @@ discard block |
||
| 747 | 747 | { |
| 748 | 748 | if(($definition=$this->getRecordRelation($name))!==null) |
| 749 | 749 | { |
| 750 | - list($property, $relation) = $definition; |
|
| 751 | - return new TActiveRecordRelationContext($this,$property,$relation); |
|
| 750 | + list($property, $relation)=$definition; |
|
| 751 | + return new TActiveRecordRelationContext($this, $property, $relation); |
|
| 752 | 752 | } |
| 753 | 753 | else |
| 754 | 754 | return null; |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | */ |
| 792 | 792 | protected function fetchResultsFor($property) |
| 793 | 793 | { |
| 794 | - if( ($context=$this->createRelationContext($property)) !== null) |
|
| 794 | + if(($context=$this->createRelationContext($property))!==null) |
|
| 795 | 795 | return $context->getRelationHandler()->fetchResultsInto($this); |
| 796 | 796 | else |
| 797 | 797 | return false; |
@@ -826,31 +826,31 @@ discard block |
||
| 826 | 826 | * @return mixed single record if method name starts with "findBy", 0 or more records |
| 827 | 827 | * if method name starts with "findAllBy" |
| 828 | 828 | */ |
| 829 | - public function __call($method,$args) |
|
| 829 | + public function __call($method, $args) |
|
| 830 | 830 | { |
| 831 | - $delete =false; |
|
| 832 | - if(strncasecmp($method,'with',4)===0) |
|
| 831 | + $delete=false; |
|
| 832 | + if(strncasecmp($method, 'with', 4)===0) |
|
| 833 | 833 | { |
| 834 | - $property= $method[4]==='_' ? substr($method,5) : substr($method,4); |
|
| 834 | + $property=$method[4]==='_' ? substr($method, 5) : substr($method, 4); |
|
| 835 | 835 | return $this->getRelationHandler($property, $args); |
| 836 | 836 | } |
| 837 | - else if($findOne=strncasecmp($method,'findby',6)===0) |
|
| 838 | - $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
|
| 839 | - else if(strncasecmp($method,'findallby',9)===0) |
|
| 840 | - $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
|
| 841 | - else if($delete=strncasecmp($method,'deleteby',8)===0) |
|
| 842 | - $condition = $method[8]==='_' ? substr($method,9) : substr($method,8); |
|
| 843 | - else if($delete=strncasecmp($method,'deleteallby',11)===0) |
|
| 844 | - $condition = $method[11]==='_' ? substr($method,12) : substr($method,11); |
|
| 837 | + else if($findOne=strncasecmp($method, 'findby', 6)===0) |
|
| 838 | + $condition=$method[6]==='_' ? substr($method, 7) : substr($method, 6); |
|
| 839 | + else if(strncasecmp($method, 'findallby', 9)===0) |
|
| 840 | + $condition=$method[9]==='_' ? substr($method, 10) : substr($method, 9); |
|
| 841 | + else if($delete=strncasecmp($method, 'deleteby', 8)===0) |
|
| 842 | + $condition=$method[8]==='_' ? substr($method, 9) : substr($method, 8); |
|
| 843 | + else if($delete=strncasecmp($method, 'deleteallby', 11)===0) |
|
| 844 | + $condition=$method[11]==='_' ? substr($method, 12) : substr($method, 11); |
|
| 845 | 845 | else |
| 846 | 846 | { |
| 847 | - if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception) |
|
| 848 | - throw new TActiveRecordException('ar_invalid_finder_method',$method); |
|
| 847 | + if($this->getInvalidFinderResult()==TActiveRecordInvalidFinderResult::Exception) |
|
| 848 | + throw new TActiveRecordException('ar_invalid_finder_method', $method); |
|
| 849 | 849 | else |
| 850 | 850 | return null; |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - $criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args); |
|
| 853 | + $criteria=$this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args); |
|
| 854 | 854 | if($delete) |
| 855 | 855 | return $this->deleteAll($criteria); |
| 856 | 856 | else |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | */ |
| 865 | 865 | public function getInvalidFinderResult() |
| 866 | 866 | { |
| 867 | - if($this->_invalidFinderResult !== null) |
|
| 867 | + if($this->_invalidFinderResult!==null) |
|
| 868 | 868 | return $this->_invalidFinderResult; |
| 869 | 869 | |
| 870 | 870 | return self::getRecordManager()->getInvalidFinderResult(); |
@@ -879,10 +879,10 @@ discard block |
||
| 879 | 879 | */ |
| 880 | 880 | public function setInvalidFinderResult($value) |
| 881 | 881 | { |
| 882 | - if($value === null) |
|
| 883 | - $this->_invalidFinderResult = null; |
|
| 882 | + if($value===null) |
|
| 883 | + $this->_invalidFinderResult=null; |
|
| 884 | 884 | else |
| 885 | - $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'Prado\\Data\\ActiveRecord\\TActiveRecordInvalidFinderResult'); |
|
| 885 | + $this->_invalidFinderResult=TPropertyValue::ensureEnum($value, 'Prado\\Data\\ActiveRecord\\TActiveRecordInvalidFinderResult'); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | /** |
@@ -898,8 +898,8 @@ discard block |
||
| 898 | 898 | { |
| 899 | 899 | if(is_string($criteria)) |
| 900 | 900 | { |
| 901 | - $useArgs = !is_array($parameters) && is_array($args); |
|
| 902 | - return new TActiveRecordCriteria($criteria,$useArgs ? $args : $parameters); |
|
| 901 | + $useArgs=!is_array($parameters) && is_array($args); |
|
| 902 | + return new TActiveRecordCriteria($criteria, $useArgs ? $args : $parameters); |
|
| 903 | 903 | } |
| 904 | 904 | else if($criteria instanceof TSqlCriteria) |
| 905 | 905 | return $criteria; |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | * @param mixed the corresponding column value |
| 994 | 994 | * @since 3.1.1 |
| 995 | 995 | */ |
| 996 | - public function setColumnValue($columnName,$value) |
|
| 996 | + public function setColumnValue($columnName, $value) |
|
| 997 | 997 | { |
| 998 | 998 | $className=get_class($this); |
| 999 | 999 | if(isset(self::$_columnMapping[$className][$columnName])) |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | { |
| 1011 | 1011 | $className=get_class($this); |
| 1012 | 1012 | $property=strtolower($property); |
| 1013 | - return isset(self::$_relations[$className][$property])?self::$_relations[$className][$property]:null; |
|
| 1013 | + return isset(self::$_relations[$className][$property]) ?self::$_relations[$className][$property] : null; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
@@ -1037,9 +1037,9 @@ discard block |
||
| 1037 | 1037 | * @return array of column name and column values |
| 1038 | 1038 | * @since 3.2.4 |
| 1039 | 1039 | */ |
| 1040 | - public function toArray(){ |
|
| 1040 | + public function toArray() { |
|
| 1041 | 1041 | $result=array(); |
| 1042 | - foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName){ |
|
| 1042 | + foreach($this->getRecordTableInfo()->getLowerCaseColumnNames() as $columnName) { |
|
| 1043 | 1043 | $result[$columnName]=$this->getColumnValue($columnName); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | * @return JSON |
| 1052 | 1052 | * @since 3.2.4 |
| 1053 | 1053 | */ |
| 1054 | - public function toJSON(){ |
|
| 1054 | + public function toJSON() { |
|
| 1055 | 1055 | return json_encode($this->toArray()); |
| 1056 | 1056 | } |
| 1057 | 1057 | } |
| 1058 | 1058 | \ No newline at end of file |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | protected function collectForeignObjects(&$results) |
| 79 | 79 | { |
| 80 | - $fkeys = $this->getRelationForeignKeys(); |
|
| 80 | + $fkeys=$this->getRelationForeignKeys(); |
|
| 81 | 81 | |
| 82 | - $properties = array_keys($fkeys); |
|
| 83 | - $fields = array_values($fkeys); |
|
| 84 | - $indexValues = $this->getIndexValues($properties, $results); |
|
| 85 | - $fkObjects = $this->findForeignObjects($fields, $indexValues); |
|
| 86 | - $this->populateResult($results,$properties,$fkObjects,$fields); |
|
| 82 | + $properties=array_keys($fkeys); |
|
| 83 | + $fields=array_values($fkeys); |
|
| 84 | + $indexValues=$this->getIndexValues($properties, $results); |
|
| 85 | + $fkObjects=$this->findForeignObjects($fields, $indexValues); |
|
| 86 | + $this->populateResult($results, $properties, $fkObjects, $fields); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getRelationForeignKeys() |
| 94 | 94 | { |
| 95 | - $fkObject = $this->getContext()->getForeignRecordFinder(); |
|
| 96 | - return $this->findForeignKeys($this->getSourceRecord(),$fkObject); |
|
| 95 | + $fkObject=$this->getContext()->getForeignRecordFinder(); |
|
| 96 | + return $this->findForeignKeys($this->getSourceRecord(), $fkObject); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | protected function setObjectProperty($source, $properties, &$collections) |
| 105 | 105 | { |
| 106 | - $hash = $this->getObjectHash($source, $properties); |
|
| 107 | - $prop = $this->getContext()->getProperty(); |
|
| 106 | + $hash=$this->getObjectHash($source, $properties); |
|
| 107 | + $prop=$this->getContext()->getProperty(); |
|
| 108 | 108 | if(isset($collections[$hash]) && count($collections[$hash]) > 0) |
| 109 | 109 | { |
| 110 | 110 | if(count($collections[$hash]) > 1) |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function updateAssociatedRecords() |
| 123 | 123 | { |
| 124 | - $obj = $this->getContext()->getSourceRecord(); |
|
| 125 | - $fkObject = $obj->getColumnValue($this->getContext()->getProperty()); |
|
| 124 | + $obj=$this->getContext()->getSourceRecord(); |
|
| 125 | + $fkObject=$obj->getColumnValue($this->getContext()->getProperty()); |
|
| 126 | 126 | if($fkObject!==null) |
| 127 | 127 | { |
| 128 | 128 | $fkObject->save(); |
| 129 | - $source = $this->getSourceRecord(); |
|
| 130 | - $fkeys = $this->findForeignKeys($source, $fkObject); |
|
| 129 | + $source=$this->getSourceRecord(); |
|
| 130 | + $fkeys=$this->findForeignKeys($source, $fkObject); |
|
| 131 | 131 | foreach($fkeys as $srcKey => $fKey) |
| 132 | 132 | $source->setColumnValue($srcKey, $fkObject->getColumnValue($fKey)); |
| 133 | 133 | return true; |
@@ -112,8 +112,7 @@ |
||
| 112 | 112 | if(count($collections[$hash]) > 1) |
| 113 | 113 | throw new TActiveRecordException('ar_belongs_to_multiple_result'); |
| 114 | 114 | $source->$prop=$collections[$hash][0]; |
| 115 | - } |
|
| 116 | - else |
|
| 115 | + } else |
|
| 117 | 116 | $source->$prop=null; |
| 118 | 117 | } |
| 119 | 118 | |