Changeset 334

Show
Ignore:
Timestamp:
04/19/10 04:22:07 (22 months ago)
Author:
john
Message:

added unset() and isset() to ActiveRecord?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/active_record.php

    r333 r334  
    108108     *  @see __get() 
    109109     *  @see __set() 
     110     *  @see __unset() 
     111     *  @see __isset()   
    110112     */  
    111113    private $attributes = array(); 
     
    578580        } 
    579581 
    580         # initialize the internal attributes array to all nulls 
    581         $this->reset_attributes(); 
    582  
    583582        # If $attributes array is passed in update the class with its contents 
    584583        if(!is_null($attributes)) { 
     
    612611            return $this->attributes[$key]; 
    613612        } 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"); 
    615614            switch($association_type) { 
    616615                case "has_many": 
     
    675674        //echo "setting: $key = $value<br>"; 
    676675        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; 
    684679                } 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            }                
    691688            $this->attributes[$key] = $value; 
    692689            return; 
     
    712709        //  Assignment to something else, do it 
    713710        $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        } 
    714739    } 
    715740 
     
    28382863        } 
    28392864    } 
    2840  
    2841     /** 
    2842      *  Resets the attributes array to keys of the columns from the database 
    2843      *  and sets all the values to null 
    2844      * 
    2845      *  @uses $content_columns 
    2846      *  @uses $attributes 
    2847      */ 
    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     } 
    28572865 
    28582866    /**