mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Initial refactoring of scaffold and bake.
Removing unused vars git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5917 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8f12e402df
commit
6ab2b013bc
3 changed files with 44 additions and 63 deletions
|
@ -231,28 +231,15 @@ class ViewTask extends Shell {
|
|||
$this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller.");
|
||||
exit();
|
||||
}
|
||||
|
||||
$controllerObj = & new $controllerClassName();
|
||||
$controllerObj->constructClasses();
|
||||
$modelClass = $controllerObj->modelClass;
|
||||
$modelKey = $controllerObj->modelKey;
|
||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||
$primaryKey = $modelObj->primaryKey;
|
||||
$displayField = $modelObj->displayField;
|
||||
$singularVar = Inflector::variable($modelClass);
|
||||
$pluralVar = Inflector::variable($this->controllerName);
|
||||
$singularHumanName = Inflector::humanize($modelClass);
|
||||
$pluralHumanName = Inflector::humanize($this->controllerName);
|
||||
$fields = array_keys($modelObj->schema());
|
||||
$foreignKeys = $modelObj->keyToTable;
|
||||
$belongsTo = $modelObj->belongsTo;
|
||||
$hasOne = $modelObj->hasOne;
|
||||
$hasMany = $modelObj->hasMany;
|
||||
$hasAndBelongsToMany = $modelObj->hasAndBelongsToMany;
|
||||
|
||||
return compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
||||
'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
|
||||
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
$fields = array_keys($modelObj->schema());
|
||||
$associations = $this->__associations($modelObj);
|
||||
|
||||
return compact('fields', 'associations');
|
||||
}
|
||||
/**
|
||||
* Assembles and writes bakes the view file.
|
||||
|
@ -339,5 +326,24 @@ class ViewTask extends Shell {
|
|||
$this->out("");
|
||||
exit();
|
||||
}
|
||||
/**
|
||||
* Returns associations for controllers models.
|
||||
*
|
||||
* @return array $associations
|
||||
* @access private
|
||||
*/
|
||||
function __associations($model) {
|
||||
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
|
||||
foreach ($keys as $key => $type){
|
||||
foreach ($model->{$type} as $assocKey => $assocData) {
|
||||
$associations[$type][$assocKey]['primaryKey'] = $model->{$assocKey}->primaryKey;
|
||||
$associations[$type][$assocKey]['displayField'] = $model->{$assocKey}->displayField;
|
||||
$associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey'];
|
||||
$associations[$type][$assocKey]['controller'] = Inflector::pluralize($assocData['className']);
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -169,25 +169,10 @@ class Scaffold extends Object {
|
|||
$this->scaffoldActions = $controller->scaffold;
|
||||
$this->controller->pageTitle = __('Scaffold :: ', true) . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
|
||||
|
||||
//template variables
|
||||
$modelClass = $this->controller->modelClass;
|
||||
$modelKey = $this->controller->modelKey;
|
||||
$primaryKey = $this->ScaffoldModel->primaryKey;
|
||||
$displayField = $this->ScaffoldModel->displayField;
|
||||
$singularVar = Inflector::variable($modelClass);
|
||||
$pluralVar = Inflector::variable($this->controller->name);
|
||||
$singularHumanName = Inflector::humanize($modelClass);
|
||||
$pluralHumanName = Inflector::humanize($this->controller->name);
|
||||
$fields = array_keys($this->ScaffoldModel->schema());
|
||||
$foreignKeys = $this->ScaffoldModel->keyToTable;
|
||||
$belongsTo = $this->ScaffoldModel->belongsTo;
|
||||
$hasOne = $this->ScaffoldModel->hasOne;
|
||||
$hasMany = $this->ScaffoldModel->hasMany;
|
||||
$hasAndBelongsToMany = $this->ScaffoldModel->hasAndBelongsToMany;
|
||||
$associations = $this->__associations();
|
||||
|
||||
$this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
||||
'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
|
||||
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'));
|
||||
$this->controller->set(compact('fields', 'associations'));
|
||||
$this->__scaffold($params);
|
||||
}
|
||||
/**
|
||||
|
@ -508,5 +493,24 @@ class Scaffold extends Object {
|
|||
}
|
||||
return LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.ctp';
|
||||
}
|
||||
/**
|
||||
* Returns associations for controllers models.
|
||||
*
|
||||
* @return array $associations
|
||||
* @access private
|
||||
*/
|
||||
function __associations() {
|
||||
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
|
||||
foreach ($keys as $key => $type){
|
||||
foreach ($this->ScaffoldModel->{$type} as $assocKey => $assocData) {
|
||||
$associations[$type][$assocKey]['primaryKey'] = $this->ScaffoldModel->{$assocKey}->primaryKey;
|
||||
$associations[$type][$assocKey]['displayField'] = $this->ScaffoldModel->{$assocKey}->displayField;
|
||||
$associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey'];
|
||||
$associations[$type][$assocKey]['controller'] = Inflector::pluralize($assocData['className']);
|
||||
}
|
||||
}
|
||||
return $associations;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -99,11 +99,6 @@ class Model extends Overloadable {
|
|||
* @access protected
|
||||
*/
|
||||
var $_schema = null;
|
||||
/**
|
||||
*
|
||||
* @deprecated see $_schema
|
||||
*/
|
||||
var $_tableInfo = null;
|
||||
/**
|
||||
* List of validation rules. Append entries for validation as ('field_name' => '/^perl_compat_regexp$/')
|
||||
* that have to match with preg_match(). Use these rules with Model::validate()
|
||||
|
@ -145,20 +140,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $tableToModel = array();
|
||||
/**
|
||||
* List of Model names by used tables. Used for associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $modelToTable = array();
|
||||
/**
|
||||
* List of Foreign Key names to used tables. Used for associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $keyToTable = array();
|
||||
/**
|
||||
* Whether or not transactions for this model should be logged
|
||||
*
|
||||
|
@ -678,7 +659,6 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
$this->tableToModel[$this->{$assoc}->table] = $assoc;
|
||||
$this->modelToTable[$assoc] = $this->{$assoc}->table;
|
||||
}
|
||||
/**
|
||||
* Build array-based association from string.
|
||||
|
@ -724,15 +704,6 @@ class Model extends Overloadable {
|
|||
}
|
||||
$this->{$type}[$assocKey][$key] = $data;
|
||||
}
|
||||
|
||||
if ($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) {
|
||||
$this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table;
|
||||
$this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->alias;
|
||||
|
||||
if ($this->{$class}->alias != $class) {
|
||||
$this->keyToTable[$this->{$type}[$assocKey][$key]][2] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->{$type}[$assocKey]['with']) && !empty($this->{$type}[$assocKey]['with'])) {
|
||||
|
|
Loading…
Reference in a new issue