ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ResourceToComponent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 
34 {
35  private \ILIAS\ResourceStorage\Revision\Revision $current_revision;
37 
38  public function __construct(
39  protected StorableResource $resource,
41  ) {
43  $this->current_revision = $this->resource->getCurrentRevision();
44  $this->revision_to_component = new RevisionToComponent(
45  $this->current_revision,
47  );
48  }
49 
50  public function getAsRowMapping(): \Closure
51  {
52  return function (
53  PresentationRow $row,
54  ResourceIdentification $resource_identification
55  ): PresentationRow {
57  $row = $this->revision_to_component->getAsRowMapping()($row, $resource_identification);
58  return $row
60  ->withContent(
61  $this->ui_factory->listing()->descriptive($this->getCommonProperties())
62  )
63  ->withFurtherFields(
64  $this->getDetailedProperties()
65  );
66  };
67  }
68 
69 
70  public function getAsItem(bool $with_image): \ILIAS\UI\Component\Item\Standard
71  {
72  $properties = array_merge(
73  $this->getCommonProperties(),
74  $this->getDetailedProperties()
75  );
76  return $this->revision_to_component->getAsItem($with_image)
77  ->withProperties($properties);
78  }
79 
80  public function getAsCard(): Card
81  {
82  return $this->revision_to_component->getAsCard();
83  }
84 
85  public function getImportantProperties(): array
86  {
87  return array_merge(
88  [],
89  $this->revision_to_component->getImportantProperties()
90  );
91  }
92 
93  public function getCommonProperties(): array
94  {
95  $stakeholders = implode(
96  ', ',
97  array_map(function (ResourceStakeholder $stakeholder): string {
98  return $stakeholder->getConsumerNameForPresentation();
99  }, $this->resource->getStakeholders())
100  );
101 
102 
103  return array_merge(
104  [
105  $this->language->txt('stakeholders') => $stakeholders,
106  $this->language->txt('full_size') => $this->formatSize($this->resource->getFullSize()),
107  ],
108  $this->revision_to_component->getCommonProperties()
109  );
110  }
111 
112  public function getDetailedProperties(): array
113  {
114  return array_merge(
115  [
116  $this->language->txt('revisions') => (string)count($this->resource->getAllRevisionsIncludingDraft()),
117  ],
118  $this->revision_to_component->getImportantProperties()
119  );
120  }
121 }
__construct(protected StorableResource $resource, ?ActionGenerator $action_generator=null)
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a Row used in Presentation Table.
withImportantFields(array $fields)
Get a row like this with the record-fields and labels to be shown in the collapsed row...
__construct(Container $dic, ilPlugin $plugin)
language()
description: > Example for rendring a language glyph.
Definition: language.php:25