Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created February 26, 2010 01:51
Show Gist options
  • Select an option

  • Save sminnee/315301 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/315301 to your computer and use it in GitHub Desktop.
Index: sapphire/forms/TableListField.php
===================================================================
--- sapphire/forms/TableListField.php (revision 100001)
+++ sapphire/forms/TableListField.php (working copy)
@@ -777,13 +777,29 @@
return $this->extraLinkParams;
}
+ /**
+ * Base link for this table field that includes the current sort information, but no pagination
+ * information
+ */
+ function LinkWithSort() {
+ $name = $this->Name();
+ $link = $this->Link();
+ if(!empty($_REQUEST['ctf'][$name]['sort'])) {
+ $link = Controller::join_links($link, "?ctf[{$name}][sort]=" . urlencode($_REQUEST['ctf'][$name]['sort']));
+ }
+ if(!empty($_REQUEST['ctf'][$name]['dir'])) {
+ $link = Controller::join_links($link, "?ctf[{$name}][dir]=" . urlencode($_REQUEST['ctf'][$name]['dir']));
+ }
+ return $link;
+ }
+
function FirstLink() {
$start = 0;
if(!isset($_REQUEST['ctf'][$this->Name()]['start']) || !is_numeric($_REQUEST['ctf'][$this->Name()]['start']) || $_REQUEST['ctf'][$this->Name()]['start'] == 0) {
return null;
}
- $link = Controller::join_links($this->Link(), "?ctf[{$this->Name()}][start]={$start}");
+ $link = Controller::join_links($this->LinkWithSort(), "?ctf[{$this->Name()}][start]={$start}");
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
return $link;
}
@@ -797,7 +813,7 @@
$start = ($_REQUEST['ctf'][$this->Name()]['start'] - $this->pageSize < 0) ? 0 : $_REQUEST['ctf'][$this->Name()]['start'] - $this->pageSize;
- $link = Controller::join_links($this->Link(), "?ctf[{$this->Name()}][start]={$start}");
+ $link = Controller::join_links($this->LinkWithSort(), "?ctf[{$this->Name()}][start]={$start}");
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
return $link;
}
@@ -809,7 +825,7 @@
if($currentStart >= $start-1) {
return null;
}
- $link = Controller::join_links($this->Link(), "?ctf[{$this->Name()}][start]={$start}");
+ $link = Controller::join_links($this->LinkWithSort(), "?ctf[{$this->Name()}][start]={$start}");
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
return $link;
}
@@ -822,7 +838,7 @@
return null;
}
- $link = Controller::join_links($this->Link(), "?ctf[{$this->Name()}][start]={$start}");
+ $link = Controller::join_links($this->LinkWithSort(), "?ctf[{$this->Name()}][start]={$start}");
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
return $link;
}
@@ -991,7 +1007,7 @@
* We need to instanciate this button manually as a normal button has no means of adding inline onclick-behaviour.
*/
function ExportLink() {
- $exportLink = Controller::join_links($this->Link(), 'export');
+ $exportLink = Controller::join_links($this->LinkWithSort(), 'export');
if($this->extraLinkParams) $exportLink .= "?" . http_build_query($this->extraLinkParams);
return $exportLink;
@@ -1018,11 +1034,7 @@
}
function PrintLink() {
- $link = Controller::join_links($this->Link(), 'printall');
- if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
- $link = HTTP::setGetVar("ctf[{$this->Name()}][sort]",Convert::raw2xml($_REQUEST['ctf'][$this->Name()]['sort']), $link);
- }
- return $link;
+ return Controller::join_links($this->LinkWithSort(), 'printall');
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment