Removing deprecated Controller::generateFieldNames(); and Controller::_selectedArray();

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5903 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-10-27 01:15:11 +00:00
parent 8d6599c34b
commit f25e3b273c

View file

@ -725,179 +725,6 @@ class Controller extends Object {
}
$this->render(null, false, $flash);
}
/**
* @deprecated on 1.2.0.5258
* @see FormHelper::create()
* @access public
*/
function generateFieldNames($data = null, $doCreateOptions = true) {
trigger_error(sprintf(__('Method generateFieldNames() is deprecated in %s: see FormHelper::create()', true), get_class($this)), E_USER_NOTICE);
$fieldNames = array();
$model = $this->modelClass;
$modelKey = $this->modelKey;
$modelObj =& ClassRegistry::getObject($modelKey);
foreach ($modelObj->_tableInfo->value as $column) {
$humanName = $column['name'];
if ($modelObj->isForeignKey($column['name'])) {
foreach ($modelObj->belongsTo as $associationName => $assoc) {
if ($column['name'] == $assoc['foreignKey']) {
$humanName = Inflector::underscore($associationName);
$fkNames = $modelObj->keyToTable[$column['name']];
$fieldNames[$column['name']]['table'] = $fkNames[0];
$fieldNames[$column['name']]['model'] = Inflector::classify($associationName);
$fieldNames[$column['name']]['modelKey'] = Inflector::underscore($modelObj->tableToModel[$fieldNames[$column['name']]['table']]);
$fieldNames[$column['name']]['controller'] = Inflector::pluralize($fieldNames[$column['name']]['modelKey']);
$fieldNames[$column['name']]['foreignKey'] = true;
break;
}
}
}
$fieldNames[$column['name']]['label'] = Inflector::humanize($humanName);
$fieldNames[$column['name']]['prompt'] = $fieldNames[$column['name']]['label'];
$fieldNames[$column['name']]['fieldName'] = $model . '.' . $column['name'];
$fieldNames[$column['name']]['name'] = $column['name'];
$fieldNames[$column['name']]['class'] = 'optional';
$validationFields = $modelObj->validate;
if (isset($validationFields[$column['name']])) {
if (VALID_NOT_EMPTY == $validationFields[$column['name']]) {
$fieldNames[$column['name']]['required'] = true;
$fieldNames[$column['name']]['class'] = 'required';
$fieldNames[$column['name']]['error'] = "Required Field";
}
}
$lParenPos = strpos($column['type'], '(');
$rParenPos = strpos($column['type'], ')');
if (false != $lParenPos) {
$type = substr($column['type'], 0, $lParenPos);
$fieldLength = substr($column['type'], $lParenPos + 1, $rParenPos - $lParenPos - 1);
} else {
$type = $column['type'];
}
switch($type) {
case "text":
$fieldNames[$column['name']]['type'] = 'textarea';
$fieldNames[$column['name']]['cols'] = '30';
$fieldNames[$column['name']]['rows'] = '10';
break;
case "string":
if (isset($fieldNames[$column['name']]['foreignKey'])) {
$fieldNames[$column['name']]['type'] = 'select';
$fieldNames[$column['name']]['options'] = array();
$otherModelObj =& ClassRegistry::getObject($fieldNames[$column['name']]['modelKey']);
if (is_object($otherModelObj)) {
if ($doCreateOptions) {
$fieldNames[$column['name']]['options'] = $otherModelObj->generateList();
}
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
}
} else {
$fieldNames[$column['name']]['type'] = 'text';
}
break;
case "boolean":
$fieldNames[$column['name']]['type'] = 'checkbox';
break;
case "integer":
case "float":
if (strcmp($column['name'], $this->$model->primaryKey) == 0) {
$fieldNames[$column['name']]['type'] = 'hidden';
} elseif (isset($fieldNames[$column['name']]['foreignKey'])) {
$fieldNames[$column['name']]['type'] = 'select';
$fieldNames[$column['name']]['options'] = array();
$otherModelObj =& ClassRegistry::getObject($fieldNames[$column['name']]['modelKey']);
if (is_object($otherModelObj)) {
if ($doCreateOptions) {
$fieldNames[$column['name']]['options'] = $otherModelObj->generateList();
}
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
}
} else {
$fieldNames[$column['name']]['type'] = 'text';
}
break;
case "enum":
$fieldNames[$column['name']]['type'] = 'select';
$fieldNames[$column['name']]['options'] = array();
$enumValues = split(',', $fieldLength);
foreach ($enumValues as $enum) {
$enum = trim($enum, "'");
$fieldNames[$column['name']]['options'][$enum] = $enum;
}
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
break;
case "date":
case "datetime":
case "time":
case "year":
if (0 != strncmp("created", $column['name'], 7) && 0 != strncmp("modified", $column['name'], 8) && 0 != strncmp("updated", $column['name'], 7)) {
$fieldNames[$column['name']]['type'] = $type;
if (isset($data[$model][$column['name']])) {
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
} else {
$fieldNames[$column['name']]['selected'] = null;
}
} else {
unset($fieldNames[$column['name']]);
}
break;
default:
break;
}
}
foreach ($modelObj->hasAndBelongsToMany as $associationName => $assocData) {
$otherModelKey = Inflector::underscore($assocData['className']);
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
if ($doCreateOptions) {
$fkName = $modelObj->alias[$associationName];
$fieldNames[$associationName]['table'] = $assocData['joinTable'];
$fieldNames[$associationName]['model'] = $associationName;
$fieldNames[$associationName]['label'] = "Related " . Inflector::humanize($fkName);
$fieldNames[$associationName]['prompt'] = $fieldNames[$associationName]['label'];
$fieldNames[$associationName]['type'] = "select";
$fieldNames[$associationName]['multiple'] = "multiple";
$fieldNames[$associationName]['fieldName'] = $associationName . '.' . $associationName;
$fieldNames[$associationName]['name'] = $associationName;
$fieldNames[$associationName]['class'] = 'optional';
$fieldNames[$associationName]['options'] = $otherModelObj->generateList();
if (isset($data[$associationName])) {
$fieldNames[$associationName]['selected'] = $this->_selectedArray($data[$associationName], $otherModelObj->primaryKey);
}
}
}
return $fieldNames;
}
/**
* @deprecated on 1.2.0.5821
* @see FormHelper::create()
* @access protected
*/
function _selectedArray($data, $key = 'id') {
if (!is_array($data)) {
$model = $data;
if (!empty($this->data[$model][$model])) {
return $this->data[$model][$model];
}
if (!empty($this->data[$model])) {
$data = $this->data[$model];
}
}
$array = array();
if (!empty($data)) {
foreach ($data as $var) {
$array[$var[$key]] = $var[$key];
}
}
return $array;
}
/**
* Converts POST'ed model data to a model conditions array, suitable for a find
* or findAll Model query