ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DataHelper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\MetaData\DataHelper\DataHelperInterface as InternalDataHelper;
25use ILIAS\MetaData\Presentation\DataInterface as DataPresentation;
26
28{
29 protected InternalDataHelper $internal_helper;
30 protected DataPresentation $data_presentation;
31
32 public function __construct(
33 InternalDataHelper $internal_helper,
34 DataPresentation $data_presentation
35 ) {
36 $this->data_presentation = $data_presentation;
37 $this->internal_helper = $internal_helper;
38 }
39
40 public function makePresentable(DataInterface $data): string
41 {
42 return $this->data_presentation->dataValue($data);
43 }
44
45 public function makePresentableAsList(string $separator, DataInterface ...$data): string
46 {
47 $presentable = [];
48 foreach ($data as $datum) {
49 $presentable[] = $this->makePresentable($datum);
50 }
51 return implode($separator, $presentable);
52 }
53
57 public function durationToArray(string $duration): array
58 {
59 $array = [];
60 foreach ($this->internal_helper->durationToIterator($duration) as $value) {
61 $array[] = is_null($value) ? $value : (int) $value;
62 }
63 return $array;
64 }
65
66 public function durationToSeconds(string $duration): int
67 {
68 return $this->internal_helper->durationToSeconds($duration);
69 }
70
71 public function datetimeToObject(string $datetime): \DateTimeImmutable
72 {
73 return $this->internal_helper->datetimeToObject($datetime);
74 }
75
76 public function durationFromIntegers(
77 ?int $years,
78 ?int $months,
79 ?int $days,
80 ?int $hours,
81 ?int $minutes,
82 ?int $seconds
83 ): string {
84 return $this->internal_helper->durationFromIntegers(
85 $years,
86 $months,
87 $days,
88 $hours,
89 $minutes,
90 $seconds
91 );
92 }
93
94 public function datetimeFromObject(\DateTimeImmutable $object): string
95 {
96 return $this->internal_helper->datetimeFromObject($object);
97 }
98
102 public function getAllLanguages(): array
103 {
104 $languages = [];
105 foreach ($this->internal_helper->getAllLanguages() as $language) {
106 $languages[] = new LabelledValue(
107 $language,
108 $this->data_presentation->language($language)
109 );
110 }
111 return $languages;
112 }
113}
$datetime
$duration
__construct(InternalDataHelper $internal_helper, DataPresentation $data_presentation)
Definition: DataHelper.php:32
datetimeToObject(string $datetime)
Translates strings in the LOM-internal datetime format to datetime objects.
Definition: DataHelper.php:71
durationFromIntegers(?int $years, ?int $months, ?int $days, ?int $hours, ?int $minutes, ?int $seconds)
Get a string in the LOM-internal duration format as specified by the provided integers.
Definition: DataHelper.php:76
datetimeFromObject(\DateTimeImmutable $object)
Translates datetime objects to strings in the LOM-internal datetime format.
Definition: DataHelper.php:94
makePresentableAsList(string $separator, DataInterface ... $data)
Definition: DataHelper.php:45
durationToSeconds(string $duration)
Translates strings in the LOM-internal duration format to seconds.
Definition: DataHelper.php:66
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...