diff --git a/fid_bbi/config/vufind/EmailProfiles.ini b/fid_bbi/config/vufind/EmailProfiles.ini index 37d1e72ca8e8150c19a2f8a2e7fef7b3f19607fd..1c72efb0b4b1e78f42b8c861a0664e09dd478e76 100644 --- a/fid_bbi/config/vufind/EmailProfiles.ini +++ b/fid_bbi/config/vufind/EmailProfiles.ini @@ -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 diff --git a/module/fid_bbi/config/module.config.php b/module/fid_bbi/config/module.config.php index 071441b40aee7dd65b8ab16a5f5c13f4cfe45172..50d8be03c83ffa960361fd8dc994109d1c1c56be 100644 --- a/module/fid_bbi/config/module.config.php +++ b/module/fid_bbi/config/module.config.php @@ -130,7 +130,8 @@ $config = [ $nonTabRecordActions = [ 'PDA', 'EmailHold', - 'ReportErrors' + 'ReportErrors', + 'Acquisition' ]; diff --git a/module/fid_bbi/src/fid_bbi/Controller/RecordController.php b/module/fid_bbi/src/fid_bbi/Controller/RecordController.php index 8ca53522797856d023868fb867979bb5d192a13e..25cf95de74dabecccda2e5d2fe086e5c1b091a3c 100644 --- a/module/fid_bbi/src/fid_bbi/Controller/RecordController.php +++ b/module/fid_bbi/src/fid_bbi/Controller/RecordController.php @@ -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 + ); + } } diff --git a/themes/fid_bbi/templates/Email/acquisition-html.phtml b/themes/fid_bbi/templates/Email/acquisition-html.phtml new file mode 100644 index 0000000000000000000000000000000000000000..2e6acaa5a6568fba11569cf34bc60a5958b8575f --- /dev/null +++ b/themes/fid_bbi/templates/Email/acquisition-html.phtml @@ -0,0 +1,45 @@ +<?=$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> diff --git a/themes/fid_bbi/templates/Email/acquisition-plain.phtml b/themes/fid_bbi/templates/Email/acquisition-plain.phtml new file mode 100644 index 0000000000000000000000000000000000000000..fab386798005223fb4d2d2bc9d26814bdc95d9c8 --- /dev/null +++ b/themes/fid_bbi/templates/Email/acquisition-plain.phtml @@ -0,0 +1,28 @@ + +== 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 : "" ?> diff --git a/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml b/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml index c822a09c91e03f3dc327c48f11bb3fa62aab8bf3..a78e22e8cf2ffd820f132d7c86263b26d9068d00 100644 --- a/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml +++ b/themes/fid_bbi/templates/RecordDriver/DefaultRecord/toolbar.phtml @@ -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 -->