mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
[1335]
Author: phpnut Date: 2:11:57 PM, Saturday, November 05, 2005 Message: Fixing Controller::generateFieldNames() to work with changes to Model [1334] Author: phpnut Date: 1:18:02 PM, Saturday, November 05, 2005 Message: More work on changes made in the model to allow association names to be used as an alias. These changes are being made to update scaffold to work with changes in [1330]. Added var $alias that holds an array with the key value pair of the table name and the association name. [1330] Author: phpnut Date: 10:25:16 PM, Friday, November 04, 2005 Message: Adding fix for Ticket #127. The query returns properly now but, this breaks scaffold which I will be fixing soon. Also the save methods for the model have not been tested but I am sure these need to be corrected also. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1336 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b50276f976
commit
94e5730b41
7 changed files with 106 additions and 95 deletions
|
@ -564,6 +564,7 @@ class Controller extends Object
|
||||||
$model = $this->modelClass;
|
$model = $this->modelClass;
|
||||||
$modelKey = $this->modelKey;
|
$modelKey = $this->modelKey;
|
||||||
$table = $this->{$model}->table;
|
$table = $this->{$model}->table;
|
||||||
|
$association = array_search($table,$this->{$model}->alias);
|
||||||
|
|
||||||
$classRegistry =& ClassRegistry::getInstance();
|
$classRegistry =& ClassRegistry::getInstance();
|
||||||
$objRegistryModel = $classRegistry->getObject($modelKey);
|
$objRegistryModel = $classRegistry->getObject($modelKey);
|
||||||
|
@ -580,12 +581,13 @@ class Controller extends Object
|
||||||
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName);
|
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName);
|
||||||
// this is a foreign key, also set up the other controller
|
// this is a foreign key, also set up the other controller
|
||||||
$fieldNames[ $tabl['name'] ]['table'] = Inflector::pluralize($niceName);
|
$fieldNames[ $tabl['name'] ]['table'] = Inflector::pluralize($niceName);
|
||||||
|
$association = array_search($fieldNames[ $tabl['name'] ]['table'],$this->{$model}->alias);
|
||||||
if($this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] == $model)
|
if($this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] == $model)
|
||||||
{
|
{
|
||||||
$alias = 'Child_';
|
$alias = 'Child_';
|
||||||
}
|
}
|
||||||
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName);
|
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName);
|
||||||
$fieldNames[ $tabl['name'] ]['model'] = $alias.$this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']];
|
$fieldNames[ $tabl['name'] ]['model'] = $alias.$association;
|
||||||
$fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']];
|
$fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']];
|
||||||
$fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($niceName)]);
|
$fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($niceName)]);
|
||||||
$fieldNames[ $tabl['name'] ]['foreignKey'] = true;
|
$fieldNames[ $tabl['name'] ]['foreignKey'] = true;
|
||||||
|
@ -666,14 +668,15 @@ class Controller extends Object
|
||||||
{
|
{
|
||||||
foreach( $pass as $key=>$value )
|
foreach( $pass as $key=>$value )
|
||||||
{
|
{
|
||||||
if( $alias.$key == $fieldNames[ $tabl['name']]['model'] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) )
|
|
||||||
|
if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) )
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField];
|
$fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$fieldNames[ $tabl['name']]['selected'] = $data[$table][$tabl['name']];
|
$fieldNames[ $tabl['name']]['selected'] = $data[$association][$tabl['name']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -728,7 +731,7 @@ class Controller extends Object
|
||||||
{
|
{
|
||||||
foreach( $pass as $key=>$value )
|
foreach( $pass as $key=>$value )
|
||||||
{
|
{
|
||||||
if( $alias.$key == $fieldNames[ $tabl['name']]['model'] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) )
|
if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) )
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField];
|
$fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField];
|
||||||
}
|
}
|
||||||
|
@ -779,8 +782,8 @@ class Controller extends Object
|
||||||
// loop through the many to many relations to make a list box.
|
// loop through the many to many relations to make a list box.
|
||||||
foreach( $objRegistryModel->_manyToMany as $relation )
|
foreach( $objRegistryModel->_manyToMany as $relation )
|
||||||
{
|
{
|
||||||
list($modelName) = $relation;
|
//list($modelName) = $relation;
|
||||||
|
list($manyAssociation, $modelName, $value) = $relation;
|
||||||
$modelKeyM = Inflector::underscore($modelName);
|
$modelKeyM = Inflector::underscore($modelName);
|
||||||
$modelObject = new $modelName();
|
$modelObject = new $modelName();
|
||||||
|
|
||||||
|
@ -790,7 +793,7 @@ class Controller extends Object
|
||||||
$fieldNames[$modelKeyM]['model'] = $modelName;
|
$fieldNames[$modelKeyM]['model'] = $modelName;
|
||||||
$fieldNames[$modelKeyM]['prompt'] = "Related ".Inflector::humanize(Inflector::pluralize($modelName));
|
$fieldNames[$modelKeyM]['prompt'] = "Related ".Inflector::humanize(Inflector::pluralize($modelName));
|
||||||
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
||||||
$fieldNames[$modelKeyM]['tagName'] = $modelName.'/'.$modelName;
|
$fieldNames[$modelKeyM]['tagName'] = $manyAssociation.'/'.$manyAssociation;
|
||||||
|
|
||||||
foreach( $modelObject->findAll() as $pass )
|
foreach( $modelObject->findAll() as $pass )
|
||||||
{
|
{
|
||||||
|
@ -802,9 +805,9 @@ class Controller extends Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( isset( $data[$modelName] ) )
|
if( isset( $data[$manyAssociation] ) )
|
||||||
{
|
{
|
||||||
foreach( $data[$modelName] as $key => $row )
|
foreach( $data[$manyAssociation] as $key => $row )
|
||||||
{
|
{
|
||||||
$fieldNames[$modelKeyM]['selected'][$row['id']] = $row['id'];
|
$fieldNames[$modelKeyM]['selected'][$row['id']] = $row['id'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -409,45 +409,45 @@ class Scaffold extends Object {
|
||||||
*/
|
*/
|
||||||
function _cleanUpFields()
|
function _cleanUpFields()
|
||||||
{
|
{
|
||||||
$modelKey = Inflector::underscore($this->modelKey);
|
|
||||||
foreach( $this->controllerClass->{$this->modelKey}->_tableInfo as $table )
|
foreach( $this->controllerClass->{$this->modelKey}->_tableInfo as $table )
|
||||||
{
|
{
|
||||||
foreach ($table as $field)
|
foreach ($table as $field)
|
||||||
{
|
{
|
||||||
if('date' == $field['type'] && isset($this->controllerClass->params['data'][$modelKey][$field['name'].'_year']))
|
if('date' == $field['type'] && isset($this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year']))
|
||||||
{
|
{
|
||||||
$newDate = mktime( 0,0,0,
|
$newDate = mktime( 0,0,0,
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_month'],
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_month'],
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_day'],
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_day'],
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] );
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] );
|
||||||
$newDate = date( 'Y-m-d', $newDate );
|
$newDate = date( 'Y-m-d', $newDate );
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name']] = $newDate;
|
$this->controllerClass->params['data'][$this->modelKey][$field['name']] = $newDate;
|
||||||
}
|
}
|
||||||
else if( 'datetime' == $field['type'] && isset($this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] ) )
|
else if( 'datetime' == $field['type'] && isset($this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] ) )
|
||||||
{
|
{
|
||||||
$hour = $this->controllerClass->params['data'][$modelKey][$field['name'].'_hour'];
|
$hour = $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_hour'];
|
||||||
if( $hour != 12 && 'pm' == $this->controllerClass->params['data'][$modelKey][$field['name'].'_meridian'] )
|
if( $hour != 12 && 'pm' == $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_meridian'] )
|
||||||
{
|
{
|
||||||
$hour = $hour + 12;
|
$hour = $hour + 12;
|
||||||
}
|
}
|
||||||
$newDate = mktime( $hour,
|
$newDate = mktime( $hour,
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_min'],0,
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_min'],0,
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_month'],
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_month'],
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_day'],
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_day'],
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] );
|
$this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] );
|
||||||
$newDate = date( 'Y-m-d H:i:s', $newDate );
|
$newDate = date( 'Y-m-d H:i:s', $newDate );
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name']] = $newDate;
|
$this->controllerClass->params['data'][$this->modelKey][$field['name']] = $newDate;
|
||||||
}
|
}
|
||||||
else if( 'tinyint(1)' == $field['type'] )
|
else if( 'tinyint(1)' == $field['type'] )
|
||||||
{
|
{
|
||||||
if( isset( $this->controllerClass->params['data'][$modelKey][$field['name']]) &&
|
if( isset( $this->controllerClass->params['data'][$this->modelKey][$field['name']]) &&
|
||||||
"on" == $this->controllerClass->params['data'][$modelKey][$field['name']] )
|
"on" == $this->controllerClass->params['data'][$this->modelKey][$field['name']] )
|
||||||
{
|
{
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name']] = true;
|
$this->controllerClass->params['data'][$this->modelKey][$field['name']] = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->controllerClass->params['data'][$modelKey][$field['name']] = false;
|
$this->controllerClass->params['data'][$this->modelKey][$field['name']] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,17 +61,17 @@
|
||||||
<?php
|
<?php
|
||||||
if( isset($value['foreignKey']) )
|
if( isset($value['foreignKey']) )
|
||||||
{
|
{
|
||||||
|
|
||||||
// this is a foreign key, figure out what the display field should be for this model.
|
// this is a foreign key, figure out what the display field should be for this model.
|
||||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
$otherModelKey = Inflector::underscore($value['modelKey']);
|
||||||
$otherControllerName = $value['controller'];
|
$otherControllerName = $value['controller'];
|
||||||
$registry = ClassRegistry::getInstance();
|
$registry = ClassRegistry::getInstance();
|
||||||
$otherModelObject = $registry->getObject( $otherModelKey );
|
$otherModelObject = $registry->getObject( $otherModelKey );
|
||||||
|
$alias = array_search($value['table'],$this->controller->{$model}->alias);
|
||||||
if( is_object($otherModelObject) )
|
if( is_object($otherModelObject) )
|
||||||
{
|
{
|
||||||
$displayText = $row[$value['model']][ $otherModelObject->getDisplayField() ];
|
$displayText = $row[$alias][ $otherModelObject->getDisplayField() ];
|
||||||
} else{
|
} else{
|
||||||
$displayText = $row[$value['model']][$field];
|
$displayText = $row[$alias][$field];
|
||||||
}
|
}
|
||||||
echo $html->linkTo( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
|
echo $html->linkTo( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,10 @@
|
||||||
echo "<dt>".$value['prompt']."</dt>";
|
echo "<dt>".$value['prompt']."</dt>";
|
||||||
if(isset($value['foreignKey']))
|
if(isset($value['foreignKey']))
|
||||||
{
|
{
|
||||||
|
$alias = array_search($value['table'],$objModel->alias);
|
||||||
$otherModelObject = $registry->getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
|
$otherModelObject = $registry->getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
|
||||||
$displayField = $otherModelObject->getDisplayField();
|
$displayField = $otherModelObject->getDisplayField();
|
||||||
$displayText = $data[$objModel->tableToModel[$value['table']]][$displayField];
|
$displayText = $data[$alias][$displayField];
|
||||||
|
|
||||||
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]))
|
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]))
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
foreach( $fieldNames as $field => $value ) {
|
foreach( $fieldNames as $field => $value ) {
|
||||||
if( isset( $value['foreignKey'] ) )
|
if( isset( $value['foreignKey'] ) )
|
||||||
{
|
{
|
||||||
echo "<li>".$html->linkTo( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$objModel->tableToModel[$value['table']]]['id'] )."</li>";
|
echo "<li>".$html->linkTo( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$alias]['id'] )."</li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -94,15 +94,15 @@
|
||||||
<?php
|
<?php
|
||||||
foreach ($objModel->_oneToOne as $relation)
|
foreach ($objModel->_oneToOne as $relation)
|
||||||
{
|
{
|
||||||
list($model, $value) = $relation;
|
list($association, $model, $value) = $relation;
|
||||||
$otherModelName = $objModel->tableToModel[$model];
|
$otherModelName = $objModel->tableToModel[$model];
|
||||||
$controller = Inflector::pluralize($model);
|
$controller = Inflector::pluralize($model);
|
||||||
|
|
||||||
echo "<div class='related'><H2>Related ".Inflector::humanize($otherModelName)."</H2>";
|
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
||||||
echo "<dl>";
|
echo "<dl>";
|
||||||
if( isset($data[$otherModelName]) && is_array($data[$otherModelName]) )
|
if( isset($data[$association]) && is_array($data[$association]) )
|
||||||
{
|
{
|
||||||
foreach( $data[$otherModelName] as $field=>$value )
|
foreach( $data[$association] as $field=>$value )
|
||||||
{
|
{
|
||||||
echo "<dt>".Inflector::humanize($field)."</dt>";
|
echo "<dt>".Inflector::humanize($field)."</dt>";
|
||||||
if( !empty($value) )
|
if( !empty($value) )
|
||||||
|
@ -115,7 +115,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
echo "</dl>";
|
echo "</dl>";
|
||||||
echo "<ul class='actions'><li>".$html->linkTo('Edit '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/edit/{$data[$otherModelName]['id']}")."</li></ul></div>";
|
echo "<ul class='actions'><li>".$html->linkTo('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association]['id']}")."</li></ul></div>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -134,13 +134,13 @@
|
||||||
|
|
||||||
foreach( $relations as $relation )
|
foreach( $relations as $relation )
|
||||||
{
|
{
|
||||||
list($model, $value) = $relation;
|
list($association, $model, $value) = $relation;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$otherModelName = Inflector::singularize($model);
|
$otherModelName = Inflector::singularize($model);
|
||||||
$controller = Inflector::pluralize($model);
|
$controller = Inflector::pluralize($model);
|
||||||
|
|
||||||
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($objModel->tableToModel[$objModel->{$model}->table]))."</H2>";
|
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($association))."</H2>";
|
||||||
if( isset($data[$objModel->tableToModel[$objModel->{$model}->table]]) && is_array($data[$objModel->tableToModel[$objModel->{$model}->table]]) )
|
if( isset($data[$association]) && is_array($data[$association]) )
|
||||||
{
|
{
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@
|
||||||
<?php // Loop through and create the header row.
|
<?php // Loop through and create the header row.
|
||||||
// find a row that matches this title.
|
// find a row that matches this title.
|
||||||
$bFound = false;
|
$bFound = false;
|
||||||
foreach( $data[$objModel->tableToModel[$objModel->{$model}->table]][0] as $column=>$value ) {
|
foreach( $data[$association][0] as $column=>$value ) {
|
||||||
echo "<th>".Inflector::humanize($column)."</th>";
|
echo "<th>".Inflector::humanize($column)."</th>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -157,7 +157,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
// now find all matching rows
|
// now find all matching rows
|
||||||
foreach( $data[$objModel->tableToModel[$objModel->$model->table]] as $row )
|
foreach( $data[$association] as $row )
|
||||||
{
|
{
|
||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
foreach( $row as $column=>$value )
|
foreach( $row as $column=>$value )
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
<?php
|
<?php
|
||||||
// add a link to create a new relation.
|
// add a link to create a new relation.
|
||||||
|
|
||||||
echo "<li>".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/add/")."</li>";
|
echo "<li>".$html->linkTo('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/")."</li>";
|
||||||
// echo "<li>".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."</li>";
|
// echo "<li>".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."</li>";
|
||||||
?>
|
?>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
|
|
|
@ -189,6 +189,13 @@ class Model extends Object
|
||||||
*/
|
*/
|
||||||
var $tableToModel = array();
|
var $tableToModel = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $alias = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Binds the Model's database table to the object.
|
* Constructor. Binds the Model's database table to the object.
|
||||||
*
|
*
|
||||||
|
@ -287,7 +294,7 @@ class Model extends Object
|
||||||
foreach ($this->belongsTo as $association => $associationValue)
|
foreach ($this->belongsTo as $association => $associationValue)
|
||||||
{
|
{
|
||||||
$className = $association;
|
$className = $association;
|
||||||
$this->_associationSwitch($className, $associationValue, 'Belongs');
|
$this->_associationSwitch($association, $className, $associationValue, 'Belongs');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -296,7 +303,7 @@ class Model extends Object
|
||||||
foreach ($association as $className)
|
foreach ($association as $className)
|
||||||
{
|
{
|
||||||
$this->_constructAssociatedModels($className , 'Belongs');
|
$this->_constructAssociatedModels($className , 'Belongs');
|
||||||
$this->linkAssociation('Belongs', $className, $this->id);
|
$this->linkAssociation('Belongs', $className, $className, $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,7 +320,7 @@ class Model extends Object
|
||||||
foreach ($this->hasOne as $association => $associationValue)
|
foreach ($this->hasOne as $association => $associationValue)
|
||||||
{
|
{
|
||||||
$className = $association;
|
$className = $association;
|
||||||
$this->_associationSwitch($className, $associationValue, 'One');
|
$this->_associationSwitch($className, $className, $associationValue, 'One');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -322,7 +329,7 @@ class Model extends Object
|
||||||
foreach ($association as $className)
|
foreach ($association as $className)
|
||||||
{
|
{
|
||||||
$this->_constructAssociatedModels($className , 'One');
|
$this->_constructAssociatedModels($className , 'One');
|
||||||
$this->linkAssociation('One', $className, $this->id);
|
$this->linkAssociation('One', $className, $className, $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,7 +346,7 @@ class Model extends Object
|
||||||
foreach ($this->hasMany as $association => $associationValue)
|
foreach ($this->hasMany as $association => $associationValue)
|
||||||
{
|
{
|
||||||
$className = $association;
|
$className = $association;
|
||||||
$this->_associationSwitch($className, $associationValue, 'Many');
|
$this->_associationSwitch($association, $className, $associationValue, 'Many');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -348,7 +355,7 @@ class Model extends Object
|
||||||
foreach ($association as $className)
|
foreach ($association as $className)
|
||||||
{
|
{
|
||||||
$this->_constructAssociatedModels($className , 'Many');
|
$this->_constructAssociatedModels($className , 'Many');
|
||||||
$this->linkAssociation('Many', $className, $this->id);
|
$this->linkAssociation('Many', $className, $className, $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +372,7 @@ class Model extends Object
|
||||||
foreach ($this->hasAndBelongsToMany as $association => $associationValue)
|
foreach ($this->hasAndBelongsToMany as $association => $associationValue)
|
||||||
{
|
{
|
||||||
$className = $association;
|
$className = $association;
|
||||||
$this->_associationSwitch($className, $associationValue, 'ManyTo');
|
$this->_associationSwitch($association, $className, $associationValue, 'ManyTo');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -374,7 +381,7 @@ class Model extends Object
|
||||||
foreach ($association as $className)
|
foreach ($association as $className)
|
||||||
{
|
{
|
||||||
$this->_constructAssociatedModels($className , 'ManyTo');
|
$this->_constructAssociatedModels($className , 'ManyTo');
|
||||||
$this->linkAssociation('ManyTo', $className, $this->id);
|
$this->linkAssociation('ManyTo', $className, $className, $this->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,7 +394,7 @@ class Model extends Object
|
||||||
* @param unknown_type $type
|
* @param unknown_type $type
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _associationSwitch($className, $associationValue, $type)
|
function _associationSwitch($association, $className, $associationValue, $type)
|
||||||
{
|
{
|
||||||
$classCreated = false;
|
$classCreated = false;
|
||||||
|
|
||||||
|
@ -463,7 +470,7 @@ class Model extends Object
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->linkAssociation($type, $className, $this->id);
|
$this->linkAssociation($type, $association, $className, $this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -543,24 +550,28 @@ class Model extends Object
|
||||||
* @param unknown_type $tableName
|
* @param unknown_type $tableName
|
||||||
* @param unknown_type $value
|
* @param unknown_type $value
|
||||||
*/
|
*/
|
||||||
function linkAssociation ($type, $model, $value=null)
|
function linkAssociation ($type, $association, $model, $value=null)
|
||||||
{
|
{
|
||||||
switch ($type)
|
switch ($type)
|
||||||
{
|
{
|
||||||
case 'Belongs':
|
case 'Belongs':
|
||||||
$this->_belongsToOther[] = array($model, $value);
|
$this->alias[$association] = $this->{$model}->table;
|
||||||
|
$this->_belongsToOther[] = array($association, $model, $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'One':
|
case 'One':
|
||||||
$this->_oneToOne[] = array($model, $value);
|
$this->alias[$association] = $this->{$model}->table;
|
||||||
|
$this->_oneToOne[] = array($association, $model, $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Many':
|
case 'Many':
|
||||||
$this->_oneToMany[] = array($model, $value);
|
$this->alias[$association] = $this->{$model}->table;
|
||||||
|
$this->_oneToMany[] = array($association, $model, $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ManyTo':
|
case 'ManyTo':
|
||||||
$this->_manyToMany[] = array($model, $value);
|
$this->alias[$association] = $this->{$model}->table;
|
||||||
|
$this->_manyToMany[] = array($association, $model, $value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -728,7 +739,7 @@ class Model extends Object
|
||||||
*/
|
*/
|
||||||
function saveField($name, $value)
|
function saveField($name, $value)
|
||||||
{
|
{
|
||||||
return Model::save(array($this->table=>array($name=>$value)), false);
|
return Model::save(array($this->name=>array($name=>$value)), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1041,16 +1052,16 @@ class Model extends Object
|
||||||
{
|
{
|
||||||
foreach ($this->_oneToOne as $rule)
|
foreach ($this->_oneToOne as $rule)
|
||||||
{
|
{
|
||||||
list($model, $value) = $rule;
|
list($association, $model, $value) = $rule;
|
||||||
if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'}))
|
if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'}))
|
||||||
{
|
{
|
||||||
if($this->name == $this->{$model}->name)
|
if($this->name == $this->{$model}->name)
|
||||||
{
|
{
|
||||||
$alias = 'Child_'.$this->{$model}->name;
|
$alias = 'Child_'.$association;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$alias = $this->{$model}->name;
|
$alias = $association;
|
||||||
}
|
}
|
||||||
$oneToOneConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
$oneToOneConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
||||||
$oneToOneOrder = $this->{$model}->{$this->currentModel.'_order'};
|
$oneToOneOrder = $this->{$model}->{$this->currentModel.'_order'};
|
||||||
|
@ -1067,17 +1078,16 @@ class Model extends Object
|
||||||
{
|
{
|
||||||
foreach ($this->_belongsToOther as $rule)
|
foreach ($this->_belongsToOther as $rule)
|
||||||
{
|
{
|
||||||
list($model, $value) = $rule;
|
list($association, $model, $value) = $rule;
|
||||||
|
|
||||||
if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'}))
|
if(!empty($this->{$model}->{$this->currentModel.'_foreignkey'}))
|
||||||
{
|
{
|
||||||
if($this->name == $this->{$model}->name)
|
if($this->name == $this->{$model}->name)
|
||||||
{
|
{
|
||||||
$alias = 'Child_'.$this->{$model}->name;
|
$alias = 'Child_'.$association;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$alias = $this->{$model}->name;
|
$alias = $association;
|
||||||
}
|
}
|
||||||
$belongsToOtherConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
$belongsToOtherConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
||||||
$belongsToOtherOrder = $this->{$model}->{$this->currentModel.'_order'};
|
$belongsToOtherOrder = $this->{$model}->{$this->currentModel.'_order'};
|
||||||
|
@ -1141,8 +1151,7 @@ class Model extends Object
|
||||||
foreach ($this->_oneToMany as $rule)
|
foreach ($this->_oneToMany as $rule)
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
list($model, $value) = $rule;
|
list($association, $model, $value) = $rule;
|
||||||
|
|
||||||
foreach ($datacheck as $key => $value1)
|
foreach ($datacheck as $key => $value1)
|
||||||
{
|
{
|
||||||
foreach ($value1 as $key2 => $value2)
|
foreach ($value1 as $key2 => $value2)
|
||||||
|
@ -1158,24 +1167,24 @@ class Model extends Object
|
||||||
$oneToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
$oneToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
||||||
$oneToManyOrder = $this->{$model}->{$this->currentModel.'_order'};
|
$oneToManyOrder = $this->{$model}->{$this->currentModel.'_order'};
|
||||||
|
|
||||||
$tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$this->{$model}->name}`
|
$tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$association}`
|
||||||
WHERE ({$this->{$model}->{$this->currentModel.'_foreignkey'}}) = '{$value2['id']}'"
|
WHERE ({$this->{$model}->{$this->currentModel.'_foreignkey'}}) = '{$value2['id']}'"
|
||||||
.($oneToManyConditions? " WHERE {$oneToManyConditions}":null)
|
.($oneToManyConditions? " WHERE {$oneToManyConditions}":null)
|
||||||
.($oneToManyOrder? " ORDER BY {$oneToManyOrder}": null);
|
.($oneToManyOrder? " ORDER BY {$oneToManyOrder}": null);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oneToManySelect[$this->{$model}->name] = $this->db->all($tmpSQL);
|
$oneToManySelect[$association] = $this->db->all($tmpSQL);
|
||||||
|
|
||||||
if( !empty($oneToManySelect[$this->{$model}->name]) && is_array($oneToManySelect[$this->{$model}->name]))
|
if( !empty($oneToManySelect[$association]) && is_array($oneToManySelect[$association]))
|
||||||
{
|
{
|
||||||
$newKey = $this->{$model}->name;
|
$newKey = $association;
|
||||||
foreach ($oneToManySelect[$this->{$model}->name] as $key => $value)
|
foreach ($oneToManySelect[$association] as $key => $value)
|
||||||
{
|
{
|
||||||
$oneToManySelect1[$newKey][$key] = $value[$newKey];
|
$oneToManySelect1[$newKey][$key] = $value[$newKey];
|
||||||
}
|
}
|
||||||
$merged = array_merge_recursive($data[$count],$oneToManySelect1);
|
$merged = array_merge_recursive($data[$count],$oneToManySelect1);
|
||||||
$newdata[$count] = $merged;
|
$newdata[$count] = $merged;
|
||||||
unset( $oneToManySelect[$this->{$model}->name], $oneToManySelect1);
|
unset( $oneToManySelect[$association], $oneToManySelect1);
|
||||||
}
|
}
|
||||||
if(!empty($newdata[$count]))
|
if(!empty($newdata[$count]))
|
||||||
{
|
{
|
||||||
|
@ -1219,8 +1228,7 @@ class Model extends Object
|
||||||
foreach ($this->_manyToMany as $rule)
|
foreach ($this->_manyToMany as $rule)
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
list($model, $value) = $rule;
|
list($association, $model, $value) = $rule;
|
||||||
|
|
||||||
foreach ($datacheck as $key => $value1)
|
foreach ($datacheck as $key => $value1)
|
||||||
{
|
{
|
||||||
foreach ($value1 as $key2 => $value2)
|
foreach ($value1 as $key2 => $value2)
|
||||||
|
@ -1240,29 +1248,29 @@ class Model extends Object
|
||||||
$manyToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
$manyToManyConditions = $this->parseConditions($this->{$model}->{$this->currentModel.'_conditions'});
|
||||||
$manyToManyOrder = $this->{$model}->{$this->currentModel.'_order'};
|
$manyToManyOrder = $this->{$model}->{$this->currentModel.'_order'};
|
||||||
|
|
||||||
$tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$this->{$model}->name}`
|
$tmpSQL = "SELECT {$this->{$model}->{$this->currentModel.'_fields'}} FROM {$this->{$model}->table} AS `{$association}`
|
||||||
JOIN {$this->{$model}->{$this->currentModel.'_jointable'}}
|
JOIN {$this->{$model}->{$this->currentModel.'_jointable'}}
|
||||||
ON {$this->{$model}->{$this->currentModel.'_jointable'}}.
|
ON {$this->{$model}->{$this->currentModel.'_jointable'}}.
|
||||||
{$this->{$model}->{$this->currentModel.'_foreignkey'}} = '$value2[id]'
|
{$this->{$model}->{$this->currentModel.'_foreignkey'}} = '$value2[id]'
|
||||||
AND {$this->{$model}->{$this->currentModel.'_jointable'}}.
|
AND {$this->{$model}->{$this->currentModel.'_jointable'}}.
|
||||||
{$this->{$model}->{$this->currentModel.'_associationforeignkey'}} = `{$this->{$model}->name}` .id"
|
{$this->{$model}->{$this->currentModel.'_associationforeignkey'}} = `{$association}` .id"
|
||||||
.($manyToManyConditions? " WHERE {$manyToManyConditions}":null)
|
.($manyToManyConditions? " WHERE {$manyToManyConditions}":null)
|
||||||
.($manyToManyOrder? " ORDER BY {$manyToManyOrder}": null);
|
.($manyToManyOrder? " ORDER BY {$manyToManyOrder}": null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$manyToManySelect[$this->{$model}->name] = $this->db->all($tmpSQL);
|
$manyToManySelect[$association] = $this->db->all($tmpSQL);
|
||||||
}
|
}
|
||||||
if( !empty($manyToManySelect[$this->{$model}->name]) && is_array($manyToManySelect[$this->{$model}->name]))
|
if( !empty($manyToManySelect[$association]) && is_array($manyToManySelect[$association]))
|
||||||
{
|
{
|
||||||
$newKey = $this->{$model}->name;
|
$newKey = $association;
|
||||||
foreach ($manyToManySelect[$this->{$model}->name] as $key => $value)
|
foreach ($manyToManySelect[$association] as $key => $value)
|
||||||
{
|
{
|
||||||
$manyToManySelect1[$newKey][$key] = $value[$newKey];
|
$manyToManySelect1[$newKey][$key] = $value[$newKey];
|
||||||
}
|
}
|
||||||
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
|
$merged = array_merge_recursive($data[$count],$manyToManySelect1);
|
||||||
$newdata[$count] = $merged;
|
$newdata[$count] = $merged;
|
||||||
unset( $manyToManySelect[$this->{$model}->name], $manyToManySelect1 );
|
unset( $manyToManySelect[$association], $manyToManySelect1 );
|
||||||
}
|
}
|
||||||
if(!empty($newdata[$count]))
|
if(!empty($newdata[$count]))
|
||||||
{
|
{
|
||||||
|
@ -1273,22 +1281,20 @@ class Model extends Object
|
||||||
}
|
}
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
if(empty($newValue2) && !empty($original))
|
if(empty($newValue) && !empty($original))
|
||||||
{
|
{
|
||||||
for ($i = 0; $i< count($original); $i++)
|
$originalCount = count($original);
|
||||||
|
for ($i = 0; $i< $originalCount; $i++)
|
||||||
{
|
{
|
||||||
$newValue2[$i] = $original[$i];
|
$newValue[$i] = $original[$i];
|
||||||
}
|
|
||||||
if(count($this->_manyToMany < 2))
|
|
||||||
{
|
|
||||||
$newValue = $newValue2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif(!empty($original))
|
elseif(!empty($original))
|
||||||
{
|
{
|
||||||
for ($i = 0; $i< count($original); $i++)
|
$originalCount = count($original);
|
||||||
|
for ($i = 0; $i< $originalCount; $i++)
|
||||||
{
|
{
|
||||||
$newValue[$i] = array_merge($newValue2[$i], $original[$i]);
|
$newValue[$i] = array_merge($newValue[$i], $original[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1481,7 +1487,7 @@ class Model extends Object
|
||||||
|
|
||||||
foreach ($this->_belongsToOther as $rule)
|
foreach ($this->_belongsToOther as $rule)
|
||||||
{
|
{
|
||||||
list($model, $value) = $rule;
|
list($association, $model, $value) = $rule;
|
||||||
$foreignKeys[$this->{$model}->{$this->currentModel.'_foreignkey'}] = $this->{$model}->{$this->currentModel.'_foreignkey'};
|
$foreignKeys[$this->{$model}->{$this->currentModel.'_foreignkey'}] = $this->{$model}->{$this->currentModel.'_foreignkey'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,6 +367,7 @@ class CakeSession extends Object
|
||||||
ini_set('session.name', CAKE_SESSION_COOKIE);
|
ini_set('session.name', CAKE_SESSION_COOKIE);
|
||||||
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
|
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
|
||||||
ini_set('session.cookie_path', $this->path);
|
ini_set('session.cookie_path', $this->path);
|
||||||
|
ini_set('session.gc_probability', 1);
|
||||||
ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60);
|
ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60);
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
@ -380,6 +381,7 @@ class CakeSession extends Object
|
||||||
ini_set('session.name', CAKE_SESSION_COOKIE);
|
ini_set('session.name', CAKE_SESSION_COOKIE);
|
||||||
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
|
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
|
||||||
ini_set('session.cookie_path', $this->path);
|
ini_set('session.cookie_path', $this->path);
|
||||||
|
ini_set('session.gc_probability', 1);
|
||||||
ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60);
|
ini_set('session.gc_maxlifetime', Security::inactiveMins() * 60);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
<?php if(is_object($this->controller->Session)){$this->controller->Session->flash();} ?>
|
<?php $this->controller->Session->flash(); ?>
|
||||||
<?php echo $content_for_layout?>
|
<?php echo $content_for_layout?>
|
||||||
</div>
|
</div>
|
||||||
<div id="pb-cake">
|
<div id="pb-cake">
|
||||||
|
|
Loading…
Add table
Reference in a new issue