From b8470c66ed0ab78fd75f721ba3c7a1f64215feb6 Mon Sep 17 00:00:00 2001 From: helpfulrobot Date: Sat, 26 Dec 2015 10:39:31 +1300 Subject: [PATCH] Converted to PSR-2 --- code/forms/GridFieldPaginatorWithShowAll.php | 118 +++++++------- tests/GridFieldPaginatorWithShowAllTest.php | 161 ++++++++++--------- 2 files changed, 146 insertions(+), 133 deletions(-) diff --git a/code/forms/GridFieldPaginatorWithShowAll.php b/code/forms/GridFieldPaginatorWithShowAll.php index 9da9e7c..61a1aa4 100644 --- a/code/forms/GridFieldPaginatorWithShowAll.php +++ b/code/forms/GridFieldPaginatorWithShowAll.php @@ -1,68 +1,76 @@ getShowAllMode(); - if($showAllMode) $checked = ' checked="checked"'; - else $checked = ''; + if (is_a($data, "ArrayData")) { + $showAllMode = $showAllMode =$this->getShowAllMode(); + if ($showAllMode) { + $checked = ' checked="checked"'; + } else { + $checked = ''; + } - $data->setField("ID", $gridField->ID()); - $data->setField("Checked", $checked); - return $data; - }else{ - return; - } - } + $data->setField("ID", $gridField->ID()); + $data->setField("Checked", $checked); + return $data; + } else { + return; + } + } - /** - * Manipulate the datalist as needed by this grid modifier. - * @param GridField $gridField Grid Field Reference - * @param SS_List $dataList Data List to adjust - * @return DataList Modified Data List - */ - public function getManipulatedData(GridField $gridField, SS_List $dataList) { - $this->setShowAllMode($gridField); + /** + * Manipulate the datalist as needed by this grid modifier. + * @param GridField $gridField Grid Field Reference + * @param SS_List $dataList Data List to adjust + * @return DataList Modified Data List + */ + public function getManipulatedData(GridField $gridField, SS_List $dataList) + { + $this->setShowAllMode($gridField); - $dataList = parent::getManipulatedData($gridField, $dataList); - $showAllMode =$this->getShowAllMode(); - if($showAllMode){ - $dataList = $dataList->limit(999, 0); - $component = $gridField->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll'); - $component->setItemsPerPage(1+$dataList->count()); - } + $dataList = parent::getManipulatedData($gridField, $dataList); + $showAllMode =$this->getShowAllMode(); + if ($showAllMode) { + $dataList = $dataList->limit(999, 0); + $component = $gridField->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll'); + $component->setItemsPerPage(1+$dataList->count()); + } - return $dataList; - } + return $dataList; + } - protected function setShowAllMode(GridField $gridField){ - $state =$gridField->State->GridFieldShowAll; + protected function setShowAllMode(GridField $gridField) + { + $state =$gridField->State->GridFieldShowAll; - $sessionMode = Session::get("GridField.PaginatorWithShowAll.Mode"); - if(isset($sessionMode)){ - if(is_bool($state->showAllMode)) { - if($sessionMode != $state->showAllMode){ - Session::set("GridField.PaginatorWithShowAll.Mode",$state->showAllMode); - } - } - }else{ - if(is_bool($state->showAllMode)) { - Session::set("GridField.PaginatorWithShowAll.Mode",$state->showAllMode); - } - } - } + $sessionMode = Session::get("GridField.PaginatorWithShowAll.Mode"); + if (isset($sessionMode)) { + if (is_bool($state->showAllMode)) { + if ($sessionMode != $state->showAllMode) { + Session::set("GridField.PaginatorWithShowAll.Mode", $state->showAllMode); + } + } + } else { + if (is_bool($state->showAllMode)) { + Session::set("GridField.PaginatorWithShowAll.Mode", $state->showAllMode); + } + } + } - protected function getShowAllMode(){ - $sessionMode = Session::get("GridField.PaginatorWithShowAll.Mode"); - return isset($sessionMode) && $sessionMode; - } -} \ No newline at end of file + protected function getShowAllMode() + { + $sessionMode = Session::get("GridField.PaginatorWithShowAll.Mode"); + return isset($sessionMode) && $sessionMode; + } +} diff --git a/tests/GridFieldPaginatorWithShowAllTest.php b/tests/GridFieldPaginatorWithShowAllTest.php index a3f6041..ec02018 100644 --- a/tests/GridFieldPaginatorWithShowAllTest.php +++ b/tests/GridFieldPaginatorWithShowAllTest.php @@ -1,94 +1,99 @@ list = GridFieldPaginator_ShowAll_Item::get(); - $config = GridFieldConfig::create()->addComponents( - new GridFieldDataColumns(), new GridFieldPaginatorWithShowAll(2) - ); - $this->gridField1 = new GridField('testfield1', 'testfield1', $this->list, $config); - $this->gridField2 = new GridField('testfield2', 'testfield2', $this->list, $config); - $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField1, $this->gridField2)), new FieldList()); - } + public function setUp() + { + parent::setUp(); + $this->list = GridFieldPaginator_ShowAll_Item::get(); + $config = GridFieldConfig::create()->addComponents( + new GridFieldDataColumns(), new GridFieldPaginatorWithShowAll(2) + ); + $this->gridField1 = new GridField('testfield1', 'testfield1', $this->list, $config); + $this->gridField2 = new GridField('testfield2', 'testfield2', $this->list, $config); + $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField1, $this->gridField2)), new FieldList()); + } - public function testTurnOnShowAllMode() { - Session::clear('GridField.PaginatorWithShowAll.Mode'); - $fieldHolder1 = $this->gridField1->FieldHolder(); - $content1 = new CSSContentParser($fieldHolder1); - $this->assertEquals(2, count($content1->getBySelector('tr.ss-gridfield-item'))); - $this->gridField1->State->GridFieldShowAll->showAllMode = true; - - /*$stateID = 'testGridStateWithShowAllTurnedOn'; - Session::set($stateID, array('grid'=>'', 'actionName'=>'setShowAllMode', - 'args'=>array( - 'GridFieldShowAll'=>array('showAllMode'=>true), - 'GridFieldPaginator'=> array('currentPage1'=>1) - ) - )); - $request = new SS_HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); - $this->gridField1->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);*/ + public function testTurnOnShowAllMode() + { + Session::clear('GridField.PaginatorWithShowAll.Mode'); + $fieldHolder1 = $this->gridField1->FieldHolder(); + $content1 = new CSSContentParser($fieldHolder1); + $this->assertEquals(2, count($content1->getBySelector('tr.ss-gridfield-item'))); + $this->gridField1->State->GridFieldShowAll->showAllMode = true; + + /*$stateID = 'testGridStateWithShowAllTurnedOn'; + Session::set($stateID, array('grid'=>'', 'actionName'=>'setShowAllMode', + 'args'=>array( + 'GridFieldShowAll'=>array('showAllMode'=>true), + 'GridFieldPaginator'=> array('currentPage1'=>1) + ) + )); + $request = new SS_HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID='.$stateID=>true)); + $this->gridField1->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);*/ - $fieldHolder1 = $this->gridField1->FieldHolder(); - $content1 = new CSSContentParser($fieldHolder1); - $this->assertEquals(6, count($content1->getBySelector('tr.ss-gridfield-item'))); - Session::clear('GridField.PaginatorWithShowAll.Mode'); - } + $fieldHolder1 = $this->gridField1->FieldHolder(); + $content1 = new CSSContentParser($fieldHolder1); + $this->assertEquals(6, count($content1->getBySelector('tr.ss-gridfield-item'))); + Session::clear('GridField.PaginatorWithShowAll.Mode'); + } - public function testTurnOffShowAllMode() { - Session::clear('GridField.PaginatorWithShowAll.Mode'); - $this->gridField1->State->GridFieldShowAll->showAllMode = true; + public function testTurnOffShowAllMode() + { + Session::clear('GridField.PaginatorWithShowAll.Mode'); + $this->gridField1->State->GridFieldShowAll->showAllMode = true; - $fieldHolder1 = $this->gridField1->FieldHolder(); - $content1 = new CSSContentParser($fieldHolder1); - $this->assertEquals(6, count($content1->getBySelector('tr.ss-gridfield-item'))); + $fieldHolder1 = $this->gridField1->FieldHolder(); + $content1 = new CSSContentParser($fieldHolder1); + $this->assertEquals(6, count($content1->getBySelector('tr.ss-gridfield-item'))); - $this->gridField1->State->GridFieldShowAll->showAllMode = false; - $this->gridField1->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll')->setItemsPerPage(2); + $this->gridField1->State->GridFieldShowAll->showAllMode = false; + $this->gridField1->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll')->setItemsPerPage(2); - $fieldHolder2 = $this->gridField1->FieldHolder(); - $content1 = new CSSContentParser($fieldHolder2); - $this->assertEquals(2, count($content1->getBySelector('tr.ss-gridfield-item'))); + $fieldHolder2 = $this->gridField1->FieldHolder(); + $content1 = new CSSContentParser($fieldHolder2); + $this->assertEquals(2, count($content1->getBySelector('tr.ss-gridfield-item'))); - Session::clear('GridField.PaginatorWithShowAll.Mode'); - } + Session::clear('GridField.PaginatorWithShowAll.Mode'); + } - public function testGoballyEffected() { - Session::clear('GridField.PaginatorWithShowAll.Mode'); - $this->gridField1->State->GridFieldShowAll->showAllMode = true; - $this->gridField1->FieldHolder(); + public function testGoballyEffected() + { + Session::clear('GridField.PaginatorWithShowAll.Mode'); + $this->gridField1->State->GridFieldShowAll->showAllMode = true; + $this->gridField1->FieldHolder(); - $fieldHolder21 = $this->gridField2->FieldHolder(); - $content21 = new CSSContentParser($fieldHolder21); - $this->assertEquals(6, count($content21->getBySelector('tr.ss-gridfield-item'))); + $fieldHolder21 = $this->gridField2->FieldHolder(); + $content21 = new CSSContentParser($fieldHolder21); + $this->assertEquals(6, count($content21->getBySelector('tr.ss-gridfield-item'))); - $this->gridField1->State->GridFieldShowAll->showAllMode = false; - $this->gridField1->FieldHolder(); + $this->gridField1->State->GridFieldShowAll->showAllMode = false; + $this->gridField1->FieldHolder(); - $this->gridField2->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll')->setItemsPerPage(2); - $fieldHolder22 = $this->gridField2->FieldHolder(); - $content22 = new CSSContentParser($fieldHolder22); - $this->assertEquals(2, count($content22->getBySelector('tr.ss-gridfield-item'))); - Session::clear('GridField.PaginatorWithShowAll.Mode'); - } - + $this->gridField2->getConfig()->getComponentByType('GridFieldPaginatorWithShowAll')->setItemsPerPage(2); + $fieldHolder22 = $this->gridField2->FieldHolder(); + $content22 = new CSSContentParser($fieldHolder22); + $this->assertEquals(2, count($content22->getBySelector('tr.ss-gridfield-item'))); + Session::clear('GridField.PaginatorWithShowAll.Mode'); + } } -class GridFieldPaginator_ShowAll_Item extends DataObject implements TestOnly { - static $db = array( - 'Title' => 'Varchar', - ); -} \ No newline at end of file +class GridFieldPaginator_ShowAll_Item extends DataObject implements TestOnly +{ + public static $db = array( + 'Title' => 'Varchar', + ); +}