ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailErrorFormatter Class Reference

Class ilMailErrorFormatter. More...

+ Collaboration diagram for ilMailErrorFormatter:

Public Member Functions

 __construct (\ilLanguage $lng)
 ilMailErrorFormatter constructor. More...
 
 format (array $errors)
 Formats an error string based on the passed list of errors. More...
 

Protected Attributes

 $lng
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailErrorFormatter::__construct ( \ilLanguage  $lng)

ilMailErrorFormatter constructor.

Parameters
ilLanguage$lng

Definition at line 17 of file class.ilMailErrorFormatter.php.

References $lng.

18  {
19  $this->lng = $lng;
20  }

Member Function Documentation

◆ format()

ilMailErrorFormatter::format ( array  $errors)

Formats an error string based on the passed list of errors.

If the list contains > 1 elements, the 1st error will be used as a headline for the list of errors.

Parameters
$errors[]
Returns
string

Definition at line 28 of file class.ilMailErrorFormatter.php.

References $tpl.

28  : string
29  {
30  if (0 === count($errors)) {
31  return '';
32  }
33 
34  $errorsToDisplay = [];
35  foreach ($errors as $error) {
36  $translation = $this->lng->txt($error->getLanguageVariable());
37  if ($translation === '-' . $this->lng->txt($error->getLanguageVariable()) . '-') {
38  $translation = $error->getLanguageVariable();
39  }
40 
41  if (
42  0 === count($error->getPlaceHolderValues()) ||
43  $translation === $error->getLanguageVariable()
44  ) {
45  $errorsToDisplay[] = $translation;
46  } else {
47  $escapedPlaceholderValues = array_map(function (string $address) {
48  return \ilUtil::prepareFormOutput($address);
49  }, $error->getPlaceHolderValues());
50 
51  array_unshift($escapedPlaceholderValues, $translation);
52  $errorsToDisplay[] = call_user_func_array('sprintf', $escapedPlaceholderValues);
53  }
54  }
55 
56  if (0 === count($errorsToDisplay)) {
57  return '';
58  }
59 
60  $tpl = new \ilTemplate('tpl.mail_new_submission_errors.html', true, true, 'Services/Mail');
61  if (1 === count($errorsToDisplay)) {
62  $tpl->setCurrentBlock('single_error');
63  $tpl->setVariable('SINGLE_ERROR', current($errorsToDisplay));
64  $tpl->parseCurrentBlock();
65  } else {
66  $firstError = array_shift($errorsToDisplay);
67 
68  foreach ($errorsToDisplay as $error) {
69  $tpl->setCurrentBlock('error_loop');
70  $tpl->setVariable('ERROR', $error);
71  $tpl->parseCurrentBlock();
72  }
73 
74  $tpl->setCurrentBlock('multiple_errors');
75  $tpl->setVariable('FIRST_ERROR', $firstError);
76  $tpl->parseCurrentBlock();
77  }
78 
79  return $tpl->get();
80  }
$tpl
Definition: ilias.php:10
$errors
Definition: index.php:6

Field Documentation

◆ $lng

ilMailErrorFormatter::$lng
protected

Definition at line 11 of file class.ilMailErrorFormatter.php.

Referenced by __construct().


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