Skip to content

Commit a4c5f04

Browse files
authored
Merge pull request #100 from beluga-core/develop-5
Develop 5
2 parents 3e51df9 + 510db1e commit a4c5f04

File tree

7 files changed

+309
-0
lines changed

7 files changed

+309
-0
lines changed

module/ResultFeedback/Module.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Template for ZF2 module for storing local overrides.
4+
*
5+
* PHP version 5
6+
*
7+
* Copyright (C) Villanova University 2010.
8+
*
9+
* This program is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License version 2,
11+
* as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
*
22+
* @category VuFind2
23+
* @package Module
24+
* @author Demian Katz <[email protected]>
25+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
26+
* @link https://github.com/dmj/vf2-proxy
27+
*/
28+
namespace ResultFeedback;
29+
use Zend\ModuleManager\ModuleManager,
30+
Zend\Mvc\MvcEvent;
31+
32+
/**
33+
* Template for ZF2 module for storing local overrides.
34+
*
35+
* @category VuFind2
36+
* @package Module
37+
* @author Demian Katz <[email protected]>
38+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39+
* @link https://github.com/dmj/vf2-proxy
40+
*/
41+
class Module
42+
{
43+
/**
44+
* Get module configuration
45+
*
46+
* @return array
47+
*/
48+
public function getConfig()
49+
{
50+
return include __DIR__ . '/config/module.config.php';
51+
}
52+
53+
/**
54+
* Get autoloader configuration
55+
*
56+
* @return array
57+
*/
58+
public function getAutoloaderConfig()
59+
{
60+
return array(
61+
'Zend\Loader\StandardAutoloader' => array(
62+
'namespaces' => array(
63+
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
64+
),
65+
),
66+
);
67+
}
68+
69+
/**
70+
* Initialize the module
71+
*
72+
* @param ModuleManager $m Module manager
73+
*
74+
* @return void
75+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
76+
*/
77+
public function init(ModuleManager $m)
78+
{
79+
}
80+
81+
/**
82+
* Bootstrap the module
83+
*
84+
* @param MvcEvent $e Event
85+
*
86+
* @return void
87+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
88+
*/
89+
public function onBootstrap(MvcEvent $e)
90+
{
91+
}
92+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace ResultFeedback\Module\Configuration;
3+
4+
$config = [
5+
'controllers' => [
6+
'factories' => [
7+
'ResultFeedback\Controller\ResultFeedbackController' => 'VuFind\Controller\AbstractBaseFactory',
8+
],
9+
'aliases' => [
10+
'ResultFeedback' => 'ResultFeedback\Controller\ResultFeedbackController',
11+
'resultfeedback' => 'ResultFeedback\Controller\ResultFeedbackController',
12+
],
13+
],
14+
];
15+
16+
$staticRoutes = [
17+
'ResultFeedback/Email', 'ResultFeedback/Home'
18+
];
19+
20+
$routeGenerator = new \VuFind\Route\RouteGenerator();
21+
$routeGenerator->addRecordRoutes($config, $recordRoutes);
22+
$routeGenerator->addDynamicRoutes($config, $dynamicRoutes);
23+
$routeGenerator->addStaticRoutes($config, $staticRoutes);
24+
25+
// Add the home route last
26+
$config['router']['routes']['home'] = [
27+
'type' => 'Zend\Router\Http\Literal',
28+
'options' => [
29+
'route' => '/',
30+
'defaults' => [
31+
'controller' => 'index',
32+
'action' => 'Home',
33+
]
34+
]
35+
];
36+
37+
return $config;
38+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Feedback Controller
4+
*
5+
* PHP version 7
6+
*
7+
* @category VuFind
8+
* @package Controller
9+
* @author Johannes Schultze <[email protected]>
10+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
11+
* @link https://vufind.org Main Site
12+
*/
13+
namespace ResultFeedback\Controller;
14+
15+
use VuFind\Exception\Mail as MailException;
16+
use Zend\Mail\Address;
17+
18+
/**
19+
* Feedback Class
20+
*
21+
* Controls the Feedback
22+
*
23+
* @category VuFind
24+
* @package Controller
25+
* @author Johannes Schultze <[email protected]>
26+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27+
* @link https://vufind.org/wiki/development Wiki
28+
*/
29+
class ResultFeedbackController extends \VuFind\Controller\AbstractBase
30+
{
31+
/**
32+
* Display Feedback home form.
33+
*
34+
* @return \Zend\View\Model\ViewModel
35+
*/
36+
public function homeAction()
37+
{
38+
return $this->forwardTo('ResultFeedback', 'Email');
39+
}
40+
41+
/**
42+
* Receives input from the user and sends an email to the recipient set in
43+
* the resultFeedback.ini
44+
*
45+
* @return void
46+
*/
47+
public function emailAction()
48+
{
49+
$translator = $this->serviceLocator->get('Zend\Mvc\I18n\Translator');
50+
51+
$view = $this->createViewModel();
52+
$view->useRecaptcha = $this->recaptcha()->active('feedback');
53+
$view->name = $this->params()->fromPost('name');
54+
$view->email = $this->params()->fromPost('email');
55+
$view->comments = $this->params()->fromPost('comments');
56+
$view->usertype = $this->params()->fromPost('usertype');
57+
$view->recordid = $this->params()->fromPost('recordid');
58+
$view->recordtitle = $this->params()->fromPost('recordtitle');
59+
60+
$id = $this->params()->fromRoute('id', $this->params()->fromQuery('id'));
61+
$view->id = $id;
62+
$searchClassId = $this->params()->fromRoute('searchclassid', $this->params()->fromQuery('searchclassid'));
63+
$view->searchClassId = $searchClassId;
64+
$recordLoader = $this->serviceLocator->get('VuFind\Record\Loader');;
65+
$driver = $recordLoader->load($id, $searchClassId, false);
66+
$view->driver = $driver;
67+
68+
$resultFeedbackConfig = $this->serviceLocator->get('VuFind\Config\PluginManager')->get('resultFeedback')->toArray();
69+
$resultUserTypes = [];
70+
if (isset($resultFeedbackConfig['resultFeedback']['user_types'])) {
71+
$resultUserTypes = $resultFeedbackConfig['resultFeedback']['user_types'];
72+
}
73+
$view->resultUserTypes = $resultUserTypes;
74+
75+
// Process form submission:
76+
$view->hideForm = false;
77+
if ($this->formWasSubmitted('submit', $view->useRecaptcha)) {
78+
if (empty($view->email) || empty($view->comments)) {
79+
$this->flashMessenger()->addMessage('bulk_error_missing', 'error');
80+
return;
81+
}
82+
83+
$recipient_email = isset($resultFeedbackConfig['resultFeedback']['recipient_email']) ? $resultFeedbackConfig['resultFeedback']['recipient_email'] : null;
84+
$recipient_name = isset($resultFeedbackConfig['resultFeedback']['recipient_name']) ? $resultFeedbackConfig['resultFeedback']['recipient_name'] : 'Your Library';
85+
$email_subject = isset($resultFeedbackConfig['resultFeedback']['email_subject']) ? $resultFeedbackConfig['resultFeedback']['email_subject'] : 'Result Feedback';
86+
$sender_email = isset($resultFeedbackConfig['resultFeedback']['sender_email']) ? $resultFeedbackConfig['resultFeedback']['sender_email'] : '[email protected]';
87+
$sender_name = isset($resultFeedbackConfig['resultFeedback']['sender_name']) ? $resultFeedbackConfig['resultFeedback']['sender_name'] : 'Result Feedback';
88+
if ($recipient_email == null) {
89+
throw new \Exception(
90+
'Result Feedback Module Error: Recipient Email Unset (see resultFeedback.ini)'
91+
);
92+
}
93+
94+
$email_message = $translator->translate('resultfeedback_usertype') . ':' . "\n" . $translator->translate($view->usertype) . "\n\n";
95+
$email_message .= empty($view->name) ? '' : 'Name:' . "\n" . $view->name . "\n\n";
96+
$email_message .= $translator->translate('Email') . ':' . "\n" . $view->email . "\n\n";
97+
$email_message .= $translator->translate('PPN') . ':' . "\n" . $view->recordid . "\n\n";
98+
$email_message .= $translator->translate('Title') . ':' . "\n" . $view->recordtitle . "\n\n";
99+
$email_message .= $translator->translate('Message') . ':' . "\n" . $view->comments . "\n\n";
100+
101+
// This sets up the email to be sent
102+
// Attempt to send the email and show an appropriate flash message:
103+
try {
104+
$mailer = $this->serviceLocator->get('VuFind\Mailer\Mailer');
105+
$mailer->send(
106+
new Address($recipient_email, $recipient_name),
107+
new Address($sender_email, $sender_name),
108+
$email_subject,
109+
$email_message,
110+
null,
111+
$view->email
112+
);
113+
$this->flashMessenger()->addMessage(
114+
'Your result feedback has been send', 'success'
115+
);
116+
$view->hideForm = true;
117+
} catch (MailException $e) {
118+
$this->flashMessenger()->addMessage($e->getMessage(), 'error');
119+
}
120+
}
121+
122+
return $view;
123+
}
124+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.result-feedback .privacy a {
2+
text-decoration: underline;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
return [
3+
'css' => [
4+
'resultfeedback.css'
5+
],
6+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Set page title
3+
$this->headTitle($this->translate('Contact us about this title'));
4+
// Get rid of the feedback tab since this uses the same variables
5+
$this->layout()->feedbacktab = false;
6+
?>
7+
<?=$this->render('resultfeedback/form.phtml');?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><?=$this->transEsc("Contact us about this title")?></h2>
2+
<?=$this->flashmessages() ?>
3+
<?php if(!$this->hideForm): ?>
4+
<div class="resultfeedback-title">
5+
<?=$this->render('RecordDriver/SolrDefault/recorddriver-core-title.phtml', ['driver' => $this->driver]) ?>
6+
</div>
7+
<form class="form-feedback result-feedback" name="feedback" method="post" action="<?=$this->url('resultfeedback-email').'?id='.$this->id.'&searchclassid='.$this->searchClassId?>">
8+
<input type="hidden" id="recordid" name="recordid" value="<?=$this->escapeHtmlAttr($this->driver->getUniqueID() ?? '')?>" />
9+
<input type="hidden" id="recordtitle" name="recordtitle" value="<?=$this->escapeHtmlAttr($this->driver->getTitle() ?? '')?>" />
10+
<div class="form-group">
11+
<label class="control-label" for="usertype"><?=$this->transEsc("resultfeedback_usertype")?></label><br/>
12+
<select name="usertype">
13+
<?php foreach($this->resultUserTypes as $resultUserType): ?>
14+
<option value="<?=$resultUserType?>"><?=$this->transEsc($resultUserType)?></option>
15+
<?php endforeach; ?>
16+
</select>
17+
</div>
18+
<div class="form-group">
19+
<label class="control-label" for="name"><?=$this->transEsc("feedback_name")?></label>
20+
<input type="text" id="name" name="name" value="<?=$this->escapeHtmlAttr($name ?? '')?>" class="form-control"/>
21+
</div>
22+
<div class="form-group">
23+
<label class="control-label" for="email"><?=$this->transEsc("Email")?></label>
24+
<input type="email" id="email" name="email" value="<?=$this->escapeHtmlAttr($email ?? '')?>" class="form-control" required />
25+
</div>
26+
<div class="form-group">
27+
<label class="control-label" for="comments"><?=$this->transEsc("Comments")?></label>
28+
<textarea id="comments" name="comments" class="form-control" required><?=$this->escapeHtml($comments ?? '')?></textarea>
29+
</div>
30+
<div class="form-group">
31+
<input type="checkbox" name="privacy" required />
32+
<label class="control-label privacy" for="privacy"><?=$this->translate("I Accept The Privacy Policy")?></label>
33+
</div>
34+
<?=$this->recaptcha()->html($this->useRecaptcha) ?>
35+
<div class="form-group">
36+
<input type="submit" name="submit" class="btn btn-primary" value="<?=$this->transEsc("Send")?>" />
37+
</div>
38+
</form>
39+
<?php endif; ?>

0 commit comments

Comments
 (0)