Adding fix for Ticket #1435

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3526 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-09-20 04:43:28 +00:00
parent bdf3e7e61f
commit daf235cd23

View file

@ -879,56 +879,60 @@ class Controller extends Object {
* Cleans up the date fields of current Model. * Cleans up the date fields of current Model.
* *
*/ */
function cleanUpFields() { function cleanUpFields($modelClass = null) {
foreach($this->{$this->modelClass}->_tableInfo as $table) { if ($modelClass == null) {
$modelClass = $this->modelClass;
}
foreach($this->{$modelClass}->_tableInfo as $table) {
foreach($table as $field) { foreach($table as $field) {
if ('date' == $field['type'] && isset($this->params['data'][$this->modelClass][$field['name'] . '_year'])) { if ('date' == $field['type'] && isset($this->params['data'][$modelClass][$field['name'] . '_year'])) {
$newDate = $this->params['data'][$this->modelClass][$field['name'] . '_year'] . '-'; $newDate = $this->params['data'][$modelClass][$field['name'] . '_year'] . '-';
$newDate .= $this->params['data'][$this->modelClass][$field['name'] . '_month'] . '-'; $newDate .= $this->params['data'][$modelClass][$field['name'] . '_month'] . '-';
$newDate .= $this->params['data'][$this->modelClass][$field['name'] . '_day']; $newDate .= $this->params['data'][$modelClass][$field['name'] . '_day'];
unset($this->params['data'][$this->modelClass][$field['name'] . '_year']); unset($this->params['data'][$modelClass][$field['name'] . '_year']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_month']); unset($this->params['data'][$modelClass][$field['name'] . '_month']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_day']); unset($this->params['data'][$modelClass][$field['name'] . '_day']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_hour']); unset($this->params['data'][$modelClass][$field['name'] . '_hour']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_min']); unset($this->params['data'][$modelClass][$field['name'] . '_min']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_meridian']); unset($this->params['data'][$modelClass][$field['name'] . '_meridian']);
$this->params['data'][$this->modelClass][$field['name']] = $newDate; $this->params['data'][$modelClass][$field['name']] = $newDate;
$this->data[$this->modelClass][$field['name']] = $newDate; $this->data[$modelClass][$field['name']] = $newDate;
} elseif('datetime' == $field['type'] && isset($this->params['data'][$this->modelClass][$field['name'] . '_year'])) { } elseif('datetime' == $field['type'] && isset($this->params['data'][$modelClass][$field['name'] . '_year'])) {
$hour = $this->params['data'][$this->modelClass][$field['name'] . '_hour']; $hour = $this->params['data'][$modelClass][$field['name'] . '_hour'];
if ($hour != 12 && (isset($this->params['data'][$this->modelClass][$field['name'] . '_meridian']) && 'pm' == $this->params['data'][$this->modelClass][$field['name'] . '_meridian'])) { if ($hour != 12 && (isset($this->params['data'][$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->params['data'][$modelClass][$field['name'] . '_meridian'])) {
$hour = $hour + 12; $hour = $hour + 12;
} }
$newDate = $this->params['data'][$this->modelClass][$field['name'] . '_year'] . '-'; $newDate = $this->params['data'][$modelClass][$field['name'] . '_year'] . '-';
$newDate .= $this->params['data'][$this->modelClass][$field['name'] . '_month'] . '-'; $newDate .= $this->params['data'][$modelClass][$field['name'] . '_month'] . '-';
$newDate .= $this->params['data'][$this->modelClass][$field['name'] . '_day'] . ' '; $newDate .= $this->params['data'][$modelClass][$field['name'] . '_day'] . ' ';
$newDate .= $hour . ':' . $this->params['data'][$this->modelClass][$field['name'] . '_min'] . ':00'; $newDate .= $hour . ':' . $this->params['data'][$modelClass][$field['name'] . '_min'] . ':00';
unset($this->params['data'][$this->modelClass][$field['name'] . '_year']); unset($this->params['data'][$modelClass][$field['name'] . '_year']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_month']); unset($this->params['data'][$modelClass][$field['name'] . '_month']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_day']); unset($this->params['data'][$modelClass][$field['name'] . '_day']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_hour']); unset($this->params['data'][$modelClass][$field['name'] . '_hour']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_min']); unset($this->params['data'][$modelClass][$field['name'] . '_min']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_meridian']); unset($this->params['data'][$modelClass][$field['name'] . '_meridian']);
$this->params['data'][$this->modelClass][$field['name']] = $newDate; $this->params['data'][$modelClass][$field['name']] = $newDate;
$this->data[$this->modelClass][$field['name']] = $newDate; $this->data[$modelClass][$field['name']] = $newDate;
} elseif('time' == $field['type'] && isset($this->params['data'][$this->modelClass][$field['name'] . '_hour'])) { } elseif('time' == $field['type'] && isset($this->params['data'][$modelClass][$field['name'] . '_hour'])) {
$hour = $this->params['data'][$this->modelClass][$field['name'] . '_hour']; $hour = $this->params['data'][$modelClass][$field['name'] . '_hour'];
if ($hour != 12 && (isset($this->params['data'][$this->modelClass][$field['name'] . '_meridian']) && 'pm' == $this->params['data'][$this->modelClass][$field['name'] . '_meridian'])) { if ($hour != 12 && (isset($this->params['data'][$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->params['data'][$modelClass][$field['name'] . '_meridian'])) {
$hour = $hour + 12; $hour = $hour + 12;
} }
$newDate = $hour . ':' . $this->params['data'][$this->modelClass][$field['name'] . '_min'] . ':00'; $newDate = $hour . ':' . $this->params['data'][$modelClass][$field['name'] . '_min'] . ':00';
unset($this->params['data'][$this->modelClass][$field['name'] . '_hour']); unset($this->params['data'][$modelClass][$field['name'] . '_hour']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_min']); unset($this->params['data'][$modelClass][$field['name'] . '_min']);
unset($this->params['data'][$this->modelClass][$field['name'] . '_meridian']); unset($this->params['data'][$modelClass][$field['name'] . '_meridian']);
$this->params['data'][$this->modelClass][$field['name']] = $newDate; $this->params['data'][$modelClass][$field['name']] = $newDate;
$this->data[$this->modelClass][$field['name']] = $newDate; $this->data[$modelClass][$field['name']] = $newDate;
} }
} }
} }