@@ -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 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function getPropertyValue() |
| 50 | 50 | { |
| 51 | - $obj = $this->getSourceRecord(); |
|
| 51 | + $obj=$this->getSourceRecord(); |
|
| 52 | 52 | return $obj->getColumnValue($this->getProperty()); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function getCondition() |
| 113 | 113 | { |
| 114 | - return isset($this->_relation[3])?$this->_relation[3]:null; |
|
| 114 | + return isset($this->_relation[3]) ? $this->_relation[3] : null; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getParameters() |
| 122 | 122 | { |
| 123 | - return isset($this->_relation[4])?$this->_relation[4]:array(); |
|
| 123 | + return isset($this->_relation[4]) ? $this->_relation[4] : array(); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function hasFkField() |
| 131 | 131 | { |
| 132 | - $notManyToMany = $this->getRelationType() !== TActiveRecord::MANY_TO_MANY; |
|
| 132 | + $notManyToMany=$this->getRelationType()!==TActiveRecord::MANY_TO_MANY; |
|
| 133 | 133 | return $notManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function hasAssociationTable() |
| 148 | 148 | { |
| 149 | - $isManyToMany = $this->getRelationType() === TActiveRecord::MANY_TO_MANY; |
|
| 149 | + $isManyToMany=$this->getRelationType()===TActiveRecord::MANY_TO_MANY; |
|
| 150 | 150 | return $isManyToMany && isset($this->_relation[2]) && !empty($this->_relation[2]); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $this->_property, get_class($this->_record), 'RELATIONS'); |
| 175 | 175 | } |
| 176 | 176 | if($criteria===null) |
| 177 | - $criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters()); |
|
| 177 | + $criteria=new TActiveRecordCriteria($this->getCondition(), $this->getParameters()); |
|
| 178 | 178 | switch($this->getRelationType()) |
| 179 | 179 | { |
| 180 | 180 | case TActiveRecord::HAS_MANY: |
@@ -202,15 +202,15 @@ discard block |
||
| 202 | 202 | $success=true; |
| 203 | 203 | foreach($this->_record->getRecordRelations() as $data) |
| 204 | 204 | { |
| 205 | - list($property, $relation) = $data; |
|
| 206 | - $belongsTo = $relation[0]==TActiveRecord::BELONGS_TO; |
|
| 205 | + list($property, $relation)=$data; |
|
| 206 | + $belongsTo=$relation[0]==TActiveRecord::BELONGS_TO; |
|
| 207 | 207 | if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo)) |
| 208 | 208 | { |
| 209 | - $obj = $this->getSourceRecord(); |
|
| 209 | + $obj=$this->getSourceRecord(); |
|
| 210 | 210 | if(!$this->isEmptyFkObject($obj->getColumnValue($property))) |
| 211 | 211 | { |
| 212 | - $context = new TActiveRecordRelationContext($this->getSourceRecord(),$property,$relation); |
|
| 213 | - $success = $context->getRelationHandler()->updateAssociatedRecords() && $success; |
|
| 212 | + $context=new TActiveRecordRelationContext($this->getSourceRecord(), $property, $relation); |
|
| 213 | + $success=$context->getRelationHandler()->updateAssociatedRecords() && $success; |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | protected function isEmptyFkObject($obj) |
| 221 | 221 | { |
| 222 | 222 | if(is_object($obj)) |
| 223 | - return $obj instanceof TList ? $obj->count() === 0 : false; |
|
| 223 | + return $obj instanceof TList ? $obj->count()===0 : false; |
|
| 224 | 224 | else if(is_array($obj)) |
| 225 | 225 | return count($obj)===0; |
| 226 | 226 | else |
@@ -35,6 +35,9 @@ discard block |
||
| 35 | 35 | private $_relation; //data from an entry of TActiveRecord::$RELATION |
| 36 | 36 | private $_fkeys; |
| 37 | 37 | |
| 38 | + /** |
|
| 39 | + * @param TActiveRecord $record |
|
| 40 | + */ |
|
| 38 | 41 | public function __construct($record, $property=null, $relation=null) |
| 39 | 42 | { |
| 40 | 43 | $this->_record=$record; |
@@ -168,6 +171,7 @@ discard block |
||
| 168 | 171 | * An instance of TActiveRecordHasOne, TActiveRecordBelongsTo, TActiveRecordHasMany, |
| 169 | 172 | * or TActiveRecordHasManyAssocation will be returned. |
| 170 | 173 | * @param TActiveRecordCriteria search criteria |
| 174 | + * @param \Prado\Data\DataGateway\TSqlCriteria $criteria |
|
| 171 | 175 | * @return TActiveRecordRelation record relationship handler instnace. |
| 172 | 176 | * @throws TActiveRecordException if property is not defined or missing. |
| 173 | 177 | */ |
@@ -196,7 +200,7 @@ discard block |
||
| 196 | 200 | } |
| 197 | 201 | |
| 198 | 202 | /** |
| 199 | - * @return TActiveRecordRelationCommand |
|
| 203 | + * @return boolean |
|
| 200 | 204 | */ |
| 201 | 205 | public function updateAssociatedRecords($updateBelongsTo=false) |
| 202 | 206 | { |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function collectForeignObjects(&$results) |
| 77 | 77 | { |
| 78 | - $fkeys = $this->getRelationForeignKeys(); |
|
| 78 | + $fkeys=$this->getRelationForeignKeys(); |
|
| 79 | 79 | |
| 80 | - $properties = array_values($fkeys); |
|
| 81 | - $fields = array_keys($fkeys); |
|
| 80 | + $properties=array_values($fkeys); |
|
| 81 | + $fields=array_keys($fkeys); |
|
| 82 | 82 | |
| 83 | - $indexValues = $this->getIndexValues($properties, $results); |
|
| 84 | - $fkObjects = $this->findForeignObjects($fields,$indexValues); |
|
| 85 | - $this->populateResult($results,$properties,$fkObjects,$fields); |
|
| 83 | + $indexValues=$this->getIndexValues($properties, $results); |
|
| 84 | + $fkObjects=$this->findForeignObjects($fields, $indexValues); |
|
| 85 | + $this->populateResult($results, $properties, $fkObjects, $fields); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function getRelationForeignKeys() |
| 93 | 93 | { |
| 94 | - $fkObject = $this->getContext()->getForeignRecordFinder(); |
|
| 94 | + $fkObject=$this->getContext()->getForeignRecordFinder(); |
|
| 95 | 95 | return $this->findForeignKeys($fkObject, $this->getSourceRecord()); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function updateAssociatedRecords() |
| 103 | 103 | { |
| 104 | - $obj = $this->getContext()->getSourceRecord(); |
|
| 105 | - $fkObjects = &$obj->{$this->getContext()->getProperty()}; |
|
| 104 | + $obj=$this->getContext()->getSourceRecord(); |
|
| 105 | + $fkObjects=&$obj->{$this->getContext()->getProperty()}; |
|
| 106 | 106 | $success=true; |
| 107 | - if(($total = count($fkObjects))> 0) |
|
| 107 | + if(($total=count($fkObjects)) > 0) |
|
| 108 | 108 | { |
| 109 | - $source = $this->getSourceRecord(); |
|
| 110 | - $fkeys = $this->findForeignKeys($fkObjects[0], $source); |
|
| 111 | - for($i=0;$i<$total;$i++) |
|
| 109 | + $source=$this->getSourceRecord(); |
|
| 110 | + $fkeys=$this->findForeignKeys($fkObjects[0], $source); |
|
| 111 | + for($i=0; $i < $total; $i++) |
|
| 112 | 112 | { |
| 113 | 113 | foreach($fkeys as $fKey => $srcKey) |
| 114 | 114 | $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey)); |
| 115 | - $success = $fkObjects[$i]->save() && $success; |
|
| 115 | + $success=$fkObjects[$i]->save() && $success; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | return $success; |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | protected function collectForeignObjects(&$results) |
| 94 | 94 | { |
| 95 | - $fkeys = $this->getRelationForeignKeys(); |
|
| 96 | - $properties = array_values($fkeys); |
|
| 97 | - $fields = array_keys($fkeys); |
|
| 95 | + $fkeys=$this->getRelationForeignKeys(); |
|
| 96 | + $properties=array_values($fkeys); |
|
| 97 | + $fields=array_keys($fkeys); |
|
| 98 | 98 | |
| 99 | - $indexValues = $this->getIndexValues($properties, $results); |
|
| 100 | - $fkObjects = $this->findForeignObjects($fields,$indexValues); |
|
| 101 | - $this->populateResult($results,$properties,$fkObjects,$fields); |
|
| 99 | + $indexValues=$this->getIndexValues($properties, $results); |
|
| 100 | + $fkObjects=$this->findForeignObjects($fields, $indexValues); |
|
| 101 | + $this->populateResult($results, $properties, $fkObjects, $fields); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function getRelationForeignKeys() |
| 109 | 109 | { |
| 110 | - $fkObject = $this->getContext()->getForeignRecordFinder(); |
|
| 110 | + $fkObject=$this->getContext()->getForeignRecordFinder(); |
|
| 111 | 111 | return $this->findForeignKeys($fkObject, $this->getSourceRecord()); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function setObjectProperty($source, $properties, &$collections) |
| 120 | 120 | { |
| 121 | - $hash = $this->getObjectHash($source, $properties); |
|
| 122 | - $prop = $this->getContext()->getProperty(); |
|
| 121 | + $hash=$this->getObjectHash($source, $properties); |
|
| 122 | + $prop=$this->getContext()->getProperty(); |
|
| 123 | 123 | if(isset($collections[$hash]) && count($collections[$hash]) > 0) |
| 124 | 124 | { |
| 125 | 125 | if(count($collections[$hash]) > 1) |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function updateAssociatedRecords() |
| 136 | 136 | { |
| 137 | - $fkObject = $this->getContext()->getPropertyValue(); |
|
| 138 | - $source = $this->getSourceRecord(); |
|
| 139 | - $fkeys = $this->findForeignKeys($fkObject, $source); |
|
| 137 | + $fkObject=$this->getContext()->getPropertyValue(); |
|
| 138 | + $source=$this->getSourceRecord(); |
|
| 139 | + $fkeys=$this->findForeignKeys($fkObject, $source); |
|
| 140 | 140 | foreach($fkeys as $fKey => $srcKey) |
| 141 | 141 | $fkObject->setColumnValue($fKey, $source->getColumnValue($srcKey)); |
| 142 | 142 | return $fkObject->save(); |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | protected function getTableInfo() |
| 42 | 42 | { |
| 43 | - $finder = $this->getRecordFinder(); |
|
| 44 | - $gateway = $finder->getRecordManager()->getRecordGateWay(); |
|
| 43 | + $finder=$this->getRecordFinder(); |
|
| 44 | + $gateway=$finder->getRecordManager()->getRecordGateWay(); |
|
| 45 | 45 | return $gateway->getRecordTableInfo($finder); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | protected function getRecordPropertyValues($record) |
| 53 | 53 | { |
| 54 | - $data = array(); |
|
| 54 | + $data=array(); |
|
| 55 | 55 | foreach($this->getTableInfo()->getColumns() as $name=>$column) |
| 56 | - $data[] = $record->getColumnValue($name); |
|
| 56 | + $data[]=$record->getColumnValue($name); |
|
| 57 | 57 | return $data; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | foreach($this->getTableInfo()->getColumns() as $name=>$column) |
| 68 | 68 | { |
| 69 | 69 | if($column->getIsPrimaryKey()) |
| 70 | - $data[] = $record->getColumnValue($name); |
|
| 70 | + $data[]=$record->getColumnValue($name); |
|
| 71 | 71 | } |
| 72 | 72 | return $data; |
| 73 | 73 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | protected function copyFrom(TScaffoldBase $obj) |
| 98 | 98 | { |
| 99 | - $this->_record = $obj->_record; |
|
| 99 | + $this->_record=$obj->_record; |
|
| 100 | 100 | $this->setRecordClass($obj->getRecordClass()); |
| 101 | 101 | $this->setEnableDefaultStyle($obj->getEnableDefaultStyle()); |
| 102 | 102 | } |
@@ -128,13 +128,13 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | else |
| 130 | 130 | { |
| 131 | - $class = $this->getRecordClass(); |
|
| 131 | + $class=$this->getRecordClass(); |
|
| 132 | 132 | if($class!==null) |
| 133 | 133 | $this->_record=Prado::createComponent($class); |
| 134 | 134 | else |
| 135 | 135 | { |
| 136 | 136 | throw new TConfigurationException('scaffold_invalid_record_class', |
| 137 | - $this->getRecordClass(),$this->getID()); |
|
| 137 | + $this->getRecordClass(), $this->getID()); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | parent::onPreRender($param); |
| 198 | 198 | if($this->getEnableDefaultStyle()) |
| 199 | 199 | { |
| 200 | - $url = $this->publishAsset($this->getDefaultStyle().'.css'); |
|
| 201 | - $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url); |
|
| 200 | + $url=$this->publishAsset($this->getDefaultStyle().'.css'); |
|
| 201 | + $this->getPage()->getClientScript()->registerStyleSheetFile($url, $url); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -91,6 +91,7 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * Name of the Active Record class to be viewed or scaffolded. |
| 93 | 93 | * @param string Active Record class name. |
| 94 | + * @param string $value |
|
| 94 | 95 | */ |
| 95 | 96 | public function setRecordClass($value) |
| 96 | 97 | { |
@@ -190,6 +191,7 @@ discard block |
||
| 190 | 191 | |
| 191 | 192 | /** |
| 192 | 193 | * @param boolean enable default stylesheet, default is true. |
| 194 | + * @param boolean $value |
|
| 193 | 195 | */ |
| 194 | 196 | public function setEnableDefaultStyle($value) |
| 195 | 197 | { |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @link https://github.com/pradosoft/prado |
| 7 | 7 | * @copyright Copyright © 2005-2016 The PRADO Group |
| 8 | 8 | * @license https://github.com/pradosoft/prado/blob/master/LICENSE |
| 9 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
| 9 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace Prado\Data\ActiveRecord\Scaffold; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * file explicitly. |
| 33 | 33 | * |
| 34 | 34 | * @author Wei Zhuo <weizho[at]gmail[dot]com> |
| 35 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
| 35 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
| 36 | 36 | * @since 3.1 |
| 37 | 37 | */ |
| 38 | 38 | abstract class TScaffoldBase extends TTemplateControl |
@@ -132,8 +132,7 @@ |
||
| 132 | 132 | if($this->_record===null) |
| 133 | 133 | throw new TConfigurationException('scaffold_invalid_record_pk', |
| 134 | 134 | $this->getRecordClass(), $pk); |
| 135 | - } |
|
| 136 | - else |
|
| 135 | + } else |
|
| 137 | 136 | { |
| 138 | 137 | $class = $this->getRecordClass(); |
| 139 | 138 | if($class!==null) |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected function initializeSort() |
| 55 | 55 | { |
| 56 | - $table = $this->getTableInfo(); |
|
| 57 | - $sorts = array('Sort By', str_repeat('-',15)); |
|
| 58 | - $headers = array(); |
|
| 56 | + $table=$this->getTableInfo(); |
|
| 57 | + $sorts=array('Sort By', str_repeat('-', 15)); |
|
| 58 | + $headers=array(); |
|
| 59 | 59 | foreach($table->getColumns() as $name=>$colum) |
| 60 | 60 | { |
| 61 | - $fname = ucwords(str_replace('_', ' ', $name)); |
|
| 62 | - $sorts[$name.' ASC'] = $fname .' Ascending'; |
|
| 63 | - $sorts[$name.' DESC'] = $fname .' Descending'; |
|
| 64 | - $headers[] = $fname ; |
|
| 61 | + $fname=ucwords(str_replace('_', ' ', $name)); |
|
| 62 | + $sorts[$name.' ASC']=$fname.' Ascending'; |
|
| 63 | + $sorts[$name.' DESC']=$fname.' Descending'; |
|
| 64 | + $headers[]=$fname; |
|
| 65 | 65 | } |
| 66 | 66 | $this->_sort->setDataSource($sorts); |
| 67 | 67 | $this->_sort->dataBind(); |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | protected function loadRecordData() |
| 90 | 90 | { |
| 91 | - $search = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); |
|
| 91 | + $search=new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); |
|
| 92 | 92 | $this->_list->setVirtualItemCount($this->getRecordFinder()->count($search)); |
| 93 | - $finder = $this->getRecordFinder(); |
|
| 94 | - $criteria = $this->getRecordCriteria(); |
|
| 93 | + $finder=$this->getRecordFinder(); |
|
| 94 | + $criteria=$this->getRecordCriteria(); |
|
| 95 | 95 | $this->_list->setDataSource($finder->findAll($criteria)); |
| 96 | 96 | $this->_list->dataBind(); |
| 97 | 97 | } |
@@ -101,21 +101,21 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | protected function getRecordCriteria() |
| 103 | 103 | { |
| 104 | - $total = $this->_list->getVirtualItemCount(); |
|
| 105 | - $limit = $this->_list->getPageSize(); |
|
| 106 | - $offset = $this->_list->getCurrentPageIndex()*$limit; |
|
| 104 | + $total=$this->_list->getVirtualItemCount(); |
|
| 105 | + $limit=$this->_list->getPageSize(); |
|
| 106 | + $offset=$this->_list->getCurrentPageIndex() * $limit; |
|
| 107 | 107 | if($offset + $limit > $total) |
| 108 | - $limit = $total - $offset; |
|
| 109 | - $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); |
|
| 108 | + $limit=$total - $offset; |
|
| 109 | + $criteria=new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); |
|
| 110 | 110 | if($limit > 0) |
| 111 | 111 | { |
| 112 | 112 | $criteria->setLimit($limit); |
| 113 | 113 | if($offset <= $total) |
| 114 | 114 | $criteria->setOffset($offset); |
| 115 | 115 | } |
| 116 | - $order = explode(' ',$this->_sort->getSelectedValue(), 2); |
|
| 117 | - if(is_array($order) && count($order) === 2) |
|
| 118 | - $criteria->OrdersBy[$order[0]] = $order[1]; |
|
| 116 | + $order=explode(' ', $this->_sort->getSelectedValue(), 2); |
|
| 117 | + if(is_array($order) && count($order)===2) |
|
| 118 | + $criteria->OrdersBy[$order[0]]=$order[1]; |
|
| 119 | 119 | return $criteria; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function setSearchParameters($value) |
| 142 | 142 | { |
| 143 | - $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array()); |
|
| 143 | + $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value), array()); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | { |
| 177 | 177 | if($param instanceof TRepeaterCommandEventParameter) |
| 178 | 178 | { |
| 179 | - $pk = $param->getItem()->getCustomData(); |
|
| 179 | + $pk=$param->getItem()->getCustomData(); |
|
| 180 | 180 | $ctrl->setRecordPk($pk); |
| 181 | 181 | $ctrl->initializeEditForm(); |
| 182 | 182 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | { |
| 191 | 191 | if($param instanceof TRepeaterCommandEventParameter) |
| 192 | 192 | { |
| 193 | - $pk = $param->getItem()->getCustomData(); |
|
| 193 | + $pk=$param->getItem()->getCustomData(); |
|
| 194 | 194 | $this->getRecordFinder()->deleteByPk($pk); |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | protected function listItemCreated($sender, $param) |
| 202 | 202 | { |
| 203 | - $item = $param->getItem(); |
|
| 203 | + $item=$param->getItem(); |
|
| 204 | 204 | if($item instanceof IItemDataRenderer) |
| 205 | 205 | { |
| 206 | - $type = $item->getItemType(); |
|
| 206 | + $type=$item->getItemType(); |
|
| 207 | 207 | if($type==TListItemType::Item || $type==TListItemType::AlternatingItem) |
| 208 | 208 | $this->populateField($sender, $param); |
| 209 | 209 | } |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | protected function populateField($sender, $param) |
| 217 | 217 | { |
| 218 | - $item = $param->getItem(); |
|
| 219 | - if(($data = $item->getData()) !== null) |
|
| 218 | + $item=$param->getItem(); |
|
| 219 | + if(($data=$item->getData())!==null) |
|
| 220 | 220 | { |
| 221 | 221 | $item->setCustomData($this->getRecordPkValues($data)); |
| 222 | - if(($prop = $item->findControl('_properties'))!==null) |
|
| 222 | + if(($prop=$item->findControl('_properties'))!==null) |
|
| 223 | 223 | { |
| 224 | 224 | $item->_properties->setDataSource($this->getRecordPropertyValues($data)); |
| 225 | 225 | $item->_properties->dataBind(); |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | { |
| 295 | 295 | if(($id=$this->getEditViewID())!==null) |
| 296 | 296 | { |
| 297 | - $ctrl = $this->getParent()->findControl($id); |
|
| 297 | + $ctrl=$this->getParent()->findControl($id); |
|
| 298 | 298 | if($ctrl===null) |
| 299 | 299 | throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id); |
| 300 | 300 | return $ctrl; |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | * Parameters property of TActiveRecordCriteria. |
| 53 | 53 | * |
| 54 | 54 | * @author Wei Zhuo <weizho[at]gmail[dot]com> |
| 55 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
| 55 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
| 56 | 56 | * @since 3.1 |
| 57 | 57 | */ |
| 58 | 58 | class TScaffoldListView extends TScaffoldBase |
@@ -130,6 +130,7 @@ |
||
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * @param string search condition, the SQL string after the WHERE clause. |
| 133 | + * @param string $value |
|
| 133 | 134 | */ |
| 134 | 135 | public function setSearchCondition($value) |
| 135 | 136 | { |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | * Handle the "edit" and "new" commands by displaying the edit view. |
| 91 | 91 | * Default command shows the list view. |
| 92 | 92 | */ |
| 93 | - public function bubbleEvent($sender,$param) |
|
| 93 | + public function bubbleEvent($sender, $param) |
|
| 94 | 94 | { |
| 95 | 95 | switch(strtolower($param->getCommandName())) |
| 96 | 96 | { |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * the Active Record class to be displayed/edited/added. |
| 35 | 35 | * |
| 36 | 36 | * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
| 37 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
| 37 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
| 38 | 38 | * @since 3.0 |
| 39 | 39 | */ |
| 40 | 40 | class TScaffoldView extends TScaffoldBase |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | case 'char': case 'varchar': |
| 30 | 30 | return $this->createMultiLineControl($container, $column, $record); |
| 31 | 31 | default: |
| 32 | - return $this->createDefaultControl($container,$column, $record); |
|
| 32 | + return $this->createDefaultControl($container, $column, $record); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | case 'timestamp': |
| 45 | 45 | return $this->getDateTimeValue($container, $column, $record); |
| 46 | 46 | default: |
| 47 | - return $this->getDefaultControlValue($container,$column, $record); |
|
| 47 | + return $this->getDefaultControlValue($container, $column, $record); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | } |