TYPO3 CMS  TYPO3_6-2
MailView.php
Go to the documentation of this file.
1 <?php
3 
22 class MailView {
23 
29  const LOCALISATION_OBJECT_NAME = 'tx_form_view_mail';
30 
36  protected $mailMessage;
37 
43  protected $typoScript = array();
44 
51 
57  protected $localCobj;
58 
62  public function __construct(\TYPO3\CMS\Core\Mail\MailMessage $mailMessage, array $typoScript) {
63  $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
64  $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
65  $this->mailMessage = $mailMessage;
66  $this->typoScript = $typoScript;
67  }
68 
69  public function render() {
70  if ($this->mailMessage->isSent()) {
71  $output = $this->success();
72  } else {
73  $output = $this->error();
74  }
75  return $output;
76  }
77 
83  protected function success() {
84  return $this->makeContentObject('success');
85  }
86 
92  protected function error() {
93  return $this->makeContentObject('error');
94  }
95 
101  protected function makeContentObject($isSent) {
102  $message = NULL;
103  $type = NULL;
104  if ($this->typoScript['messages.'][$isSent]) {
105  $type = $this->typoScript['messages.'][$isSent];
106  }
107  if ($this->typoScript['messages.'][$isSent . '.']) {
108  $message = $this->typoScript['messages.'][$isSent . '.'];
109  }
110  if (empty($message)) {
111  if (!empty($type)) {
112  $message = $type;
113  $type = 'TEXT';
114  } else {
115  $type = 'TEXT';
116  $message = $this->getLocalLanguageLabel($isSent);
117  }
118  $value['value'] = $message;
119  $value['wrap'] = '<p>|</p>';
120  } elseif (!is_array($message)) {
121  $value['value'] = $message;
122  $value['wrap'] = '<p>|</p>';
123  } else {
124  $value = $message;
125  }
126  return $this->localCobj->cObjGetSingle($type, $value);
127  }
128 
136  protected function getLocalLanguageLabel($type) {
137  $label = self::LOCALISATION_OBJECT_NAME . '.' . $type;
138  $message = $this->localizationHandler->getLocalLanguageLabel($label);
139  return $message;
140  }
141 
142 }
__construct(\TYPO3\CMS\Core\Mail\MailMessage $mailMessage, array $typoScript)
Definition: MailView.php:62