Skip to content

Commit

Permalink
Fixing whitespacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 17, 2009
1 parent c65e2f3 commit b190e46
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -1078,7 +1078,7 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {

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;
Expand Down
22 changes: 11 additions & 11 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -399,13 +399,13 @@ function fetchAll($sql, $cache = true, $modelName = null) {
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)) {
Expand Down Expand Up @@ -1365,7 +1365,7 @@ function buildStatement($query, &$model) {
'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'])
Expand Down Expand Up @@ -1820,13 +1820,13 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
$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;
}
Expand Down Expand Up @@ -1884,7 +1884,7 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
}
}
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);
}
Expand Down Expand Up @@ -2199,7 +2199,7 @@ function order($keys, $direction = 'ASC', &$model = null) {
$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)) {
Expand All @@ -2212,10 +2212,10 @@ function order($keys, $direction = 'ASC', &$model = null) {
}
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;
}
Expand Down Expand Up @@ -2250,7 +2250,7 @@ function order($keys, $direction = 'ASC', &$model = null) {
$result[] = $key;
}
if (!empty($result)) {
return ' ORDER BY ' . implode(', ',$result);
return ' ORDER BY ' . implode(', ', $result);
}
return '';
}
Expand Down
6 changes: 3 additions & 3 deletions cake/libs/model/model.php
Expand Up @@ -1018,7 +1018,7 @@ function getColumnType($column) {
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;
}
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ function hasField($name, $checkVirtual = false) {
* @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);
}

/**
Expand Down Expand Up @@ -1159,7 +1159,7 @@ function field($name, $conditions = null, $order = null) {
$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];
Expand Down
6 changes: 3 additions & 3 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -1254,15 +1254,15 @@ function testPaginateOrderVirtualField() {
);

$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));
}
}
?>
34 changes: 17 additions & 17 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -215,14 +215,14 @@ function testGroupBy() {
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);
Expand Down Expand Up @@ -7176,70 +7176,70 @@ function testVirtualFields() {
$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');
$result = $Post->find('first',array(
'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);
}
}
?>

0 comments on commit b190e46

Please sign in to comment.