Index: trunk/phase3/includes/DBDataObject.php |
— | — | @@ -94,6 +94,7 @@ |
95 | 95 | * |
96 | 96 | * @since 1.20 |
97 | 97 | * |
| 98 | + * @param DBTable $table |
98 | 99 | * @param array|null $fields |
99 | 100 | * @param boolean $loadDefaults |
100 | 101 | */ |
— | — | @@ -529,20 +530,6 @@ |
530 | 531 | } |
531 | 532 | |
532 | 533 | /** |
533 | | - * Get a new instance of the class from an array. |
534 | | - * |
535 | | - * @since 1.20 |
536 | | - * |
537 | | - * @param array $data |
538 | | - * @param boolean $loadDefaults |
539 | | - * |
540 | | - * @return DBDataObject |
541 | | - */ |
542 | | - public function newFromArray( array $data, $loadDefaults = false ) { |
543 | | - return new self( $data, $loadDefaults ); |
544 | | - } |
545 | | - |
546 | | - /** |
547 | 534 | * Get the database type used for read operations. |
548 | 535 | * |
549 | 536 | * @since 1.20 |
— | — | @@ -706,44 +693,8 @@ |
707 | 694 | |
708 | 695 | return false; |
709 | 696 | } |
710 | | - |
711 | | - protected function getDBTable() { |
712 | | - return $this->table->getDBTable(); |
713 | | - } |
714 | | - |
| 697 | + |
715 | 698 | /** |
716 | | - * Get an array with fields from a database result, |
717 | | - * that can be fed directly to the constructor or |
718 | | - * to setFields. |
719 | | - * |
720 | | - * @since 1.20 |
721 | | - * |
722 | | - * @param object $result |
723 | | - * |
724 | | - * @return array |
725 | | - */ |
726 | | - public function getFieldsFromDBResult( $result ) { |
727 | | - $result = (array)$result; |
728 | | - return array_combine( |
729 | | - $this->unprefixFieldNames( array_keys( $result ) ), |
730 | | - array_values( $result ) |
731 | | - ); |
732 | | - } |
733 | | - |
734 | | - /** |
735 | | - * Get a new instance of the class from a database result. |
736 | | - * |
737 | | - * @since 1.20 |
738 | | - * |
739 | | - * @param stdClass $result |
740 | | - * |
741 | | - * @return DBDataObject |
742 | | - */ |
743 | | - public function newFromDBResult( stdClass $result ) { |
744 | | - return $this->newFromArray( $this->getFieldsFromDBResult( $result ) ); |
745 | | - } |
746 | | - |
747 | | - /** |
748 | 699 | * Returns the table this DBDataObject is a row in. |
749 | 700 | * |
750 | 701 | * @since 1.20 |
Index: trunk/phase3/includes/DBTable.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | * |
31 | 31 | * @return string |
32 | 32 | */ |
33 | | - protected abstract function getDataObjectClass(); |
| 33 | + public abstract function getDataObjectClass(); |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Gets the db field prefix. |
— | — | @@ -482,7 +482,7 @@ |
483 | 483 | * @return array |
484 | 484 | */ |
485 | 485 | public function unprefixFieldNames( array $fieldNames ) { |
486 | | - return array_map( '$this->unprefixFieldName', $fieldNames ); |
| 486 | + return array_map( array( $this, 'unprefixFieldName' ), $fieldNames ); |
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
— | — | @@ -518,5 +518,63 @@ |
519 | 519 | |
520 | 520 | return $instance; |
521 | 521 | } |
| 522 | + |
| 523 | + /** |
| 524 | + * Get an array with fields from a database result, |
| 525 | + * that can be fed directly to the constructor or |
| 526 | + * to setFields. |
| 527 | + * |
| 528 | + * @since 1.20 |
| 529 | + * |
| 530 | + * @param stdClass $result |
| 531 | + * |
| 532 | + * @return array |
| 533 | + */ |
| 534 | + public function getFieldsFromDBResult( stdClass $result ) { |
| 535 | + $result = (array)$result; |
| 536 | + return array_combine( |
| 537 | + $this->unprefixFieldNames( array_keys( $result ) ), |
| 538 | + array_values( $result ) |
| 539 | + ); |
| 540 | + } |
| 541 | + |
| 542 | + /** |
| 543 | + * Get a new instance of the class from a database result. |
| 544 | + * |
| 545 | + * @since 1.20 |
| 546 | + * |
| 547 | + * @param stdClass $result |
| 548 | + * |
| 549 | + * @return DBDataObject |
| 550 | + */ |
| 551 | + public function newFromDBResult( stdClass $result ) { |
| 552 | + return $this->newFromArray( $this->getFieldsFromDBResult( $result ) ); |
| 553 | + } |
| 554 | + |
| 555 | + /** |
| 556 | + * Get a new instance of the class from an array. |
| 557 | + * |
| 558 | + * @since 1.20 |
| 559 | + * |
| 560 | + * @param array $data |
| 561 | + * @param boolean $loadDefaults |
| 562 | + * |
| 563 | + * @return DBDataObject |
| 564 | + */ |
| 565 | + public function newFromArray( array $data, $loadDefaults = false ) { |
| 566 | + $class = $this->getDataObjectClass(); |
| 567 | + return new $class( $this, $data, $loadDefaults ); |
| 568 | + } |
| 569 | + |
| 570 | + /** |
| 571 | + * Return the names of the fields. |
| 572 | + * |
| 573 | + * @since 1.20 |
| 574 | + * |
| 575 | + * @return array |
| 576 | + */ |
| 577 | + public function getFieldNames() { |
| 578 | + return array_keys( $this->getFieldTypes() ); |
| 579 | + } |
522 | 580 | |
523 | 581 | } |