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..1321b1a410 --- /dev/null +++ b/module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php @@ -0,0 +1,124 @@ + + * @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 Johannes Schultze + * @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 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($id, $searchClassId, false); + $view->driver = $driver; + + $resultFeedbackConfig = $this->serviceLocator->get('VuFind\Config\PluginManager')->get('resultFeedback')->toArray(); + $resultUserTypes = []; + if (isset($resultFeedbackConfig['resultFeedback']['user_types'])) { + $resultUserTypes = $resultFeedbackConfig['resultFeedback']['user_types']; + } + $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; + } + + $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( + 'Result Feedback Module Error: Recipient Email Unset (see resultFeedback.ini)' + ); + } + + $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: + 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, + null, + $view->email + ); + $this->flashMessenger()->addMessage( + '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 new file mode 100644 index 0000000000..9ae6b3c9dd --- /dev/null +++ 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/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..263431cf50 --- /dev/null +++ b/themes/resultfeedback/templates/resultfeedback/form.phtml @@ -0,0 +1,39 @@ +

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

+flashmessages() ?> +hideForm): ?> +
+ render('RecordDriver/SolrDefault/recorddriver-core-title.phtml', ['driver' => $this->driver]) ?> +
+ + \ No newline at end of file