Changeset 198 for trunk/trax/vendor/trax/active_record.php
- Timestamp:
- 04/20/06 10:20:30 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/active_record.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r197 r198 49 49 * a table named "order_details" would be associated with a subclass 50 50 * 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> 52 53 * 53 54 * <p>For a discussion of the ActiveRecord design pattern, see … … 764 765 765 766 /** 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 767 774 */ 768 775 function column_attribute_exists($attribute) { … … 778 785 779 786 /** 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 783 793 * @uses $db 794 * @uses column_attribute_exists() 784 795 * @throws {@link ActiveRecordError} 785 796 * @uses is_error() … … 1207 1218 */ 1208 1219 function save($attributes = null, $dont_validate = false) { 1220 //error_log("ActiveRecord::save() \$attributes=" 1221 // . var_export($attributes,true)); 1209 1222 if(!is_null($attributes)) { 1210 1223 $this->update_attributes($attributes); … … 1237 1250 */ 1238 1251 private function add_record_or_update_record() { 1252 //error_log('add_record_or_update_record()'); 1239 1253 $this->before_save(); 1240 1254 if($this->new_record) { … … 1319 1333 */ 1320 1334 private function update_record() { 1335 //error_log('update_record()'); 1321 1336 $updates = $this->get_updates_sql(); 1322 1337 $conditions = $this->get_primary_key_conditions(); 1323 1338 $sql = "UPDATE $this->table_name SET $updates WHERE $conditions"; 1324 //e cho "update_record: SQL: $sql<br>";1339 //error_log("update_record: SQL: $sql<br>"); 1325 1340 $result = $this->query($sql); 1326 1341 if($this->is_error($result)) { … … 1655 1670 /** 1656 1671 * 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}. 1657 1677 * @param string[] $attributes List of name => value pairs giving 1658 1678 * name and value of attributes to set. … … 1661 1681 */ 1662 1682 function update_attributes($attributes) { 1683 //error_log('update_attributes()'); 1684 1685 // Test each attribute to be updated 1686 // and process according to its type 1663 1687 foreach($attributes as $field => $value) { 1664 1688 # datetime / date parts check 1665 1689 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. 1666 1698 $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. 1668 1704 $old_datetime_key = $datetime_key; 1705 1706 // $datetime_value accumulates the pieces of the 1707 // date/time attribute $datetime_key 1669 1708 $datetime_value = ""; 1670 1709 } 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? 1671 1714 if(strstr($field, "2i") || strstr($field, "3i")) { 1672 1715 $datetime_value .= "-".$value; … … 1694 1737 } 1695 1738 } else { 1739 1740 // Just a simple attribute, copy it 1696 1741 $this->$field = $value; 1697 1742 } 1698 1743 } 1744 1745 // If any date/time fields were found, assign the 1746 // accumulated values to corresponding attributes 1699 1747 if(isset($datetime_fields) 1700 1748 && is_array($datetime_fields)) { 1701 1749 foreach($datetime_fields as $field => $value) { 1750 //error_log("$field = $value"); 1702 1751 $this->$field = $value; 1703 1752 }
