implement MailApi for generating mail content

This commit is contained in:
coderkun 2014-05-25 10:16:49 +02:00
commit e89c3ad550
4 changed files with 210 additions and 1 deletions

127
app/apis/MailApi.inc Normal file
View 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 email 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();
}
}
?>

View 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
{
}
?>

View 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;
}
}
?>

View file

@ -34,7 +34,7 @@
'genericname' => 'The Legend of Z', 'genericname' => 'The Legend of Z',
'namespace' => 'hhu\\z\\', 'namespace' => 'hhu\\z\\',
'timeZone' => 'Europe/Berlin', 'timeZone' => 'Europe/Berlin',
'mailsender' => 'noreply@zyren.inf-d.de' 'mailsender' => 'questlab@hhu.de'
); );
@ -47,8 +47,11 @@
public static $defaults = array( public static $defaults = array(
'toplevel' => 'html', 'toplevel' => 'html',
'toplevel-error' => 'fault', 'toplevel-error' => 'fault',
'toplevel-mail' => 'textmail',
'toplevel-htmlmail' => 'htmlmail',
'intermediate' => 'introduction', 'intermediate' => 'introduction',
'intermediate-error' => 'error', 'intermediate-error' => 'error',
'intermediate-mail' => 'mail',
'language' => 'de_DE.utf8', 'language' => 'de_DE.utf8',
'locale' => 'de-DE' 'locale' => 'de-DE'
); );