You are here

public function EntityLegalDocument::getVersion in Entity Legal 7.2

Same name and namespace in other branches
  1. 7 entity_legal.entity.inc \EntityLegalDocument::getVersion()

Get a version of this document.

Parameters

bool $version_name: If set, load the version otherwise load the default version or create one.

Return value

EntityLegalDocumentVersion The legal document version.

File

./entity_legal.entity.inc, line 38
Entity API main classes used by entity_legal module.

Class

EntityLegalDocument
Legal Document entity with revision support.

Code

public function getVersion($version_name = FALSE) {

  // If a version name is supplied, load it.
  if ($version_name) {
    return entity_load_single(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME, $version_name);
  }

  // If no version name is supplied but a published version exists, return it.
  $published_version = $this
    ->getPublishedVersion();
  if (!$version_name && $published_version) {
    return $published_version;
  }
  $all_versions = $this
    ->getAllVersions();

  // If no versions exist return a new one.
  if (empty($all_versions) && !$version_name) {
    return $this
      ->getNewVersion();
  }

  // Return the first version.
  if (!$version_name && !$published_version) {
    return array_pop($all_versions);
  }
}