ENHANCEMENT Supporting full parameter signature in Versioned->Versions(), allVersions()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@86216 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-09-14 05:15:49 +00:00
parent 3386e8223a
commit d834223142

View File

@ -506,20 +506,20 @@ class Versioned extends DataObjectDecorator {
return !$stagesAreEqual;
}
function Versions($filter = "") {
return $this->allVersions($filter);
function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "") {
return $this->allVersions($filter, $sort, $limit, $join, $having);
}
/**
* Return a list of all the versions available.
* @param string $filter
*/
function allVersions($filter = "") {
$query = $this->owner->extendedSQL($filter,"");
function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "") {
$query = $this->owner->extendedSQL($filter, $sort, $limit, $join, $having);
foreach($query->from as $table => $join) {
if($join[0] == '"') $baseTable = str_replace('"','',$join);
else if (substr($join,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
foreach($query->from as $table => $tableJoin) {
if($tableJoin[0] == '"') $baseTable = str_replace('"','',$tableJoin);
else if (substr($tableJoin,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
$query->renameTable($table, $table . '_versions');
}
@ -529,7 +529,7 @@ class Versioned extends DataObjectDecorator {
}
$query->where[] = "\"{$baseTable}_versions\".\"RecordID\" = '{$this->owner->ID}'";
$query->orderby = "\"{$baseTable}_versions\".\"LastEdited\" DESC, \"{$baseTable}_versions\".\"Version\" DESC";
$query->orderby = ($sort) ? $sort : "\"{$baseTable}_versions\".\"LastEdited\" DESC, \"{$baseTable}_versions\".\"Version\" DESC";
$records = $query->execute();