mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60268 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
935ee6d1bc
commit
124a6e3934
@ -2625,6 +2625,12 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
* view of this object.
|
||||
*/
|
||||
public static $summary_fields = null;
|
||||
|
||||
/**
|
||||
* User defined permissions for search result table by ModelAdmin to act on.
|
||||
* Such as print search
|
||||
*/
|
||||
public static $results_permissions = null;
|
||||
|
||||
}
|
||||
|
||||
|
@ -165,6 +165,14 @@ class TableListField extends FormField {
|
||||
*/
|
||||
public $fieldFormatting = array();
|
||||
|
||||
/**
|
||||
* @var array Specify custom escape for the fields, e.g. to escape all accurance of "\r", "\r\n" and "\n" of the field
|
||||
* value, we need to set this field as array("\r"=>"", "\r\n"=>"", "\n"=>"") ;
|
||||
* Example: setFieldEscape(array("\""=>"\"\"","\r"=>"", "\r\n"=>"", "\n"=>"") is needed for exporting the table to a .csv
|
||||
* file
|
||||
*/
|
||||
public $fieldEscape = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -312,7 +320,7 @@ JS
|
||||
// get query
|
||||
$dataQuery = $this->getQuery();
|
||||
|
||||
// we don't limit when doing certain actions
|
||||
// we don't limit when doing certain actions T
|
||||
if(!isset($_REQUEST['methodName']) || !in_array($_REQUEST['methodName'],array('printall','export'))) {
|
||||
$dataQuery->limit(array(
|
||||
'limit' => $SQL_limit,
|
||||
@ -335,9 +343,9 @@ JS
|
||||
function Items() {
|
||||
$fieldItems = new DataObjectSet();
|
||||
if($items = $this->sourceItems()) foreach($items as $item) {
|
||||
$fieldItem = new TableListField_Item($item, $this);
|
||||
if($item) $fieldItems->push(new TableListField_Item($item, $this));
|
||||
}
|
||||
|
||||
return $fieldItems;
|
||||
}
|
||||
|
||||
@ -740,7 +748,6 @@ JS
|
||||
$record = $records->nextRecord();
|
||||
$this->totalCount = $record['TotalCount'];
|
||||
}
|
||||
|
||||
return $this->totalCount;
|
||||
}
|
||||
|
||||
@ -782,6 +789,13 @@ JS
|
||||
$this->csvSeparator = $csvSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CSV separator character. Defaults to ,
|
||||
*/
|
||||
function getCsvSeparator() {
|
||||
return $this->csvSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the header row from the CSV export
|
||||
*/
|
||||
@ -812,21 +826,32 @@ JS
|
||||
// get data
|
||||
$dataQuery = $this->getCsvQuery();
|
||||
$records = $dataQuery->execute();
|
||||
|
||||
$sourceClass = $this->sourceClass;
|
||||
$dataobject = new $sourceClass();
|
||||
$items = $dataobject->buildDataObjectSet($records, 'DataObjectSet');
|
||||
|
||||
if($items) {
|
||||
foreach($items as $item) {
|
||||
$columnData = array();
|
||||
foreach($csvColumns as $columnName => $columnTitle) {
|
||||
$tmpColumnData = "\"" . str_replace("\"", "\"\"", $item->$columnName) . "\"";
|
||||
$tmpColumnData = str_replace(array("\r", "\n"), "", $tmpColumnData);
|
||||
$columnData[] = $tmpColumnData;
|
||||
}
|
||||
$fileData .= implode($separator, $columnData);
|
||||
$fileData .= "\n";
|
||||
$fieldItems = new DataObjectSet();
|
||||
|
||||
if($items&&$items->count()) foreach($items as $item) {
|
||||
$fieldItem = new TableListField_Item($item, $this);
|
||||
if($item) $fieldItems->push(new TableListField_Item($item, $this));
|
||||
}
|
||||
|
||||
$this->setFieldFormatting(array());
|
||||
$this->setFieldEscape(array(
|
||||
"\""=>"\"\"",
|
||||
"\r\n"=>"",
|
||||
"\r"=>"",
|
||||
"\n"=>"",
|
||||
));
|
||||
|
||||
if($fieldItems) {
|
||||
|
||||
foreach($fieldItems as $fieldItem) {
|
||||
$fileData .= $fieldItem->renderwith("TableListField_Item_export");
|
||||
}
|
||||
|
||||
HTTP::sendFileToBrowser($fileData, $fileName);
|
||||
} else {
|
||||
user_error("No records found", E_USER_ERROR);
|
||||
@ -838,7 +863,9 @@ JS
|
||||
* We need to instanciate this button manually as a normal button has no means of adding inline onclick-behaviour.
|
||||
*/
|
||||
function ExportLink() {
|
||||
return Controller::join_links($this->Link(), 'export');
|
||||
$exportLink = Controller::join_links($this->Link(), 'export');
|
||||
if($this->extraLinkParams) $exportLink .= "?" . http_build_query($this->extraLinkParams);
|
||||
return $exportLink;
|
||||
}
|
||||
|
||||
function printall() {
|
||||
@ -904,6 +931,10 @@ JS
|
||||
$this->fieldFormatting = $formatting;
|
||||
}
|
||||
|
||||
function setFieldEscape($escape){
|
||||
$this->fieldEscape = $escape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
@ -1057,14 +1088,21 @@ class TableListField_Item extends ViewableData {
|
||||
$format = str_replace('__VAL__', '$value', $format);
|
||||
eval('$value = "' . $format . '";');
|
||||
}
|
||||
|
||||
//escape
|
||||
if($escape = $this->parent->fieldEscape){
|
||||
foreach($escape as $search => $replace){
|
||||
$value = str_replace($search, $replace, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$fields[] = new ArrayData(array(
|
||||
"Name" => $fieldName,
|
||||
"Title" => $fieldTitle,
|
||||
"Value" => $value,
|
||||
"CsvSeparator" => $this->parent->getCsvSeparator(),
|
||||
));
|
||||
}
|
||||
|
||||
return new DataObjectSet($fields);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,10 @@ class SearchContext extends Object {
|
||||
$SQL_sort = (!empty($sort)) ? Convert::raw2sql($sort) : singleton($this->modelClass)->stat('default_sort');
|
||||
$query->orderby($SQL_sort);
|
||||
foreach($searchParams as $key => $value) {
|
||||
//if ($value != '0') {
|
||||
/*We add $value!='' here to not include a filter like this: $fieldname like '%%', which abviously filter out some
|
||||
records with the $fieldname set to null. and this is not the search intention.
|
||||
*/
|
||||
if ($value != '0'&&$value!='') {
|
||||
$key = str_replace('__', '.', $key);
|
||||
$filter = $this->getFilter($key);
|
||||
if ($filter) {
|
||||
|
1
templates/Includes/TableListField_Item_export.ss
Executable file
1
templates/Includes/TableListField_Item_export.ss
Executable file
@ -0,0 +1 @@
|
||||
<% control Fields %>"$Value"<% if Last %>\n<% else %>$CsvSeparator<% end_if %><% end_control %>
|
Loading…
Reference in New Issue
Block a user