From 4c6ddb142d7a4a3299367453a76a688d1c80b5d8 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 26 Aug 2011 14:05:54 +1200 Subject: [PATCH] ENHANCEMENT: added isLatestVersion() method for checking whether a record is the latest version of this ID --- model/Versioned.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/model/Versioned.php b/model/Versioned.php index 2084a0411..3f741be46 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -952,6 +952,22 @@ class Versioned extends DataExtension { return new $className($record); } + + /** + * Returns whether the current record is the latest one. + * + * @todo Performance - could do this directly via SQL. + * + * @see get_latest_version() + * @see latestPublished + * + * @return bool + */ + function isLatestVersion() { + $version = self::get_latest_version($this->owner->class, $this->owner->ID); + + return ($version->Version == $this->owner->Version); + } /** * Return the equivalent of a DataObject::get() call, querying the latest @@ -1055,8 +1071,10 @@ class Versioned extends DataExtension { /** * Represents a single version of a record. + * * @package sapphire * @subpackage model + * * @see Versioned */ class Versioned_Version extends ViewableData { @@ -1092,4 +1110,4 @@ class Versioned_Version extends ViewableData { function Published() { return !empty( $this->record['WasPublished'] ); } -} +} \ No newline at end of file