ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\ResourceStorage\Revision\RevisionCollection Class Reference

Class RevisionCollection. More...

+ Collaboration diagram for ILIAS\ResourceStorage\Revision\RevisionCollection:

Public Member Functions

 __construct (ResourceIdentification $identification, array $revisions=[])
 RevisionCollection constructor. More...
 
 add (Revision $revision)
 
 remove (Revision $revision)
 
 replaceSingleRevision (Revision $revision)
 
 replaceAllRevisions (Revision $revision)
 
 getCurrent ()
 
 getAll ()
 
 getMax ()
 

Private Attributes

 $revisions = []
 
 $identification
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\ResourceStorage\Revision\RevisionCollection::__construct ( ResourceIdentification  $identification,
array  $revisions = [] 
)

RevisionCollection constructor.

Parameters
FileRevision[]$revisions
ResourceIdentification$identification

Definition at line 28 of file RevisionCollection.php.

References ILIAS\ResourceStorage\Revision\RevisionCollection\$identification, and ILIAS\ResourceStorage\Revision\RevisionCollection\$revisions.

Member Function Documentation

◆ add()

ILIAS\ResourceStorage\Revision\RevisionCollection::add ( Revision  $revision)

Definition at line 34 of file RevisionCollection.php.

References ILIAS\ResourceStorage\Revision\Revision\getIdentification(), and ILIAS\ResourceStorage\Revision\Revision\getVersionNumber().

Referenced by ILIAS\ResourceStorage\Revision\Repository\RevisionARRepository\get(), ILIAS\ResourceStorage\Revision\Repository\RevisionDBRepository\get(), and ILIAS\ResourceStorage\Revision\RevisionCollection\replaceAllRevisions().

34  : void
35  {
36  if ($this->identification->serialize() !== $revision->getIdentification()->serialize()) {
37  throw new NonMatchingIdentificationException("Can't add Revision since it's not the same ResourceIdentification");
38  }
39  foreach ($this->revisions as $r) {
40  if ($r->getVersionNumber() === $revision->getVersionNumber()) {
41  throw new RevisionExistsException(sprintf("Can't add already existing version number: %s",
42  $revision->getVersionNumber()));
43  }
44  }
45  $this->revisions[$revision->getVersionNumber()] = $revision;
46  asort($this->revisions);
47  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAll()

ILIAS\ResourceStorage\Revision\RevisionCollection::getAll ( )

◆ getCurrent()

ILIAS\ResourceStorage\Revision\RevisionCollection::getCurrent ( )

Definition at line 75 of file RevisionCollection.php.

75  : Revision
76  {
77  $v = array_values($this->revisions);
78  sort($v);
79  $current = end($v);
80  if (!$current instanceof Revision) {
81  $current = new NullRevision($this->identification);
82  }
83 
84  return $current;
85  }

◆ getMax()

ILIAS\ResourceStorage\Revision\RevisionCollection::getMax ( )

Definition at line 95 of file RevisionCollection.php.

95  : int
96  {
97  if (count($this->revisions) === 0) {
98  return 0;
99  }
100  return max(array_keys($this->revisions));
101  }

◆ remove()

ILIAS\ResourceStorage\Revision\RevisionCollection::remove ( Revision  $revision)

Definition at line 49 of file RevisionCollection.php.

49  : void
50  {
51  foreach ($this->revisions as $k => $revision_e) {
52  if ($revision->getVersionNumber() === $revision_e->getVersionNumber()) {
53  unset($this->revisions[$k]);
54 
55  return;
56  }
57  }
58  }

◆ replaceAllRevisions()

ILIAS\ResourceStorage\Revision\RevisionCollection::replaceAllRevisions ( Revision  $revision)

Definition at line 69 of file RevisionCollection.php.

References ILIAS\ResourceStorage\Revision\RevisionCollection\add().

69  : void
70  {
71  $this->revisions = [];
72  $this->add($revision);
73  }
+ Here is the call graph for this function:

◆ replaceSingleRevision()

ILIAS\ResourceStorage\Revision\RevisionCollection::replaceSingleRevision ( Revision  $revision)

Definition at line 60 of file RevisionCollection.php.

References ILIAS\ResourceStorage\Revision\Revision\getVersionNumber().

60  : void
61  {
62  foreach ($this->revisions as $k => $revision_e) {
63  if ($revision_e->getVersionNumber() === $revision->getVersionNumber()) {
64  $this->revisions[$k] = $revision;
65  }
66  }
67  }
+ Here is the call graph for this function:

Field Documentation

◆ $identification

ILIAS\ResourceStorage\Revision\RevisionCollection::$identification
private

◆ $revisions

ILIAS\ResourceStorage\Revision\RevisionCollection::$revisions = []
private

The documentation for this class was generated from the following file: