merging changes from [619] [620] [622] [623] and [630]

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@632 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-08-22 02:48:37 +00:00
parent e2af5c8608
commit 650c85809a
7 changed files with 119 additions and 16 deletions

View file

@ -10,6 +10,10 @@
<body>
<div id="main">
<?=$content_for_layout?>
<p>
<a id="logo" href="http://www.cakephp.org/" target="_new"><img src="/img/pbcake.gif" width="120" height="28" alt="CakePHP : Rapid Development Framework" /></a>
</p>
</div>
</body>
</html>

View file

@ -62,6 +62,9 @@ radio = "<input type="radio" name="data[%s][%s]" id="tag_%s"%s/>"
; Tag template for a select opening tag.
selectStart = "<select name="data[%s][%s]"%s>"
; Tag template for a select opening tag.
selectMultipleStart = "<select name="data[%s][%s][]"%s>"
; Tag template for an empty select option tag.
selectEmpty = "<option value=""%s></option>"

View file

@ -695,7 +695,7 @@ class Controller extends Object
$fieldNames[$tableName]['model'] = $tableName;
$fieldNames[$tableName]['prompt'] = "Related ".Inflector::humanize($tableName);
$fieldNames[$tableName]['type'] = "selectMultiple";
$fieldNames[$tableName]['tagName'] = $tableName;
$fieldNames[$tableName]['tagName'] = $otherModelName.'/'.$tableName;
foreach( $otherModel->findAll() as $pass )
{

View file

@ -995,13 +995,19 @@ class HtmlHelper extends Helper
if (!is_array($option_elements) || !count($option_elements))
return null;
$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($select_attr));
if( isset($select_attr) && array_key_exists( "multiple", $select_attr) )
{
$select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($select_attr));
}
else
{
$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($select_attr));
}
$select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));
foreach ($option_elements as $name=>$title)
{
$options_here = $optionAttr;
if ($selected == $name)
{
$options_here['selected'] = 'selected';

View file

@ -804,7 +804,7 @@ class Model extends Object
*/
function setId ($id)
{
$this->id = $id;
$this->id[0] = $id;
if(!empty($this->_belongsToOther))
{
@ -866,9 +866,14 @@ class Model extends Object
function read ($fields=null)
{
$this->validationErrors = null;
//return $this->id? $this->find("id = '{$this->id}'", $fields): false;
if(is_array($this->id))
{
return $this->id? $this->find("$this->table.id = '{$this->id[0]}'", $fields): false;
}
else
{
return $this->id? $this->find("id = '{$this->id}'", $fields): false;
}
}
/**
@ -936,20 +941,45 @@ class Model extends Object
}
$fields = $values = array();
if(count($this->data) > 1)
{
$weHaveMulti = true;
$count = 0;
$joined = false;
}
else
{
$weHaveMulti = false;
}
foreach ($this->data as $n=>$v)
{
if(isset($weHaveMulti) && $count > 0)
{
$joined = array($v);
}
else
{
foreach ($v as $x => $y)
{
if ($this->hasField($x))
{
$fields[] = $x;
$values[] = $this->db->prepare($y);
}
}
if ($this->hasField($x))
{
$fields[] = $x;
$values[] = $this->db->prepare($y);
if($x == 'id' && !is_numeric($y))
{
$newID = $y;
}
}
}
$count++;
}
}
if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields))
{
$fields[] = 'created';
@ -976,9 +1006,13 @@ class Model extends Object
}
$sql = "UPDATE {$this->table} SET ".join(',', $sql)." WHERE id = '{$this->id}'";
if ($this->db->query($sql) && $this->db->lastAffected())
if ($this->db->query($sql)) // && $this->db->lastAffected())
{
if(!empty($joined))
{
$this->saveMulti($joined, $this->id);
}
$this->data = false;
return true;
}
@ -989,6 +1023,7 @@ class Model extends Object
}
else
{
$fields = join(',', $fields);
$values = join(',', $values);
@ -997,6 +1032,14 @@ class Model extends Object
if($this->db->query($sql))
{
$this->id = $this->db->lastInsertId($this->table, 'id');
if(!empty($joined))
{
if(!$this->id > 0)
{
$this->id = $newID;
}
$this->saveMulti($joined, $this->id);
}
return true;
}
else
@ -1012,6 +1055,49 @@ class Model extends Object
}
/**
* Saves model hasAndBelongsToMany data to the database.
*
* @param array $joined Data to save.
* @param string $id
* @return boolean success
*/
function saveMulti ($joined, $id)
{
$sql = array();
foreach ($joined as $x => $y)
{
foreach ($y as $name => $value)
{
$tableSort[0] = $this->table;
$tableSort[1] = $name;
sort($tableSort);
$joinTable = $tableSort[0] . '_' . $tableSort[1];
$key1 = Inflector::singularize($this->table) . '_id';
$key2 = Inflector::singularize($name) . '_id';
foreach ($value as $update)
{
$fields1[] = $key1;
$values1[] = $this->db->prepare($id);
$fields1[] = $key2;
$values1[] = $this->db->prepare($update);
$fields1 = join(',', $fields1);
$values1 = join(',', $values1);
$joinedSql[] = "INSERT INTO {$joinTable} ({$fields1}) VALUES ({$values1})";
unset($fields1);
unset($values1);
}
$this->db->query("DELETE FROM {$joinTable} WHERE $key1 = '{$id}'");
}
foreach ($joinedSql as $insert){
$this->db->query($insert);
}
}
}
/**
* Synonym for del().
*

View file

@ -325,4 +325,8 @@ form div.wide small {
div.date select {
width:auto;
}
option {
padding-left:1em;
}

BIN
public/img/pbcake.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB