Skip to content

Commit

Permalink
Removing code that should not have existed in the first place
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 27, 2011
1 parent faa8b3d commit ad456bd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
51 changes: 0 additions & 51 deletions lib/Cake/Test/Case/Utility/SanitizeTest.php
Expand Up @@ -465,55 +465,4 @@ function testStripTags() {
$result = Sanitize::stripTags($string, 'h2', 'a', 'img');
$this->assertEqual($expected, $result);
}

/**
* testFormatColumns method
*
* @access public
* @return void
*/
function testFormatColumns() {
$this->autoFixtures = true;
$this->fixtureManager->load($this);
$this->loadFixtures('DataTest', 'Article');

$this->DataTest = new SanitizeDataTest(array('alias' => 'DataTest'));
$data = array('DataTest' => array(
'id' => 'z',
'count' => '12a',
'float' => '2.31456',
'updated' => '2008-01-01'
)
);
$this->DataTest->set($data);
$expected = array('DataTest' => array(
'id' => '0',
'count' => '12',
'float' => 2.31456,
'updated' => '2008-01-01 00:00:00',
));
Sanitize::formatColumns($this->DataTest);
$result = $this->DataTest->data;
$this->assertEqual($expected, $result);

$this->Article = new SanitizeArticle(array('alias' => 'Article'));
$data = array('Article' => array(
'id' => 'ZB',
'user_id' => '12',
'title' => 'title of article',
'body' => 'body text',
'published' => 'QQQQQQQ',
));
$this->Article->set($data);
$expected = array('Article' => array(
'id' => '0',
'user_id' => '12',
'title' => 'title of article',
'body' => 'body text',
'published' => 'QQQQQQQ',
));
Sanitize::formatColumns($this->Article);
$result = $this->Article->data;
$this->assertEqual($expected, $result);
}
}
69 changes: 0 additions & 69 deletions lib/Cake/Utility/Sanitize.php
Expand Up @@ -257,73 +257,4 @@ public static function clean($data, $options = array()) {
return $data;
}
}

/**
* Formats column data from definition in DBO's $columns array
*
* @param Model $model The model containing the data to be formatted
*/
public static function formatColumns($model) {
foreach ($model->data as $name => $values) {
if ($name == $model->alias) {
$curModel = $model;
} elseif (isset($model->{$name}) && is_object($model->{$name}) && is_subclass_of($model->{$name}, 'Model')) {
$curModel = $model->{$name};
} else {
$curModel = null;
}

if ($curModel != null) {
foreach ($values as $column => $data) {
$colType = $curModel->getColumnType($column);

if ($colType != null) {
$db = ConnectionManager::getDataSource($curModel->useDbConfig);
$colData = $db->columns[$colType];

if (isset($colData['limit']) && strlen(strval($data)) > $colData['limit']) {
$data = substr(strval($data), 0, $colData['limit']);
}

if (isset($colData['formatter']) || isset($colData['format'])) {

switch (strtolower($colData['formatter'])) {
case 'date':
$data = date($colData['format'], strtotime($data));
break;
case 'sprintf':
$data = sprintf($colData['format'], $data);
break;
case 'intval':
$data = intval($data);
break;
case 'floatval':
$data = floatval($data);
break;
}
}
$model->data[$name][$column]=$data;
/*
switch ($colType) {
case 'integer':
case 'int':
return $data;
break;
case 'string':
case 'text':
case 'binary':
case 'date':
case 'time':
case 'datetime':
case 'timestamp':
case 'date':
return "'" . $data . "'";
break;
}
*/
}
}
}
}
}
}

0 comments on commit ad456bd

Please sign in to comment.