/** * @param GridField $grid * @return array */ public function getHTMLFragments($grid) { $cols = new ArrayList(); foreach ($grid->getColumns() as $name) { $meta = $grid->getColumnMetadata($name); $cols->push(new ArrayData(array('Name' => $name, 'Title' => $meta['title']))); } $days = new ArrayList(); for ($i = 0; $i < 5; $i++) { $date = new Date(); $date->setValue(date('d-m-Y', strtotime('+' . $i . ' days', strtotime($this->startDate)))); $isHoliday = in_array($date->Format('Y-m-d'), $this->holidays); $days->push(new ArrayData(array('Day' => $date->Format('l'), 'IsHoliday' => $isHoliday))); } return array('header' => $cols->renderWith('RosterGridFieldTitleHeader', array('StartDate' => $this->startDate, 'Days' => $days))); }
/** * @covers GridField::getColumns */ public function testGetColumns() { $obj = new GridField('testfield', 'testfield', Member::get()); $expected = array(0 => 'FirstName', 1 => 'Surname', 2 => 'Email'); $this->assertEquals($expected, $obj->getColumns()); }
/** * @param GridField $gridField * * @return array */ public function getHTMLFragments($gridField) { Requirements::css(BULKEDITTOOLS_MANAGER_PATH . '/css/GridFieldBulkManager.css'); Requirements::javascript(BULKEDITTOOLS_MANAGER_PATH . '/javascript/GridFieldBulkManager.js'); Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH . '/lang/js'); if (!count($this->config['actions'])) { user_error('Trying to use GridFieldBulkManager without any bulk action.', E_USER_ERROR); } $actionsListSource = array(); $actionsConfig = array(); foreach ($this->config['actions'] as $action => $actionData) { $actionsListSource[$action] = $actionData['label']; $actionsConfig[$action] = $actionData['config']; } reset($this->config['actions']); $firstAction = key($this->config['actions']); $dropDownActionsList = DropdownField::create('bulkActionName', '')->setSource($actionsListSource)->setAttribute('class', 'bulkActionName no-change-track')->setAttribute('id', ''); $templateData = array('Menu' => $dropDownActionsList->FieldHolder(), 'Button' => array('Label' => _t('GRIDFIELD_BULK_MANAGER.ACTION_BTN_LABEL', 'Go'), 'DataURL' => $gridField->Link('bulkAction'), 'Icon' => $this->config['actions'][$firstAction]['config']['icon'], 'DataConfig' => htmlspecialchars(json_encode($actionsConfig), ENT_QUOTES, 'UTF-8')), 'Select' => array('Label' => _t('GRIDFIELD_BULK_MANAGER.SELECT_ALL_LABEL', 'Select all')), 'Colspan' => count($gridField->getColumns()) - 1); $templateData = new ArrayData($templateData); return array('header' => $templateData->renderWith('BulkManagerButtons')); }
/** * * @param GridField $gridField * @return array */ public function getHTMLFragments($gridField) { if(!$this->checkDataType($gridField->getList())) return; $state = $gridField->State->GridFieldPaginator; if(!is_int($state->currentPage)) $state->currentPage = 1; // Figure out which page and record range we're on $totalRows = $this->totalItems; if(!$totalRows) return array(); $totalPages = ceil($totalRows/$this->itemsPerPage); if($totalPages == 0) $totalPages = 1; $firstShownRecord = ($state->currentPage - 1) * $this->itemsPerPage + 1; if($firstShownRecord > $totalRows) $firstShownRecord = $totalRows; $lastShownRecord = $state->currentPage * $this->itemsPerPage; if($lastShownRecord > $totalRows) $lastShownRecord = $totalRows; // First page button $firstPage = new GridField_FormAction($gridField, 'pagination_first', 'First', 'paginate', 1); $firstPage->addExtraClass('ss-gridfield-firstpage'); if($state->currentPage == 1) $firstPage = $firstPage->performDisabledTransformation(); // Previous page button $previousPageNum = $state->currentPage <= 1 ? 1 : $state->currentPage - 1; $previousPage = new GridField_FormAction($gridField, 'pagination_prev', 'Previous', 'paginate', $previousPageNum); $previousPage->addExtraClass('ss-gridfield-previouspage'); if($state->currentPage == 1) $previousPage = $previousPage->performDisabledTransformation(); // Next page button $nextPageNum = $state->currentPage >= $totalPages ? $totalPages : $state->currentPage + 1; $nextPage = new GridField_FormAction($gridField, 'pagination_next', 'Next', 'paginate', $nextPageNum); $nextPage->addExtraClass('ss-gridfield-nextpage'); if($state->currentPage == $totalPages) $nextPage = $nextPage->performDisabledTransformation(); // Last page button $lastPage = new GridField_FormAction($gridField, 'pagination_last', 'Last', 'paginate', $totalPages); $lastPage->addExtraClass('ss-gridfield-lastpage'); if($state->currentPage == $totalPages) $lastPage = $lastPage->performDisabledTransformation(); // Render in template $forTemplate = new ArrayData(array( 'FirstPage' => $firstPage, 'PreviousPage' => $previousPage, 'CurrentPageNum' => $state->currentPage, 'NumPages' => $totalPages, 'NextPage' => $nextPage, 'LastPage' => $lastPage, 'FirstShownRecord' => $firstShownRecord, 'LastShownRecord' => $lastShownRecord, 'NumRecords' => $totalRows )); return array( 'footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan'=>count($gridField->getColumns()))), ); }
/** * @covers GridField::getColumns */ public function testGetColumns(){ $obj = new GridField('testfield', 'testfield', DataList::create('Member')); $expected = array ( 0 => 'FirstName', 1 => 'Surname', 2 => 'Email', ); $this->assertEquals($expected, $obj->getColumns()); }
/** * * @param GridField $gridField * @return array */ public function getHTMLFragments($gridField) { if (!$this->checkDataType($gridField->getList())) { return; } $state = $gridField->State->GridFieldPaginator; if (!is_int($state->currentPage)) { $state->currentPage = 1; } // Figure out which page and record range we're on $totalRows = $this->totalItems; if (!$totalRows) { return array(); } $totalPages = (int) ceil($totalRows / $this->itemsPerPage); if ($totalPages == 0) { $totalPages = 1; } $firstShownRecord = ($state->currentPage - 1) * $this->itemsPerPage + 1; if ($firstShownRecord > $totalRows) { $firstShownRecord = $totalRows; } $lastShownRecord = $state->currentPage * $this->itemsPerPage; if ($lastShownRecord > $totalRows) { $lastShownRecord = $totalRows; } // If there is only 1 page for all the records in list, we don't need to go further // to sort out those first page, last page, pre and next pages, etc // we are not render those in to the paginator. if ($totalPages === 1) { $forTemplate = new ArrayData(array('OnlyOnePage' => true, 'FirstShownRecord' => $firstShownRecord, 'LastShownRecord' => $lastShownRecord, 'NumRecords' => $totalRows)); } else { // First page button $firstPage = new GridField_FormAction($gridField, 'pagination_first', 'First', 'paginate', 1); $firstPage->addExtraClass('ss-gridfield-firstpage'); if ($state->currentPage == 1) { $firstPage = $firstPage->performDisabledTransformation(); } // Previous page button $previousPageNum = $state->currentPage <= 1 ? 1 : $state->currentPage - 1; $previousPage = new GridField_FormAction($gridField, 'pagination_prev', 'Previous', 'paginate', $previousPageNum); $previousPage->addExtraClass('ss-gridfield-previouspage'); if ($state->currentPage == 1) { $previousPage = $previousPage->performDisabledTransformation(); } // Next page button $nextPageNum = $state->currentPage >= $totalPages ? $totalPages : $state->currentPage + 1; $nextPage = new GridField_FormAction($gridField, 'pagination_next', 'Next', 'paginate', $nextPageNum); $nextPage->addExtraClass('ss-gridfield-nextpage'); if ($state->currentPage == $totalPages) { $nextPage = $nextPage->performDisabledTransformation(); } // Last page button $lastPage = new GridField_FormAction($gridField, 'pagination_last', 'Last', 'paginate', $totalPages); $lastPage->addExtraClass('ss-gridfield-lastpage'); if ($state->currentPage == $totalPages) { $lastPage = $lastPage->performDisabledTransformation(); } // Render in template $forTemplate = new ArrayData(array('OnlyOnePage' => false, 'FirstPage' => $firstPage, 'PreviousPage' => $previousPage, 'CurrentPageNum' => $state->currentPage, 'NumPages' => $totalPages, 'NextPage' => $nextPage, 'LastPage' => $lastPage, 'FirstShownRecord' => $firstShownRecord, 'LastShownRecord' => $lastShownRecord, 'NumRecords' => $totalRows)); } return array('footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan' => count($gridField->getColumns())))); }