Show
Ignore:
Timestamp:
04/20/06 10:20:30 (6 years ago)
Author:
haas
Message:

DateHelper? docs and tests

Files:
1 modified

Legend:

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

    r197 r198  
    4949 *  a table named "order_details" would be associated with a subclass 
    5050 *  of ActiveRecord named "OrderDetail", and a table named "people" 
    51  *  would be associated with subclass "Person".</p> 
     51 *  would be associated with subclass "Person".  See the tutorial 
     52 *  {@tutorial PHPonTrax/naming.pkg}</p> 
    5253 * 
    5354 *  <p>For a discussion of the ActiveRecord design pattern, see 
     
    764765     
    765766    /** 
    766      *  checks if a column exists or not in the table 
     767     *  Check whether a column exists in the associated table 
     768     * 
     769     *  When called, {@link $content_columns} lists the columns in 
     770     *  the table described by this object. 
     771     *  @param string Name of the column 
     772     *  @return boolean true=>the column exists; false=>it doesn't 
     773     *  @uses content_columns 
    767774     */ 
    768775    function column_attribute_exists($attribute) { 
     
    778785 
    779786    /** 
    780      *  @todo Document this API 
    781      *  Returns PEAR result set of one record with only the passed in column in the result set. 
    782      * 
     787     *  Get contents of one column of record selected by id and table 
     788     * 
     789     *  When called, {@link $id} identifies one record in the table 
     790     *  identified by {@link $table}.  Fetch from the database the 
     791     *  contents of column $column of this record. 
     792     *  @param string Name of column to retrieve 
    783793     *  @uses $db 
     794     *  @uses column_attribute_exists() 
    784795     *  @throws {@link ActiveRecordError} 
    785796     *  @uses is_error() 
     
    12071218     */ 
    12081219    function save($attributes = null, $dont_validate = false) { 
     1220        //error_log("ActiveRecord::save() \$attributes=" 
     1221        //          . var_export($attributes,true)); 
    12091222        if(!is_null($attributes)) { 
    12101223            $this->update_attributes($attributes); 
     
    12371250     */ 
    12381251    private function add_record_or_update_record() {  
     1252        //error_log('add_record_or_update_record()'); 
    12391253        $this->before_save(); 
    12401254        if($this->new_record) { 
     
    13191333     */ 
    13201334    private function update_record() { 
     1335        //error_log('update_record()'); 
    13211336        $updates = $this->get_updates_sql(); 
    13221337        $conditions = $this->get_primary_key_conditions(); 
    13231338        $sql = "UPDATE $this->table_name SET $updates WHERE $conditions"; 
    1324         //echo "update_record: SQL: $sql<br>"; 
     1339        //error_log("update_record: SQL: $sql<br>"); 
    13251340        $result = $this->query($sql); 
    13261341        if($this->is_error($result)) { 
     
    16551670    /** 
    16561671     *  Update object attributes from list in argument 
     1672     * 
     1673     *  The elements of $attributes are parsed and assigned to 
     1674     *  attributes of the ActiveRecord object.  Date/time fields are 
     1675     *  treated according to the 
     1676     *  {@tutorial PHPonTrax/naming.pkg#naming.naming_forms}. 
    16571677     *  @param string[] $attributes List of name => value pairs giving 
    16581678     *    name and value of attributes to set. 
     
    16611681     */ 
    16621682    function update_attributes($attributes) { 
     1683        //error_log('update_attributes()'); 
     1684 
     1685        //  Test each attribute to be updated 
     1686        //  and process according to its type 
    16631687        foreach($attributes as $field => $value) { 
    16641688            # datetime / date parts check 
    16651689            if(preg_match('/^\w+\(.*i\)$/i', $field)) { 
     1690 
     1691                //  The name of this attribute ends in "(?i)" 
     1692                //  indicating that it's part of a date or time 
     1693 
     1694                //  Accumulate all the pieces of a date and time in 
     1695                //  array $datetime_key.  The keys in the array are 
     1696                //  the names of date/time attributes with the final 
     1697                //  "(?i)" stripped off. 
    16661698                $datetime_key = substr($field, 0, strpos($field, "(")); 
    1667                 if($datetime_key != $old_datetime_key) { 
     1699                if( !isset($old_datetime_key) 
     1700                    || ($datetime_key != $old_datetime_key)) { 
     1701 
     1702                    //  This value of $datetime_key hasn't been seen 
     1703                    //  before, so remember it. 
    16681704                    $old_datetime_key = $datetime_key;                      
     1705 
     1706                    //  $datetime_value accumulates the pieces of the 
     1707                    //  date/time attribute $datetime_key 
    16691708                    $datetime_value = "";    
    16701709                }  
     1710 
     1711                //  Concatentate pieces of the attribute's value 
     1712                //  FIXME: this only works if the array elements 
     1713                //  are sorted by key.  Is this guaranteed? 
    16711714                if(strstr($field, "2i") || strstr($field, "3i")) { 
    16721715                    $datetime_value .= "-".$value;     
     
    16941737                } 
    16951738            } else { 
     1739 
     1740                //  Just a simple attribute, copy it 
    16961741                $this->$field = $value; 
    16971742            } 
    16981743        } 
     1744 
     1745        //  If any date/time fields were found, assign the 
     1746        //  accumulated values to corresponding attributes 
    16991747        if(isset($datetime_fields) 
    17001748           && is_array($datetime_fields)) { 
    17011749            foreach($datetime_fields as $field => $value) { 
     1750                //error_log("$field = $value"); 
    17021751                $this->$field = $value;     
    17031752            }