Fixed can sorting cutted array with CArrayDataProvider #1534

Merged
merged 6 commits into from Oct 5, 2012

Conversation

Projects
None yet
5 participants
Contributor

Yiivgeny commented Oct 4, 2012

Sample code

$testArray = array(
    array('id' => 1, 'field1' => 'value1', 'field2' => 'value2'),
    array('id' => 2, 'field1' => 'value3'),
);

$dataProvider = new CArrayDataProvider($testArray,array(
    'sort' => array(
        'attributes' => array('id', 'field1', 'field2')
    )
));

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider,
    'columns' => array('field1', 'field2')
));

Initial rendered correctly, but sort this grid by field2 thrown exception Undefined index: field2 on framework/web/CArrayDataProvider.php(160)

framework/web/CArrayDataProvider.php
- $data = is_object($data) ? $data->$field : $data[$field];
+ foreach($fields as $field){
+ if(is_object($data))
+ $data = isset($data->$field)?$data->$field:null;
@creocoder

creocoder Oct 4, 2012

Contributor

$data=isset($data->$field) ? $data->$field : null;

framework/web/CArrayDataProvider.php
+ if(is_object($data))
+ $data = isset($data->$field)?$data->$field:null;
+ else
+ $data = isset($data[$field])?$data[$field]:null;
@creocoder

creocoder Oct 4, 2012

Contributor

same here

Owner

cebe commented Oct 5, 2012

This is about #1531

CHANGELOG
@@ -3,6 +3,7 @@
Version 1.1.13 work in progress
-------------------------------
+- Bug: Fixed can sorting cutted array with CArrayDataProvider (Yiivgeny)
@cebe

cebe Oct 5, 2012

Owner

add issue number #1531 and make sure, changelog lines are sorted by number.

Contributor

Yiivgeny commented Oct 5, 2012

@cebe, @creocoder, fixed.

framework/web/CArrayDataProvider.php
+ $data=isset($data->$field) ? $data->$field : null;
+ else
+ $data=isset($data[$field]) ? $data[$field] : null;
+ }
@cebe

cebe Oct 5, 2012

Owner

sry, missed that last time. Your indentation is wrong, please use tabs instead of spaces.

CHANGELOG
@@ -25,6 +25,7 @@ Version 1.1.13 work in progress
- Bug #1444: Fixed CGoogleApi::register call to registerScriptFile (mdomba)
- Bug #1465: Fixed CHtml::beginForm() when CActiveForm with method GET and ajaxButton is used (mdomba)
- Bug #1485 CSort does not quote table alias when using CDbCriteria (undsoft)
+- Bug #1531: Fixed can sorting cutted array with CArrayDataProvider (Yiivgeny)
@cebe

cebe Oct 5, 2012

Owner

I'd see this as an enhancement, also description can be improved a bit:

Enh #1531: CArrayDataProvider is now able to sort cutted array, where sorting column is not available in every entry (Yiivgeny)

@ghost ghost assigned cebe Oct 5, 2012

Contributor

Yiivgeny commented Oct 5, 2012

@cebe, fixed.

Member

mdomba commented Oct 5, 2012

Regarding performace it would be better to put is_object() check outsite foreach{}

Owner

samdark commented Oct 5, 2012

Looks good to me. @mdomba merging?

Member

mdomba commented Oct 5, 2012

Yes, looks good to me too... I did not merge it because the issue is assigned to @cebe

samdark added a commit that referenced this pull request Oct 5, 2012

Merge pull request #1534 from Yiivgeny/CArrayDataProvider-bug
Fixed can sorting cutted array with CArrayDataProvider

@samdark samdark merged commit a793880 into yiisoft:master Oct 5, 2012

Owner

cebe commented Oct 7, 2012

Yeah, assigned it to me, to merge it later, all fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment