Fixing whitespacing.

This commit is contained in:
Mark Story 2009-12-17 00:15:42 -05:00
parent c65e2f3f18
commit b190e462b8
5 changed files with 35 additions and 35 deletions

View file

@ -1078,7 +1078,7 @@ class Controller extends Object {
if ($object->hasField($field)) {
$options['order'][$alias . '.' . $field] = $value;
} elseif ($object->hasField($field,true)) {
} elseif ($object->hasField($field, true)) {
$options['order'][$field] = $value;
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
$options['order'][$alias . '.' . $field] = $value;

View file

@ -399,13 +399,13 @@ class DboSource extends DataSource {
function fetchVirtualField(&$result) {
if (isset($result[0]) && is_array($result[0])) {
foreach ($result[0] as $field => $value) {
if (strpos($field,'__') === false) {
if (strpos($field, '__') === false) {
continue;
}
list($alias,$virtual) = explode('__',$field);
list($alias, $virtual) = explode('__', $field);
if (!ClassRegistry::isKeySet($alias)) {
retrun;
return;
}
$model = ClassRegistry::getObject($alias);
if ($model->isVirtualField($virtual)) {
@ -1365,7 +1365,7 @@ class DboSource extends DataSource {
'fields' => implode(', ', $query['fields']),
'table' => $query['table'],
'alias' => $this->alias . $this->name($query['alias']),
'order' => $this->order($query['order'],'ASC',$model),
'order' => $this->order($query['order'], 'ASC', $model),
'limit' => $this->limit($query['limit'], $query['offset']),
'joins' => implode(' ', $query['joins']),
'group' => $this->group($query['group'])
@ -1820,13 +1820,13 @@ class DboSource extends DataSource {
$virtual = array();
if ($model->getVirtualField()) {
$keys = array_keys($model->getVirtualField());
$virtual = ($allFields) ? $keys : array_intersect($keys,$fields);
$virtual = ($allFields) ? $keys : array_intersect($keys, $fields);
}
$count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
for ($i = 0; $i < $count; $i++) {
if (in_array($fields[$i],$virtual)) {
if (in_array($fields[$i], $virtual)) {
unset($fields[$i]);
continue;
}
@ -1884,7 +1884,7 @@ class DboSource extends DataSource {
}
}
if (!empty($virtual)) {
$fields = array_merge($fields,$this->_constructVirtualFields($model,$alias,$virtual));
$fields = array_merge($fields,$this->_constructVirtualFields($model, $alias, $virtual));
}
return array_unique($fields);
}
@ -2199,7 +2199,7 @@ class DboSource extends DataSource {
$keys = array_filter($keys);
$result = array();
while (!empty($keys)) {
list($key,$dir) = each($keys);
list($key, $dir) = each($keys);
array_shift($keys);
if (is_numeric($key)) {
@ -2212,10 +2212,10 @@ class DboSource extends DataSource {
}
if (is_array($key)) {
//Flatten the array
$key = array_reverse($key,true);
$key = array_reverse($key, true);
foreach ($key as $k => $v) {
if (is_numeric($k)) {
array_unshift($keys,$v);
array_unshift($keys, $v);
} else {
$keys = array($k => $v) + $keys;
}
@ -2250,7 +2250,7 @@ class DboSource extends DataSource {
$result[] = $key;
}
if (!empty($result)) {
return ' ORDER BY ' . implode(', ',$result);
return ' ORDER BY ' . implode(', ', $result);
}
return '';
}

View file

@ -1018,7 +1018,7 @@ class Model extends Overloadable {
function hasField($name, $checkVirtual = false) {
if (is_array($name)) {
foreach ($name as $n) {
if ($this->hasField($n,$checkVirtual)) {
if ($this->hasField($n, $checkVirtual)) {
return $n;
}
}
@ -1049,7 +1049,7 @@ class Model extends Overloadable {
* @access public
*/
function isVirtualField($field) {
return !empty($this->virtualFields) && is_string($field) && array_key_exists($field,$this->virtualFields);
return !empty($this->virtualFields) && is_string($field) && array_key_exists($field, $this->virtualFields);
}
/**
@ -1159,7 +1159,7 @@ class Model extends Overloadable {
$recursive = $this->recursive;
}
$fields = $name;
if ($data = $this->find('first',compact('conditions','fields','order','recursive'))) {
if ($data = $this->find('first', compact('conditions', 'fields', 'order', 'recursive'))) {
if (strpos($name, '.') === false) {
if (isset($data[$this->alias][$name])) {
return $data[$this->alias][$name];

View file

@ -1254,15 +1254,15 @@ class ControllerTest extends CakeTestCase {
);
$Controller->paginate = array(
'fields' => array('id', 'title','offset_test'),
'fields' => array('id', 'title', 'offset_test'),
'order' => array('offset_test' => 'DESC')
);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(4,3,2));
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(4, 3, 2));
$Controller->passedArgs = array('sort' => 'offset_test', 'direction' => 'asc');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2,3,4));
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2, 3, 4));
}
}
?>

View file

@ -215,14 +215,14 @@ class ModelReadTest extends BaseModelTest {
array('Product' => array('type' => 'Toy'), array('price' => 3))
);
$result = $Product->find('all',array(
'fields'=>array('Product.type','MIN(Product.price) as price'),
'fields'=>array('Product.type', 'MIN(Product.price) as price'),
'group'=> 'Product.type',
'order' => 'Product.type ASC'
));
$this->assertEqual($result, $expected);
$result = $Product->find('all', array(
'fields'=>array('Product.type','MIN(Product.price) as price'),
'fields'=>array('Product.type', 'MIN(Product.price) as price'),
'group'=> array('Product.type'),
'order' => 'Product.type ASC'));
$this->assertEqual($result, $expected);
@ -7176,45 +7176,45 @@ class ModelReadTest extends BaseModelTest {
$Post = ClassRegistry::init('Post');
$Post->virtualFields = array('two' => "1 + 1");
$result = $Post->find('first');
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$Post->Author->virtualFields = array('false' => '1 = 2');
$result = $Post->find('first');
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$this->assertEqual($result['Author']['false'],false);
$result = $Post->find('first',array('fields' => array('author_id')));
$this->assertFalse(isset($result['Post']['two']));
$this->assertFalse(isset($result['Author']['false']));
$result = $Post->find('first',array('fields' => array('author_id','two')));
$this->assertEqual($result['Post']['two'],2);
$result = $Post->find('first',array('fields' => array('author_id', 'two')));
$this->assertEqual($result['Post']['two'], 2);
$this->assertFalse(isset($result['Author']['false']));
$result = $Post->find('first',array('fields' => array('two')));
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$Post->id = 1;
$result = $Post->field('two');
$this->assertEqual($result,2);
$this->assertEqual($result, 2);
$result = $Post->find('first',array(
'conditions' => array('two' => 2),
'limit' => 1
));
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$result = $Post->find('first',array(
'conditions' => array('two <' => 3),
'limit' => 1
));
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$result = $Post->find('first',array(
'conditions' => array('NOT' => array('two >' => 3)),
'limit' => 1
));
$this->assertEqual($result['Post']['two'],2);
$this->assertEqual($result['Post']['two'], 2);
$dbo =& $Post->getDataSource();
$Post->virtualFields = array('other_field' => 'Post.id + 1');
@ -7222,24 +7222,24 @@ class ModelReadTest extends BaseModelTest {
'conditions' => array('other_field' => 3),
'limit' => 1
));
$this->assertEqual($result['Post']['id'],2);
$this->assertEqual($result['Post']['id'], 2);
$Post->virtualFields = array('other_field' => 'Post.id + 1');
$result = $Post->find('all',array(
'fields' => array($dbo->calculate($Post,'max',array('other_field')))
'fields' => array($dbo->calculate($Post, 'max',array('other_field')))
));
$this->assertEqual($result[0][0]['other_field'],4);
$this->assertEqual($result[0][0]['other_field'], 4);
ClassRegistry::flush();
$Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'),'Model');
$Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
$Writing->virtualFields = array('two' => "1 + 1");
$result = $Writing->find('first');
$this->assertEqual($result['Writing']['two'],2);
$this->assertEqual($result['Writing']['two'], 2);
$Post->create();
$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
$result = $Post->field('other_field');
$this->assertEqual($result,4);
$this->assertEqual($result, 4);
}
}
?>