ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\DataHelper\DataHelper Class Reference
+ Inheritance diagram for ILIAS\MetaData\DataHelper\DataHelper:
+ Collaboration diagram for ILIAS\MetaData\DataHelper\DataHelper:

Public Member Functions

 matchesDurationPattern (string $string)
 
 matchesDatetimePattern (string $string)
 
 durationToIterator (string $duration)
 
 durationToSeconds (string $duration)
 
 datetimeToIterator (string $datetime)
 
 datetimeToObject (string $datetime)
 
 durationFromIntegers (?int $years, ?int $months, ?int $days, ?int $hours, ?int $minutes, ?int $seconds)
 
 datetimeFromObject (\DateTimeImmutable $object)
 Note that LOM in ILIAS ignores the time part of any datetimes. More...
 
 getAllLanguages ()
 
 matchesDurationPattern (string $string)
 
 matchesDatetimePattern (string $string)
 
 durationToIterator (string $duration)
 Returns in sequence years, months, days, hours, minutes, seconds. More...
 
 durationToSeconds (string $duration)
 
 datetimeToIterator (string $datetime)
 Returns in sequence: YYYY, MM, DD, hh, mm, ss, s (arbitrary many digits for decimal fractions of seconds), 8: timezone, either Z for UTC or +- hh:mm (mm is optional) Note that datetimes distinguish between a field being set to zero or not set at all. More...
 
 datetimeToObject (string $datetime)
 
 durationFromIntegers (?int $years, ?int $months, ?int $days, ?int $hours, ?int $minutes, ?int $seconds)
 
 datetimeFromObject (\DateTimeImmutable $object)
 Note that LOM in ILIAS ignores the time part of any datetimes. More...
 
 getAllLanguages ()
 

Additional Inherited Members

Detailed Description

Definition at line 23 of file DataHelper.php.

Member Function Documentation

◆ datetimeFromObject()

ILIAS\MetaData\DataHelper\DataHelper::datetimeFromObject ( \DateTimeImmutable  $object)

Note that LOM in ILIAS ignores the time part of any datetimes.

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 136 of file DataHelper.php.

136 : string
137 {
138 return $object->format('Y-m-d');
139 }

◆ datetimeToIterator()

ILIAS\MetaData\DataHelper\DataHelper::datetimeToIterator ( string  $datetime)
Returns
string[]|null[]

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 66 of file DataHelper.php.

66 : \Generator
67 {
68 if (!preg_match(
71 $matches,
72 PREG_UNMATCHED_AS_NULL
73 )) {
74 return;
75 }
76 yield from array_slice($matches, 1);
77 }
$datetime
const string DATETIME_REGEX
This monstrosity makes sure datetimes conform to the format given by LOM, and picks out the relevant ...
Definition: Constants.php:40

References $datetime, ILIAS\MetaData\DataHelper\Constants\DATETIME_REGEX, and ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from().

+ Here is the call graph for this function:

◆ datetimeToObject()

ILIAS\MetaData\DataHelper\DataHelper::datetimeToObject ( string  $datetime)

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 79 of file DataHelper.php.

79 : \DateTimeImmutable
80 {
81 preg_match(
84 $matches,
85 PREG_UNMATCHED_AS_NULL
86 );
87 return new \DateTimeImmutable(
88 ($matches[1] ?? '0000') . '-' .
89 ($matches[2] ?? '01') . '-' .
90 ($matches[3] ?? '01')
91 );
92 }

References $datetime, and ILIAS\MetaData\DataHelper\Constants\DATETIME_REGEX.

◆ durationFromIntegers()

ILIAS\MetaData\DataHelper\DataHelper::durationFromIntegers ( ?int  $years,
?int  $months,
?int  $days,
?int  $hours,
?int  $minutes,
?int  $seconds 
)

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 94 of file DataHelper.php.

101 : string {
102 $has_time = !is_null($hours) || !is_null($minutes) || !is_null($seconds);
103
104 if (is_null($years) && is_null($months) && is_null($days) && !$has_time) {
105 return '';
106 }
107
108 $string = 'P';
109 if (!is_null($years)) {
110 $string .= max($years, 0) . 'Y';
111 }
112 if (!is_null($months)) {
113 $string .= max($months, 0) . 'M';
114 }
115 if (!is_null($days)) {
116 $string .= max($days, 0) . 'D';
117 }
118
119 if (!$has_time) {
120 return $string;
121 }
122 $string .= 'T';
123 if (!is_null($hours)) {
124 $string .= max($hours, 0) . 'H';
125 }
126 if (!is_null($minutes)) {
127 $string .= max($minutes, 0) . 'M';
128 }
129 if (!is_null($seconds)) {
130 $string .= max($seconds, 0) . 'S';
131 }
132
133 return $string;
134 }

◆ durationToIterator()

ILIAS\MetaData\DataHelper\DataHelper::durationToIterator ( string  $duration)
Returns
string[]|null[]

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 38 of file DataHelper.php.

38 : \Generator
39 {
40 if (!preg_match(
43 $matches,
44 PREG_UNMATCHED_AS_NULL
45 )) {
46 return;
47 }
48 yield from array_slice($matches, 1);
49 }
$duration
const string DURATION_REGEX
This monstrosity makes sure durations conform to the format given by LOM, and picks out the relevant ...
Definition: Constants.php:30

References $duration, ILIAS\MetaData\DataHelper\Constants\DURATION_REGEX, and ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from().

Referenced by ILIAS\MetaData\DataHelper\DataHelper\durationToSeconds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ durationToSeconds()

ILIAS\MetaData\DataHelper\DataHelper::durationToSeconds ( string  $duration)

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 51 of file DataHelper.php.

51 : int
52 {
53 $factors = [1, 12, 30, 24, 60, 60];
54 $factor_index = 0;
55 $result = 0;
56 foreach ($this->durationToIterator($duration) as $number) {
57 $result = $factors[$factor_index] * $result + $number;
58 $factor_index++;
59 }
60 return $result;
61 }
durationToIterator(string $duration)
Definition: DataHelper.php:38

References ILIAS\MetaData\DataHelper\DataHelper\durationToIterator().

+ Here is the call graph for this function:

◆ getAllLanguages()

ILIAS\MetaData\DataHelper\DataHelper::getAllLanguages ( )
Returns
string[]

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 144 of file DataHelper.php.

144 : \Generator
145 {
147 }
const array LANGUAGES
Note that 'xx' should be translated to 'none'.
Definition: Constants.php:47

References ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), and ILIAS\MetaData\DataHelper\Constants\LANGUAGES.

+ Here is the call graph for this function:

◆ matchesDatetimePattern()

ILIAS\MetaData\DataHelper\DataHelper::matchesDatetimePattern ( string  $string)

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 30 of file DataHelper.php.

30 : bool
31 {
32 return (bool) preg_match(Constants::DATETIME_REGEX, $string);
33 }

References ILIAS\MetaData\DataHelper\Constants\DATETIME_REGEX.

◆ matchesDurationPattern()

ILIAS\MetaData\DataHelper\DataHelper::matchesDurationPattern ( string  $string)

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 25 of file DataHelper.php.

25 : bool
26 {
27 return (bool) preg_match(Constants::DURATION_REGEX, $string);
28 }

References ILIAS\MetaData\DataHelper\Constants\DURATION_REGEX.


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