From 47f5235f94872afbc28af4da1466c2333474915e Mon Sep 17 00:00:00 2001 From: ARNHOE Date: Thu, 29 Nov 2012 12:12:26 +0100 Subject: [PATCH 1/4] MINOR: Forgot Apostrophe in comment --- search/FulltextSearchable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/FulltextSearchable.php b/search/FulltextSearchable.php index c8615ed0e..314a66a1a 100644 --- a/search/FulltextSearchable.php +++ b/search/FulltextSearchable.php @@ -32,7 +32,7 @@ class FulltextSearchable extends DataExtension { * It can be used to limit the searched classes, but not to add your own classes. * For this purpose, please use {@link Object::add_extension()} directly: * - * Object::add_extension('MyObject', "FulltextSearchable('MySearchableField,'MyOtherField')"); + * Object::add_extension('MyObject', "FulltextSearchable('MySearchableField','MyOtherField')"); * * * Caution: This is a wrapper method that should only be used in _config.php, From cc3e500f82867a48caf4c3cbd0981544290ee618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Martins?= Date: Fri, 30 Nov 2012 01:37:36 +0000 Subject: [PATCH 2/4] return $this, for do things like this: new DropdownField('XPTOName', 'XPTO Label', XPTOModel::get()->map("ID", "Name")->unshift(0,'- Select -')) This does not break anything and makes things more natural --- model/Map.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/Map.php b/model/Map.php index d2cf4f456..c2d3a15cc 100644 --- a/model/Map.php +++ b/model/Map.php @@ -77,6 +77,8 @@ class SS_Map implements ArrayAccess, Countable, IteratorAggregate { $oldItems = $this->firstItems; $this->firstItems = array($key => $value); if($oldItems) $this->firstItems = $this->firstItems + $oldItems; + + return $this; } // ArrayAccess From 8590bec1a9ec994aff93c4ed6898cf2fc7bf5b70 Mon Sep 17 00:00:00 2001 From: ARNHOE Date: Fri, 30 Nov 2012 09:53:01 +0100 Subject: [PATCH 3/4] SummaryFields doesn't change Title of Field $field_labels does for me. --- docs/en/reference/modeladmin.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/modeladmin.md b/docs/en/reference/modeladmin.md index fda699538..a92d69729 100644 --- a/docs/en/reference/modeladmin.md +++ b/docs/en/reference/modeladmin.md @@ -72,14 +72,17 @@ for the search form, override `[api:DataObject->getCustomSearchContext()]` on yo The results are shown in a tabular listing, powered by the `[GridField](/reference/grid-field)`, more specifically the `[api:GridFieldDataColumns]` component. It looks for a `[api:DataObject::$summary_fields]` static on your model class, -where you can add or remove columns, or change their title. +where you can add or remove columns. To change the title, use `[api:DataObject::$field_labels]`. :::php class Product extends DataObject { // ... + static $field_labels = array( + 'Price' => 'Cost' // renames the column to "Cost" + ); static $summary_fields = array( - 'Name' => 'Name', - 'Price' => 'Cost', // renames the column to "Cost" + 'Name', + 'Price', // leaves out the 'ProductCode' field, removing the column ); } From 3f67404a8a81119565edd70778f5840e5dc6dc3c Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 30 Nov 2012 14:22:50 +0100 Subject: [PATCH 4/4] Revert "BUGFIX: ArrayList now discards keys of the array passed in and keeps the numerically indexed array sequential." This reverts commit b6017a7c902e5e66835dfbd4884924a56ac9a370. It breaks SelectionGroup, and its most prominent usage, the "add page" dialog. --- model/ArrayList.php | 28 +++----- tests/model/ArrayListTest.php | 124 +++++++++++++++++----------------- 2 files changed, 70 insertions(+), 82 deletions(-) diff --git a/model/ArrayList.php b/model/ArrayList.php index 0a4f63b70..4335b405c 100644 --- a/model/ArrayList.php +++ b/model/ArrayList.php @@ -19,7 +19,7 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta * @param array $items - an initial array to fill this object with */ public function __construct(array $items = array()) { - $this->items = array_values($items); + $this->items = $items; parent::__construct(); } @@ -138,14 +138,9 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta * @param mixed $item */ public function remove($item) { - $renumberKeys = false; foreach ($this->items as $key => $value) { - if ($item === $value) { - $renumberKeys = true; - unset($this->items[$key]); - } + if ($item === $value) unset($this->items[$key]); } - if($renumberKeys) $this->items = array_values($this->items); } /** @@ -182,20 +177,16 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta */ public function removeDuplicates($field = 'ID') { $seen = array(); - $renumberKeys = false; foreach ($this->items as $key => $item) { $value = $this->extractValue($item, $field); if (array_key_exists($value, $seen)) { - $renumberKeys = true; unset($this->items[$key]); } $seen[$value] = true; } - - if($renumberKeys) $this->items = array_values($this->items); } /** @@ -483,6 +474,7 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta } } + $itemsToKeep = array(); $hitsRequiredToRemove = count($removeUs); $matches = array(); @@ -497,17 +489,13 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta } $keysToRemove = array_keys($matches,$hitsRequiredToRemove); - - $itemsToKeep = array(); - foreach($this->items as $key => $value) { - if(!in_array($key, $keysToRemove)) { - $itemsToKeep[] = $value; - } - } - // TODO 3.1: This currently mutates existing array $list = /* clone */ $this; - $list->items = $itemsToKeep; + + foreach($keysToRemove as $itemToRemoveIdx){ + $list->remove($this->items[$itemToRemoveIdx]); + } + return $list; } diff --git a/tests/model/ArrayListTest.php b/tests/model/ArrayListTest.php index abcf662be..4a73a376e 100644 --- a/tests/model/ArrayListTest.php +++ b/tests/model/ArrayListTest.php @@ -428,15 +428,15 @@ class ArrayListTest extends SapphireTest { */ public function testSimpleExclude() { $list = new ArrayList(array( - array('Name' => 'Steve'), - array('Name' => 'Bob'), - array('Name' => 'John') + 0=>array('Name' => 'Steve'), + 1=>array('Name' => 'Bob'), + 2=>array('Name' => 'John') )); $list->exclude('Name', 'Bob'); $expected = array( - array('Name' => 'Steve'), - array('Name' => 'John') + 0=>array('Name' => 'Steve'), + 2=>array('Name' => 'John') ); $this->assertEquals(2, $list->count()); $this->assertEquals($expected, $list->toArray(), 'List should not contain Bob'); @@ -466,12 +466,12 @@ class ArrayListTest extends SapphireTest { */ public function testSimpleExcludeWithArray() { $list = new ArrayList(array( - array('Name' => 'Steve'), - array('Name' => 'Bob'), - array('Name' => 'John') + 0=>array('Name' => 'Steve'), + 1=>array('Name' => 'Bob'), + 2=>array('Name' => 'John') )); $list->exclude('Name', array('Steve','John')); - $expected = array(array('Name' => 'Bob')); + $expected = array(1=>array('Name' => 'Bob')); $this->assertEquals(1, $list->count()); $this->assertEquals($expected, $list->toArray(), 'List should only contain Bob'); } @@ -481,16 +481,16 @@ class ArrayListTest extends SapphireTest { */ public function testExcludeWithTwoArrays() { $list = new ArrayList(array( - array('Name' => 'Bob' , 'Age' => 21), - array('Name' => 'Bob' , 'Age' => 32), - array('Name' => 'John', 'Age' => 21) + 0=>array('Name' => 'Bob' , 'Age' => 21), + 1=>array('Name' => 'Bob' , 'Age' => 32), + 2=>array('Name' => 'John', 'Age' => 21) )); $list->exclude(array('Name' => 'Bob', 'Age' => 21)); $expected = array( - array('Name' => 'Bob', 'Age' => 32), - array('Name' => 'John', 'Age' => 21) + 1=>array('Name' => 'Bob', 'Age' => 32), + 2=>array('Name' => 'John', 'Age' => 21) ); $this->assertEquals(2, $list->count()); @@ -502,23 +502,23 @@ class ArrayListTest extends SapphireTest { */ public function testMultipleExclude() { $list = new ArrayList(array( - array('Name' => 'bob', 'Age' => 10), - array('Name' => 'phil', 'Age' => 11), - array('Name' => 'bob', 'Age' => 12), - array('Name' => 'phil', 'Age' => 12), - array('Name' => 'bob', 'Age' => 14), - array('Name' => 'phil', 'Age' => 14), - array('Name' => 'bob', 'Age' => 16), - array('Name' => 'phil', 'Age' => 16) + 0 => array('Name' => 'bob', 'Age' => 10), + 1 => array('Name' => 'phil', 'Age' => 11), + 2 => array('Name' => 'bob', 'Age' => 12), + 3 => array('Name' => 'phil', 'Age' => 12), + 4 => array('Name' => 'bob', 'Age' => 14), + 5 => array('Name' => 'phil', 'Age' => 14), + 6 => array('Name' => 'bob', 'Age' => 16), + 7 => array('Name' => 'phil', 'Age' => 16) )); $list->exclude(array('Name'=>array('bob','phil'),'Age'=>array(10, 16))); $expected = array( - array('Name' => 'phil', 'Age' => 11), - array('Name' => 'bob', 'Age' => 12), - array('Name' => 'phil', 'Age' => 12), - array('Name' => 'bob', 'Age' => 14), - array('Name' => 'phil', 'Age' => 14), + 1 => array('Name' => 'phil', 'Age' => 11), + 2 => array('Name' => 'bob', 'Age' => 12), + 3 => array('Name' => 'phil', 'Age' => 12), + 4 => array('Name' => 'bob', 'Age' => 14), + 5 => array('Name' => 'phil', 'Age' => 14), ); $this->assertEquals($expected, $list->toArray()); } @@ -528,26 +528,26 @@ class ArrayListTest extends SapphireTest { */ public function testMultipleExcludeNoMatch() { $list = new ArrayList(array( - array('Name' => 'bob', 'Age' => 10), - array('Name' => 'phil', 'Age' => 11), - array('Name' => 'bob', 'Age' => 12), - array('Name' => 'phil', 'Age' => 12), - array('Name' => 'bob', 'Age' => 14), - array('Name' => 'phil', 'Age' => 14), - array('Name' => 'bob', 'Age' => 16), - array('Name' => 'phil', 'Age' => 16) + 0 => array('Name' => 'bob', 'Age' => 10), + 1 => array('Name' => 'phil', 'Age' => 11), + 2 => array('Name' => 'bob', 'Age' => 12), + 3 => array('Name' => 'phil', 'Age' => 12), + 4 => array('Name' => 'bob', 'Age' => 14), + 5 => array('Name' => 'phil', 'Age' => 14), + 6 => array('Name' => 'bob', 'Age' => 16), + 7 => array('Name' => 'phil', 'Age' => 16) )); $list->exclude(array('Name'=>array('bob','phil'),'Age'=>array(10, 16),'Bananas'=>true)); $expected = array( - array('Name' => 'bob', 'Age' => 10), - array('Name' => 'phil', 'Age' => 11), - array('Name' => 'bob', 'Age' => 12), - array('Name' => 'phil', 'Age' => 12), - array('Name' => 'bob', 'Age' => 14), - array('Name' => 'phil', 'Age' => 14), - array('Name' => 'bob', 'Age' => 16), - array('Name' => 'phil', 'Age' => 16) + 0 => array('Name' => 'bob', 'Age' => 10), + 1 => array('Name' => 'phil', 'Age' => 11), + 2 => array('Name' => 'bob', 'Age' => 12), + 3 => array('Name' => 'phil', 'Age' => 12), + 4 => array('Name' => 'bob', 'Age' => 14), + 5 => array('Name' => 'phil', 'Age' => 14), + 6 => array('Name' => 'bob', 'Age' => 16), + 7 => array('Name' => 'phil', 'Age' => 16) ); $this->assertEquals($expected, $list->toArray()); } @@ -557,29 +557,29 @@ class ArrayListTest extends SapphireTest { */ public function testMultipleExcludeThreeArguments() { $list = new ArrayList(array( - array('Name' => 'bob', 'Age' => 10, 'HasBananas'=>false), - array('Name' => 'phil','Age' => 11, 'HasBananas'=>true), - array('Name' => 'bob', 'Age' => 12, 'HasBananas'=>true), - array('Name' => 'phil','Age' => 12, 'HasBananas'=>true), - array('Name' => 'bob', 'Age' => 14, 'HasBananas'=>false), - array('Name' => 'ann', 'Age' => 14, 'HasBananas'=>true), - array('Name' => 'phil','Age' => 14, 'HasBananas'=>false), - array('Name' => 'bob', 'Age' => 16, 'HasBananas'=>false), - array('Name' => 'phil','Age' => 16, 'HasBananas'=>true), - array('Name' => 'clair','Age' => 16, 'HasBananas'=>true) + 0 => array('Name' => 'bob', 'Age' => 10, 'HasBananas'=>false), + 1 => array('Name' => 'phil','Age' => 11, 'HasBananas'=>true), + 2 => array('Name' => 'bob', 'Age' => 12, 'HasBananas'=>true), + 3 => array('Name' => 'phil','Age' => 12, 'HasBananas'=>true), + 4 => array('Name' => 'bob', 'Age' => 14, 'HasBananas'=>false), + 4 => array('Name' => 'ann', 'Age' => 14, 'HasBananas'=>true), + 5 => array('Name' => 'phil','Age' => 14, 'HasBananas'=>false), + 6 => array('Name' => 'bob', 'Age' => 16, 'HasBananas'=>false), + 7 => array('Name' => 'phil','Age' => 16, 'HasBananas'=>true), + 8 => array('Name' => 'clair','Age' => 16, 'HasBananas'=>true) )); $list->exclude(array('Name'=>array('bob','phil'),'Age'=>array(10, 16),'HasBananas'=>true)); $expected = array( - array('Name' => 'bob', 'Age' => 10, 'HasBananas'=>false), - array('Name' => 'phil','Age' => 11, 'HasBananas'=>true), - array('Name' => 'bob', 'Age' => 12, 'HasBananas'=>true), - array('Name' => 'phil','Age' => 12, 'HasBananas'=>true), - array('Name' => 'bob', 'Age' => 14, 'HasBananas'=>false), - array('Name' => 'ann', 'Age' => 14, 'HasBananas'=>true), - array('Name' => 'phil','Age' => 14, 'HasBananas'=>false), - array('Name' => 'bob', 'Age' => 16, 'HasBananas'=>false), - array('Name' => 'clair','Age' => 16, 'HasBananas'=>true) + 0 => array('Name' => 'bob', 'Age' => 10, 'HasBananas'=>false), + 1 => array('Name' => 'phil','Age' => 11, 'HasBananas'=>true), + 2 => array('Name' => 'bob', 'Age' => 12, 'HasBananas'=>true), + 3 => array('Name' => 'phil','Age' => 12, 'HasBananas'=>true), + 4 => array('Name' => 'bob', 'Age' => 14, 'HasBananas'=>false), + 4 => array('Name' => 'ann', 'Age' => 14, 'HasBananas'=>true), + 5 => array('Name' => 'phil','Age' => 14, 'HasBananas'=>false), + 6 => array('Name' => 'bob', 'Age' => 16, 'HasBananas'=>false), + 8 => array('Name' => 'clair','Age' => 16, 'HasBananas'=>true) ); $this->assertEquals($expected, $list->toArray()); }