diff --git a/app/apis/MailApi.inc b/app/apis/MailApi.inc new file mode 100644 index 00000000..ab297ab6 --- /dev/null +++ b/app/apis/MailApi.inc @@ -0,0 +1,127 @@ + + * @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 + */ + 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(); + } + + } + +?> diff --git a/app/requests/MailRequest.inc b/app/requests/MailRequest.inc new file mode 100644 index 00000000..bc910f0c --- /dev/null +++ b/app/requests/MailRequest.inc @@ -0,0 +1,24 @@ + + * @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 + */ + class MailRequest extends \nre\core\Request + { + } + +?> diff --git a/app/responses/MailResponse.inc b/app/responses/MailResponse.inc new file mode 100644 index 00000000..71ced1bc --- /dev/null +++ b/app/responses/MailResponse.inc @@ -0,0 +1,55 @@ + + * @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 + */ + 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; + } + + } + +?> diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 1a70a84e..77a1894a 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -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' );