From 668b53e479a8f23d2c7f75086096bee2e4f667bd Mon Sep 17 00:00:00 2001 From: Johannes Schultze Date: Thu, 16 Apr 2020 20:09:05 +0200 Subject: [PATCH 1/4] Added new module. --- module/ResultFeedback/Module.php | 92 ++++++++++++++ .../ResultFeedback/config/module.config.php | 38 ++++++ .../Controller/ResultFeedbackController.php | 112 ++++++++++++++++++ themes/resultfeedback/css/resultfeedback.css | 0 themes/resultfeedback/mixin.config.php | 6 + .../templates/resultfeedback/email.phtml | 7 ++ .../templates/resultfeedback/form.phtml | 38 ++++++ 7 files changed, 293 insertions(+) create mode 100644 module/ResultFeedback/Module.php create mode 100644 module/ResultFeedback/config/module.config.php create mode 100644 module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php create mode 100644 themes/resultfeedback/css/resultfeedback.css create mode 100644 themes/resultfeedback/mixin.config.php create mode 100644 themes/resultfeedback/templates/resultfeedback/email.phtml create mode 100644 themes/resultfeedback/templates/resultfeedback/form.phtml diff --git a/module/ResultFeedback/Module.php b/module/ResultFeedback/Module.php new file mode 100644 index 0000000000..c24229c8b1 --- /dev/null +++ b/module/ResultFeedback/Module.php @@ -0,0 +1,92 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://github.com/dmj/vf2-proxy + */ +namespace ResultFeedback; +use Zend\ModuleManager\ModuleManager, + Zend\Mvc\MvcEvent; + +/** + * Template for ZF2 module for storing local overrides. + * + * @category VuFind2 + * @package Module + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://github.com/dmj/vf2-proxy + */ +class Module +{ + /** + * Get module configuration + * + * @return array + */ + public function getConfig() + { + return include __DIR__ . '/config/module.config.php'; + } + + /** + * Get autoloader configuration + * + * @return array + */ + public function getAutoloaderConfig() + { + return array( + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + ); + } + + /** + * Initialize the module + * + * @param ModuleManager $m Module manager + * + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function init(ModuleManager $m) + { + } + + /** + * Bootstrap the module + * + * @param MvcEvent $e Event + * + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function onBootstrap(MvcEvent $e) + { + } +} diff --git a/module/ResultFeedback/config/module.config.php b/module/ResultFeedback/config/module.config.php new file mode 100644 index 0000000000..17521fc017 --- /dev/null +++ b/module/ResultFeedback/config/module.config.php @@ -0,0 +1,38 @@ + [ + 'factories' => [ + 'ResultFeedback\Controller\ResultFeedbackController' => 'VuFind\Controller\AbstractBaseFactory', + ], + 'aliases' => [ + 'ResultFeedback' => 'ResultFeedback\Controller\ResultFeedbackController', + 'resultfeedback' => 'ResultFeedback\Controller\ResultFeedbackController', + ], + ], +]; + +$staticRoutes = [ + 'ResultFeedback/Email', 'ResultFeedback/Home' +]; + +$routeGenerator = new \VuFind\Route\RouteGenerator(); +$routeGenerator->addRecordRoutes($config, $recordRoutes); +$routeGenerator->addDynamicRoutes($config, $dynamicRoutes); +$routeGenerator->addStaticRoutes($config, $staticRoutes); + +// Add the home route last +$config['router']['routes']['home'] = [ + 'type' => 'Zend\Router\Http\Literal', + 'options' => [ + 'route' => '/', + 'defaults' => [ + 'controller' => 'index', + 'action' => 'Home', + ] + ] +]; + +return $config; + diff --git a/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php new file mode 100644 index 0000000000..7bde16364e --- /dev/null +++ b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php @@ -0,0 +1,112 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +namespace ResultFeedback\Controller; + +use VuFind\Exception\Mail as MailException; +use Zend\Mail\Address; + +/** + * Feedback Class + * + * Controls the Feedback + * + * @category VuFind + * @package Controller + * @author Josiah Knoll + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ResultFeedbackController extends \VuFind\Controller\AbstractBase +{ + /** + * Display Feedback home form. + * + * @return \Zend\View\Model\ViewModel + */ + public function homeAction() + { + return $this->forwardTo('ResultFeedback', 'Email'); + } + + /** + * Receives input from the user and sends an email to the recipient set in + * the config.ini + * + * @return void + */ + public function emailAction() + { + $view = $this->createViewModel(); + $view->useRecaptcha = $this->recaptcha()->active('feedback'); + $view->name = $this->params()->fromPost('name'); + $view->email = $this->params()->fromPost('email'); + $view->comments = $this->params()->fromPost('comments'); + + $recordLoader = $this->serviceLocator->get('VuFind\Record\Loader');; + $driver = $recordLoader->load( + $this->params()->fromRoute('id', $this->params()->fromQuery('id')), + $this->params()->fromRoute('searchclassid', $this->params()->fromQuery('searchclassid')), + false + ); + $view->driver = $driver; + + // Process form submission: + if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { + if (empty($view->email) || empty($view->comments)) { + $this->flashMessenger()->addMessage('bulk_error_missing', 'error'); + return; + } + + // These settings are set in the feedback settion of your config.ini + $config = $this->serviceLocator->get('VuFind\Config\PluginManager') + ->get('config'); + $feedback = isset($config->Feedback) ? $config->Feedback : null; + $recipient_email = isset($feedback->recipient_email) + ? $feedback->recipient_email : null; + $recipient_name = isset($feedback->recipient_name) + ? $feedback->recipient_name : 'Your Library'; + $email_subject = isset($feedback->email_subject) + ? $feedback->email_subject : 'VuFind Feedback'; + $sender_email = isset($feedback->sender_email) + ? $feedback->sender_email : 'noreply@vufind.org'; + $sender_name = isset($feedback->sender_name) + ? $feedback->sender_name : 'VuFind Feedback'; + if ($recipient_email == null) { + throw new \Exception( + 'Feedback Module Error: Recipient Email Unset (see config.ini)' + ); + } + + $email_message = empty($view->name) ? '' : 'Name: ' . $view->name . "\n"; + $email_message .= 'Email: ' . $view->email . "\n"; + $email_message .= 'Comments: ' . $view->comments . "\n\n"; + + // This sets up the email to be sent + // Attempt to send the email and show an appropriate flash message: + try { + $mailer = $this->serviceLocator->get('VuFind\Mailer\Mailer'); + $mailer->send( + new Address($recipient_email, $recipient_name), + new Address($sender_email, $sender_name), + $email_subject, $email_message + ); + $this->flashMessenger()->addMessage( + 'Thank you for your feedback.', 'success' + ); + } catch (MailException $e) { + $this->flashMessenger()->addMessage($e->getMessage(), 'error'); + } + } + return $view; + } +} diff --git a/themes/resultfeedback/css/resultfeedback.css b/themes/resultfeedback/css/resultfeedback.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/themes/resultfeedback/mixin.config.php b/themes/resultfeedback/mixin.config.php new file mode 100644 index 0000000000..53bcd25a34 --- /dev/null +++ b/themes/resultfeedback/mixin.config.php @@ -0,0 +1,6 @@ + [ + 'resultfeedback.css' + ], +]; diff --git a/themes/resultfeedback/templates/resultfeedback/email.phtml b/themes/resultfeedback/templates/resultfeedback/email.phtml new file mode 100644 index 0000000000..018ef3a6aa --- /dev/null +++ b/themes/resultfeedback/templates/resultfeedback/email.phtml @@ -0,0 +1,7 @@ +headTitle($this->translate('Contact us about this title')); + // Get rid of the feedback tab since this uses the same variables + $this->layout()->feedbacktab = false; +?> +render('resultfeedback/form.phtml');?> diff --git a/themes/resultfeedback/templates/resultfeedback/form.phtml b/themes/resultfeedback/templates/resultfeedback/form.phtml new file mode 100644 index 0000000000..9473a514d2 --- /dev/null +++ b/themes/resultfeedback/templates/resultfeedback/form.phtml @@ -0,0 +1,38 @@ +

