ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMailErrorFormatter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $lng;
12
17 public function __construct(\ilLanguage $lng)
18 {
19 $this->lng = $lng;
20 }
21
28 public function format(array $errors) : 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 }
81}
An exception for terminatinating execution or to throw for unit testing.
language handling
Class ilMailErrorFormatter.
format(array $errors)
Formats an error string based on the passed list of errors.
__construct(\ilLanguage $lng)
ilMailErrorFormatter constructor.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$errors