vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Entity/File.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\MediaBundle\Entity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection as DoctrineCollection;
  13. use Sulu\Component\Persistence\Model\AuditableInterface;
  14. use Sulu\Component\Persistence\Model\AuditableTrait;
  15. /**
  16. * File.
  17. */
  18. class File implements AuditableInterface
  19. {
  20. use AuditableTrait;
  21. /**
  22. * @var int
  23. */
  24. private $version;
  25. /**
  26. * @var int
  27. */
  28. private $id;
  29. /**
  30. * @var DoctrineCollection<int, FileVersion>
  31. */
  32. private $fileVersions;
  33. /**
  34. * @var MediaInterface
  35. */
  36. private $media;
  37. /**
  38. * Constructor.
  39. */
  40. public function __construct()
  41. {
  42. $this->fileVersions = new ArrayCollection();
  43. }
  44. /**
  45. * Set version.
  46. *
  47. * @param int $version
  48. *
  49. * @return File
  50. */
  51. public function setVersion($version)
  52. {
  53. $this->version = $version;
  54. return $this;
  55. }
  56. /**
  57. * Get version.
  58. *
  59. * @return int
  60. */
  61. public function getVersion()
  62. {
  63. return $this->version;
  64. }
  65. /**
  66. * Get id.
  67. *
  68. * @return int
  69. */
  70. public function getId()
  71. {
  72. return $this->id;
  73. }
  74. /**
  75. * Add fileVersions.
  76. *
  77. * @return File
  78. */
  79. public function addFileVersion(FileVersion $fileVersions)
  80. {
  81. $this->fileVersions[] = $fileVersions;
  82. return $this;
  83. }
  84. /**
  85. * Remove fileVersions.
  86. */
  87. public function removeFileVersion(FileVersion $fileVersions)
  88. {
  89. $this->fileVersions->removeElement($fileVersions);
  90. }
  91. /**
  92. * Get fileVersions.
  93. *
  94. * @return DoctrineCollection<int, FileVersion>
  95. */
  96. public function getFileVersions()
  97. {
  98. return $this->fileVersions;
  99. }
  100. /**
  101. * Get file version.
  102. *
  103. * @param int $version
  104. *
  105. * @return FileVersion|null
  106. */
  107. public function getFileVersion($version)
  108. {
  109. /** @var FileVersion $fileVersion */
  110. foreach ($this->fileVersions as $fileVersion) {
  111. if ($fileVersion->getVersion() === $version) {
  112. return $fileVersion;
  113. }
  114. }
  115. return null;
  116. }
  117. /**
  118. * Get latest file version.
  119. *
  120. * @return FileVersion|null
  121. */
  122. public function getLatestFileVersion()
  123. {
  124. return $this->getFileVersion($this->version);
  125. }
  126. /**
  127. * Set media.
  128. *
  129. * @return File
  130. */
  131. public function setMedia(MediaInterface $media)
  132. {
  133. $this->media = $media;
  134. return $this;
  135. }
  136. /**
  137. * Get media.
  138. *
  139. * @return MediaInterface
  140. */
  141. public function getMedia()
  142. {
  143. return $this->media;
  144. }
  145. }