Completed mailing templates management
This commit is contained in:
125
core/lib/Thelia/Action/Message.php
Normal file
125
core/lib/Thelia/Action/Message.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program 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 */
|
||||
/* */
|
||||
/* 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, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Thelia\Model\MessageQuery;
|
||||
use Thelia\Model\Message as MessageModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\MessageChangeEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
|
||||
class Message extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a new messageuration entry
|
||||
*
|
||||
* @param MessageCreateEvent $event
|
||||
*/
|
||||
public function create(MessageCreateEvent $event)
|
||||
{
|
||||
$message = new MessageModel();
|
||||
|
||||
$message
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setName($event->getMessageName())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
->setTitle($event->getTitle())
|
||||
|
||||
->setSecured($event->getSecured())
|
||||
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setMessage($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a message
|
||||
*
|
||||
* @param MessageChangeEvent $event
|
||||
*/
|
||||
public function modify(MessageChangeEvent $event)
|
||||
{
|
||||
$search = MessageQuery::create();
|
||||
|
||||
if (null !== $message = MessageQuery::create()->findOneById($event->getMessageId())) {
|
||||
|
||||
$message
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setName($event->getMessageName())
|
||||
->setSecured($event->getSecured())
|
||||
|
||||
->setLocale($event->getLocale())
|
||||
|
||||
->setTitle($event->getTitle())
|
||||
->setSubject($event->getSubject())
|
||||
->setHtmlMessage($event->getHtmlMessage())
|
||||
->setTextMessage($event->getTextMessage())
|
||||
|
||||
->save();
|
||||
|
||||
$event->setMessage($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a messageuration entry
|
||||
*
|
||||
* @param MessageDeleteEvent $event
|
||||
*/
|
||||
public function delete(MessageDeleteEvent $event)
|
||||
{
|
||||
|
||||
if (null !== ($message = MessageQuery::create()->findOneById($event->getMessageId()))) {
|
||||
|
||||
$message
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->delete()
|
||||
;
|
||||
|
||||
$event->setMessage($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::MESSAGE_CREATE => array("create", 128),
|
||||
TheliaEvents::MESSAGE_MODIFY => array("modify", 128),
|
||||
TheliaEvents::MESSAGE_DELETE => array("delete", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user