ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\ResourceStorage\Revision\RevisionCollection Class Reference

Class RevisionCollection. More...

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

Public Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

RevisionCollection constructor.

Parameters
FileRevision[]$revisions

Definition at line 35 of file RevisionCollection.php.

36  {
37  }

Member Function Documentation

◆ add()

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

Definition at line 39 of file RevisionCollection.php.

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

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

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

◆ getAll()

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

Definition at line 106 of file RevisionCollection.php.

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

106  : array
107  {
108  if ($including_drafts) {
109  return $this->revisions;
110  }
111  return array_filter($this->revisions, static fn(Revision $revision): bool => $revision->getStatus() === RevisionStatus::PUBLISHED);
112  }
+ Here is the call graph for this function:

◆ getCurrent()

ILIAS\ResourceStorage\Revision\RevisionCollection::getCurrent ( bool  $including_drafts)

Definition at line 86 of file RevisionCollection.php.

References Vendor\Package\$a, Vendor\Package\$b, ILIAS\ResourceStorage\Revision\Revision\getStatus(), and ILIAS\ResourceStorage\Revision\Revision\getVersionNumber().

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

86  : Revision
87  {
88  $v = $this->revisions;
89 
90  if (!$including_drafts) {
91  $v = array_filter($v, static fn(Revision $revision): bool => $revision->getStatus() === RevisionStatus::PUBLISHED);
92  }
93  usort($v, static fn(Revision $a, Revision $b): int => $a->getVersionNumber() <=> $b->getVersionNumber());
94 
95  $current = end($v);
96  if (!$current instanceof Revision) {
97  return new NullRevision($this->identification);
98  }
99 
100  return $current;
101  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFullSize()

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

Definition at line 122 of file RevisionCollection.php.

122  : int
123  {
124  $size = 0;
125  foreach ($this->revisions as $revision) {
126  $size += $revision->getInformation()->getSize();
127  }
128 
129  return $size;
130  }

◆ getMax()

ILIAS\ResourceStorage\Revision\RevisionCollection::getMax ( bool  $including_drafts)

Definition at line 114 of file RevisionCollection.php.

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

114  : int
115  {
116  if ($this->revisions === []) {
117  return 0;
118  }
119  return $this->getCurrent($including_drafts)->getVersionNumber();
120  }
+ Here is the call graph for this function:

◆ remove()

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

Definition at line 60 of file RevisionCollection.php.

60  : void
61  {
62  foreach ($this->revisions as $k => $revision_e) {
63  if ($revision->getVersionNumber() === $revision_e->getVersionNumber()) {
64  unset($this->revisions[$k]);
65 
66  return;
67  }
68  }
69  }

◆ replaceAllRevisions()

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

Definition at line 80 of file RevisionCollection.php.

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

80  : void
81  {
82  $this->revisions = [];
83  $this->add($revision);
84  }
+ Here is the call graph for this function:

◆ replaceSingleRevision()

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

Definition at line 71 of file RevisionCollection.php.

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

71  : void
72  {
73  foreach ($this->revisions as $k => $revision_e) {
74  if ($revision_e->getVersionNumber() === $revision->getVersionNumber()) {
75  $this->revisions[$k] = $revision;
76  }
77  }
78  }
+ Here is the call graph for this function:

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