mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
Merging fixes to trunk
Revision: [1809] Fixed self join code, may refactor after looking at it more. Currently it is working as expected. Fixed errors in scaffold view caused by the changes I made. Removed adding Child_ prefix to self joined associations. Revision: [1808] Adding changes I started on the self join code. Revision: [1807] Adding patch from Ticket #283. Changed doc comment in SessionComponent class. Added fix for Ticket #285 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1810 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
44cd92d739
commit
8a77108c44
7 changed files with 172 additions and 60 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.5.1806 RC 1
|
||||
0.10.5.1810 RC 1
|
|
@ -46,7 +46,7 @@ class Aco extends AclNode
|
|||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $hasMany = 'ArosAco,AcoActions';
|
||||
var $hasMany = 'ArosAco,AcoAction';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -153,9 +153,8 @@ class SessionComponent extends Object
|
|||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* Use like this. $this->Session->valid();
|
||||
* This will return true if session is valid
|
||||
* false if session is invalid
|
||||
* Use like this. $this->Session->renew();
|
||||
* This will renew sessions
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
|
@ -493,10 +493,6 @@ class Controller extends Object
|
|||
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($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)
|
||||
{
|
||||
$alias = 'Child_';
|
||||
}
|
||||
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName);
|
||||
$fieldNames[ $tabl['name'] ]['model'] = $alias.$association;
|
||||
$fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']];
|
||||
|
|
|
@ -338,9 +338,19 @@ class DboSource extends DataSource
|
|||
foreach($model->{$type} as $assoc => $assocData)
|
||||
{
|
||||
$linkModel =& $model->{$assocData['className']};
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
if($model->name == $linkModel->name)
|
||||
{
|
||||
$linkedModels[] = $type.$assoc;
|
||||
if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
$linkedModels[] = $type.$assoc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
$linkedModels[] = $type.$assoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -401,24 +411,84 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
|
||||
function generateSelfAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
|
||||
{
|
||||
$alias = $association;
|
||||
if(!isset($queryData['selfJoin']))
|
||||
{
|
||||
$queryData['selfJoin'] = array();
|
||||
|
||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])). ', ';
|
||||
$sql .= join(', ', $this->fields($linkModel, $alias, ''));
|
||||
$sql .= ' FROM '.$model->table.' AS ' . $model->name;
|
||||
$sql .= ' LEFT JOIN '.$linkModel->table.' AS ' . $alias;
|
||||
$sql .= ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= ' = '.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||
if (!in_array($sql, $queryData['selfJoin']))
|
||||
{
|
||||
$queryData['selfJoin'][] = $sql;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->joinFieldJoin))
|
||||
{
|
||||
$replace = ', ';
|
||||
$replace .= join(', ', $this->joinFieldJoin['fields']);
|
||||
$replace .= ' FROM';
|
||||
}
|
||||
else
|
||||
{
|
||||
$replace = 'FROM';
|
||||
}
|
||||
$sql = $queryData['selfJoin'][0];
|
||||
$sql .= ' ' . join(' ', $queryData['joins']);
|
||||
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
|
||||
$sql .= ' '.$this->limit($queryData['limit']);
|
||||
$result = preg_replace('/FROM/', $replace, $sql);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
|
||||
{
|
||||
$this->__scrubQueryData($queryData);
|
||||
if ($linkModel == null)
|
||||
{
|
||||
if(array_key_exists('selfJoin', $queryData))
|
||||
{
|
||||
return $this->generateSelfAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->joinFieldJoin))
|
||||
{
|
||||
$joinFields = ', ';
|
||||
$joinFields .= join(', ', $this->joinFieldJoin['fields']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$joinFields = null;
|
||||
}
|
||||
// Generates primary query
|
||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) . ' FROM ';
|
||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) .$joinFields. ' FROM ';
|
||||
$sql .= $this->name($model->table).' AS ';
|
||||
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
|
||||
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
|
||||
$sql .= ' '.$this->limit($queryData['limit']);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
$alias = $association;
|
||||
if($model->name == $linkModel->name)
|
||||
{
|
||||
// $alias = Inflector::pluralize($association);
|
||||
$joinedOnSelf = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$joinedOnSelf = false;
|
||||
}
|
||||
|
||||
switch ($type)
|
||||
|
@ -452,11 +522,23 @@ class DboSource extends DataSource
|
|||
}
|
||||
else
|
||||
{
|
||||
$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']);
|
||||
if($joinedOnSelf == true)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
$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;
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
@ -491,11 +573,22 @@ class DboSource extends DataSource
|
|||
}
|
||||
else
|
||||
{
|
||||
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
|
||||
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= '='.$linkModel->escapeField($linkModel->primaryKey);
|
||||
|
||||
if($joinedOnSelf == true)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isset($assocData['fields']))
|
||||
{
|
||||
$assocData['fields'] = '';
|
||||
}
|
||||
$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;
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
@ -798,4 +891,4 @@ class DboSource extends DataSource
|
|||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
|
@ -7,10 +7,10 @@
|
|||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
|
@ -37,17 +37,17 @@
|
|||
?>
|
||||
<table class="inav" cellspacing="0">
|
||||
<tr>
|
||||
<?php foreach ( $fieldNames as $fieldName ) { ?>
|
||||
<?php foreach ( $fieldNames as $fieldName ) { ?>
|
||||
<th><?php echo $fieldName['prompt'];?></th>
|
||||
<?php } ?>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
<?php
|
||||
$iRowIndex = 0;
|
||||
|
||||
if( is_array( $data ) )
|
||||
|
||||
if( is_array( $data ) )
|
||||
{
|
||||
foreach ( $data as $row ) {
|
||||
foreach ( $data as $row ) {
|
||||
if( $iRowIndex++ % 2 == 0 )
|
||||
{
|
||||
echo "<tr>";
|
||||
|
@ -57,23 +57,23 @@
|
|||
foreach( $fieldNames as $field=>$value ) { ?>
|
||||
<td>
|
||||
<?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.
|
||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
||||
$otherControllerName = $value['controller'];
|
||||
$otherModelObject = ClassRegistry::getObject( $otherModelKey );
|
||||
$alias = array_search($value['table'],$this->controller->{$model}->alias);
|
||||
if( is_object($otherModelObject) )
|
||||
if( is_object($otherModelObject) )
|
||||
{
|
||||
$displayText = $row[$alias][ $otherModelObject->getDisplayField() ];
|
||||
} else{
|
||||
$displayText = $row[$alias][$field];
|
||||
}
|
||||
}
|
||||
echo $html->link( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
|
||||
|
||||
|
||||
} else {
|
||||
echo $row[$modelKey][$field];
|
||||
echo $row[$modelKey][$field];
|
||||
} ?>
|
||||
</td>
|
||||
<?php } // end for each $fieldNames as $field=>value ?>
|
||||
|
@ -81,12 +81,12 @@
|
|||
<?php echo $html->link('Edit',"/".$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',"/".$this->viewPath."/destroy/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||
</td>
|
||||
|
||||
|
||||
</tr>
|
||||
<?php } // end for each data as row
|
||||
} // end if( $data )?>
|
||||
|
||||
|
||||
|
||||
|
||||
</table>
|
||||
<ul class="actions">
|
||||
<li><?php echo $html->link('New '.$humanSingularName, '/'.$this->viewPath.'/add'); ?></li>
|
||||
|
|
|
@ -93,28 +93,40 @@
|
|||
<?php
|
||||
foreach ($objModel->hasOne as $association => $relation)
|
||||
{
|
||||
$model = $relation['className'];
|
||||
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
|
||||
$controller = Inflector::pluralize($model);
|
||||
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
||||
echo "<dl>";
|
||||
if( isset($data[$association]) && is_array($data[$association]) )
|
||||
{
|
||||
foreach( $data[$association] as $field=>$value )
|
||||
{
|
||||
echo "<dt>".Inflector::humanize($field)."</dt>";
|
||||
if( !empty($value) )
|
||||
{
|
||||
echo "<dd>".$value."</dd>";
|
||||
} else {
|
||||
echo "<dd> </dd>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
echo "</dl>";
|
||||
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||
$model = $relation['className'];
|
||||
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
|
||||
$controller = Inflector::pluralize($model);
|
||||
$new = true;
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
||||
echo "<dl>";
|
||||
if( isset($data[$association]) && is_array($data[$association]) )
|
||||
{
|
||||
foreach( $data[$association] as $field => $value )
|
||||
{
|
||||
if( isset($value) )
|
||||
{
|
||||
echo "<dt>".Inflector::humanize($field)."</dt>";
|
||||
if( !empty($value) )
|
||||
{
|
||||
echo "<dd>".$value."</dd>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<dd> </dd>";
|
||||
}
|
||||
$new = null;
|
||||
}
|
||||
}
|
||||
echo "</dl>";
|
||||
if($new == null)
|
||||
{
|
||||
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<ul class='actions'><li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -155,10 +167,22 @@
|
|||
echo "<td>".$value."</td>";
|
||||
}
|
||||
?>
|
||||
<?php if (isset($this->controller->{$modelName}->{$association}))
|
||||
{?>
|
||||
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{?>
|
||||
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
|
||||
</td>
|
||||
<?php
|
||||
}?>
|
||||
<?php
|
||||
echo "</tr>";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue