ENHANCEMENT: added isLatestVersion() method for checking whether a record is the latest version of this ID

This commit is contained in:
Will Rossiter 2011-08-26 14:05:54 +12:00 committed by Ingo Schommer
parent 4448325ad3
commit 4c6ddb142d

View File

@ -952,6 +952,22 @@ class Versioned extends DataExtension {
return new $className($record); 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 * 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. * Represents a single version of a record.
*
* @package sapphire * @package sapphire
* @subpackage model * @subpackage model
*
* @see Versioned * @see Versioned
*/ */
class Versioned_Version extends ViewableData { class Versioned_Version extends ViewableData {
@ -1092,4 +1110,4 @@ class Versioned_Version extends ViewableData {
function Published() { function Published() {
return !empty( $this->record['WasPublished'] ); return !empty( $this->record['WasPublished'] );
} }
} }