Changeset 247 for trunk/trax/vendor
- Timestamp:
- 08/23/06 00:21:16 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/active_record.php (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r241 r247 120 120 121 121 /** 122 * Table prefix 123 * 124 * Name to prefix to the $table_name. May be overridden. 125 * @var string 126 */ 127 public $table_prefix = null; 128 129 /** 122 130 * Database name override 123 131 * … … 154 162 */ 155 163 public $force_reconnect = false; # should we force a connection everytime 156 157 public $index_on = "id"; # find_all returns an array of objects each object index is off of this field 158 159 public $lock_optimistically = true; # page 222 Rails books 164 165 /** 166 * find_all() returns an array of objects, 167 * each object index is off of this field 168 * 169 * @var boolean 170 */ 171 public $index_on = "id"; 172 173 /** 174 * Not yet implemented (page 222 Rails books) 175 * 176 * @var boolean 177 */ 178 public $lock_optimistically = true; 160 179 161 180 # Table associations … … 271 290 * @var string[] 272 291 */ 273 protected $aggreg rations = array("count","sum","avg","max","min");274 292 protected $aggregations = array("count","sum","avg","max","min"); 293 275 294 /** 276 295 * Primary key of the associated table … … 471 490 * Override call() to dynamically call the database associations 472 491 * @todo Document this API 473 * @uses $aggreg rations474 * @uses aggreg rate_all()492 * @uses $aggregations 493 * @uses aggregate_all() 475 494 * @uses get_association_type() 476 495 * @uses $belongs_to … … 482 501 */ 483 502 function __call($method_name, $parameters) { 484 if(method_exists($this, $method_name)) {503 if(method_exists($this, $method_name)) { 485 504 # If the method exists, just call it 486 $result = call_user_func (array($this,$method_name), $parameters);505 $result = call_user_func_array(array($this, $method_name), $parameters); 487 506 } else { 488 507 # ... otherwise, check to see if the method call is one of our … … 490 509 # ... first check for method names that match any of our explicitly 491 510 # declared associations for this model ( e.g. $this->has_many = array("movies" => null) ) ... 511 if(is_array($parameters[0])) { 512 $parameters = $parameters[0]; 513 } 492 514 $association_type = $this->get_association_type($method_name); 493 515 switch($association_type) { … … 507 529 508 530 # check for the [count,sum,avg,etc...]_all magic functions 509 if(substr($method_name, -4) == "_all" && in_array(substr($method_name, 0, -4), $this->aggregrations)) {531 if(substr($method_name, -4) == "_all" && in_array(substr($method_name, 0, -4), $this->aggregations)) { 510 532 //echo "calling method: $method_name<br>"; 511 $result = $this->aggreg rate_all($method_name, $parameters);533 $result = $this->aggregate_all($method_name, $parameters); 512 534 } 513 535 # check for the find_all_by_* magic functions … … 527 549 } 528 550 return $result; 529 }530 531 /**532 * Returns a the name of the join table that would be used for the two533 * tables. The join table name is decided from the alphabetical order534 * of the two tables. e.g. "genres_movies" because "g" comes before "m"535 *536 * Parameters: $first_table, $second_table: the names of two database tables,537 * e.g. "movies" and "genres"538 * @todo Document this API539 */540 private function get_join_table_name($first_table, $second_table) {541 $tables = array();542 $tables["one"] = $first_table;543 $tables["many"] = $second_table;544 @asort($tables);545 return @implode("_", $tables);546 551 } 547 552 … … 561 566 */ 562 567 private function find_all_habtm($other_table_name, $parameters = null) { 563 568 $additional_conditions = null; 564 569 # Use any passed-in parameters 565 if (!is_null($parameters)) {570 if(!is_null($parameters)) { 566 571 if(@array_key_exists("conditions", $parameters)) { 567 572 $additional_conditions = " AND (".$parameters['conditions'].")"; … … 630 635 631 636 # Primary key value 632 $this_primary_key_value = is_numeric($this->$this_primary_key) ? $this->$this_primary_key : "'".$this->$this_primary_key."'"; 637 $this_primary_key_value = $this->attribute_is_string($this_primary_key) ? 638 "'".$this->$this_primary_key."'" : 639 $this->$this_primary_key; 633 640 634 641 # Set up the SQL segments … … 652 659 $additional_conditions = null; 653 660 # Use any passed-in parameters 654 if (is_array($parameters)) {661 if(is_array($parameters)) { 655 662 if(@array_key_exists("conditions", $parameters)) { 656 663 $additional_conditions = " AND (".$parameters['conditions'].")"; … … 705 712 706 713 $foreign_key_value = $this->$this_primary_key; 707 $conditions = ( is_numeric($foreign_key_value) ?708 "$foreign_key = {$foreign_key_value}" :709 "$foreign_key = '{$foreign_key_value}'") . $additional_conditions;714 $conditions = ($other_class_object->attribute_is_string($foreign_key) ? 715 "$foreign_key = '{$foreign_key_value}'" : 716 "$foreign_key = {$foreign_key_value}") . $additional_conditions; 710 717 } 711 718 … … 722 729 * @todo Document this API 723 730 */ 724 private function find_one_has_one($other_object_name, $parameters = null) { 725 731 private function find_one_has_one($other_object_name, $parameters = null) { 726 732 $additional_conditions = null; 727 733 # Use any passed-in parameters 728 if (is_array($parameters)) {734 if(is_array($parameters)) { 729 735 //echo "<pre>";print_r($parameters); 730 736 if(@array_key_exists("conditions", $parameters)) { … … 759 765 760 766 $foreign_key_value = $this->$this_primary_key; 761 $conditions = ( is_numeric($foreign_key_value) ?762 "{$foreign_key} = {$foreign_key_value}" :763 "{$foreign_key} = '{$foreign_key_value}'") . $additional_conditions;767 $conditions = ($other_class_object->attribute_is_string($foreign_key) ? 768 "{$foreign_key} = '{$foreign_key_value}'" : 769 "{$foreign_key} = {$foreign_key_value}") . $additional_conditions; 764 770 765 771 # Get the list of other_class_name objects 766 772 $result = $other_class_object->find_first($conditions, $order); 773 767 774 # There should only be one result, an object, if so return it 768 if(is_object($result)) { 769 return $result; 770 } else { 771 return null; 772 } 775 return (is_object($result) ? $result : null); 773 776 } 774 777 … … 786 789 $additional_conditions = null; 787 790 # Use any passed-in parameters 788 if (is_array($parameters)) {791 if(is_array($parameters)) { 789 792 //echo "<pre>";print_r($parameters); 790 793 if(@array_key_exists("conditions", $parameters)) { … … 819 822 820 823 $other_primary_key_value = $this->$foreign_key; 821 $conditions = ( is_numeric($other_primary_key_value) ?822 "{$other_primary_key} = {$other_primary_key_value}" :823 "{$other_primary_key} = '{$other_primary_key_value}'") . $additional_conditions;824 $conditions = ($other_class_object->attribute_is_string($other_primary_key) ? 825 "{$other_primary_key} = '{$other_primary_key_value}'" : 826 "{$other_primary_key} = {$other_primary_key_value}") . $additional_conditions; 824 827 825 828 # Get the list of other_class_name objects 826 829 $result = $other_class_object->find_first($conditions, $order); 830 827 831 # There should only be one result, an object, if so return it 828 if(is_object($result)) { 829 return $result; 830 } else { 831 return null; 832 } 832 return (is_object($result) ? $result : null); 833 833 } 834 834 … … 842 842 * @param string $agrregrate_type SQL aggregate function to 843 843 * apply, suffixed '_all'. The aggregate function is one of 844 * the strings in {@link $aggreg rations}.844 * the strings in {@link $aggregations}. 845 845 * @param string[] $parameters Conditions to apply to the 846 846 * aggregate function. If present, must be an array of three … … 857 857 * @uses is_error() 858 858 */ 859 private function aggreg rate_all($aggregrate_type, $parameters = null) {860 $aggreg rate_type = strtoupper(substr($aggregrate_type, 0, -4));859 private function aggregate_all($aggregate_type, $parameters = null) { 860 $aggregate_type = strtoupper(substr($aggregate_type, 0, -4)); 861 861 ($parameters[0]) ? $field = $parameters[0] : $field = "*"; 862 $sql = "SELECT $aggreg rate_type($field) AS agg_result FROM $this->table_name ";862 $sql = "SELECT $aggregate_type($field) AS agg_result FROM $this->table_name "; 863 863 864 864 # Use any passed-in parameters 865 if (!is_null($parameters)) { 865 if(is_array($parameters[1])) { 866 extract($parameters[1]); 867 } elseif(!is_null($parameters)) { 866 868 $conditions = $parameters[1]; 867 $joins = $parameters[2]; 868 } 869 870 if(!empty($joins)) $sql .= ",$joins "; 871 if(!empty($conditions)) $sql .= "WHERE $conditions "; 872 873 # echo "$aggregrate_type sql:$sql<br>"; 869 $order = $parameters[2]; 870 $joins = $parameters[3]; 871 } 872 873 if(!empty($joins)) $sql .= " $joins "; 874 if(!empty($conditions)) $sql .= " WHERE $conditions "; 875 if(!empty($order)) $sql .= " ORDER BY $order "; 876 877 # echo "$aggregate_type sql:$sql<br>"; 874 878 if($this->is_error($rs = $this->query($sql))) { 875 879 $this->raise($rs->getMessage()); … … 881 885 } 882 886 return 0; 887 } 888 889 /** 890 * Returns a the name of the join table that would be used for the two 891 * tables. The join table name is decided from the alphabetical order 892 * of the two tables. e.g. "genres_movies" because "g" comes before "m" 893 * 894 * Parameters: $first_table, $second_table: the names of two database tables, 895 * e.g. "movies" and "genres" 896 * @todo Document this API 897 */ 898 public function get_join_table_name($first_table, $second_table) { 899 $tables = array($first_table, $second_table); 900 @sort($tables); 901 return @implode("_", $tables); 883 902 } 884 903 … … 1010 1029 1011 1030 /** 1012 * Implement find_by_*() and find_all_by_* methods1031 * Implement find_by_*() and =_* methods 1013 1032 * 1014 1033 * Converts a method name beginning 'find_by_' or 'find_all_by_' … … 1043 1062 $param_index = 0; 1044 1063 foreach($method_parts as $part) { 1045 $value = is_numeric($parameters[$param_index]) ? $parameters[$param_index] : "'".$parameters[$param_index]."'";1046 1064 if($part == "AND") { 1047 1065 $conditions .= " AND "; 1048 1066 $param_index++; 1049 1067 } else { 1068 $value = $this->attribute_is_string($part) ? 1069 "'".$parameters[$param_index]."'" : 1070 $parameters[$param_index]; 1050 1071 $create_fields[$part] = $parameters[$param_index]; 1051 1072 $conditions .= "{$part} = {$value}"; … … 1282 1303 # passed in array of numbers array(1,2,4,23) 1283 1304 $primary_key = $this->primary_keys[0]; 1284 $primary_key_values = is_numeric($id[0]) ? implode(",", $id) : "'".implode("','", $id)."'"; 1305 $primary_key_values = $this->attribute_is_string($primary_key) ? 1306 "'".implode("','", $id)."'" : 1307 implode(",", $id); 1285 1308 $options['conditions'] = "{$primary_key} IN({$primary_key_values})"; 1286 1309 $find_all = true; … … 1295 1318 # find an single record with id = $id 1296 1319 $primary_key = $this->primary_keys[0]; 1297 $primary_key_value = is_numeric($id) ? $id : "'".$id."'";1320 $primary_key_value = $this->attribute_is_string($primary_key) ? "'".$id."'" : $id ; 1298 1321 $options['conditions'] = "{$primary_key} = {$primary_key_value}"; 1299 1322 } … … 1389 1412 * either create a row with all empty values, or it tries 1390 1413 * to recurse once for each attribute in $attributes. 1391 * FIXME: resolve calling sequence1392 1414 * Creates an object, instantly saves it as a record (if the validation permits it). 1393 1415 * If the save fails under validations it returns false and $errors array gets set. 1394 1416 */ 1395 1417 function create($attributes, $dont_validate = false) { 1396 if(is_array($attributes)) { 1397 foreach($attributes as $attr) { 1398 $this->create($attr, $dont_validate); 1399 } 1400 } else { 1401 $class_name = $this->get_class_name(); 1402 $object = new $class_name(); 1403 $object->save($attributes, $dont_validate); 1404 } 1418 $class_name = $this->get_class_name(); 1419 $object = new $class_name(); 1420 $result = $object->save($attributes, $dont_validate); 1421 return ($result ? $object : false); 1405 1422 } 1406 1423 … … 1470 1487 //error_log("ActiveRecord::save() \$attributes=" 1471 1488 // . var_export($attributes,true)); 1472 if( !is_null($attributes)) {1489 if(is_array($attributes)) { 1473 1490 $this->update_attributes($attributes); 1474 1491 } … … 1522 1539 * $content_columns} and the values from object variables. 1523 1540 * Send the insert to the RDBMS. 1524 * FIXME: Shouldn't we be saving the insert ID value as an object1525 * variable $this->id?1526 1541 * @uses $auto_save_habtm 1527 1542 * @uses add_habtm_records() … … 1547 1562 //echo "add_record: SQL: $sql<br>"; 1548 1563 $result = $this->query($sql); 1549 if ($this->is_error($result)) {1564 if($this->is_error($result)) { 1550 1565 $this->raise($results->getMessage()); 1551 1566 } else { … … 1554 1569 $primary_key_value = $this->get_insert_id(); 1555 1570 $this->$primary_key = $primary_key_value; 1556 if($primary_key_value > 0) {1571 if($primary_key_value != '') { 1557 1572 if($this->auto_save_habtm) { 1558 1573 $habtm_result = $this->add_habtm_records($primary_key_value); … … 1612 1627 * returns the association type if defined in child class or null 1613 1628 * @todo Document this API 1614 * @todo <b>FIXME:</b> does the match algorithm match a substring1615 * of what we want to match?1616 1629 * @uses $belongs_to 1617 1630 * @uses $has_and_belongs_to_many … … 1720 1733 */ 1721 1734 function delete($id = null) { 1722 1735 $deleted_ids = array(); 1723 1736 $primary_key_value = null; 1724 1737 $primary_key = $this->primary_keys[0]; … … 1726 1739 # Primary key's where clause from already loaded values 1727 1740 $conditions = $this->get_primary_key_conditions(); 1728 $ primary_key_value= $this->$primary_key;1729 } elseif(!is_array($id)) { 1730 $ primary_key_value = $id;1731 $id = is_numeric($id) ? $id : "'".$id."'";1732 $conditions = "{$primary_key} = $id";1741 $deleted_ids[] = $this->$primary_key; 1742 } elseif(!is_array($id)) { 1743 $deleted_ids[] = $id; 1744 $id = $this->attribute_is_string($primary_key) ? "'".$id."'" : $id; 1745 $conditions = "{$primary_key} = {$id}"; 1733 1746 } elseif(is_array($id)) { 1734 //$ids = ($this->attribute_is_string($primary_key)) ? "'".implode("','", $id)."'" : implode(',', $id); 1735 //$conditions = "{$primary_key} IN ($ids)"; 1747 $deleted_ids = $id; 1748 $ids = ($this->attribute_is_string($primary_key)) ? 1749 "'".implode("','", $id)."'" : 1750 implode(',', $id); 1751 $conditions = "{$primary_key} IN ({$ids})"; 1736 1752 } 1737 1753 … … 1742 1758 1743 1759 $this->before_delete(); 1744 $result = $this->delete_all($conditions); 1745 if($this->auto_delete_habtm && $primary_key_value != '') { 1746 if(is_string($this->has_and_belongs_to_many)) { 1747 $habtms = explode(",", $this->has_and_belongs_to_many); 1748 foreach($habtms as $other_table_name) { 1749 $this->delete_all_habtm_records(trim($other_table_name), $primary_key_value); 1760 if($result = $this->delete_all($conditions)) { 1761 foreach($deleted_ids as $id) { 1762 if($this->auto_delete_habtm && $id != '') { 1763 if(is_string($this->has_and_belongs_to_many)) { 1764 $habtms = explode(",", $this->has_and_belongs_to_many); 1765 foreach($habtms as $other_table_name) { 1766 $this->delete_all_habtm_records(trim($other_table_name), $id); 1767 } 1768 } elseif(is_array($this->has_and_belongs_to_many)) { 1769 foreach($this->has_and_belongs_to_many as $other_table_name => $values) { 1770 $this->delete_all_habtm_records($other_table_name, $id); 1771 } 1772 } 1750 1773 } 1751 } elseif(is_array($this->has_and_belongs_to_many)) { 1752 foreach($this->has_and_belongs_to_many as $other_table_name => $values) { 1753 $this->delete_all_habtm_records($other_table_name, $primary_key_value); 1754 } 1755 } 1756 } 1757 $this->after_delete(); 1758 1774 } 1775 $this->after_delete(); 1776 } 1777 1759 1778 return $result; 1760 1779 } … … 1787 1806 $this->raise($rs->getMessage()); 1788 1807 } 1789 1790 // <b>FIXME: We don't know whether this row was deleted. 1791 // What are the implications of making this a new record?</b> 1792 $this->id = 0; 1808 1793 1809 $this->new_record = true; 1794 1810 return true; … … 1882 1898 $habtm_table_name = $this->get_join_table_name($this->table_name,$other_table_name); 1883 1899 $this_foreign_key = Inflector::singularize($this->table_name)."_id"; 1884 $sql = "DELETE FROM $habtm_table_name WHERE $this_foreign_key = $this_foreign_value";1900 $sql = "DELETE FROM {$habtm_table_name} WHERE {$this_foreign_key} = {$this_foreign_value}"; 1885 1901 //echo "delete_all_habtm_records: SQL: $sql<br>"; 1886 1902 $result = $this->query($sql); … … 1952 1968 //error_log('update_attributes()'); 1953 1969 1954 // Test each attribute to be updated 1955 // and process according to its type 1956 foreach($attributes as $field => $value) { 1957 # datetime / date parts check 1958 if(preg_match('/^\w+\(.*i\)$/i', $field)) { 1959 1960 // The name of this attribute ends in "(?i)" 1961 // indicating that it's part of a date or time 1962 1963 // Accumulate all the pieces of a date and time in 1964 // array $datetime_key. The keys in the array are 1965 // the names of date/time attributes with the final 1966 // "(?i)" stripped off. 1967 $datetime_key = substr($field, 0, strpos($field, "(")); 1968 if( !isset($old_datetime_key) 1969 || ($datetime_key != $old_datetime_key)) { 1970 1971 // This value of $datetime_key hasn't been seen 1972 // before, so remember it. 1973 $old_datetime_key = $datetime_key; 1974 1975 // $datetime_value accumulates the pieces of the 1976 // date/time attribute $datetime_key 1977 $datetime_value = ""; 1978 } 1979 1980 // Concatentate pieces of the attribute's value 1981 // FIXME: this only works if the array elements 1982 // are sorted by key. Is this guaranteed? 1983 if(strstr($field, "2i") || strstr($field, "3i")) { 1984 $datetime_value .= "-".$value; 1985 } elseif(strstr($field, "4i")) { 1986 $datetime_value .= " ".$value; 1987 } elseif(strstr($field, "5i")) { 1988 $datetime_value .= ":".$value; 1970 if(is_array($attributes)) { 1971 // Test each attribute to be updated 1972 // and process according to its type 1973 foreach($attributes as $field => $value) { 1974 # datetime / date parts check 1975 if(preg_match('/^\w+\(.*i\)$/i', $field)) { 1976 1977 // The name of this attribute ends in "(?i)" 1978 // indicating that it's part of a date or time 1979 1980 // Accumulate all the pieces of a date and time in 1981 // array $datetime_key. The keys in the array are 1982 // the names of date/time attributes with the final 1983 // "(?i)" stripped off. 1984 $datetime_key = substr($field, 0, strpos($field, "(")); 1985 if( !isset($old_datetime_key) 1986 || ($datetime_key != $old_datetime_key)) { 1987 1988 // This value of $datetime_key hasn't been seen 1989 // before, so remember it. 1990 $old_datetime_key = $datetime_key; 1991 1992 // $datetime_value accumulates the pieces of the 1993 // date/time attribute $datetime_key 1994 $datetime_value = ""; 1995 } 1996 1997 // Concatentate pieces of the attribute's value 1998 // FIXME: this only works if the array elements 1999 // are sorted by key. Is this guaranteed? 2000 if(strstr($field, "2i") || strstr($field, "3i")) { 2001 $datetime_value .= "-".$value; 2002 } elseif(strstr($field, "4i")) { 2003 $datetime_value .= " ".$value; 2004 } elseif(strstr($field, "5i")) { 2005 $datetime_value .= ":".$value; 2006 } else { 2007 $datetime_value .= $value; 2008 } 2009 $datetime_fields[$old_datetime_key] = $datetime_value; 2010 # this elseif checks if first its an object if its parent is ActiveRecord 2011 } elseif(is_object($value) && get_parent_class($value) == __CLASS__ && $this->auto_save_associations) { 2012 if($association_type = $this->get_association_type($field)) { 2013 $this->save_associations[$association_type][] = $value; 2014 if($association_type == "belongs_to") { 2015 $primary_key = $value->primary_keys[0]; 2016 $foreign_key = Inflector::singularize($value->table_name)."_".$primary_key; 2017 $this->$foreign_key = $value->$primary_key; 2018 } 2019 } 2020 # this elseif checks if its an array of objects and if its parent is ActiveRecord 2021 } elseif(is_array($value) && $this->auto_save_associations) { 2022 if($association_type = $this->get_association_type($field)) { 2023 $this->save_associations[$association_type][] = $value; 2024 } 1989 2025 } else { 1990 $datetime_value .= $value; 1991 } 1992 $datetime_fields[$old_datetime_key] = $datetime_value; 1993 # this elseif checks if first its an object if its parent is ActiveRecord 1994 } elseif(is_object($value) && get_parent_class($value) == __CLASS__ && $this->auto_save_associations) { 1995 if($association_type = $this->get_association_type($field)) { 1996 $this->save_associations[$association_type][] = $value; 1997 if($association_type == "belongs_to") { 1998 $primary_key = $value->primary_keys[0]; 1999 $foreign_key = Inflector::singularize($value->table_name)."_".$primary_key; 2000 $this->$foreign_key = $value->$primary_key; 2001 } 2026 2027 // Just a simple attribute, copy it 2028 $this->$field = $value; 2002 2029 } 2003 # this elseif checks if its an array of objects and if its parent is ActiveRecord 2004 } elseif(is_array($value) && $this->auto_save_associations) { 2005 if($association_type = $this->get_association_type($field)) { 2006 $this->save_associations[$association_type][] = $value; 2007 } 2008 } else { 2009 2010 // Just a simple attribute, copy it 2011 $this->$field = $value; 2012 } 2013 } 2014 2015 // If any date/time fields were found, assign the 2016 // accumulated values to corresponding attributes 2017 if(isset($datetime_fields) 2018 && is_array($datetime_fields)) { 2019 foreach($datetime_fields as $field => $value) { 2020 //error_log("$field = $value"); 2021 $this->$field = $value; 2022 } 2023 } 2024 $this->set_habtm_attributes($attributes); 2030 } 2031 2032 // If any date/time fields were found, assign the 2033 // accumulated values to corresponding attributes 2034 if(isset($datetime_fields) 2035 && is_array($datetime_fields)) { 2036 foreach($datetime_fields as $field => $value) { 2037 //error_log("$field = $value"); 2038 $this->$field = $value; 2039 } 2040 } 2041 $this->set_habtm_attributes($attributes); 2042 } 2025 2043 } 2026 2044 … … 2076 2094 if(!(preg_match('/^\w+\(.*\)$/U', $value)) 2077 2095 && !(strcasecmp($value, 'NULL') == 0) 2078 && !is_numeric($value)) {2079 $value = str_replace("\\\"","\"", $value);2080 $value = str_replace("\'","'", $value);2081 $value = str_replace("\\\\","\\", $value);2096 && $this->attribute_is_string($key)) { 2097 $value = str_replace("\\\"","\"", $value); 2098 $value = str_replace("\'","'", $value); 2099 $value = str_replace("\\\\","\\", $value); 2082 2100 $return[$key] = "'" . addslashes($value) . "'"; 2083 2101 } else { … … 2158 2176 # run through our fields and join them with their values 2159 2177 foreach($attributes as $key => $value) { 2160 if($key && ($value || is_numeric($value)) && !in_array($key, $this->primary_keys)) {2178 if($key && isset($value) && !in_array($key, $this->primary_keys)) { 2161 2179 $updates[] = "$key = $value"; 2162 2180 } … … 2204 2222 * store it in {@link $content_columns}. Add a more human 2205 2223 * friendly name to the element for each column. 2206 * <b>FIXME: should throw an exception if tableInfo() fails</b>2207 2224 * @uses $db 2208 2225 * @uses $content_columns … … 2213 2230 function set_content_columns($table_name) { 2214 2231 $this->content_columns = self::$db->tableInfo($table_name); 2232 if($this->is_error($this->content_columns)) { 2233 $this->raise($this->content_columns->getMessage()); 2234 } 2215 2235 if(is_array($this->content_columns)) { 2216 2236 $i = 0; … … 2376 2396 function get_errors_as_string($seperator = "<br>") { 2377 2397 return $this->get_errors(true, $seperator); 2398 } 2399 2400 /** 2401 * Determine if passed in attribute (table column) is a string 2402 * @param string $attribute Name of the table column 2403 * @uses column_for_attribute() 2404 */ 2405 function attribute_is_string($attribute) { 2406 $column = $this->column_for_attribute($attribute); 2407 switch($column['type']) { 2408 case 'string': 2409 case 'varchar': 2410 case 'varchar2': 2411 case 'text': 2412 case 'blob': 2413 case 'date': 2414 case 'datetime': 2415 case 'timestamp': 2416 return true; 2417 } 2418 return false; 2378 2419 } 2379 2420
