Show
Ignore:
Timestamp:
03/01/06 12:50:12 (6 years ago)
Author:
john
Message:

added to AR so it can preserve null dates

Files:
1 modified

Legend:

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

    r155 r158  
    7070 
    7171    /** 
    72      *  <b>FIXME: dead code?  Never referenced in ActiveRecord</b><br> 
    73      *  <b>FIXME: static should be after protected</b><br> 
    74      *  <b>FIXME: static variables $rows_per_page, $page, $offset are 
    75      *  not declared.  Declaring them would provide a good place to 
    76      *  document them.  On the other hand, if the intent is to give 
    77      *  the user the ability to page through a result set, these 
    78      *  variables need to go in $_SESSION.</b> 
    79      */ 
    80     static protected $inflector = null; # object to do class inflection 
    81  
    82     /** 
    8372     *  Description of a row in the associated table in the database 
    8473     * 
     
    212201 
    213202    /** 
     203     *  Date format for use with auto timestamping 
     204     * 
     205     *  The format for this should be compatiable with the php date() function. 
     206     *  http://www.php.net/date 
     207     *  @var string  
     208     */ 
     209     protected $date_format = "Y-m-d"; 
     210 
     211    /** 
     212     *  Time format for use with auto timestamping 
     213     * 
     214     *  The format for this should be compatiable with the php date() function. 
     215     *  http://www.php.net/date 
     216     *  @var string  
     217     */     
     218     protected $time_format = "H:i:s"; 
     219        
     220    /** 
     221     *  Whether to keep date/datetime fields NULL if not set 
     222     * 
     223     *  true => If date field is not set it try to preserve NULL 
     224     *  false => Don't try to preserve NULL if field is already NULL 
     225     *  @var boolean 
     226     */        
     227     protected $preserve_null_dates = true; 
     228 
     229    /** 
    214230     *  SQL aggregate functions that may be applied to the associated 
    215231     *  table. 
     
    220236     */ 
    221237    protected $aggregrations = array("count","sum","avg","max","min"); 
    222  
     238      
    223239    /** 
    224240     *  Primary key of the associated table 
     
    15541570            if(is_array($this->content_columns)) { 
    15551571                foreach($this->content_columns as $field_info) { 
    1556                     if(($field_info['name'] == $field) && ($field_info['type'] == "datetime")) { 
    1557                         if($this->new_record && in_array($field, $this->auto_create_timestamps)) { 
    1558                             return date("Y-m-d H:i:s"); 
    1559                         } elseif(!$this->new_record && in_array($field, $this->auto_update_timestamps)) { 
    1560                             return date("Y-m-d H:i:s"); 
     1572                    if(($field_info['name'] == $field) && stristr($field_info['type'], "date")) { 
     1573                        $format = ($field_info['type'] == "date") ? $this->date_format : "{$this->date_format} {$this->time_format}"; 
     1574                        if($this->new_record) { 
     1575                            if(in_array($field, $this->auto_create_timestamps)) { 
     1576                                return date($format); 
     1577                            } elseif($this->preserve_null_dates && is_null($value) && !stristr($field_info['flags'], "not_null")) { 
     1578                                return 'NULL';     
     1579                            } 
     1580                        } elseif(!$this->new_record) { 
     1581                            if(in_array($field, $this->auto_update_timestamps)) { 
     1582                                return date($format); 
     1583                            } elseif($this->preserve_null_dates && is_null($value) && !stristr($field_info['flags'], "not_null")) { 
     1584                                return 'NULL';     
     1585                            } 
    15611586                        } 
    1562                     } 
     1587                    }   
    15631588                } 
    15641589            }