merging [880] [881] [882] and [883] fixes

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@884 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-18 13:25:20 +00:00
parent 7eb53efb5b
commit a86866a7a1
13 changed files with 231 additions and 169 deletions

View file

@ -75,7 +75,7 @@ class Cache extends Model {
* *
* @var string * @var string
*/ */
var $use_table = 'cache'; var $useTable = 'cache';
/** /**
* Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well. * Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well.
@ -111,7 +111,7 @@ class Cache extends Model {
{ {
$data = addslashes($this->for_caching.$content); $data = addslashes($this->for_caching.$content);
$expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999)); $expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999));
return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')"); return $this->query("REPLACE {$this->useTable} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
} }
/** /**
@ -155,7 +155,7 @@ class Cache extends Model {
*/ */
function clear() function clear()
{ {
return $this->query("DELETE FROM {$this->use_table}"); return $this->query("DELETE FROM {$this->useTable}");
} }
} }

View file

@ -213,7 +213,7 @@ class Controller extends Object
* Enter description here... * Enter description here...
* *
*/ */
function contructClasses(){ function constructClasses(){
if(empty($this->params['pass'])) if(empty($this->params['pass']))
{ {
@ -261,6 +261,28 @@ class Controller extends Object
} }
} }
} }
if (!empty($this->beforeFilter))
{
if(is_array($this->beforeFilter))
{
foreach($this->beforeFilter as $filter)
{
if(is_callable(array($this,$filter)))
{
$this->$filter();
}
}
}
else
{
if(is_callable(array($this,$this->beforeFilter)))
{
$this->{$this->beforeFilter}();
}
}
}
} }
/** /**
@ -394,9 +416,9 @@ class Controller extends Object
* Renders the Missing Table web page. * Renders the Missing Table web page.
* *
*/ */
function missingTable($table_name) function missingTable($tableName)
{ {
$this->missingTableName = $table_name; $this->missingTableName = $tableName;
$this->pageTitle = 'Missing Database Table'; $this->pageTitle = 'Missing Database Table';
//We are simulating action call below, this is not a filename! //We are simulating action call below, this is not a filename!
$this->render('../errors/missingTable'); $this->render('../errors/missingTable');
@ -517,7 +539,7 @@ class Controller extends Object
$classRegistry =& ClassRegistry::getInstance(); $classRegistry =& ClassRegistry::getInstance();
$objRegistryModel = $classRegistry->getObject(Inflector::singularize($model)); $objRegistryModel = $classRegistry->getObject(Inflector::singularize($model));
foreach ($objRegistryModel->_table_info as $tables) foreach ($objRegistryModel->_tableInfo as $tables)
{ {
foreach ($tables as $tabl) foreach ($tables as $tabl)
{ {

View file

@ -129,12 +129,12 @@ class DBO_AdoDB extends DBO
/** /**
* Returns an array of the fields in given table name. * Returns an array of the fields in given table name.
* *
* @param string $table_name Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function fields ($table_name) function fields ($tableName)
{ {
$data = $this->_adodb->MetaColumns($table_name); $data = $this->_adodb->MetaColumns($tableName);
$fields = false; $fields = false;
foreach ($data as $item) foreach ($data as $item)

View file

@ -89,7 +89,7 @@ class DBO_generic extends DBO
* Abstract method defined in subclasses. * Abstract method defined in subclasses.
* *
*/ */
function fields ($table_name) function fields ($tableName)
{ {
} }

View file

@ -135,13 +135,13 @@ class DBO_MySQL extends DBO
/** /**
* Returns an array of the fields in given table name. * Returns an array of the fields in given table name.
* *
* @param string $table_name Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function fields ($table_name) function fields ($tableName)
{ {
$fields = false; $fields = false;
$cols = $this->all("DESC {$table_name}"); $cols = $this->all("DESC {$tableName}");
foreach ($cols as $column) foreach ($cols as $column)
{ {

View file

@ -167,12 +167,12 @@ class DBO_Pear extends DBO
/** /**
* Returns an array of the fields in given table name. * Returns an array of the fields in given table name.
* *
* @param string $table_name Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function fields ($table_name) function fields ($tableName)
{ {
$data = $this->_pear->tableInfo($table_name); $data = $this->_pear->tableInfo($tableName);
$fields = false; $fields = false;
foreach ($data as $item) foreach ($data as $item)

View file

@ -133,12 +133,12 @@ class DBO_Postgres extends DBO
/** /**
* Returns an array of the fields in given table name. * Returns an array of the fields in given table name.
* *
* @param string $table_name Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function fields ($table_name) function fields ($tableName)
{ {
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid"; $sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
$fields = false; $fields = false;
foreach ($this->all($sql) as $field) { foreach ($this->all($sql) as $field) {

View file

@ -132,13 +132,13 @@ class DBO_SQLite extends DBO
/** /**
* Returns an array of the fields in given table name. * Returns an array of the fields in given table name.
* *
* @param string $table_name Name of database table to inspect * @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function fields($table_name) function fields($tableName)
{ {
$fields = false; $fields = false;
$cols = sqlite_fetch_column_types($table_name, $this->_conn); $cols = sqlite_fetch_column_types($tableName, $this->_conn);
foreach ($cols as $column => $type) foreach ($cols as $column => $type)
{ {

View file

@ -161,7 +161,7 @@ class Dispatcher extends Object
} }
} }
$controller->contructClasses(); $controller->constructClasses();
if ($missingAction) if ($missingAction)
{ {

View file

@ -49,7 +49,7 @@ class JavascriptHelper extends Helper
*/ */
function codeBlock($script) function codeBlock($script)
{ {
return sprintf($this->tags['javascriptBlock'], $script); return sprintf($this->tags['javascriptblock'], $script);
} }
/** /**
@ -60,7 +60,7 @@ class JavascriptHelper extends Helper
*/ */
function link($url) function link($url)
{ {
return sprintf($this->tags['javascriptLink'], $this->base.$url); return sprintf($this->tags['javascriptlink'], $this->base.$url);
} }
/** /**
@ -71,7 +71,7 @@ class JavascriptHelper extends Helper
*/ */
function linkOut($url) function linkOut($url)
{ {
return sprintf($this->tags['javascriptLink'], $url); return sprintf($this->tags['javascriptlink'], $url);
} }
/** /**

View file

@ -193,12 +193,12 @@ class Inflector extends Object
/** /**
* Returns Cake class name ("Post" for the database table "posts".) for given database table. * Returns Cake class name ("Post" for the database table "posts".) for given database table.
* *
* @param string $table_name Name of database table to get class name for * @param string $tableName Name of database table to get class name for
* @return string * @return string
*/ */
function classify($table_name) function classify($tableName)
{ {
return Inflector::camelize(Inflector::singularize($table_name)); return Inflector::camelize(Inflector::singularize($tableName));
} }
/** /**

View file

@ -68,7 +68,7 @@ class Model extends Object
* @var string * @var string
* @access public * @access public
*/ */
var $use_table = false; var $useTable = false;
/** /**
* Enter description here... * Enter description here...
@ -100,7 +100,7 @@ class Model extends Object
* @var array * @var array
* @access private * @access private
*/ */
var $_table_info = null; var $_tableInfo = null;
/** /**
* Enter description here... * Enter description here...
@ -232,12 +232,12 @@ class Model extends Object
$this->id = $id; $this->id = $id;
} }
$table_name = $table? $table: ($this->use_table? $this->use_table: Inflector::tableize(get_class($this))); $tableName = $table? $table: ($this->useTable? $this->useTable: Inflector::tableize(get_class($this)));
//Table Prefix Hack - Check to see if the function exists. //Table Prefix Hack - Check to see if the function exists.
if (in_array('settableprefix', get_class_methods(get_class($this)))) $this->setTablePrefix(); if (in_array('settableprefix', get_class_methods(get_class($this)))) $this->setTablePrefix();
// Table Prefix Hack - Get the prefix for this view. // Table Prefix Hack - Get the prefix for this view.
$this->tablePrefix? $this->useTable($this->tablePrefix.$table_name): $this->useTable ($table_name); $this->tablePrefix? $this->useTable($this->tablePrefix.$tableName): $this->useTable ($tableName);
//$this->useTable ($table_name); //$this->useTable ($tableName);
parent::__construct(); parent::__construct();
$this->createLinks(); $this->createLinks();
} }
@ -752,18 +752,18 @@ class Model extends Object
/** /**
* Sets a custom table for your controller class. Used by your controller to select a database table. * Sets a custom table for your controller class. Used by your controller to select a database table.
* *
* @param string $table_name Name of the custom table * @param string $tableName Name of the custom table
*/ */
function useTable ($table_name) function useTable ($tableName)
{ {
if (!in_array(strtolower($table_name), $this->db->tables())) if (!in_array(strtolower($tableName), $this->db->tables()))
{ {
$this->_throwMissingTable($table_name); $this->_throwMissingTable($tableName);
die(); die();
} }
else else
{ {
$this->table = $table_name; $this->table = $tableName;
$this->loadInfo(); $this->loadInfo();
} }
} }
@ -845,11 +845,11 @@ class Model extends Object
*/ */
function loadInfo () function loadInfo ()
{ {
if (empty($this->_table_info)) if (empty($this->_tableInfo))
{ {
$this->_table_info = new NeatArray($this->db->fields($this->table)); $this->_tableInfo = new NeatArray($this->db->fields($this->table));
} }
return $this->_table_info; return $this->_tableInfo;
} }
/** /**
@ -861,11 +861,11 @@ class Model extends Object
*/ */
function hasField ($name) function hasField ($name)
{ {
if (empty($this->_table_info)) if (empty($this->_tableInfo))
{ {
$this->loadInfo(); $this->loadInfo();
} }
return $this->_table_info->findIn('name', $name); return $this->_tableInfo->findIn('name', $name);
} }
/** /**
@ -1290,32 +1290,129 @@ class Model extends Object
if(!empty($this->_oneToMany)) if(!empty($this->_oneToMany))
{ {
$newValue = $this->_findOneToMany($data);
$datacheck = $data; if(!empty($newValue))
$original = $data;
foreach ($this->_oneToMany as $rule)
{ {
$count = 0; $data = $newValue;
list($table, $field, $value) = $rule; }
}
foreach ($datacheck as $key => $value1) if(!empty($this->_manyToMany))
{
$newValue = $this->_findManyToMany($data);
if(!empty($newValue))
{
$data = $newValue;
}
}
return $data;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function _findOneToMany(&$data)
{
$datacheck = $data;
$original = $data;
foreach ($this->_oneToMany as $rule)
{
$count = 0;
list($table, $field, $value) = $rule;
foreach ($datacheck as $key => $value1)
{
foreach ($value1 as $key2 => $value2)
{ {
foreach ($value1 as $key2 => $value2) if($key2 === Inflector::singularize($this->table))
{ {
if($key2 === Inflector::singularize($this->table)) $oneToManySelect[$table] = $this->db->all("SELECT * FROM {$table}
WHERE ($field) = '{$value2['id']}'");
if( !empty($oneToManySelect[$table]) && is_array($oneToManySelect[$table]))
{ {
$oneToManySelect[$table] = $this->db->all("SELECT * FROM {$table} WHERE ($field) = '{$value2['id']}'"); $newKey = Inflector::singularize($table);
foreach ($oneToManySelect[$table] as $key => $value)
{
$oneToManySelect1[$table][$key] = $value[$newKey];
}
$merged = array_merge_recursive($data[$count],$oneToManySelect1);
$newdata[$count] = $merged;
unset( $oneToManySelect[$table], $oneToManySelect1);
}
if(!empty($newdata[$count]))
{
$original[$count] = $newdata[$count];
}
}
}
$count++;
}
if(empty($newValue2) && !empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue2[$i] = $original[$i];
}
if(count($this->_oneToMany < 2))
{
$newValue = $newValue2;
}
}
elseif(!empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue[$i] = array_merge($newValue2[$i], $original[$i]);
}
}
$this->joinedHasMany[] = new NeatArray($this->db->fields($table));
}
return $newValue;
}
if( !empty($oneToManySelect[$table]) && is_array($oneToManySelect[$table])) /**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function _findManyToMany(&$data)
{
$datacheck = $data;
$original = $data;
foreach ($this->_manyToMany as $rule)
{
$count = 0;
list($table, $field, $value, $joineTable, $joinKey1, $JoinKey2) = $rule;
foreach ($datacheck as $key => $value1)
{
foreach ($value1 as $key2 => $value2)
{
if($key2 === Inflector::singularize($this->table))
{
if( 0 == strncmp($key2, $joinKey1, strlen($key2)) )
{
if(!empty ($value2['id']))
{
$tmpSQL = "SELECT * FROM {$table}
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
AND {$joineTable}.{$JoinKey2} = {$table} .id";
$manyToManySelect[$table] = $this->db->all($tmpSQL);
}
if( !empty($manyToManySelect[$table]) && is_array($manyToManySelect[$table]))
{ {
$newKey = Inflector::singularize($table); $newKey = Inflector::singularize($table);
foreach ($oneToManySelect[$table] as $key => $value) foreach ($manyToManySelect[$table] as $key => $value)
{ {
$oneToManySelect1[$table][$key] = $value[$newKey]; $manyToManySelect1[$table][$key] = $value[$newKey];
} }
$merged = array_merge_recursive($data[$count],$oneToManySelect1); $merged = array_merge_recursive($data[$count],$manyToManySelect1);
$newdata[$count] = $merged; $newdata[$count] = $merged;
unset( $oneToManySelect[$table], $oneToManySelect1); unset( $manyToManySelect[$table], $manyToManySelect1 );
} }
if(!empty($newdata[$count])) if(!empty($newdata[$count]))
{ {
@ -1323,106 +1420,30 @@ class Model extends Object
} }
} }
} }
$count++;
} }
if(empty($newValue2) && !empty($original)) $count++;
{
for ($i = 0; $i< count($original); $i++)
{
$newValue2[$i] = $original[$i];
}
if(count($this->_oneToMany < 2))
{
$newValue = $newValue2;
}
}
elseif(!empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue[$i] = array_merge($newValue2[$i], $original[$i]);
}
}
$this->joinedHasMany[] = new NeatArray($this->db->fields($table));
} }
if(!empty($newValue)) if(empty($newValue2) && !empty($original))
{ {
$data = $newValue; for ($i = 0; $i< count($original); $i++)
unset($newValue); {
$newValue2[$i] = $original[$i];
}
if(count($this->_manyToMany < 2))
{
$newValue = $newValue2;
}
} }
elseif(!empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue[$i] = array_merge($newValue2[$i], $original[$i]);
}
}
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
} }
return $newValue;
if(!empty($this->_manyToMany))
{
$datacheck = $data;
$original = $data;
foreach ($this->_manyToMany as $rule)
{
$count = 0;
list($table, $field, $value, $joineTable, $joinKey1, $JoinKey2) = $rule;
foreach ($datacheck as $key => $value1)
{
foreach ($value1 as $key2 => $value2)
{
if($key2 === Inflector::singularize($this->table))
{
if( 0 == strncmp($key2, $joinKey1, strlen($key2)) )
{
if(!empty ($value2['id']))
{
$tmpSQL = "SELECT * FROM {$table}
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
AND {$joineTable}.{$JoinKey2} = {$table} .id";
$manyToManySelect[$table] = $this->db->all($tmpSQL);
}
if( !empty($manyToManySelect[$table]) && is_array($manyToManySelect[$table]))
{
$newKey = Inflector::singularize($table);
foreach ($manyToManySelect[$table] as $key => $value)
{
$manyToManySelect1[$table][$key] = $value[$newKey];
}
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
$newdata[$count] = $merged;
unset( $manyToManySelect[$table], $manyToManySelect1 );
}
if(!empty($newdata[$count]))
{
$original[$count] = $newdata[$count];
}
}
}
}
$count++;
}
if(empty($newValue2) && !empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue2[$i] = $original[$i];
}
if(count($this->_manyToMany < 2))
{
$newValue = $newValue2;
}
}
elseif(!empty($original))
{
for ($i = 0; $i< count($original); $i++)
{
$newValue[$i] = array_merge($newValue2[$i], $original[$i]);
}
}
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
}
if(!empty($newValue))
{
$data = $newValue;
}
}
return $data;
} }
/** /**
@ -1601,6 +1622,11 @@ class Model extends Object
return false; return false;
} }
/**
* Enter description here...
*
* @return unknown
*/
function getDisplayField() function getDisplayField()
{ {
// $displayField defaults to 'name' // $displayField defaults to 'name'
@ -1618,19 +1644,33 @@ class Model extends Object
return $dispField; return $dispField;
} }
/**
* Enter description here...
*
* @return unknown
*/
function getLastInsertID() function getLastInsertID()
{ {
return $this->db->lastInsertId($this->table, 'id'); return $this->db->lastInsertId($this->table, 'id');
} }
function _throwMissingTable($table_name) /**
* Enter description here...
*
* @param unknown_type $tableName
*/
function _throwMissingTable($tableName)
{ {
$error = new AppController(); $error = new AppController();
$error->missingTable = get_class($this); $error->missingTable = get_class($this);
call_user_func_array(array(&$error, 'missingTable'), $table_name); call_user_func_array(array(&$error, 'missingTable'), $tableName);
exit; exit;
} }
/**
* Enter description here...
*
*/
function _throwMissingConnection() function _throwMissingConnection()
{ {
$error = new AppController(); $error = new AppController();

View file

@ -114,7 +114,7 @@ class Scaffold extends Object {
$this->scaffoldTitle = Inflector::humanize($this->modelKey); $this->scaffoldTitle = Inflector::humanize($this->modelKey);
$this->controllerClass->layout = 'scaffold'; $this->controllerClass->layout = 'scaffold';
$this->controllerClass->pageTitle = $this->scaffoldTitle; $this->controllerClass->pageTitle = $this->scaffoldTitle;
$this->controllerClass->contructClasses(); $this->controllerClass->constructClasses();
} }
/** /**
@ -250,7 +250,7 @@ class Scaffold extends Object {
{ {
// clean up the date fields // clean up the date fields
$objModel = $this->controllerClass->models[$this->modelKey]; $objModel = $this->controllerClass->models[$this->modelKey];
foreach( $objModel->_table_info as $table ) foreach( $objModel->_tableInfo as $table )
{ {
foreach ($table as $field) foreach ($table as $field)
{ {