useDbConfig); $tableName = $db->fullTableName($this, false); //Get the values for the specified column (database and version specific, needs testing) $result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'"); //figure out where in the result our Types are (this varies between mysql versions) $types = null; if ( isset( $result[0]['COLUMNS']['Type'] ) ) { //MySQL 5 $types = $result[0]['COLUMNS']['Type']; $default = $result[0]['COLUMNS']['Default']; } elseif ( isset( $result[0][0]['Type'] ) ) { //MySQL 4 $types = $result[0][0]['Type']; $default = $result[0][0]['Default']; } else { //types return not accounted for return array(); } //Get the values return array_flip(array_merge(array(''), // MySQL sets 0 to be the empty string explode("','", strtoupper(preg_replace("/(enum)\('(.+?)'\)/","\\2", $types))) )); } //end getEnumValues /************************************************************************** ************************************************************************** ************************************************************************** * function: nameToID * - Returns the ID of the named item */ function nameToID($name) { $this->cacheQueries = true; $item = $this->find('first', array ('recursive' => -1, 'conditions' => compact('name'), )); $this->cacheQueries = false; $item = current($item); return $item['id']; } /************************************************************************** ************************************************************************** ************************************************************************** * function: statMerge * - Merges summary data from $b into $a */ function statsMerge (&$a, $b) { if (!isset($b)) return; if (!isset($a)) { $a = $b; } elseif (!is_array($a) && !is_array($b)) { $a += $b; } elseif (is_array($a) && is_array($b)) { foreach (array_intersect_key($a, $b) AS $k => $v) { if (preg_match("/^sp\./", $k)) $a[$k] .= '; ' . $b[$k]; else $this->statsMerge($a[$k], $b[$k]); } $a = array_merge($a, array_diff_key($b, $a)); } else { die ("Can't yet merge array and non-array stats"); } } /************************************************************************** ************************************************************************** ************************************************************************** * function: dateFormatBeforeSave * - convert dates to database format */ function dateFormatBeforeSave($dateString) { /* $time = ''; */ /* if (preg_match('/(\d+(:\d+))/', $dateString, $match)) */ /* $time = ' '.$match[1]; */ /* $dateString = preg_replace('/(\d+(:\d+))/', '', $dateString); */ /* return date('Y-m-d', strtotime($dateString)) . $time; */ if (preg_match('/:/', $dateString)) return date('Y-m-d H:i:s', strtotime($dateString)); else return date('Y-m-d', strtotime($dateString)); } }