ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RevisionToComponent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 
38 {
40  private Services $irss;
42 
43  public function __construct(
44  private Revision $revision,
46  ) {
47  global $DIC;
49  $this->irss = $DIC->resourceStorage();
50  $this->information = $this->revision->getInformation();
51  $this->preview_definition = new PreviewDefinition();
52  }
53 
54  public function getAsItem(bool $with_image): Standard
55  {
56  $properties = array_merge(
57  $this->getCommonProperties(),
58  $this->getDetailedProperties()
59  );
60  $item = $this->ui_factory->item()->standard($this->revision->getTitle())
61  ->withDescription($this->information->getTitle())
62  ->withProperties($properties);
63 
64  if ($with_image) {
65  return $item->withLeadImage($this->getImage());
66  }
67  return $item;
68  }
69 
70  public function getAsCard(): Card
71  {
72  return $this->ui_factory->card()->repositoryObject(
73  $this->information->getTitle(),
74  $this->getImage()
75  )->withSections([$this->ui_factory->listing()->descriptive($this->getCommonProperties())]);
76  }
77 
78  public function getAsRowMapping(): \Closure
79  {
80  return function (
81  PresentationRow $row,
82  ResourceIdentification $resource_identification
83  ): PresentationRow {
84  $actions = $this->action_generator->getActionsForRevision($this->revision);
85  if ($actions !== []) {
86  $row = $row->withAction(
87  $this->ui_factory->dropdown()->standard(
88  $actions
89  )
90  );
91  }
92 
93  return $row
94  ->withHeadline($this->information->getTitle())
95  ->withSubheadline($this->revision->getTitle())
96  ->withImportantFields($this->getImportantProperties())
97  ->withContent(
98  $this->ui_factory->listing()->descriptive($this->getCommonProperties())
99  )
100  ->withFurtherFields(
101  $this->getDetailedProperties()
102  );
103  };
104  }
105 
106  private function getImage(): Image
107  {
108  // We could use Flavours in the Future
109  $src = null;
110  if ($this->irss->flavours()->possible($this->revision->getIdentification(), $this->preview_definition)) {
111  $flavour = $this->irss->flavours()->get($this->revision->getIdentification(), $this->preview_definition);
112  $src = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray()[0] ?? null;
113  }
114 
115  return $this->ui_factory->image()->responsive(
116  $src ?? $this->getPlaceholderImage(),
117  $this->information->getTitle()
118  )->withAlt($this->information->getTitle());
119  }
120 
121  protected function getPlaceholderImage(): string
122  {
123  return './assets/images/placeholder/file_placeholder.svg';
124  }
125 
126  public function getImportantProperties(): array
127  {
128  return [
129  $this->formatDate($this->information->getCreationDate()),
130  $this->formatSize($this->information->getSize()),
131  ];
132  }
133 
134  public function getCommonProperties(): array
135  {
136  return [
137  $this->language->txt('file_size') => $this->formatSize($this->information->getSize()),
138  $this->language->txt('type') => $this->information->getMimeType(),
139 
140  ];
141  }
142 
143  public function getDetailedProperties(): array
144  {
145  return [
146  $this->language->txt('create_date') => $this->formatDate($this->information->getCreationDate()),
147  $this->language->txt('revision_status') => $this->language->txt(
148  'revision_status_' . $this->revision->getStatus()->value
149  ),
150  ];
151  }
152 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private Revision $revision, ?ActionGenerator $action_generator=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
withHeadline(string $headline)
Get a row like this with the given headline.
This describes a Row used in Presentation Table.
__construct(Container $dic, ilPlugin $plugin)
withAction($action)
Get a row like this with a button or a dropdown for actions in the expanded row.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41