Show
Ignore:
Timestamp:
01/10/06 09:43:07 (6 years ago)
Author:
john
Message:

finished the scaffolding stuff in AR and its helper

Files:
1 modified

Legend:

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

    r106 r110  
    834834    function check_datetime($field, $value) { 
    835835        if($this->auto_timestamps) { 
    836             if(is_array($this->table_info)) { 
    837                 foreach($this->table_info as $field_info) { 
     836            if(is_array($this->content_columns)) { 
     837                foreach($this->content_columns as $field_info) { 
    838838                    if(($field_info['name'] == $field) && ($field_info['type'] == "datetime")) { 
    839                         if($this->new_record && in_array($field, $this->auto_create_timestamps)) 
     839                        if($this->new_record && in_array($field, $this->auto_create_timestamps)) { 
    840840                            return date("Y-m-d H:i:s"); 
    841                         elseif(!$this->new_record && in_array($field, $this->auto_update_timestamps)) 
     841                        } elseif(!$this->new_record && in_array($field, $this->auto_update_timestamps)) { 
    842842                            return date("Y-m-d H:i:s"); 
     843                        } 
    843844                    } 
    844845                } 
     
    851852    # from the passed array $attributes. 
    852853    function update_attributes($attributes) { 
    853         foreach($attributes as $field => $val) { 
    854             $this->$field = $val; 
     854        foreach($attributes as $field => $value) { 
     855            # datetime parts check 
     856            if(preg_match('/^\w+\(.*i\)$/i', $field)) { 
     857                $datetime_key = substr($field, 0, strpos($field, "(")); 
     858                if($datetime_key != $old_datetime_key) { 
     859                    $old_datetime_key = $datetime_key;                      
     860                    $datetime_value = "";    
     861                }  
     862                if(strstr($field, "2i") || strstr($field, "3i")) { 
     863                    $datetime_value .= "-".$value;     
     864                } elseif(strstr($field, "4i")) { 
     865                    $datetime_value .= " ".$value;         
     866                } elseif(strstr($field, "5i")) { 
     867                    $datetime_value .= ":".$value;         
     868                } else { 
     869                    $datetime_value .= $value;     
     870                }   
     871                $datetime_fields[$old_datetime_key] = $datetime_value;                  
     872            } else { 
     873                $this->$field = $value; 
     874            } 
     875        } 
     876        if(is_array($datetime_fields)) { 
     877            foreach($datetime_fields as $field => $value) { 
     878                $this->$field = $value;     
     879            }     
    855880        } 
    856881        $this->set_habtm_attributes($attributes); 
     
    858883 
    859884    # If $this->set_content_columns() was previously called, which will mean that 
    860     # $table_info will be an array of containing the column info about the database 
     885    # $content_columns will be an array of containing the column info about the database 
    861886    # table this model is representing.  This will return an array where the keys 
    862887    # the column names and the values are the values from those columns.   
     
    883908            $value = $this->check_datetime($key, $value); 
    884909            # If the value isn't a function or null quote it. 
    885             if (!(preg_match('/^\w+\(.*\)$/U', $value)) && !(strcasecmp($value, 'NULL') == 0)) { 
    886                 $value = str_replace("\\\"","\"",$value); 
    887                 $value = str_replace("\'","'",$value); 
    888                 $value = str_replace("\\\\","\\",$value); 
    889                 $return[$key] = "'" . addslashes($value) . "'"; 
    890             } else { 
    891                 $return[$key] = $value; 
    892             } 
     910            #if(!(preg_match('/^\w+\(.*\)$/U', $value)) && !(strcasecmp($value, 'NULL') == 0)) { 
     911            #    $value = str_replace("\\\"","\"",$value); 
     912            #    $value = str_replace("\'","'",$value); 
     913            #    $value = str_replace("\\\\","\\",$value); 
     914            #    $return[$key] = "'" . addslashes($value) . "'"; 
     915            #} else { 
     916            #    $return[$key] = $value; 
     917            #} 
     918            $return[$key] = self::$db->quoteSmart($value); 
    893919        } 
    894920        return $return;