ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BaseToComponent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
31abstract class BaseToComponent implements ToComponent
32{
33 public const SIZE_FACTOR = 1000;
34 protected const DATE_FORMAT = 'd.m.Y H:i';
35 protected \ilLanguage $language;
38 protected \ilObjUser $acting_user;
39
40 public function __construct(
42 ) {
43 global $DIC;
44 $this->action_generator = $action_generator ?? new NullActionGenerator();
45 $this->language = $DIC->language();
46 $this->language->loadLanguageModule('irss');
47 $this->ui_factory = $DIC->ui()->factory();
48 $this->acting_user = $DIC->user();
49 }
50
51
52 protected function formatSize(int $size): string
53 {
54 $unit = match (true) {
55 $size > self::SIZE_FACTOR * self::SIZE_FACTOR * self::SIZE_FACTOR => DataSize::GB,
56 $size > self::SIZE_FACTOR * self::SIZE_FACTOR => DataSize::MB,
57 $size > self::SIZE_FACTOR => DataSize::KB,
58 default => DataSize::Byte,
59 };
60
61 $size = (int) (round((float) $size / (float) $unit, 2) * (float) $unit);
62
63 return (string) (new DataSize($size, $unit));
64 }
65
66 protected function formatDate(\DateTimeImmutable $date): string
67 {
68 return $date
69 ->setTimezone(new \DateTimeZone($this->acting_user->getTimeZone()))
70 ->format(self::DATE_FORMAT);
71 }
72}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
__construct(?ActionGenerator $action_generator=null)
This is how the factory for UI elements looks.
Definition: Factory.php:38
global $DIC
Definition: shib_login.php:26