Changeset 334
- Timestamp:
- 04/19/10 04:22:07 (22 months ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/active_record.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r333 r334 108 108 * @see __get() 109 109 * @see __set() 110 * @see __unset() 111 * @see __isset() 110 112 */ 111 113 private $attributes = array(); … … 578 580 } 579 581 580 # initialize the internal attributes array to all nulls581 $this->reset_attributes();582 583 582 # If $attributes array is passed in update the class with its contents 584 583 if(!is_null($attributes)) { … … 612 611 return $this->attributes[$key]; 613 612 } elseif($association_type = $this->get_association_type($key)) { 614 error_log("get key:$key association_type:$association_type");613 #error_log("get key:$key association_type:$association_type"); 615 614 switch($association_type) { 616 615 case "has_many": … … 675 674 //echo "setting: $key = $value<br>"; 676 675 if(array_key_exists($key, (array)$this->content_columns)) { 677 if(array_key_exists($key, $this->attributes)) { 678 if(array_key_exists($key, $this->changed_attributes)) { 679 if($this->changed_attributes[$key]['original'] != $value) { 680 $this->changed_attributes[$key]['modified'] = $value; 681 } else { 682 unset($this->changed_attributes[$key]); 683 } 676 if(array_key_exists($key, $this->changed_attributes)) { 677 if($this->changed_attributes[$key]['original'] != $value) { 678 $this->changed_attributes[$key]['modified'] = $value; 684 679 } else { 685 $this->changed_attributes[$key] = array( 686 'original' => $this->attributes[$key], 687 'modified' => $value 688 ); 689 } 690 } 680 unset($this->changed_attributes[$key]); 681 } 682 } else { 683 $this->changed_attributes[$key] = array( 684 'original' => $this->attributes[$key], 685 'modified' => $value 686 ); 687 } 691 688 $this->attributes[$key] = $value; 692 689 return; … … 712 709 // Assignment to something else, do it 713 710 $this->$key = $value; 711 } 712 713 /** 714 * Unsets an attribute or class member 715 * 716 * @uses $attributes 717 */ 718 function __unset($key) { 719 //echo "Unsetting '$key'\n"; 720 if(array_key_exists($key, $this->attributes)) { 721 unset($this->attributes[$key]); 722 } else { 723 unset($this->$key); 724 } 725 } 726 727 /** 728 * Checks if an attribute or class member is set 729 * 730 * @uses $attributes 731 */ 732 function __isset($key) { 733 //echo "Is '$key' set?\n"; 734 if(array_key_exists($key, $this->attributes)) { 735 return isset($this->attributes[$key]); 736 } else { 737 return isset($this->$key); 738 } 714 739 } 715 740 … … 2838 2863 } 2839 2864 } 2840 2841 /**2842 * Resets the attributes array to keys of the columns from the database2843 * and sets all the values to null2844 *2845 * @uses $content_columns2846 * @uses $attributes2847 */2848 function reset_attributes() {2849 if(is_array($this->content_columns)) {2850 $this->attributes = array();2851 #error_log("resetting attributes to null");2852 foreach($this->content_columns as $column_name => $column) {2853 $this->attributes[$column_name] = null;2854 }2855 }2856 }2857 2865 2858 2866 /**
