-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from beluga-core/develop-5
Develop 5
- Loading branch information
Showing
7 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Template for ZF2 module for storing local overrides. | ||
* | ||
* PHP version 5 | ||
* | ||
* Copyright (C) Villanova University 2010. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* @category VuFind2 | ||
* @package Module | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @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 <demian.katz@villanova.edu> | ||
* @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) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace ResultFeedback\Module\Configuration; | ||
|
||
$config = [ | ||
'controllers' => [ | ||
'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; | ||
|
124 changes: 124 additions & 0 deletions
124
module/ResultFeedback/src/ResultFeedback/Controller/ResultFeedbackController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
/** | ||
* Feedback Controller | ||
* | ||
* PHP version 7 | ||
* | ||
* @category VuFind | ||
* @package Controller | ||
* @author Johannes Schultze <schultze@effective-webwork.de> | ||
* @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 <schultze@effective-webwork.de> | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.result-feedback .privacy a { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
return [ | ||
'css' => [ | ||
'resultfeedback.css' | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
// Set page title | ||
$this->headTitle($this->translate('Contact us about this title')); | ||
// Get rid of the feedback tab since this uses the same variables | ||
$this->layout()->feedbacktab = false; | ||
?> | ||
<?=$this->render('resultfeedback/form.phtml');?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<h2><?=$this->transEsc("Contact us about this title")?></h2> | ||
<?=$this->flashmessages() ?> | ||
<?php if(!$this->hideForm): ?> | ||
<div class="resultfeedback-title"> | ||
<?=$this->render('RecordDriver/SolrDefault/recorddriver-core-title.phtml', ['driver' => $this->driver]) ?> | ||
</div> | ||
<form class="form-feedback result-feedback" name="feedback" method="post" action="<?=$this->url('resultfeedback-email').'?id='.$this->id.'&searchclassid='.$this->searchClassId?>"> | ||
<input type="hidden" id="recordid" name="recordid" value="<?=$this->escapeHtmlAttr($this->driver->getUniqueID() ?? '')?>" /> | ||
<input type="hidden" id="recordtitle" name="recordtitle" value="<?=$this->escapeHtmlAttr($this->driver->getTitle() ?? '')?>" /> | ||
<div class="form-group"> | ||
<label class="control-label" for="usertype"><?=$this->transEsc("resultfeedback_usertype")?></label><br/> | ||
<select name="usertype"> | ||
<?php foreach($this->resultUserTypes as $resultUserType): ?> | ||
<option value="<?=$resultUserType?>"><?=$this->transEsc($resultUserType)?></option> | ||
<?php endforeach; ?> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="name"><?=$this->transEsc("feedback_name")?></label> | ||
<input type="text" id="name" name="name" value="<?=$this->escapeHtmlAttr($name ?? '')?>" class="form-control"/> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="email"><?=$this->transEsc("Email")?></label> | ||
<input type="email" id="email" name="email" value="<?=$this->escapeHtmlAttr($email ?? '')?>" class="form-control" required /> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="comments"><?=$this->transEsc("Comments")?></label> | ||
<textarea id="comments" name="comments" class="form-control" required><?=$this->escapeHtml($comments ?? '')?></textarea> | ||
</div> | ||
<div class="form-group"> | ||
<input type="checkbox" name="privacy" required /> | ||
<label class="control-label privacy" for="privacy"><?=$this->translate("I Accept The Privacy Policy")?></label> | ||
</div> | ||
<?=$this->recaptcha()->html($this->useRecaptcha) ?> | ||
<div class="form-group"> | ||
<input type="submit" name="submit" class="btn btn-primary" value="<?=$this->transEsc("Send")?>" /> | ||
</div> | ||
</form> | ||
<?php endif; ?> |