Changeset 110 for trunk/trax/vendor/trax/active_record.php
- Timestamp:
- 01/10/06 09:43:07 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/active_record.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r106 r110 834 834 function check_datetime($field, $value) { 835 835 if($this->auto_timestamps) { 836 if(is_array($this-> table_info)) {837 foreach($this-> table_infoas $field_info) {836 if(is_array($this->content_columns)) { 837 foreach($this->content_columns as $field_info) { 838 838 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)) { 840 840 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)) { 842 842 return date("Y-m-d H:i:s"); 843 } 843 844 } 844 845 } … … 851 852 # from the passed array $attributes. 852 853 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 } 855 880 } 856 881 $this->set_habtm_attributes($attributes); … … 858 883 859 884 # If $this->set_content_columns() was previously called, which will mean that 860 # $ table_infowill be an array of containing the column info about the database885 # $content_columns will be an array of containing the column info about the database 861 886 # table this model is representing. This will return an array where the keys 862 887 # the column names and the values are the values from those columns. … … 883 908 $value = $this->check_datetime($key, $value); 884 909 # 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); 893 919 } 894 920 return $return;
