implement MailApi for generating mail content
This commit is contained in:
parent
5d0d90c373
commit
c93d8ad779
4 changed files with 210 additions and 1 deletions
127
app/apis/MailApi.inc
Normal file
127
app/apis/MailApi.inc
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\apis;
|
||||
|
||||
|
||||
/**
|
||||
* MailApi-implementation.
|
||||
*
|
||||
* This class runs and renders e‑mail text and subject.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MailApi extends \nre\core\Api
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MailApi.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
new \hhu\z\requests\MailRequest(),
|
||||
new \hhu\z\responses\MailResponse()
|
||||
);
|
||||
|
||||
// Set ToplevelAgent
|
||||
$this->response->addParam(\nre\configs\AppConfig::$defaults['toplevel-mail']);
|
||||
$this->response->addParam(\nre\configs\AppConfig::$defaults['intermediate-mail']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Use a ToplevelAgent for HTML-mail
|
||||
*/
|
||||
public function setHTML()
|
||||
{
|
||||
$this->response->clearParams();
|
||||
$this->response->addParam(\nre\configs\AppConfig::$defaults['toplevel-htmlmail']);
|
||||
$this->response->addParam(\nre\configs\AppConfig::$defaults['intermediate-mail']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Action for the message to render.
|
||||
*/
|
||||
public function setMessage($messageAgent)
|
||||
{
|
||||
$this->response->clearParams(2);
|
||||
$this->response->addParam($messageAgent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set additional params to pass to the Action.
|
||||
*
|
||||
* @param array $params Additional params to set
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->response->addParams($params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the subject set by the Controller.
|
||||
*
|
||||
* @return string Subject set by Controller
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->response->getSubject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run mailtext generation.
|
||||
*
|
||||
* This method runs the generation of mailtext.
|
||||
*
|
||||
* @return Exception Occured exception or null
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
$exception = parent::run();
|
||||
|
||||
|
||||
return $exception;
|
||||
}
|
||||
catch(\nre\Exception $e) {
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render output.
|
||||
*
|
||||
* @return string Rendered output
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// Generate output
|
||||
parent::render();
|
||||
|
||||
|
||||
// Return output
|
||||
return $this->response->getOutput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
24
app/requests/MailRequest.inc
Normal file
24
app/requests/MailRequest.inc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\requests;
|
||||
|
||||
|
||||
/**
|
||||
* Representation of a mail-request.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MailRequest extends \nre\core\Request
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
55
app/responses/MailResponse.inc
Normal file
55
app/responses/MailResponse.inc
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\responses;
|
||||
|
||||
|
||||
/**
|
||||
* Representation of a mail-response.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MailResponse extends \nre\core\Response
|
||||
{
|
||||
/**
|
||||
* Mail subject
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $subject = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set subject.
|
||||
*
|
||||
* @param string $subject Subject to set
|
||||
*/
|
||||
public function setSubject($subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get subject.
|
||||
*
|
||||
* @return string Subject
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
'genericname' => 'The Legend of Z',
|
||||
'namespace' => 'hhu\\z\\',
|
||||
'timeZone' => 'Europe/Berlin',
|
||||
'mailsender' => 'noreply@zyren.inf-d.de'
|
||||
'mailsender' => 'questlab@hhu.de'
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -47,8 +47,11 @@
|
|||
public static $defaults = array(
|
||||
'toplevel' => 'html',
|
||||
'toplevel-error' => 'fault',
|
||||
'toplevel-mail' => 'textmail',
|
||||
'toplevel-htmlmail' => 'htmlmail',
|
||||
'intermediate' => 'introduction',
|
||||
'intermediate-error' => 'error',
|
||||
'intermediate-mail' => 'mail',
|
||||
'language' => 'de_DE.utf8',
|
||||
'locale' => 'de-DE'
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue