Merging fixes to trunk

Revision: [1819]
Added fix for undefined index in Form::generateFields()
Adding missing doc blocks.
Adding fix for Ticket #290.
Added fix to allow setting fields for models.

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1820 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-17 17:52:23 +00:00
parent f718229a04
commit ee6ccf15b6
9 changed files with 719 additions and 494 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.6.1818 RC 1
0.10.6.1820 RC 1

View file

@ -59,7 +59,7 @@ class ConnectionManager extends Object
*/
var $_dataSources = array();
/**
/**
* Constructor.
*
*/

View file

@ -21,7 +21,7 @@
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.model.datasources
* @since CakePHP v 0.10.x.1379
* @since CakePHP v 0.10.5.1790
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
@ -35,7 +35,7 @@
*
* @package cake
* @subpackage cake.cake.libs.model.datasources
* @since CakePHP v 0.10.x.1379
* @since CakePHP v 0.10.5.1790
*
*/
class DataSource extends Object
@ -188,6 +188,10 @@ class DataSource extends Object
var $__transactionStarted = false;
/**
* Enter description here...
*
*/
function __construct ()
{
parent::__construct();
@ -270,16 +274,34 @@ class DataSource extends Object
return $conditions;
}
/**
* Enter description here...
*
* @param unknown_type $name
* @return unknown
*/
function name ($name)
{
return $name;
}
/**
* Enter description here...
*
* @param unknown_type $value
* @return unknown
*/
function value ($value)
{
return $value;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @return unknown
*/
function describe ($model)
{
if (isset($this->__descriptions[$model->table]))
@ -296,21 +318,50 @@ class DataSource extends Object
return null;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function create (&$model, $fields = null, $values = null)
{
return false;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $queryData
* @return unknown
*/
function read (&$model, $queryData = array())
{
return false;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function update (&$model, $fields = null, $values = null)
{
return false;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $id
*/
function delete (&$model, $id = null)
{
if ($id == null)
@ -319,16 +370,41 @@ class DataSource extends Object
}
}
/**
* Enter description here...
*
* @param unknown_type $fields
* @return unknown
*/
function fields ($fields)
{
return $fields;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @return unknown
*/
function getColumnType (&$model, $fields)
{
return false;
}
/**
* Enter description here...
*
* @param unknown_type $query
* @param unknown_type $data
* @param unknown_type $association
* @param unknown_type $assocData
* @param unknown_type $model
* @param unknown_type $linkModel
* @param unknown_type $index
* @return unknown
*/
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $index)
{
$keys = array('{$__cake_id__$}', '{$__cake_foreignKey__$}');
@ -362,11 +438,25 @@ class DataSource extends Object
return $query;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $key
* @return unknown
*/
function resolveKey($model, $key)
{
return $key;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @param unknown_type $path
* @return unknown
*/
function getFieldValue ($data, $path)
{
if (!is_array($path))
@ -418,6 +508,10 @@ class DataSource extends Object
return $data;
}
/**
* Enter description here...
*
*/
function __destruct ()
{
if ($this->connected)

View file

@ -46,9 +46,24 @@ uses('model'.DS.'datasources'.DS.'datasource');
*/
class DboSource extends DataSource
{
/**
* Enter description here...
*
* @var unknown_type
*/
var $description = "Database Data Source";
/**
* Enter description here...
*
* @var unknown_type
*/
var $__bypass = false;
/**
* Enter description here...
*
* @var unknown_type
*/
var $__assocJoins = null;
/**
* Constructor
*
@ -84,6 +99,11 @@ class DboSource extends DataSource
}
}
/**
* Enter description here...
*
* @return unknown
*/
function sources ()
{
return array_map('strtolower', $this->listSources());
@ -303,6 +323,14 @@ class DboSource extends DataSource
}
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function create(&$model, $fields = null, $values = null)
{
if ($fields == null)
@ -324,6 +352,14 @@ class DboSource extends DataSource
return false;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $queryData
* @param unknown_type $recursive
* @return unknown
*/
function read (&$model, $queryData = array(), $recursive = 1)
{
$this->__scrubQueryData($queryData);
@ -331,6 +367,11 @@ class DboSource extends DataSource
$array = array();
$linkedModels = array();
if(!empty($queryData['fields']))
{
$this->__bypass = true;
}
if ($recursive > 0)
{
foreach($model->__associations as $type)
@ -377,6 +418,19 @@ class DboSource extends DataSource
return $resultSet;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $linkModel
* @param unknown_type $type
* @param unknown_type $association
* @param unknown_type $assocData
* @param unknown_type $queryData
* @param unknown_type $external
* @param unknown_type $resultSet
* @param unknown_type $recursive
*/
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive = 1)
{
//$external = (($linkModel->db === $this) && $resultSet == null);
@ -411,6 +465,19 @@ class DboSource extends DataSource
}
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $linkModel
* @param unknown_type $type
* @param unknown_type $association
* @param unknown_type $assocData
* @param unknown_type $queryData
* @param unknown_type $external
* @param unknown_type $resultSet
* @return unknown
*/
function generateSelfAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
{
$alias = $association;
@ -433,10 +500,10 @@ class DboSource extends DataSource
}
else
{
if(isset($this->joinFieldJoin))
if(isset($this->__assocJoins))
{
$replace = ', ';
$replace .= join(', ', $this->joinFieldJoin['fields']);
$replace .= join(', ', $this->__assocJoins['fields']);
$replace .= ' FROM';
}
else
@ -451,9 +518,24 @@ class DboSource extends DataSource
return $result;
}
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $linkModel
* @param unknown_type $type
* @param unknown_type $association
* @param unknown_type $assocData
* @param unknown_type $queryData
* @param unknown_type $external
* @param unknown_type $resultSet
* @return unknown
*/
function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
{
$this->__scrubQueryData($queryData);
$joinedOnSelf = false;
$fields = null;
if ($linkModel == null)
{
if(array_key_exists('selfJoin', $queryData))
@ -462,10 +544,10 @@ class DboSource extends DataSource
}
else
{
if(isset($this->joinFieldJoin))// && !isset($queryData['fields']))
if(isset($this->__assocJoins['fields']))
{
$joinFields = ', ';
$joinFields .= join(', ', $this->joinFieldJoin['fields']);
$joinFields .= join(', ', $this->__assocJoins['fields']);
}
else
{
@ -486,10 +568,6 @@ class DboSource extends DataSource
{
$joinedOnSelf = true;
}
else
{
$joinedOnSelf = false;
}
switch ($type)
{
@ -519,26 +597,23 @@ class DboSource extends DataSource
}
$sql .= $this->conditions($queryData['conditions']) . $this->order($queryData['order']);
$sql .= $this->limit($queryData['limit']);
return $sql;
}
else
{
if($joinedOnSelf == true)
{
}
else
else if($joinedOnSelf != true)
{
if(!isset($assocData['fields']))
{
$assocData['fields'] = '';
}
if($this->__bypass == false)
{
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
}
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
$sql .= $this->order($assocData['order']);
}
$this->joinFieldJoin['fields'][] = $fields;
$this->__assocJoins['fields'][] = $fields;
if (!in_array($sql, $queryData['joins']))
{
$queryData['joins'][] = $sql;
@ -571,24 +646,21 @@ class DboSource extends DataSource
$sql .= $this->limit($queryData['limit']);
return $sql;
}
else
{
if($joinedOnSelf == true)
{
}
else
else if($joinedOnSelf != true)
{
if(!isset($assocData['fields']))
{
$assocData['fields'] = '';
}
if($this->__bypass == false)
{
$fields = join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
}
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
$sql .= ' AS ' . $this->name($alias) . ' ON ';
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
}
$this->joinFieldJoin['fields'][] = $fields;
$this->__assocJoins['fields'][] = $fields;
if (!in_array($sql, $queryData['joins']))
{
$queryData['joins'][] = $sql;
@ -652,6 +724,14 @@ class DboSource extends DataSource
return null;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function update (&$model, $fields = null, $values = null)
{
$updates = array();
@ -667,6 +747,13 @@ class DboSource extends DataSource
return $this->execute($sql);
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $id
* @return unknown
*/
function delete (&$model, $id = null)
{
$_id = $model->id;
@ -689,6 +776,14 @@ class DboSource extends DataSource
return false;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $key
* @param unknown_type $assoc
* @return unknown
*/
function resolveKey($model, $key, $assoc = null)
{
if ($assoc == null)
@ -703,11 +798,22 @@ class DboSource extends DataSource
return $key;
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $field
*/
function getColumnType (&$model, $field)
{
$columns = $model->loadInfo();
}
/**
* Enter description here...
*
* @param unknown_type $data
*/
function __scrubQueryData(&$data)
{
if (!isset($data['conditions']))
@ -732,6 +838,14 @@ class DboSource extends DataSource
}
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $alias
* @param unknown_type $fields
* @return unknown
*/
function fields (&$model, $alias, $fields)
{
if (is_array($fields))
@ -774,8 +888,9 @@ class DboSource extends DataSource
/**
* Parses conditions array (or just passes it if it's a string)
* @return string
*
* @param unknown_type $conditions
* @return string
*/
function conditions ($conditions)
{
@ -833,10 +948,21 @@ class DboSource extends DataSource
}
}
/**
* Enter description here...
*
*/
function limit ()
{
}
/**
* Enter description here...
*
* @param unknown_type $key
* @param unknown_type $dir
* @return unknown
*/
function order ($key, $dir = '')
{
if (trim($key) == '')
@ -847,7 +973,8 @@ class DboSource extends DataSource
}
/**
* Disconnects database, kills the connection and says the connection is closed, and if DEBUG is turned on, the log for this object is shown.
* Disconnects database, kills the connection and says the connection is closed,
* and if DEBUG is turned on, the log for this object is shown.
*
*/
function close ()
@ -888,6 +1015,4 @@ class DboSource extends DataSource
return is_array($out)? $out[0]['count']: false;
}
}
?>

View file

@ -20,8 +20,8 @@
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.model.datasources.dbo
* @since CakePHP v 0.2.9
* @subpackage cake.cake.libs.model.dbo
* @since CakePHP v 0.10.5.1790
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
@ -40,24 +40,36 @@ uses('model'.DS.'datasources'.DS.'dbo_source');
* Long description for class
*
* @package cake
* @subpackage cake.cake.libs.model.datasources.dbo
* @since CakePHP v 0.2.9
* @subpackage cake.cake.libs.model.dbo
* @since CakePHP v 0.10.5.1790
*/
class DboMysql extends DboSource
{
/**
* Enter description here...
*
* @var unknown_type
*/
var $description = "MySQL DBO Driver";
/**
* Enter description here...
*
* @var unknown_type
*/
var $_baseConfig = array('persistent' => true,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cake',
'port' => 3306
);
'port' => 3306);
var $columns = array(
'primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
/**
* Enter description here...
*
* @var unknown_type
*/
var $columns = array('primary_key' =>array('name' => 'int(11) DEFAULT NULL auto_increment'),
'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'),
'integer' => array('name' => 'int', 'limit' => '11'),
@ -67,9 +79,14 @@ class DboMysql extends DboSource
'time' => array('name' => 'time', 'format' => 'h:i:s'),
'date' => array('name' => 'date', 'format' => 'Y-m-d'),
'binary' => array('name' => 'blob'),
'boolean' => array('name' => 'tinyint', 'limit' => '1')
);
'boolean' => array('name' => 'tinyint', 'limit' => '1'));
/**
* Enter description here...
*
* @param unknown_type $config
* @return unknown
*/
function __construct ($config)
{
parent::__construct($config);
@ -84,14 +101,7 @@ class DboMysql extends DboSource
function connect ()
{
$config = $this->config;
if ($config['persistent'])
{
$connect = 'mysql_pconnect';
}
else
{
$connect = 'mysql_connect';
}
$connect = $config['connect'];
$this->connected = false;
$this->connection = $connect($config['host'], $config['login'], $config['password']);
@ -99,7 +109,6 @@ class DboMysql extends DboSource
{
$this->connected = true;
}
if ($this->connected)
{
return mysql_select_db($config['database'], $this->connection);
@ -135,8 +144,6 @@ class DboMysql extends DboSource
/**
* MySQL query abstraction
*
* @param string $method Method name
* @param array $params Parameters
* @return resource Result resource identifier
*/
function query ()
@ -160,7 +167,6 @@ class DboMysql extends DboSource
}
}
/**
* Returns a row from given resultset as an array .
*
@ -228,13 +234,11 @@ class DboMysql extends DboSource
{
$column[0] = $column[$colKey[0]];
}
if (isset($column[0]))
{
$fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']);
}
}
$this->__cacheDescription($model->table, $fields);
return $fields;
}
@ -242,7 +246,7 @@ class DboMysql extends DboSource
/**
* Returns a quoted name of $data for use in an SQL statement.
*
* @param string $data Name (table/field) to be prepared for use in an SQL statement
* @param string $data Name (table.field) to be prepared for use in an SQL statement
* @return string Quoted for MySQL
*/
function name ($data)
@ -260,6 +264,7 @@ class DboMysql extends DboSource
* @param string $data String to be prepared for use in an SQL statement
* @param string $column The column into which this data will be inserted
* @return string Quoted and escaped
* @todo Add logic that formats/escapes data based on column type
*/
function value ($data, $column = null)
{
@ -268,7 +273,6 @@ class DboMysql extends DboSource
{
return $parent;
}
if (ini_get('magic_quotes_gpc') == 1)
{
$data = stripslashes($data);
@ -282,7 +286,6 @@ class DboMysql extends DboSource
$data = mysql_real_escape_string($data, $this->connection);
}
return "'" . $data . "'";
// TODO: Add logic that formats/escapes data based on column type
}
/**
@ -311,11 +314,27 @@ class DboMysql extends DboSource
}
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function create(&$model, $fields = null, $values = null)
{
return parent::create($model, $fields, $values);
}
/**
* Enter description here...
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
*/
function update(&$model, $fields = null, $values = null)
{
return parent::update($model, $fields, $values);
@ -324,7 +343,9 @@ class DboMysql extends DboSource
/**
* Begin a transaction
*
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions).
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions).
*/
function begin (&$model)
{
@ -342,7 +363,10 @@ class DboMysql extends DboSource
/**
* Commit a transaction
*
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function commit (&$model)
{
@ -357,7 +381,10 @@ class DboMysql extends DboSource
/**
* Rollback a transaction
*
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function rollback (&$model)
{
@ -415,7 +442,8 @@ class DboMysql extends DboSource
/**
* Returns the ID generated from the previous INSERT operation.
*
* @return int
* @param unknown_type $source
* @return in
*/
function lastInsertId ($source = null)
{
@ -464,7 +492,6 @@ class DboMysql extends DboSource
while ($j < $num_fields)
{
$column = mysql_fetch_field($results,$j);
if (!empty($column->table))
{
$this->map[$index++] = array($column->table, $column->name);
@ -502,5 +529,4 @@ class DboMysql extends DboSource
}
}
}
?>

View file

@ -80,14 +80,7 @@ class DboPostgres extends DboSource
function connect ()
{
$config = $this->config;
if ($config['persistent'])
{
$connect = 'pg_pconnect';
}
else
{
$connect = 'pg_connect';
}
$connect = $config['connect'];
$this->connection = $connect("dbname={$config['database']} user={$config['login']} password={$config['password']}");
if ($this->connection)

View file

@ -28,10 +28,16 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Load the model class based on the version of PHP.
*
*/
if (phpversion() < 5)
{
require_once(LIBS.'model'.DS.'model_php4.php');
if (function_exists("overload")) {
if (function_exists("overload"))
{
overload("Model");
}
}

View file

@ -350,19 +350,25 @@ class Model extends Object
}
}
/**
* PHP4 Only
*
* Handles custom method calls, like findBy<field> for DB models,
* and custom RPC calls for remote data sources.
*
* @param unknown_type $method
* @param unknown_type $params
* @param unknown_type $return
* @return unknown
* @access protected
*/
// --- PHP4 Only
function __call($method, $params, &$return)
{
$return = $this->db->query($method, $params, $this);
return true;
}
// --- PHP4 Only
/**
* Private helper method to create a set of associations.
@ -435,6 +441,7 @@ class Model extends Object
* @param string $type "Belongs", "One", "Many", "ManyTo"
* @param string $assoc
* @param string $model
* @access private
*/
function __generateAssociation ($type, $assoc)
{
@ -651,6 +658,7 @@ class Model extends Object
*
* @param string $name Name of field to get
* @param string $conditions SQL conditions (defaults to NULL)
* @param string $order (defaults to NULL)
* @return field contents
*/
function field ($name, $conditions = null, $order = null)
@ -929,9 +937,11 @@ class Model extends Object
return false;
}
/**
* Returns true if a record that meets given conditions exists
*
* @param unknown_type $conditions
* @return boolean True if such a record exists
*/
function hasAny ($conditions = null)
@ -998,44 +1008,6 @@ class Model extends Object
return $this->afterFind($this->db->read($this, $queryData, $recursive));
}
//////////////
/* $joins[] = $join;
if (count($joins))
{
$joins = join(' ', $joins);
}
else
{
$joins = null;
}
if (count($whers))
{
$whers = '(' . join(' AND ', $whers) . ')';
}
else
{
$whers = null;
}
if ($conditions && $whers)
{
$conditions .= ' AND ';
}
$conditions .= $whers;
////////// conditions & order
$sql .= $limit_str;
$data = $this->db->fetchAll($sql);
return $data;
}*/
/**
* Runs a direct query against the bound DataSource, and returns the result
*
@ -1066,6 +1038,7 @@ class Model extends Object
* Returns number of rows matching given SQL condition.
*
* @param string $conditions SQL conditions (WHERE clause conditions)
* @param int $recursize The number of levels deep to fetch associated records
* @return int Number of matching rows
*/
function findCount ($conditions = null, $recursive = 0)
@ -1082,11 +1055,11 @@ class Model extends Object
* Special findAll variation for tables joined to themselves.
* The table needs fields id and parent_id to work.
*
* @todo Perhaps create a Component with this logic, according to a thought from Michal, its author. -OJ 22 nov 2005
* @param array $conditions Conditions for the findAll() call
* @param array $fields Fields for the findAll() call
* @param string $sort SQL ORDER BY statement
* @return unknown
* @todo Perhaps create a Component with this logic
*/
function findAllThreaded ($conditions=null, $fields=null, $sort=null)
{
@ -1287,15 +1260,18 @@ class Model extends Object
/**
* Escapes the field name and prepends the model name
*
* @param unknown_type $field
* @return string The name of the escaped field for this Model (i.e. id becomes `Post`.`id`).
*/
function escapeField($field)
{
return $this->db->name($this->name).'.'.$this->db->name($field);
}
/**
* Returns the current record's ID
*
* @param unknown_type $list
* @return mixed The ID of the current record
*/
function getID($list = 0)
@ -1383,6 +1359,7 @@ class Model extends Object
/**
* Before find callback
*
* @param unknown_type $conditions
* @return boolean True if the operation should continue, false if it should abort
*/
function beforeFind($conditions)

View file

@ -428,6 +428,10 @@ class FormHelper extends Helper
{
$field['selectAttr']['DISABLED'] = true;
}
if(!isset( $field['options']))
{
$field['options'] = null;
}
$strFormFields = $strFormFields.$this->generateSelectDiv( $field['tagName'], $field['prompt'], $field['options'], $field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg'] );
break;
case "area";