Skip to content
Snippets Groups Projects
Register.php 4.51 KiB
<?php

namespace SGalinski\SgMail\Example;

/***************************************************************
 *  Copyright notice
 *
 *  (c) sgalinski Internet Services (https://www.sgalinski.de)
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script 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.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

use SGalinski\SgMail\Service\RegisterInterface;

/**
 * Example Registration for a Template
 *
 * @package SGalinski\SgMail\Example
 */
class Register implements RegisterInterface {

	/**
	 * @var array
	 */
	private $markers = [];

	/**
	 * @var array
	 */
	private $subject = [];

	/**
	 * @var string
	 */
	private $description;

	/**
	 * the extension key
	 *
	 * @var string
	 */
	private $extensionKey;

	/**
	 * a unique name for this template
	 *
	 * @var string
	 */
	private $templateKey;

	/**
	 * path where the template is located
	 *
	 * @var string
	 */
	private $templatePath;

	/**
	 * initialize certain values
	 */
	public function init() {
		$templateArray = [
			'firstName' => 'Max',
			'lastName' => 'Mustermann'
		];

		$this->markers = [
			[
				'marker' => 'firstname',
				'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
				'value' => 'Max',
				'description' => 'The first name of the customer'
			],
			[
				'marker' => 'lastname',
				'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
				'value' => 'Mustermann',
				'description' => 'The last name of the customer'
			],
			[
				'marker' => 'person',
				'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_ARRAY,
				'value' => $templateArray,
				'description' => 'An array with the customer data',
				'usage' => '{person.firstName}, {person.lastName}'
			]
		];

		$this->description = 'Description about the Template';
		$this->subject = [
			'en' => 'The english subject text',
			'de' => 'The german subject text'
		];

		$this->templateKey = 'notice_mail_admin';
		$this->extensionKey = 'sg_sample';
	}

	/**
	 * Calls MailTemplateService registerTemplate with according values.
	 */
	public function registerTemplate() {
		\SGalinski\SgMail\Service\MailTemplateService::registerTemplate(
			$this->extensionKey, $this->templateKey, $this->templatePath, $this->description, $this->markers,
			$this->subject
		);
	}

	/**
	 * @return array
	 */
	public function getMarkers() {
		return $this->markers;
	}

	/**
	 * @param array $markers
	 * @return RegisterInterface
	 */
	public function setMarkers(array $markers) {
		$this->markers = $markers;
		return $this;
	}
	/**
	 * @return array
	 */
	public function getSubject() {
		return $this->subject;
	}

	/**
	 * @param array $subject
	 * @return RegisterInterface
	 */
	public function setSubject(array $subject) {
		$this->subject = $subject;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getDescription() {
		return $this->description;
	}

	/**
	 * @param string $description
	 * @return RegisterInterface
	 */
	public function setDescription($description) {
		$this->description = $description;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getExtensionKey() {
		return $this->extensionKey;
	}

	/**
	 * @param string $extensionKey
	 * @return RegisterInterface
	 */
	public function setExtensionKey($extensionKey) {
		$this->extensionKey = $extensionKey;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getTemplateKey() {
		return $this->templateKey;
	}

	/**
	 * @param string $templateKey
	 * @return RegisterInterface
	 */
	public function setTemplateKey($templateKey) {
		$this->templateKey = $templateKey;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getTemplatePath() {
		return $this->templatePath;
	}

	/**
	 * @param string $templatePath
	 * @return RegisterInterface
	 */
	public function setTemplatePath($templatePath) {
		$this->templatePath = $templatePath;
		return $this;
	}
}

?>