ILIAS  release_8 Revision v8.24
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

ResourceIdentification $identification
 
array $revisions = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ add()

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

Definition at line 47 of file RevisionCollection.php.

47 : void
48 {
49 if ($this->identification->serialize() !== $revision->getIdentification()->serialize()) {
50 throw new NonMatchingIdentificationException(
51 "Can't add Revision since it's not the same ResourceIdentification"
52 );
53 }
54 foreach ($this->revisions as $r) {
55 if ($r->getVersionNumber() === $revision->getVersionNumber()) {
56 throw new RevisionExistsException(
57 sprintf(
58 "Can't add already existing version number: %s",
59 $revision->getVersionNumber()
60 )
61 );
62 }
63 }
64 $this->revisions[$revision->getVersionNumber()] = $revision;
65 asort($this->revisions);
66 }

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

Referenced by ILIAS\ResourceStorage\Revision\RevisionCollection\replaceAllRevisions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAll()

ILIAS\ResourceStorage\Revision\RevisionCollection::getAll ( )
Returns
Revision[]

Definition at line 109 of file RevisionCollection.php.

109 : array
110 {
111 return $this->revisions;
112 }

References ILIAS\ResourceStorage\Revision\RevisionCollection\$revisions.

◆ getCurrent()

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

Definition at line 94 of file RevisionCollection.php.

94 : Revision
95 {
96 $v = array_values($this->revisions);
97 sort($v);
98 $current = end($v);
99 if (!$current instanceof Revision) {
100 $current = new NullRevision($this->identification);
101 }
102
103 return $current;
104 }

◆ getMax()

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

Definition at line 114 of file RevisionCollection.php.

114 : int
115 {
116 if ($this->revisions === []) {
117 return 0;
118 }
119 return max(array_keys($this->revisions));
120 }

◆ remove()

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

Definition at line 68 of file RevisionCollection.php.

68 : void
69 {
70 foreach ($this->revisions as $k => $revision_e) {
71 if ($revision->getVersionNumber() === $revision_e->getVersionNumber()) {
72 unset($this->revisions[$k]);
73
74 return;
75 }
76 }
77 }

◆ replaceAllRevisions()

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

Definition at line 88 of file RevisionCollection.php.

88 : void
89 {
90 $this->revisions = [];
91 $this->add($revision);
92 }

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

+ Here is the call graph for this function:

◆ replaceSingleRevision()

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

Definition at line 79 of file RevisionCollection.php.

79 : void
80 {
81 foreach ($this->revisions as $k => $revision_e) {
82 if ($revision_e->getVersionNumber() === $revision->getVersionNumber()) {
83 $this->revisions[$k] = $revision;
84 }
85 }
86 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $identification

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

◆ $revisions

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

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