transEsc("Contact us about this title")?>

+
+ render('RecordDriver/SolrDefault/recorddriver-core-title.phtml', ['driver' => $this->driver]) ?> +
+flashmessages() ?> + From df2c419b6a527653107277597b65a0aed87e00c8 Mon Sep 17 00:00:00 2001 From: Johannes Schultze Date: Tue, 21 Apr 2020 12:22:10 +0200 Subject: [PATCH 2/4] HAW #96 - Neuer Button "Frage zu diesem Titel?" bei jedem Treffer. --- .../Controller/ResultFeedbackController.php | 8 ++++++++ themes/resultfeedback/templates/resultfeedback/form.phtml | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php index 7bde16364e..6a8567ae45 100644 --- a/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php +++ b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php @@ -60,6 +60,14 @@ public function emailAction() ); $view->driver = $driver; + $configReader = $this->serviceLocator->get('VuFind\Config\PluginManager'); + $resultFeedbackConfig = $configReader->get('resultFeedback')->toArray(); + $resultUserTypes = []; + if (isset($resultFeedbackConfig['resultFeedback']['user_types'])) { + $resultUserTypes = $resultFeedbackConfig['resultFeedback']['user_types']; + } + $view->resultUserTypes = $resultUserTypes; + // Process form submission: if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { if (empty($view->email) || empty($view->comments)) { diff --git a/themes/resultfeedback/templates/resultfeedback/form.phtml b/themes/resultfeedback/templates/resultfeedback/form.phtml index 9473a514d2..8d364a0040 100644 --- a/themes/resultfeedback/templates/resultfeedback/form.phtml +++ b/themes/resultfeedback/templates/resultfeedback/form.phtml @@ -9,10 +9,9 @@
From de6f4407882254a8d22302dcf1750829c69f8eab Mon Sep 17 00:00:00 2001 From: Johannes Schultze Date: Wed, 22 Apr 2020 12:33:56 +0200 Subject: [PATCH 3/4] HAW #96 - Neuer Button "Frage zu diesem Titel?" bei jedem Treffer. --- .../Controller/ResultFeedbackController.php | 64 +++++++++-------- themes/resultfeedback/css/resultfeedback.css | 3 + .../templates/resultfeedback/form.phtml | 70 ++++++++++--------- 3 files changed, 73 insertions(+), 64 deletions(-) diff --git a/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php index 6a8567ae45..1321b1a410 100644 --- a/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php +++ b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php @@ -6,7 +6,7 @@ * * @category VuFind * @package Controller - * @author Josiah Knoll + * @author Johannes Schultze * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Site */ @@ -22,7 +22,7 @@ * * @category VuFind * @package Controller - * @author Josiah Knoll + * @author Johannes Schultze * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development Wiki */ @@ -40,28 +40,32 @@ public function homeAction() /** * Receives input from the user and sends an email to the recipient set in - * the config.ini + * the resultFeedback.ini * * @return void */ public function emailAction() { + $translator = $this->serviceLocator->get('Zend\Mvc\I18n\Translator'); + $view = $this->createViewModel(); $view->useRecaptcha = $this->recaptcha()->active('feedback'); $view->name = $this->params()->fromPost('name'); $view->email = $this->params()->fromPost('email'); $view->comments = $this->params()->fromPost('comments'); + $view->usertype = $this->params()->fromPost('usertype'); + $view->recordid = $this->params()->fromPost('recordid'); + $view->recordtitle = $this->params()->fromPost('recordtitle'); + $id = $this->params()->fromRoute('id', $this->params()->fromQuery('id')); + $view->id = $id; + $searchClassId = $this->params()->fromRoute('searchclassid', $this->params()->fromQuery('searchclassid')); + $view->searchClassId = $searchClassId; $recordLoader = $this->serviceLocator->get('VuFind\Record\Loader');; - $driver = $recordLoader->load( - $this->params()->fromRoute('id', $this->params()->fromQuery('id')), - $this->params()->fromRoute('searchclassid', $this->params()->fromQuery('searchclassid')), - false - ); + $driver = $recordLoader->load($id, $searchClassId, false); $view->driver = $driver; - $configReader = $this->serviceLocator->get('VuFind\Config\PluginManager'); - $resultFeedbackConfig = $configReader->get('resultFeedback')->toArray(); + $resultFeedbackConfig = $this->serviceLocator->get('VuFind\Config\PluginManager')->get('resultFeedback')->toArray(); $resultUserTypes = []; if (isset($resultFeedbackConfig['resultFeedback']['user_types'])) { $resultUserTypes = $resultFeedbackConfig['resultFeedback']['user_types']; @@ -69,35 +73,30 @@ public function emailAction() $view->resultUserTypes = $resultUserTypes; // Process form submission: + $view->hideForm = false; if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { if (empty($view->email) || empty($view->comments)) { $this->flashMessenger()->addMessage('bulk_error_missing', 'error'); return; } - // These settings are set in the feedback settion of your config.ini - $config = $this->serviceLocator->get('VuFind\Config\PluginManager') - ->get('config'); - $feedback = isset($config->Feedback) ? $config->Feedback : null; - $recipient_email = isset($feedback->recipient_email) - ? $feedback->recipient_email : null; - $recipient_name = isset($feedback->recipient_name) - ? $feedback->recipient_name : 'Your Library'; - $email_subject = isset($feedback->email_subject) - ? $feedback->email_subject : 'VuFind Feedback'; - $sender_email = isset($feedback->sender_email) - ? $feedback->sender_email : 'noreply@vufind.org'; - $sender_name = isset($feedback->sender_name) - ? $feedback->sender_name : 'VuFind Feedback'; + $recipient_email = isset($resultFeedbackConfig['resultFeedback']['recipient_email']) ? $resultFeedbackConfig['resultFeedback']['recipient_email'] : null; + $recipient_name = isset($resultFeedbackConfig['resultFeedback']['recipient_name']) ? $resultFeedbackConfig['resultFeedback']['recipient_name'] : 'Your Library'; + $email_subject = isset($resultFeedbackConfig['resultFeedback']['email_subject']) ? $resultFeedbackConfig['resultFeedback']['email_subject'] : 'Result Feedback'; + $sender_email = isset($resultFeedbackConfig['resultFeedback']['sender_email']) ? $resultFeedbackConfig['resultFeedback']['sender_email'] : 'noreply@vufind.org'; + $sender_name = isset($resultFeedbackConfig['resultFeedback']['sender_name']) ? $resultFeedbackConfig['resultFeedback']['sender_name'] : 'Result Feedback'; if ($recipient_email == null) { throw new \Exception( - 'Feedback Module Error: Recipient Email Unset (see config.ini)' + 'Result Feedback Module Error: Recipient Email Unset (see resultFeedback.ini)' ); } - $email_message = empty($view->name) ? '' : 'Name: ' . $view->name . "\n"; - $email_message .= 'Email: ' . $view->email . "\n"; - $email_message .= 'Comments: ' . $view->comments . "\n\n"; + $email_message = $translator->translate('resultfeedback_usertype') . ':' . "\n" . $translator->translate($view->usertype) . "\n\n"; + $email_message .= empty($view->name) ? '' : 'Name:' . "\n" . $view->name . "\n\n"; + $email_message .= $translator->translate('Email') . ':' . "\n" . $view->email . "\n\n"; + $email_message .= $translator->translate('PPN') . ':' . "\n" . $view->recordid . "\n\n"; + $email_message .= $translator->translate('Title') . ':' . "\n" . $view->recordtitle . "\n\n"; + $email_message .= $translator->translate('Message') . ':' . "\n" . $view->comments . "\n\n"; // This sets up the email to be sent // Attempt to send the email and show an appropriate flash message: @@ -106,15 +105,20 @@ public function emailAction() $mailer->send( new Address($recipient_email, $recipient_name), new Address($sender_email, $sender_name), - $email_subject, $email_message + $email_subject, + $email_message, + null, + $view->email ); $this->flashMessenger()->addMessage( - 'Thank you for your feedback.', 'success' + 'Your result feedback has been send', 'success' ); + $view->hideForm = true; } catch (MailException $e) { $this->flashMessenger()->addMessage($e->getMessage(), 'error'); } } + return $view; } } diff --git a/themes/resultfeedback/css/resultfeedback.css b/themes/resultfeedback/css/resultfeedback.css index e69de29bb2..9ae6b3c9dd 100644 --- a/themes/resultfeedback/css/resultfeedback.css +++ b/themes/resultfeedback/css/resultfeedback.css @@ -0,0 +1,3 @@ +.result-feedback .privacy a { + text-decoration: underline; +} \ No newline at end of file diff --git a/themes/resultfeedback/templates/resultfeedback/form.phtml b/themes/resultfeedback/templates/resultfeedback/form.phtml index 8d364a0040..5bbaefba1f 100644 --- a/themes/resultfeedback/templates/resultfeedback/form.phtml +++ b/themes/resultfeedback/templates/resultfeedback/form.phtml @@ -1,37 +1,39 @@

transEsc("Contact us about this title")?>

-
- render('RecordDriver/SolrDefault/recorddriver-core-title.phtml', ['driver' => $this->driver]) ?> -
flashmessages() ?> -