mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
refactoring scaffold and generateFieldNames
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3980 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
edef4155e3
commit
59049a0fa8
6 changed files with 432 additions and 401 deletions
|
@ -255,7 +255,7 @@ class Controller extends Object {
|
|||
$this->viewPath = Inflector::underscore($this->name);
|
||||
}
|
||||
|
||||
$this->modelClass = ucwords(Inflector::singularize($this->name));
|
||||
$this->modelClass = Inflector::classify($this->name);
|
||||
$this->modelKey = Inflector::underscore($this->modelClass);
|
||||
|
||||
if (is_subclass_of($this, 'AppController')) {
|
||||
|
@ -633,139 +633,146 @@ class Controller extends Object {
|
|||
$fieldNames = array();
|
||||
$model = $this->modelClass;
|
||||
$modelKey = $this->modelKey;
|
||||
$table = $this->{$model}->table;
|
||||
$objRegistryModel =& ClassRegistry::getObject($modelKey);
|
||||
|
||||
foreach($objRegistryModel->_tableInfo->value as $tabl) {
|
||||
|
||||
if ($objRegistryModel->isForeignKey($tabl['name'])) {
|
||||
if(false !== strpos($tabl['name'], "_id")) {
|
||||
$niceName = substr($tabl['name'], 0, strpos($tabl['name'], "_id" ));
|
||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||
|
||||
foreach($modelObj->_tableInfo->value as $column) {
|
||||
if ($modelObj->isForeignKey($column['name'])) {
|
||||
if(false !== strpos($column['name'], "_id")) {
|
||||
$niceName = substr($column['name'], 0, strpos($column['name'], "_id" ));
|
||||
} else {
|
||||
$niceName = $niceName = $tabl['name'];
|
||||
$niceName = $column['name'];
|
||||
}
|
||||
$fkNames = $this->{$model}->keyToTable[$tabl['name']];
|
||||
$fieldNames[$tabl['name']]['table'] = $fkNames[0];
|
||||
$fieldNames[$tabl['name']]['prompt'] = Inflector::humanize($niceName);
|
||||
$fieldNames[$tabl['name']]['model'] = $fkNames[1];
|
||||
$fieldNames[$tabl['name']]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']];
|
||||
$fieldNames[$tabl['name']]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[$fkNames[0]]);
|
||||
$fieldNames[$tabl['name']]['foreignKey'] = true;
|
||||
$fkNames = $modelObj->keyToTable[$column['name']];
|
||||
$fieldNames[$column['name']]['table'] = $fkNames[0];
|
||||
$fieldNames[$column['name']]['prompt'] = Inflector::humanize($niceName);
|
||||
$fieldNames[$column['name']]['model'] = Inflector::classify($niceName);
|
||||
$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;
|
||||
|
||||
} else if('created' != $tabl['name'] && 'updated' != $tabl['name']) {
|
||||
$fieldNames[$tabl['name']]['prompt'] = Inflector::humanize($tabl['name']);
|
||||
} else if('created' == $tabl['name']) {
|
||||
$fieldNames[$tabl['name']]['prompt'] = 'Created';
|
||||
} else if('updated' == $tabl['name']) {
|
||||
$fieldNames[$tabl['name']]['prompt'] = 'Modified';
|
||||
} else if('created' != $column['name'] && 'updated' != $column['name']) {
|
||||
$fieldNames[$column['name']]['prompt'] = Inflector::humanize($column['name']);
|
||||
} else if('created' == $column['name']) {
|
||||
$fieldNames[$column['name']]['prompt'] = 'Created';
|
||||
} else if('updated' == $column['name']) {
|
||||
$fieldNames[$column['name']]['prompt'] = 'Modified';
|
||||
}
|
||||
$fieldNames[$tabl['name']]['tagName'] = $model . '/' . $tabl['name'];
|
||||
$validationFields = $objRegistryModel->validate;
|
||||
$fieldNames[$column['name']]['tagName'] = $model . '/' . $column['name'];
|
||||
$validationFields = $modelObj->validate;
|
||||
|
||||
if (isset($validationFields[$tabl['name']])) {
|
||||
if (VALID_NOT_EMPTY == $validationFields[$tabl['name']]) {
|
||||
$fieldNames[$tabl['name']]['required'] = true;
|
||||
$fieldNames[$tabl['name']]['errorMsg'] = "Required Field";
|
||||
if (isset($validationFields[$column['name']])) {
|
||||
if (VALID_NOT_EMPTY == $validationFields[$column['name']]) {
|
||||
$fieldNames[$column['name']]['required'] = true;
|
||||
$fieldNames[$column['name']]['errorMsg'] = "Required Field";
|
||||
}
|
||||
}
|
||||
$lParenPos = strpos($tabl['type'], '(');
|
||||
$rParenPos = strpos($tabl['type'], ')');
|
||||
$lParenPos = strpos($column['type'], '(');
|
||||
$rParenPos = strpos($column['type'], ')');
|
||||
|
||||
if (false != $lParenPos) {
|
||||
$type = substr($tabl['type'], 0, $lParenPos);
|
||||
$fieldLength = substr($tabl['type'], $lParenPos + 1, $rParenPos - $lParenPos - 1);
|
||||
$type = substr($column['type'], 0, $lParenPos);
|
||||
$fieldLength = substr($column['type'], $lParenPos + 1, $rParenPos - $lParenPos - 1);
|
||||
} else {
|
||||
$type = $tabl['type'];
|
||||
$type = $column['type'];
|
||||
}
|
||||
|
||||
switch($type) {
|
||||
case "text":
|
||||
$fieldNames[$tabl['name']]['type'] = 'area';
|
||||
$fieldNames[$column['name']]['type'] = 'area';
|
||||
break;
|
||||
case "string":
|
||||
if (isset($fieldNames[$tabl['name']]['foreignKey'])) {
|
||||
$fieldNames[$tabl['name']]['type'] = 'select';
|
||||
$fieldNames[$tabl['name']]['options'] = array();
|
||||
$otherModel =& ClassRegistry::getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
||||
if (isset($fieldNames[$column['name']]['foreignKey'])) {
|
||||
$fieldNames[$column['name']]['type'] = 'select';
|
||||
$fieldNames[$column['name']]['options'] = array();
|
||||
$otherModelObj =& ClassRegistry::getObject(Inflector::underscore($fieldNames[$column['name']]['modelKey']));
|
||||
|
||||
if (is_object($otherModel)) {
|
||||
if (is_object($otherModelObj)) {
|
||||
|
||||
if ($doCreateOptions) {
|
||||
$otherDisplayField = $otherModel->getDisplayField();
|
||||
$otherModel->recursive = 0;
|
||||
$rec = $otherModel->findAll();
|
||||
$otherDisplayField = $otherModelObj->getDisplayField();
|
||||
$otherModelObj->recursive = 0;
|
||||
$rec = $otherModelObj->findAll();
|
||||
|
||||
foreach($rec as $pass) {
|
||||
foreach($pass as $key => $value) {
|
||||
if ($key == $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']] && isset($value[$otherModel->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
$fieldNames[$tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField];
|
||||
if ($key == $modelObj->tableToModel[$fieldNames[$column['name']]['table']] && isset($value[$otherModelObj->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
if(empty($value[$otherDisplayField])) {
|
||||
$fieldNames[$column['name']]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherModelObj->primaryKey];
|
||||
} else {
|
||||
$fieldNames[$column['name']]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherDisplayField];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
||||
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
|
||||
}
|
||||
} else {
|
||||
$fieldNames[$tabl['name']]['type'] = 'input';
|
||||
$fieldNames[$column['name']]['type'] = 'input';
|
||||
}
|
||||
break;
|
||||
case "boolean":
|
||||
$fieldNames[$tabl['name']]['type'] = 'checkbox';
|
||||
$fieldNames[$column['name']]['type'] = 'checkbox';
|
||||
break;
|
||||
case "integer":
|
||||
case "float":
|
||||
if (strcmp($tabl['name'], $this->$model->primaryKey) == 0) {
|
||||
$fieldNames[$tabl['name']]['type'] = 'hidden';
|
||||
} else if(isset($fieldNames[$tabl['name']]['foreignKey'])) {
|
||||
$fieldNames[$tabl['name']]['type'] = 'select';
|
||||
$fieldNames[$tabl['name']]['options'] = array();
|
||||
$otherModel =& ClassRegistry::getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
||||
if (strcmp($column['name'], $this->$model->primaryKey) == 0) {
|
||||
$fieldNames[$column['name']]['type'] = 'hidden';
|
||||
} else 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($otherModel)) {
|
||||
if (is_object($otherModelObj)) {
|
||||
if ($doCreateOptions) {
|
||||
$otherDisplayField = $otherModel->getDisplayField();
|
||||
$otherModel->recursive = 0;
|
||||
$rec = $otherModel->findAll();
|
||||
|
||||
foreach($rec as $pass) {
|
||||
foreach($pass as $key => $value) {
|
||||
if ($key == $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']] && isset($value[$otherModel->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
$fieldNames[$tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField];
|
||||
$otherDisplayField = $otherModelObj->getDisplayField();
|
||||
$otherModelObj->recursive = 0;
|
||||
$rec = $otherModelObj->findAll();
|
||||
if(is_array($rec)) {
|
||||
foreach($rec as $pass) {
|
||||
foreach($pass as $key => $value) {
|
||||
if ($key == $modelObj->tableToModel[$fieldNames[$column['name']]['table']] && isset($value[$otherModelObj->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
if(empty($value[$otherDisplayField])) {
|
||||
$fieldNames[$column['name']]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherModelObj->primaryKey];
|
||||
} else {
|
||||
$fieldNames[$column['name']]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherDisplayField];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
||||
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
|
||||
}
|
||||
} else {
|
||||
$fieldNames[$tabl['name']]['type'] = 'input';
|
||||
$fieldNames[$column['name']]['type'] = 'input';
|
||||
}
|
||||
|
||||
break;
|
||||
case "enum":
|
||||
$fieldNames[$tabl['name']]['type'] = 'select';
|
||||
$fieldNames[$tabl['name']]['options'] = array();
|
||||
$fieldNames[$column['name']]['type'] = 'select';
|
||||
$fieldNames[$column['name']]['options'] = array();
|
||||
$enumValues = split(',', $fieldLength);
|
||||
|
||||
foreach($enumValues as $enum) {
|
||||
$enum = trim($enum, "'");
|
||||
$fieldNames[$tabl['name']]['options'][$enum] = $enum;
|
||||
$fieldNames[$column['name']]['options'][$enum] = $enum;
|
||||
}
|
||||
|
||||
$fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
||||
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
|
||||
break;
|
||||
case "date":
|
||||
case "datetime":
|
||||
case "time":
|
||||
case "year":
|
||||
if (0 != strncmp("created", $tabl['name'], 7) && 0 != strncmp("modified", $tabl['name'], 8)) {
|
||||
$fieldNames[$tabl['name']]['type'] = $type;
|
||||
if (0 != strncmp("created", $column['name'], 7) && 0 != strncmp("modified", $column['name'], 8)) {
|
||||
$fieldNames[$column['name']]['type'] = $type;
|
||||
}
|
||||
|
||||
if (isset($data[$model][$tabl['name']])) {
|
||||
$fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
||||
if (isset($data[$model][$column['name']])) {
|
||||
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
|
||||
} else {
|
||||
$fieldNames[$tabl['name']]['selected'] = null;
|
||||
$fieldNames[$column['name']]['selected'] = null;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -774,32 +781,35 @@ class Controller extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
foreach($objRegistryModel->hasAndBelongsToMany as $relation => $relData) {
|
||||
$modelName = $relData['className'];
|
||||
$manyAssociation = $relation;
|
||||
$modelKeyM = Inflector::underscore($modelName);
|
||||
$modelObject =& new $modelName();
|
||||
|
||||
foreach($modelObj->hasAndBelongsToMany as $associationName => $assocData) {
|
||||
$otherModelClass = $associationName;
|
||||
$otherModelKey = Inflector::underscore($associationName);
|
||||
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
||||
if ($doCreateOptions) {
|
||||
$otherDisplayField = $modelObject->getDisplayField();
|
||||
$fieldNames[$modelKeyM]['model'] = $modelName;
|
||||
$fieldNames[$modelKeyM]['prompt'] = "Related " . Inflector::humanize(Inflector::pluralize($modelName));
|
||||
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
||||
$fieldNames[$modelKeyM]['tagName'] = $manyAssociation . '/' . $manyAssociation;
|
||||
$modelObject->recursive = 0;
|
||||
$rec = $modelObject->findAll();
|
||||
|
||||
foreach($rec as $pass) {
|
||||
foreach($pass as $key => $value) {
|
||||
if ($key == $modelName && isset($value[$modelObject->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
$fieldNames[$modelKeyM]['options'][$value[$modelObject->primaryKey]] = $value[$otherDisplayField];
|
||||
$otherDisplayField = $otherModelObj->getDisplayField();
|
||||
$fieldNames[$otherModelKey]['model'] = $otherModelClass;
|
||||
$fieldNames[$otherModelKey]['prompt'] = "Related " . Inflector::humanize(Inflector::pluralize($otherModelClass));
|
||||
$fieldNames[$otherModelKey]['type'] = "selectMultiple";
|
||||
$fieldNames[$otherModelKey]['tagName'] = $associationName . '/' . $associationName;
|
||||
$otherModelObj->recursive = 0;
|
||||
$rec = $otherModelObj->findAll();
|
||||
if(is_array($rec)) {
|
||||
foreach($rec as $pass) {
|
||||
foreach($pass as $key => $value) {
|
||||
if ($key == $otherModelClass && isset($value[$otherModelObj->primaryKey]) && isset($value[$otherDisplayField])) {
|
||||
if(empty($value[$otherDisplayField])) {
|
||||
$fieldNames[$otherModelKey]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherModelObj->primaryKey];
|
||||
} else {
|
||||
$fieldNames[$otherModelKey]['options'][$value[$otherModelObj->primaryKey]] = $value[$otherDisplayField];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data[$manyAssociation])) {
|
||||
foreach($data[$manyAssociation] as $key => $row) {
|
||||
$fieldNames[$modelKeyM]['selected'][$row[$modelObject->primaryKey]] = $row[$modelObject->primaryKey];
|
||||
if (isset($data[$associationName])) {
|
||||
foreach($data[$associationName] as $key => $row) {
|
||||
$fieldNames[$otherModelKey]['selected'][$row[$otherModelObj->primaryKey]] = $row[$otherModelObj->primaryKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,35 +39,48 @@
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs.controller
|
||||
*/
|
||||
class Scaffold extends Object{
|
||||
|
||||
/**
|
||||
* Name of view to render
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $actionView = null;
|
||||
|
||||
/**
|
||||
* Class name of model
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $modelKey = null;
|
||||
class Scaffold extends Object {
|
||||
|
||||
/**
|
||||
* Controller object
|
||||
*
|
||||
* @var Controller
|
||||
*/
|
||||
var $controllerClass = null;
|
||||
var $controller = null;
|
||||
|
||||
/**
|
||||
* Name of scaffolded Model
|
||||
* Name of controller to scaffold
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $modelName = null;
|
||||
var $name = null;
|
||||
/**
|
||||
* Name of view to render
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $action = null;
|
||||
|
||||
/**
|
||||
* Class name of model
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $modelClass = null;
|
||||
|
||||
/**
|
||||
* Registry key of model
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $modeKey = null;
|
||||
|
||||
/**
|
||||
* View path for scaffolded controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $viewPath = null;
|
||||
|
||||
/**
|
||||
* Title HTML element for current scaffolded view
|
||||
|
@ -76,13 +89,6 @@ class Scaffold extends Object{
|
|||
*/
|
||||
var $scaffoldTitle = null;
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $base = false;
|
||||
|
||||
/**
|
||||
* Construct and set up given controller with given parameters.
|
||||
*
|
||||
|
@ -90,17 +96,30 @@ class Scaffold extends Object{
|
|||
* @param array $params
|
||||
*/
|
||||
function __construct(&$controller, $params) {
|
||||
$this->controllerClass =&$controller;
|
||||
$this->actionView =$controller->action;
|
||||
$this->modelKey =ucwords(Inflector::singularize($controller->name));
|
||||
$this->scaffoldTitle =Inflector::humanize($this->modelKey);
|
||||
$this->viewPath =Inflector::underscore($controller->name);
|
||||
$this->controllerClass->pageTitle=$this->scaffoldTitle;
|
||||
$this->controllerClass->pageTitle=
|
||||
'Scaffold :: ' . Inflector::humanize($controller->action) . ' :: ' . Inflector::humanize(
|
||||
Inflector::pluralize(
|
||||
$this->modelKey));
|
||||
$this->__scaffold($params);
|
||||
$this->controller = &$controller;
|
||||
$this->name = $controller->name;
|
||||
$this->action = $controller->action;
|
||||
$this->modelClass = Inflector::classify($this->name);
|
||||
$this->modelKey = Inflector::underscore($this->modelClass);
|
||||
$this->scaffoldTitle = Inflector::humanize($this->name);
|
||||
$this->viewPath = Inflector::underscore($this->name);
|
||||
$this->controller->pageTitle= 'Scaffold :: ' . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
|
||||
|
||||
$this->controller->set('controllerName', $this->name);
|
||||
$this->controller->set('controllerAction', $this->action);
|
||||
$this->controller->set('modelClass', $this->modelClass);
|
||||
$this->controller->set('modelKey', $this->modelKey);
|
||||
$this->controller->set('viewPath', $this->viewPath);
|
||||
$this->controller->set('humanSingularName', Inflector::humanize($this->modelClass));
|
||||
$this->controller->set('humanPluralName', $this->scaffoldTitle);
|
||||
|
||||
if (!in_array('Form', $this->controller->helpers)) {
|
||||
$this->controller->helpers[] = 'Form';
|
||||
}
|
||||
$this->controller->constructClasses();
|
||||
$this->ScaffoldModel = &$this->controller->{$this->modelClass};
|
||||
|
||||
$this->__scaffold($params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,24 +130,31 @@ class Scaffold extends Object{
|
|||
* @access private
|
||||
*/
|
||||
function __scaffoldView($params) {
|
||||
if ($this->controllerClass->_beforeScaffold('view')) {
|
||||
$this->controllerClass->params['data']=$this->controllerClass->{$this->modelKey}->read();
|
||||
$this->controllerClass->set('data', $this->controllerClass->params['data']);
|
||||
$this->controllerClass->set('fieldNames',
|
||||
$this->controllerClass->generateFieldNames(
|
||||
$this->controllerClass->params['data'], false));
|
||||
|
||||
if ($this->controller->_beforeScaffold('view')) {
|
||||
|
||||
$this->controller->set('modelClass', $this->modelClass);
|
||||
$this->controller->set('modelKey', $this->modelKey);
|
||||
$this->controller->set('humanSingularName', Inflector::humanize($this->modelClass));
|
||||
$this->controller->set('humanPluralName', $this->scaffoldTitle);
|
||||
|
||||
|
||||
$this->controller->data = $this->ScaffoldModel->read();
|
||||
$this->controller->set('data', $this->controller->data);
|
||||
$this->controller->set('fieldNames',
|
||||
$this->controller->generateFieldNames($this->controller->data, false));
|
||||
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml');
|
||||
return $this->controller->render($this->action, '', APP . 'views' . DS . $this->viewPath
|
||||
. DS . 'scaffold.view.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml');
|
||||
return $this->controller->render($this->action, '', APP . 'views' . DS . 'scaffold'
|
||||
. DS . 'scaffold.view.thtml');
|
||||
} else {
|
||||
return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates'
|
||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates'
|
||||
. DS . 'scaffolds' . DS . 'view.thtml');
|
||||
}
|
||||
} else if($this->controllerClass->_scaffoldError('view') === false) {
|
||||
} else if($this->controller->_scaffoldError('view') === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
|
@ -141,23 +167,24 @@ class Scaffold extends Object{
|
|||
* @access private
|
||||
*/
|
||||
function __scaffoldIndex($params) {
|
||||
if ($this->controllerClass->_beforeScaffold('index')) {
|
||||
$this->controllerClass->set('fieldNames',
|
||||
$this->controllerClass->generateFieldNames(null, false));
|
||||
$this->controllerClass->{$this->modelKey}->recursive=0;
|
||||
$this->controllerClass->set('data', $this->controllerClass->{$this->modelKey}->findAll());
|
||||
|
||||
if ($this->controller->_beforeScaffold('index')) {
|
||||
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames(null, false));
|
||||
$this->ScaffoldModel->recursive = 0;
|
||||
$this->controller->set('data', $this->ScaffoldModel->findAll(null, null, $this->modelClass.'.'.$this->ScaffoldModel->primaryKey.' DESC'));
|
||||
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
return $this->controller->render($this->action, '',
|
||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
return $this->controller->render($this->action, '',
|
||||
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml');
|
||||
} else {
|
||||
return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates'
|
||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates'
|
||||
. DS . 'scaffolds' . DS . 'index.thtml');
|
||||
}
|
||||
} else if($this->controllerClass->_scaffoldError('index') === false) {
|
||||
} else if($this->controller->_scaffoldError('index') === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
|
@ -170,39 +197,27 @@ class Scaffold extends Object{
|
|||
* @return A rendered view with a form to edit or add a record in the Models database table
|
||||
* @access private
|
||||
*/
|
||||
function __scaffoldForm($params = array(), $type) {
|
||||
$thtml='edit';
|
||||
$form ='Edit';
|
||||
|
||||
if ($type === 'add') {
|
||||
$thtml='add';
|
||||
$form ='Add';
|
||||
}
|
||||
|
||||
if ($this->controllerClass->_beforeScaffold($type)) {
|
||||
if ($type == 'edit') {
|
||||
$this->controllerClass->params['data']=$this->controllerClass->{$this->modelKey}->read();
|
||||
$this->controllerClass->set('fieldNames',
|
||||
$this->controllerClass->generateFieldNames(
|
||||
$this->controllerClass->params['data']));
|
||||
$this->controllerClass->set('data', $this->controllerClass->params['data']);
|
||||
function __scaffoldForm($params = array(), $action = 'edit') {
|
||||
if ($this->controller->_beforeScaffold($action)) {
|
||||
|
||||
$this->controller->set('formName', ucwords($action));
|
||||
|
||||
if ($action == 'edit') {
|
||||
$this->controller->data = $this->ScaffoldModel->read();
|
||||
$this->controller->set('fieldNames',
|
||||
$this->controller->generateFieldNames($this->controller->data));
|
||||
$this->controller->set('data', $this->controller->data);
|
||||
} else {
|
||||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames());
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||
}
|
||||
|
||||
$this->controllerClass->set('type', $form);
|
||||
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $thtml . '.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml')) {
|
||||
return $this->controller->render($action, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffold.' . $action . '.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml')) {
|
||||
return $this->controller->render($action, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $action . '.thtml');
|
||||
} else {
|
||||
return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates'
|
||||
. DS . 'scaffolds' . DS . 'edit.thtml');
|
||||
return $this->controller->render($action, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.thtml');
|
||||
}
|
||||
} else if($this->controllerClass->_scaffoldError($type) === false) {
|
||||
} else if($this->controller->_scaffoldError($action) === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
|
@ -216,76 +231,69 @@ class Scaffold extends Object{
|
|||
* @return success on save/update, add/edit form if data is empty or error if save or update fails
|
||||
* @access private
|
||||
*/
|
||||
function __scaffoldSave($params = array(), $type) {
|
||||
$thtml ='edit';
|
||||
$form ='Edit';
|
||||
$success ='updated';
|
||||
$formError='edit';
|
||||
function __scaffoldSave($params = array(), $action = 'update') {
|
||||
$formName = 'Edit';
|
||||
$formAction = 'edit';
|
||||
$viewFileName = 'edit';
|
||||
$success = 'updated';
|
||||
|
||||
if ($this->controllerClass->_beforeScaffold($type)) {
|
||||
if (empty($this->controllerClass->params['data'])) {
|
||||
if ($type === 'create') {
|
||||
$formError = 'add';
|
||||
}
|
||||
if ($action === 'create') {
|
||||
$formName = 'New';
|
||||
$formAction = 'add';
|
||||
$viewFileName = 'add';
|
||||
$success = 'saved';
|
||||
}
|
||||
|
||||
$this->controller->set('formName', $formName);
|
||||
|
||||
if ($this->controller->_beforeScaffold($formAction)) {
|
||||
|
||||
if (empty($this->controller->data)) {
|
||||
return $this->__scaffoldForm($params, $formAction);
|
||||
}
|
||||
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames());
|
||||
$this->controller->cleanUpFields();
|
||||
|
||||
return $this->__scaffoldForm($params, $formError);
|
||||
}
|
||||
|
||||
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames());
|
||||
$this->controllerClass->cleanUpFields();
|
||||
|
||||
if ($type == 'create') {
|
||||
$this->controllerClass->{$this->modelKey}->create();
|
||||
$thtml ='add';
|
||||
$form ='Add';
|
||||
$success='saved';
|
||||
}
|
||||
|
||||
if ($this->controllerClass->{$this->modelKey}->save($this->controllerClass->params['data'])) {
|
||||
if ($this->controllerClass->_afterScaffoldSave($type)) {
|
||||
if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' has been ' . $success . '.');
|
||||
$this->controllerClass->redirect(
|
||||
'/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
} else {
|
||||
return $this->controllerClass->flash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' has been ' . $success
|
||||
. '.',
|
||||
'/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
}
|
||||
} else {
|
||||
return $this->controllerClass->_afterScaffoldSaveError($type);
|
||||
}
|
||||
if ($type == 'create') {
|
||||
$this->ScaffoldModel->create();
|
||||
$viewFileName = 'add';
|
||||
$formName = 'Add';
|
||||
$success = 'saved';
|
||||
}
|
||||
|
||||
if ($this->ScaffoldModel->save($this->controller->data)) {
|
||||
if ($this->controller->_afterScaffoldSave($type)) {
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash('The ' . Inflector::humanize($this->modelClass) . ' has been ' . $success . '.');
|
||||
$this->controller->redirect('/' . $this->viewPath);
|
||||
} else {
|
||||
return $this->controller->flash('The ' . Inflector::humanize($this->modelClass) . ' has been ' . $success. '.','/' . $this->viewPath);
|
||||
}
|
||||
} else {
|
||||
if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash('Please correct errors below.');
|
||||
}
|
||||
|
||||
$this->controllerClass->set('data', $this->controllerClass->params['data']);
|
||||
$this->controllerClass->set('fieldNames',
|
||||
$this->controllerClass->generateFieldNames(
|
||||
$this->__rebuild($this->controllerClass->params['data'])));
|
||||
$this->controllerClass->validateErrors($this->controllerClass->{$this->modelKey});
|
||||
$this->controllerClass->set('type', $form);
|
||||
|
||||
if (file_exists(
|
||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml'))
|
||||
{
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
} else {
|
||||
return $this->controllerClass->render($this->actionView, '',
|
||||
LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml');
|
||||
}
|
||||
return $this->controller->_afterScaffoldSaveError($type);
|
||||
}
|
||||
} else if($this->controllerClass->_scaffoldError($type) === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash('Please correct errors below.');
|
||||
}
|
||||
|
||||
$this->controller->set('data', $this->controller->data);
|
||||
$this->controller->set('fieldNames', $this->controller->generateFieldNames($this->__rebuild($this->controller->data)));
|
||||
$this->controller->validateErrors($this->ScaffoldModel);
|
||||
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml')) {
|
||||
return $this->controller->render($viewFileName, '', APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml')) {
|
||||
return $this->controller->render($viewFileName, '', APP . 'views' . DS . 'scaffold' . DS . 'scaffold.' . $thtml . '.thtml');
|
||||
} else {
|
||||
return $this->controller->render($viewFileName, '', LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . 'edit.thtml');
|
||||
}
|
||||
}
|
||||
} else if($this->controller->_scaffoldError($formAction) === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a delete on given scaffolded Model.
|
||||
|
@ -295,35 +303,33 @@ class Scaffold extends Object{
|
|||
* @access private
|
||||
*/
|
||||
function __scaffoldDelete($params = array()) {
|
||||
if ($this->controllerClass->_beforeScaffold('delete')) {
|
||||
$id=$params['pass'][0];
|
||||
if ($this->controller->_beforeScaffold('delete')) {
|
||||
$id = $params['pass'][0];
|
||||
|
||||
if ($this->controllerClass->{$this->modelKey}->del($id)) {
|
||||
if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id
|
||||
if ($this->ScaffoldModel->del($id)) {
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash(
|
||||
'The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id
|
||||
. ' has been deleted.');
|
||||
$this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
$this->controller->redirect('/' . $this->viewPath);
|
||||
} else {
|
||||
return $this->controllerClass->flash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id
|
||||
. ' has been deleted.',
|
||||
'/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
return $this->controller->flash(
|
||||
'The ' . Inflector::humanize($this->modelClass) . ' with id: ' . $id
|
||||
. ' has been deleted.', '/' . $this->viewPath);
|
||||
}
|
||||
} else {
|
||||
if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'There was an error deleting the ' . Inflector::humanize($this->modelKey)
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid != false) {
|
||||
$this->controller->Session->setFlash(
|
||||
'There was an error deleting the ' . Inflector::humanize($this->modelClass)
|
||||
. ' with the id ' . $id);
|
||||
$this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
$this->controller->redirect('/' . $this->viewPath);
|
||||
} else {
|
||||
return $this->controllerClass->flash(
|
||||
'There was an error deleting the ' . Inflector::humanize($this->modelKey)
|
||||
. ' with the id ' . $id,
|
||||
'/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
return $this->controller->flash(
|
||||
'There was an error deleting the ' . Inflector::humanize($this->modelClass)
|
||||
. ' with the id ' . $id, '/' . $this->viewPath);
|
||||
}
|
||||
}
|
||||
} else if($this->controllerClass->_scaffoldError('delete') === false) {
|
||||
} else if($this->controller->_scaffoldError('delete') === false) {
|
||||
return $this->__scaffoldError();
|
||||
}
|
||||
}
|
||||
|
@ -334,15 +340,14 @@ class Scaffold extends Object{
|
|||
* @return unknown
|
||||
*/
|
||||
function __scaffoldError() {
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS
|
||||
. 'scaffold.error.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . $this->viewPath
|
||||
if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffolds' . DS. 'scaffold.error.thtml')) {
|
||||
return $this->controller->render($this->action, '', APP . 'views' . DS . $this->viewPath
|
||||
. DS . 'scaffolds' . DS . 'scaffold.error.thtml');
|
||||
} elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.error.thtml')) {
|
||||
return $this->controllerClass->render($this->actionView, '', APP . 'views' . DS . 'scaffold' . DS
|
||||
. 'scaffold.error.thtml');
|
||||
return $this->controller->render($this->action, '', APP . 'views' . DS . 'scaffold'
|
||||
. DS . 'scaffold.error.thtml');
|
||||
} else {
|
||||
return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' . DS
|
||||
return $this->controller->render($this->action, '', LIBS . 'view' . DS . 'templates' . DS
|
||||
. 'errors' . DS . 'scaffold_error.thtml');
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +368,7 @@ class Scaffold extends Object{
|
|||
$count=0;
|
||||
|
||||
foreach($field[$model] as $value) {
|
||||
$params[$model][$count][$this->controllerClass->{$this->modelKey}->{$model}->primaryKey]
|
||||
$params[$model][$count][$this->ScaffoldModel->primaryKey]
|
||||
= $value;
|
||||
$count++;
|
||||
}
|
||||
|
@ -391,18 +396,12 @@ class Scaffold extends Object{
|
|||
* @access private
|
||||
*/
|
||||
function __scaffold($params) {
|
||||
if (!in_array('Form', $this->controllerClass->helpers)) {
|
||||
$this->controllerClass->helpers[] = 'Form';
|
||||
}
|
||||
|
||||
$this->controllerClass->constructClasses();
|
||||
$db=&ConnectionManager::getDataSource($this->controllerClass->{$this->modelKey}->useDbConfig);
|
||||
|
||||
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
|
||||
|
||||
if (isset($db)) {
|
||||
if ($params['action'] === 'index' || $params['action'] === 'list' || $params['action'] === 'view'
|
||||
|| $params['action'] === 'add' || $params['action'] === 'create'
|
||||
|| $params['action'] === 'edit' || $params['action'] === 'update'
|
||||
|| $params['action'] === 'delete') {
|
||||
$scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
|
||||
if (in_array($params['action'], $scaffoldActions)) {
|
||||
switch($params['action'])
|
||||
{
|
||||
case 'index':
|
||||
|
@ -446,15 +445,16 @@ class Scaffold extends Object{
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
return $this->cakeError('missingAction', array(array('className' => Inflector::camelize(
|
||||
$params['controller'] . "Controller"),
|
||||
'base' => $this->controllerClass->base,
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->controllerClass->webroot)));
|
||||
return $this->cakeError('missingAction', array(
|
||||
array('className' => $this->controller->name . "Controller"),
|
||||
'base' => $this->controller->base,
|
||||
'action' => $this->action,
|
||||
'webroot' => $this->controller->webroot
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return $this->cakeError('missingDatabase',
|
||||
array(array('webroot' => $this->controllerClass->webroot)));
|
||||
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,17 +24,25 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h1>New <?php echo Inflector::humanize($this->name)?></h1>
|
||||
<h2>New <?php echo Inflector::humanize($modelClass)?></h2>
|
||||
<?php
|
||||
if(is_null($this->plugin)) {
|
||||
$path = '/';
|
||||
} else {
|
||||
$path = '/'.$this->plugin.'/';
|
||||
}
|
||||
echo $form->create($path. Inflector::underscore($this->name).'/create');
|
||||
echo $form->generateFields( $fieldNames );
|
||||
echo $form->generateSubmitDiv( 'Add' );?>
|
||||
echo $form->create($path . $viewPath.'/create');
|
||||
echo $form->generateFields($fieldNames);
|
||||
echo $form->generateSubmitDiv('Add');?>
|
||||
</form>
|
||||
<ul class='actions'>
|
||||
<?php echo "<li>".$html->link('List '.Inflector::humanize($this->name), $path.$this->viewPath.'/index')."</li>"; ?>
|
||||
<?php echo "<li>".$html->link('List '.Inflector::humanize($viewPath), $path . $viewPath.'/index')."</li>"; ?>
|
||||
<?php
|
||||
foreach($fieldNames as $field => $value) {
|
||||
if(isset($value['foreignKey'])) {
|
||||
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), $path . Inflector::underscore($value['controller'])."/index")."</li>";
|
||||
echo "<li>".$html->link( "Add ".Inflector::humanize($value['modelKey']), $path . Inflector::underscore($value['controller'])."/add/")."</li>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
|
@ -23,33 +23,37 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/*
|
||||
$modelName = ucwords(Inflector::singularize($this->name));
|
||||
$modelKey = $modelName;
|
||||
*/
|
||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||
if(is_null($this->plugin)) {
|
||||
$path = '/';
|
||||
} else {
|
||||
$path = '/'.$this->plugin.'/';
|
||||
}?>
|
||||
<h1><?php echo $type.' '.Inflector::humanize($modelName);?></h1>
|
||||
<h2><?php echo $formName.' '.Inflector::humanize($modelClass);?></h2>
|
||||
<?php
|
||||
if($type == 'Edit') {
|
||||
echo $form->create($path . Inflector::underscore($this->name) .'/update');
|
||||
if($formName == 'Edit') {
|
||||
echo $form->create($path . $viewPath .'/update');
|
||||
} else {
|
||||
echo $form->create($path. Inflector::underscore($this->name).'/create');
|
||||
echo $form->create($path. $viewPath.'/create');
|
||||
}
|
||||
echo $form->generateFields( $fieldNames );
|
||||
echo $form->generateFields($fieldNames);
|
||||
echo $form->generateSubmitDiv( 'Save' ); ?>
|
||||
</form>
|
||||
<ul class='actions'>
|
||||
<?php
|
||||
if($type == 'Edit') {
|
||||
echo "<li>".$html->link('Delete '.Inflector::humanize($modelName), $path.$this->viewPath.'/delete/'.$data[$modelKey][$this->controller->{$modelName}->primaryKey])."</li>";
|
||||
if($formName == 'Edit') {
|
||||
echo "<li>".$html->link('Delete '.Inflector::humanize($modelClass), $path . $viewPath.'/delete/'.$data[$modelClass][$modelObj->primaryKey], null, 'Are you sure you want to delete '.$data[$modelClass][$modelObj->getDisplayField()])."</li>";
|
||||
}
|
||||
echo "<li>".$html->link('List '.Inflector::humanize($modelName), $path.$this->viewPath.'/index')."</li>";
|
||||
if($type == 'Edit') {
|
||||
echo "<li>".$html->link('List '.Inflector::humanize($viewPath), $path . $viewPath.'/index')."</li>";
|
||||
if($formName == 'Edit') {
|
||||
foreach($fieldNames as $field => $value) {
|
||||
if(isset($value['foreignKey'])) {
|
||||
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), $path.Inflector::underscore($value['controller'])."/view/".$data[$modelKey][$field] )."</li>";
|
||||
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), $path . Inflector::underscore($value['controller'])."/index")."</li>";
|
||||
echo "<li>".$html->link( "Add ".Inflector::humanize($value['modelKey']), $path . Inflector::underscore($value['controller'])."/add/")."</li>";
|
||||
}
|
||||
}
|
||||
}?>
|
||||
|
|
|
@ -24,65 +24,69 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h1>List <?php echo Inflector::humanize($this->name)?></h1>
|
||||
<h2>List <?php echo $humanPluralName;?></h2>
|
||||
<?php
|
||||
/* remove
|
||||
$model = ucwords(Inflector::singularize($this->name));
|
||||
$modelKey = $model;
|
||||
$humanName = Inflector::humanize($this->name);
|
||||
$humanSingularName = Inflector::singularize( $humanName );
|
||||
*/
|
||||
|
||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||
/*
|
||||
if(is_null($this->plugin)) {
|
||||
$path = '/';
|
||||
} else {
|
||||
$path = '/'.$this->plugin.'/';
|
||||
}
|
||||
if(!empty($this->controller->{$model}->alias)) {
|
||||
foreach ($this->controller->{$model}->alias as $key => $value) {
|
||||
$alias[] = $key;
|
||||
}
|
||||
}*/
|
||||
|
||||
if(!empty($modelObj->alias)) {
|
||||
$alias = array_combine(array_keys($modelObj->alias), array_keys($modelObj->alias));
|
||||
}?>
|
||||
<table class="inav" cellpadding="0" cellspacing="0">
|
||||
<table class="scaffold" cellpadding="0" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
foreach ($fieldNames as $fieldName) {?>
|
||||
<th><?php echo $fieldName['prompt'];?></th>
|
||||
<?php }?>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<?php foreach ($fieldNames as $fieldName) {?>
|
||||
<th><?php echo $fieldName['prompt'];?></th>
|
||||
<?php }?>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$iRowIndex = 0;
|
||||
$i = 0;
|
||||
if(is_array($data)) {
|
||||
foreach ($data as $row) {
|
||||
if($iRowIndex++ % 2 == 0) {
|
||||
echo "<tr>";
|
||||
if($i++ % 2 == 0) {
|
||||
echo '<tr>';
|
||||
} else {
|
||||
echo "<tr class='altRow'>";
|
||||
echo '<tr class="altRow"">';
|
||||
}
|
||||
$count = 0;
|
||||
foreach($fieldNames as $field=>$value) { ?>
|
||||
foreach($fieldNames as $field => $value) { //pr($value);
|
||||
?>
|
||||
<td>
|
||||
<?php
|
||||
if(isset($value['foreignKey'])) {
|
||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
||||
$otherControllerName = $value['controller'];
|
||||
$otherModelObject =& ClassRegistry::getObject( $otherModelKey );
|
||||
if(is_object($otherModelObject)) {
|
||||
$displayText = $row[$alias[$count]][ $otherModelObject->getDisplayField() ];
|
||||
} else {
|
||||
$displayText = $row[$alias[$count]][$field];
|
||||
}
|
||||
echo $html->link( $displayText, $path.Inflector::underscore($otherControllerName)."/view/".$row[$modelKey][$field] );
|
||||
$count++;
|
||||
} else {
|
||||
echo $row[$modelKey][$field];
|
||||
}?>
|
||||
<?php
|
||||
if(isset($value['foreignKey'])) {
|
||||
$otherControllerName = $value['controller'];
|
||||
$otherControllerPath = Inflector::underscore($value['controller']);
|
||||
$otherModelObject =& ClassRegistry::getObject($value['modelKey']);
|
||||
if(is_object($otherModelObject)) {
|
||||
$displayText = $row[$alias[$value['model']]][$otherModelObject->getDisplayField()];
|
||||
} else {
|
||||
$displayText = $row[$alias[$value['model']]][$field];
|
||||
}
|
||||
echo $html->link($displayText, '/'.Inflector::underscore($otherControllerName)."/view/".$row[$modelClass][$field]);
|
||||
} else {
|
||||
echo $row[$modelClass][$field];
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<td class="listactions"><?php echo $html->link('View',$path.$this->viewPath."/view/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit',$path.$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',$path.$this->viewPath."/delete/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$modelKey][$this->controller->{$model}->primaryKey].' ?')?>
|
||||
<td class="actions">
|
||||
<?php echo $html->link('View', '/'.$viewPath."/view/{$row[$modelClass][$modelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit', '/'.$viewPath."/edit/{$row[$modelClass][$modelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete', '/'.$viewPath."/delete/{$row[$modelClass][$modelObj->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$modelClass][$modelObj->primaryKey].' ?')?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
@ -91,5 +95,5 @@ if(is_array($data)) {
|
|||
</tbody>
|
||||
</table>
|
||||
<ul class="actions">
|
||||
<li><?php echo $html->link('New '.$humanSingularName, $path.$this->viewPath.'/add'); ?></li>
|
||||
<li><?php echo $html->link('New '.$humanSingularName, '/'.$viewPath.'/add'); ?></li>
|
||||
</ul>
|
|
@ -25,41 +25,41 @@
|
|||
*/
|
||||
?>
|
||||
<?php
|
||||
/*
|
||||
$modelName = ucwords(Inflector::singularize($this->name));
|
||||
$modelKey = Inflector::underscore($modelName);
|
||||
$objModel =& ClassRegistry::getObject($modelKey);
|
||||
|
||||
*/
|
||||
if(is_null($this->plugin)) {
|
||||
$path = '/';
|
||||
} else {
|
||||
$path = '/'.$this->plugin.'/';
|
||||
}
|
||||
if(!empty($objModel->alias)) {
|
||||
foreach ($objModel->alias as $key => $value) {
|
||||
$alias[] = $key;
|
||||
}
|
||||
$count = 0;
|
||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||
if(!empty($modelObj->alias)) {
|
||||
$alias = array_combine(array_keys($modelObj->alias), array_keys($modelObj->alias));
|
||||
}?>
|
||||
<h1>View
|
||||
<?php echo Inflector::humanize($modelName)?>
|
||||
<h1>View <?php echo $humanSingularName?>
|
||||
</h1>
|
||||
<dl>
|
||||
<?php
|
||||
foreach($fieldNames as $field => $value) {
|
||||
echo "<dt>".$value['prompt']."</dt>";
|
||||
if(isset($value['foreignKey'])) {
|
||||
$otherModelObject =& ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
|
||||
$displayField = $otherModelObject->getDisplayField();
|
||||
$displayText = $data[$alias[$count]][$displayField];
|
||||
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]) && (isset($displayText))) {
|
||||
echo "<dd>".$html->link($displayText, $path.Inflector::underscore($value['controller']).'/view/'
|
||||
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";
|
||||
$otherControllerName = $value['controller'];
|
||||
$otherControllerPath = Inflector::underscore($value['controller']);
|
||||
$otherModelObj =& ClassRegistry::getObject($value['modelKey']);
|
||||
$othereDisplayField = $otherModelObj->getDisplayField();
|
||||
$displayText = $data[$alias[$value['model']]][$othereDisplayField];
|
||||
if(!empty($data[$modelClass][$field]) && (isset($displayText))) {
|
||||
echo "<dd>".$html->link($displayText, $path . $otherControllerPath.'/view/'
|
||||
.$data[$modelClass][$field] )."</dd>";
|
||||
} else {
|
||||
echo "<dd> </dd>";
|
||||
}
|
||||
$count++;
|
||||
} else {
|
||||
if( !empty($data[$objModel->tableToModel[$objModel->table]][$field])) {
|
||||
echo "<dd>".$data[$objModel->tableToModel[$objModel->table]][$field]."</dd>";
|
||||
if( !empty($data[$modelClass][$field])) {
|
||||
echo "<dd>".$data[$modelClass][$field]."</dd>";
|
||||
} else {
|
||||
echo "<dd> </dd>";
|
||||
}
|
||||
|
@ -68,29 +68,29 @@ foreach($fieldNames as $field => $value) {
|
|||
</dl>
|
||||
<ul class='actions'>
|
||||
<?php
|
||||
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), $path.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
|
||||
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), $path.$this->viewPath.'/delete/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey], null, 'Are you sure you want to delete id '.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey].' ?')."</li>";
|
||||
echo "<li>".$html->link('List '.Inflector::humanize($objModel->name), $path.$this->viewPath.'/index')."</li>";
|
||||
echo "<li>".$html->link('New '.Inflector::humanize($objModel->name), $path.$this->viewPath.'/add')."</li>";
|
||||
echo "<li>".$html->link('Edit '.$humanSingularName, $path . $viewPath.'/edit/'.$data[$modelClass][$modelObj->primaryKey])."</li>";
|
||||
echo "<li>".$html->link('Delete '.$humanSingularName, $path . $viewPath.'/delete/'.$data[$modelClass][$modelObj->primaryKey], null, 'Are you sure you want to delete id '.$data[$modelClass][$modelObj->primaryKey].' ?')."</li>";
|
||||
echo "<li>".$html->link('List '.Inflector::pluralize($humanSingularName), $path . $viewPath.'/index')."</li>";
|
||||
echo "<li>".$html->link('New '.$humanSingularName, $path . $viewPath.'/add')."</li>";
|
||||
|
||||
foreach( $fieldNames as $field => $value ) {
|
||||
if( isset( $value['foreignKey'] ) ) {
|
||||
echo "<li>".$html->link( "List ".Inflector::humanize($value['controller']), $path.Inflector::underscore($value['controller'])."/index/")."</li>";
|
||||
echo "<li>".$html->link( "List ".Inflector::humanize($value['controller']), $path . $value['controller'] ."/index/")."</li>";
|
||||
}
|
||||
}?>
|
||||
</ul>
|
||||
|
||||
<!--hasOne relationships -->
|
||||
<?php
|
||||
foreach ($objModel->hasOne as $association => $relation) {
|
||||
$model = $relation['className'];
|
||||
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
|
||||
$controller = Inflector::pluralize($model);
|
||||
foreach ($modelObj->hasOne as $associationNameName => $relation) {
|
||||
$otherModelKey = Inflector::underscore($relation['className']);
|
||||
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||
$otherControllerPath = Inflector::pluralize($otherModelKey);
|
||||
$new = true;
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize($associationNameName)."</H2>";
|
||||
echo "<dl>";
|
||||
if(isset($data[$association]) && is_array($data[$association])) {
|
||||
foreach($data[$association] as $field => $value) {
|
||||
if(isset($data[$associationNameName]) && is_array($data[$associationNameName])) {
|
||||
foreach($data[$associationNameName] as $field => $value) {
|
||||
if(isset($value)) {
|
||||
echo "<dt>".Inflector::humanize($field)."</dt>";
|
||||
if(!empty($value)) {
|
||||
|
@ -103,9 +103,9 @@ foreach ($objModel->hasOne as $association => $relation) {
|
|||
}
|
||||
echo "</dl>";
|
||||
if($new == null) {
|
||||
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),$path.Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($associationNameName), $path . $otherControllerPath."/edit/{$data[$associationNameName][$otherModelObj->primaryKey]}")."</li></ul></div>";
|
||||
} else {
|
||||
echo "<ul class='actions'><li>".$html->link('New '.Inflector::humanize($association),$path.Inflector::underscore($controller)."/add/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||
echo "<ul class='actions'><li>".$html->link('New '.Inflector::humanize($associationNameName), $path . $otherControllerPath."/add/{$data[$associationNameName][$otherModelObj->primaryKey]}")."</li></ul></div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,46 +113,51 @@ foreach ($objModel->hasOne as $association => $relation) {
|
|||
|
||||
<!-- HAS MANY AND HASANDBELONGSTOMANY -->
|
||||
<?php
|
||||
$relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany);
|
||||
foreach($relations as $association => $relation) {
|
||||
$model = $relation['className'];
|
||||
$count = 0;
|
||||
$otherModelName = Inflector::singularize($model);
|
||||
$controller = Inflector::pluralize($model);
|
||||
$relations = array_merge($modelObj->hasMany, $modelObj->hasAndBelongsToMany);
|
||||
foreach($relations as $associationName => $relation) {
|
||||
|
||||
$otherModelKey = Inflector::underscore($relation['className']);
|
||||
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
||||
$otherControllerPath = Inflector::pluralize($otherModelKey);
|
||||
|
||||
$otherModelName = $relation['className'];
|
||||
|
||||
echo "<div class='related'><H2>Related ".Inflector::humanize(Inflector::pluralize($association))."</H2>";
|
||||
if(isset($data[$association][0]) && is_array($data[$association])) {?>
|
||||
echo "<div class='related'><h2>Related ".Inflector::humanize($otherControllerPath)."</h2>";
|
||||
if(isset($data[$associationName][0]) && is_array($data[$associationName])) {?>
|
||||
<table class="inav" cellspacing="0">
|
||||
<tr>
|
||||
<?php
|
||||
$bFound = false;
|
||||
foreach($data[$association][0] as $column=>$value) {
|
||||
foreach($data[$associationName][0] as $column => $value) {
|
||||
if(false !== strpos($column, "_id")) {
|
||||
$column = substr($column, 0, strpos($column, "_id" ));
|
||||
}
|
||||
echo "<th>".Inflector::humanize($column)."</th>";
|
||||
}?>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data[$association] as $row) {
|
||||
foreach($data[$associationName] as $row) {
|
||||
echo "<tr>";
|
||||
foreach($row as $column=>$value) {
|
||||
foreach($row as $column => $value) {
|
||||
echo "<td>".$value."</td>";
|
||||
}
|
||||
if (isset($this->controller->{$modelName}->{$association})) {?>
|
||||
<td class="listactions"><?php echo $html->link('View',$path.Inflector::underscore($controller).
|
||||
"/view/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit',$path.Inflector::underscore($controller).
|
||||
"/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',$path.Inflector::underscore($controller).
|
||||
"/delete/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$this->controller->{$modelName}->{$association}->primaryKey].' ?')?>
|
||||
if (isset($otherModelObj->{$associationName})) {?>
|
||||
<td class="listactions"><?php echo $html->link('View', $path . $otherControllerPath .
|
||||
"/view/{$row[$otherModelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit', $path . $otherControllerPath .
|
||||
"/edit/{$row[$otherModelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete', $path . $otherControllerPath .
|
||||
"/delete/{$row[$otherModelObj->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$otherModelObj->primaryKey].' ?')?>
|
||||
</td>
|
||||
<?php
|
||||
} else {?>
|
||||
<td class="listactions"><?php echo $html->link('View',$path.Inflector::underscore($controller).
|
||||
"/view/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit',$path.Inflector::underscore($controller).
|
||||
"/edit/{$row[$this->controller->{$modelName}->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete',$path.Inflector::underscore($controller).
|
||||
"/delete/{$row[$this->controller->{$modelName}->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$this->controller->{$modelName}->primaryKey].' ?')?>
|
||||
<td class="listactions"><?php echo $html->link('View', $path . $otherControllerPath .
|
||||
"/view/{$row[$otherModelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Edit', $path . $otherControllerPath .
|
||||
"/edit/{$row[$otherModelObj->primaryKey]}/")?>
|
||||
<?php echo $html->link('Delete', $path . $otherControllerPath .
|
||||
"/delete/{$row[$otherModelObj->primaryKey]}/", null, 'Are you sure you want to delete id '.$row[$otherModelObj->primaryKey].' ?')?>
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
|
@ -161,6 +166,6 @@ foreach($relations as $association => $relation) {
|
|||
}?>
|
||||
</table>
|
||||
<ul class="actions">
|
||||
<?php echo "<li>".$html->link('New '.Inflector::humanize($association),$path.Inflector::underscore($controller)."/add/")."</li>";?>
|
||||
<?php echo "<li>".$html->link('New '.Inflector::humanize($associationName), $path . $otherControllerPath ."/add/")."</li>";?>
|
||||
</ul></div>
|
||||
<?php }?>
|
Loading…
Add table
Reference in a new issue