ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 

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.

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

66  : \Generator
67  {
68  if (!preg_match(
70  $datetime,
71  $matches,
72  PREG_UNMATCHED_AS_NULL
73  )) {
74  return;
75  }
76  yield from array_slice($matches, 1);
77  }
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
$datetime
+ 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.

References ILIAS\MetaData\DataHelper\Constants\DATETIME_REGEX.

79  : \DateTimeImmutable
80  {
81  preg_match(
83  $datetime,
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  }
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
$datetime

◆ 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.

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

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

38  : \Generator
39  {
40  if (!preg_match(
42  $duration,
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
+ 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.

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

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  }
$duration
durationToIterator(string $duration)
Definition: DataHelper.php:38
+ 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.

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

144  : \Generator
145  {
147  }
const array LANGUAGES
Note that 'xx' should be translated to 'none'.
Definition: Constants.php:47
+ 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.

References ILIAS\MetaData\DataHelper\Constants\DATETIME_REGEX.

30  : bool
31  {
32  return (bool) preg_match(Constants::DATETIME_REGEX, $string);
33  }
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

◆ matchesDurationPattern()

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

Implements ILIAS\MetaData\DataHelper\DataHelperInterface.

Definition at line 25 of file DataHelper.php.

References ILIAS\MetaData\DataHelper\Constants\DURATION_REGEX.

25  : bool
26  {
27  return (bool) preg_match(Constants::DURATION_REGEX, $string);
28  }
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

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