ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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.

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

References $lng.

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\ilMailError[]
Returns
string

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

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 }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$errors

References $errors, and $tpl.

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: