Skip to content
Snippets Groups Projects
Commit 5bbdcd9b authored by Gregor Gawol's avatar Gregor Gawol Committed by Dorian Merz
Browse files

refs #15163 #15162 [fid_bbi] fixup for acquisition form

* adds missing commit

* set form
* set configuration
* email text html & plain
parent 00d500c5
Branches
Tags
No related merge requests found
......@@ -28,3 +28,14 @@ from = noreply@hab.de
from_name = "Katalog BBI"
; Text snippet for email subject.
subject = "[Fehlermeldung - %s] %s"
; Profile for report errors form.
[Acquisition]
; Destination email address for reported errors.
to = fid@hab.de
to_name = "Katalog BBI"
; Return email address
from = noreply@hab.de
from_name = "Katalog BBI"
; Text snippet for email subject.
subject = "[Anschaffungsvorschlag - %s] %s"
\ No newline at end of file
......@@ -130,7 +130,8 @@ $config = [
$nonTabRecordActions = [
'PDA',
'EmailHold',
'ReportErrors'
'ReportErrors',
'Acquisition'
];
......
......@@ -129,6 +129,71 @@ class RecordController extends \finc\Controller\RecordController implements
return $view;
}
/**
* Acquisition action - controller method
*
* @return \Zend\View\Model\ViewModel
*/
public function acquisitionAction()
{
// Force login if necessary:
$config = $this->getConfig();
if ((!isset($config->Mail->require_login) || $config->Mail->require_login)
&& !$this->getUser()
) {
return $this->forceLogin();
}
$params['email'] = null;
if ($user = $this->getUser()) {
$params['email'] = trim($user->email);
}
// Create view
$view = $this->createAcquisitionEmailViewModel($params);
// Set up reCaptcha
//todo: testen!
$view->useRecaptcha = $this->recaptcha()->active('acquisition');
// Process form submission
if ($this->formWasSubmitted('submit', $view->useRecaptcha)) {
// Collect the data submitted by form
$params['email'] = !empty($view->email) ? $view->email : '';
$params['comment'] = !empty($view->comment) ? $view->comment : '';
$params['subject'] = !empty($view->subject) ? $view->subject : '';
$params['eula'] = isset($view->eula) ? $view->eula : '';
// Validate data submitted by form
$validatorStrLength = new StringLength(['min' => 10]);
$validatorNotEmpty = new NotEmpty();
if (!$validatorStrLength->isValid($params['comment'])) {
$this->flashMessenger()
->addMessage('report_errors_comment_blank', 'error');
} elseif (!$validatorNotEmpty->isValid($params['eula'])) {
$this->flashMessenger()
->addMessage('fid::error_eula_accepted', 'error');
}else {
// All params are valid, set timestamp for current params set
$params['timestamp'] = date('d.m.Y H:i');
// Attempt to send the email and show an appropriate flash message:
try {
$this->sendAcquisitionEmail($params);
$this->flashMessenger()->addMessage('report_errors_send_success', 'success');
return $this->redirectToRecord();
} catch (MailException $e) {
$this->flashMessenger()->addMessage($e->getMessage(), 'error');
}
}
}
// Display the template:
$view->setTemplate('record/acquisitionform');
return $view;
}
/**
* Create a new ViewModel to use as a PDA-Email form.
*
......@@ -170,6 +235,45 @@ class RecordController extends \finc\Controller\RecordController implements
return $view;
}
/**
* Create a new ViewModel to use as a Acquisition-Email form.
*
* @param array $params Parameters to pass to ViewModel constructor.
*
* @return ViewModel
*/
protected function createAcquisitionEmailViewModel($params = null)
{
// Build view:
$view = $this->createViewModel($params);
// Send parameters back to view so form can be re-populated:
if ($this->getRequest()->isPost()) {
$view->email = $this->params()->fromPost('acquisition_email');
$view->comment = $this->params()->fromPost('acquisition_comment');
$view->subject = $this->params()->fromPost('acquisition_subject');
$view->eula = $this->params()->fromPost('acquisition_checkbox_eula');
}
// Collect the records metadata
$keyMethodMapper = [
'id' => 'getUniqueID',
'author' => 'getDeduplicatedAuthors',
'title' => 'getTitle',
'title_short' => 'getShortTitle',
'isbn' => 'getISBNs'
];
$driver = $this->loadRecord();
foreach ($keyMethodMapper as $var => $method) {
$view->$var = $driver->tryMethod($method);
}
$view->author = !empty($view->author) ?
$this->getAuthors($view->author) : null;
return $view;
}
/**
* Formatted author data
*
......@@ -213,7 +317,7 @@ class RecordController extends \finc\Controller\RecordController implements
// Collect the records metadata
$keyMethodMapper = [
'id' => 'getUniqueID',
'author' => 'getCombinedAuthors',
'author' => 'getDeduplicatedAuthors',
'title' => 'getTitle',
'title_short' => 'getShortTitle',
'year' => 'getPublishDateSort',
......@@ -223,6 +327,8 @@ class RecordController extends \finc\Controller\RecordController implements
foreach ($keyMethodMapper as $var => $method) {
$params[$var] = $driver->tryMethod($method);
}
$params['author'] = !empty($params['author']) ?
$this->getAuthors($params['author']) : null;
$params['driver'] = $driver;
// Custom template for emails (html-only)
......@@ -270,4 +376,72 @@ class RecordController extends \finc\Controller\RecordController implements
$bodyPlain
);
}
/**
* Send Acquisition via e-mail.
*
* @param array $params Data to be used for Email template
*
* @return void
* @throws MailException
*/
protected function sendAcquisitionEmail($params)
{
$emailProfile = $this->getEmailProfile('Acquisition');
$renderer = $this->getViewRenderer();
// Collect the records metadata
$keyMethodMapper = [
'id' => 'getUniqueID',
'author' => 'getDeduplicatedAuthors',
'title' => 'getTitle',
'title_short' => 'getShortTitle',
'isbn' => 'getISBNs'
];
$driver = $this->loadRecord();
foreach ($keyMethodMapper as $var => $method) {
$params[$var] = $driver->tryMethod($method);
}
$params['author'] = !empty($params['author']) ?
$this->getAuthors($params['author']) : null;
$params['driver'] = $driver;
// Custom template for emails (html-only)
$bodyHtml = $renderer->render(
'Email/acquisition-html.phtml',
$params
);
// Custom template for emails (text-only)
$bodyPlain = $renderer->render(
'Email/acquisition-plain.phtml',
$params
);
// Build the subject
$subject = (isset($emailProfile->subject))
? sprintf(
$emailProfile->subject,
$params['title'],
$params['subject']
) : $this->translate('Book Suggestion');
// Set reply address and name if available
$replyTo = !empty($params['email']) ? $params['email'] : $emailProfile->from;
$reply = new Address($replyTo);
// Get mailer
$mailer = new Mailer(
$this->serviceLocator->get('VuFind\Mailer')->getTransport()
);
// Send the email
$mailer->sendTextHtml(
new Address($emailProfile->to),
new Address($emailProfile->from),
isset($reply) ? $reply : $emailProfile->from,
$subject,
$bodyHtml,
$bodyPlain
);
}
}
<?=$this->doctype('HTML5')?>
<html>
<head>
<?php /* <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> TEST IF THIS WORKS, fixme CK */ ?>
<title>Anschaffungsvorschlag</title>
</head>
<body style="font-family: Arial, Verdana, sans-serif;">
<h2>Anschaffungsvorschlag</h2>
<table>
<?php if (isset($email)): ?>
<tr>
<td width="30%">Email:</td>
<td width="70%"><a href="mailto:<?=$email?>"><?=$email?></a></td>
</tr>
<?php endif; ?>
<tr>
<td width="30%">hat folgenden Titel zur Erwerbung empfohlen:</td>
<td width="70%">
<strong><?=$title?></strong><br/>
<?php if ($author): ?>von
<?php foreach ($author as $auth): ?>
<?=$auth?>
<?php endforeach; ?>
<?php endif; ?><br/><br/>
<?php if ($id): ?>
finc-ID: <?=$id?>
<?php endif; ?><br/>
<?php if ($isbn): ?>
ISBN: <?=implode(', ', $isbn)?>
<?php endif; ?><br/>
<br/>
</td>
</tr>
<tr>
<td width="30%">Begründung für Empfehlung:</td>
<td width="70%"><?=$comment?></td>
</tr>
<tr valign="top">
<td width="100%" colspan="2">
Zeitpunkt der Meldung: <?=$timestamp?>
</td>
</tr>
</table>
</body>
</html>
== Anschaffungsvorschlag ==
E-Mail-Adresse: <?=$email ?>
hat folgenden Titel zur Erwerbung empfohlen:
Titel: <?=$title ?>
<?php if ($author): ?>
von <?php foreach ($author as $au): ?><?= $au ?> <?php endforeach; ?>
<?php endif; ?>
<?php if ($id): ?>
finc-ID: <?=$id?>
<?php endif; ?>
<?php if ($isbn): ?>
ISBN: <?=implode(', ', $isbn)?>
<?php endif; ?>
Begründung für Empfehlung:
<?=$comment ?>
<?=isset($timestamp) ? "Zeitpunkt: " . $timestamp : "" ?>
......@@ -66,5 +66,8 @@ $cartId = $this->driver->getSourceIdentifier() . '|' . $this->driver->getUniqueI
<li>
<a class="feedbackLink item" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'ReportErrors')?>" rel="nofollow"><i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('ReportErrors')?></a>
</li>
<li>
<a class="feedbackLink item" data-lightbox href="<?=$this->recordLink()->getActionUrl($this->driver, 'Acquisition')?>" rel="nofollow"><i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('Book Suggestion')?></a>
</li>
</ul>
<!-- fid_bbi: recordDriver - DefaultRecord - toolbar - END -->
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment