Merge branch 'content'

This commit is contained in:
Manuel Raynaud
2013-09-23 23:35:05 +02:00
10 changed files with 248 additions and 6 deletions

View File

@@ -24,8 +24,11 @@
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Content\ContentCreateEvent;
use Thelia\Core\Event\Content\ContentDeleteEvent;
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
use Thelia\Core\Event\Content\ContentUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\ContentQuery;
use Thelia\Model\Content as ContentModel;
use Thelia\Model\FolderQuery;
@@ -77,6 +80,51 @@ class Content extends BaseAction implements EventSubscriberInterface
}
}
public function updatePosition(UpdatePositionEvent $event)
{
if(null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
$content->setDispatcher($this->getDispatcher());
switch($event->getMode())
{
case UpdatePositionEvent::POSITION_ABSOLUTE:
$content->changeAbsolutePosition($event->getPosition());
break;
case UpdatePositionEvent::POSITION_DOWN:
$content->movePositionDown();
break;
case UpdatePositionEvent::POSITION_UP:
$content->movePositionUp();
break;
}
}
}
public function toggleVisibility(ContentToggleVisibilityEvent $event)
{
$content = $event->getContent();
$content
->setDispatcher($this->getDispatcher())
->setVisible(!$content->getVisible())
->save();
}
public function delete(ContentDeleteEvent $event)
{
if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) {
$defaultFolderId = $content->getDefaultFolderId();
$content->setDispatcher($this->getDispatcher())
->delete();
$event->setDefaultFolderId($defaultFolderId);
$event->setContent($content);
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*

View File

@@ -235,6 +235,18 @@
<default key="_controller">Thelia\Controller\Admin\ContentController::processUpdateAction</default>
</route>
<route id="admin.content.update-position" path="/admin/content/update-position">
<default key="_controller">Thelia\Controller\Admin\ContentController::updatePositionAction</default>
</route>
<route id="admin.content.toggle-online" path="/admin/content/toggle-online">
<default key="_controller">Thelia\Controller\Admin\ContentController::setToggleVisibilityAction</default>
</route>
<route id="admin.content.delete" path="/admin/content/delete">
<default key="_controller">Thelia\Controller\Admin\ContentController::deleteAction</default>
</route>
<!-- Route to the Coupon controller (process Coupon browsing) -->

View File

@@ -23,8 +23,11 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\Content\ContentCreateEvent;
use Thelia\Core\Event\Content\ContentDeleteEvent;
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
use Thelia\Core\Event\Content\ContentUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Form\ContentCreationForm;
use Thelia\Form\ContentModificationForm;
use Thelia\Model\ContentQuery;
@@ -143,7 +146,7 @@ class ContentController extends AbstractCrudController
*/
protected function getDeleteEvent()
{
// TODO: Implement getDeleteEvent() method.
return new ContentDeleteEvent($this->getRequest()->get('content_id'));
}
/**
@@ -286,4 +289,59 @@ class ContentController extends AbstractCrudController
);
}
}
/**
* Put in this method post object delete processing if required.
*
* @param \Thelia\Core\Event\Content\ContentDeleteEvent $deleteEvent the delete event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalDeleteAction($deleteEvent)
{
// Redirect to parent category list
$this->redirectToRoute(
'admin.folders.default',
array('parent' => $deleteEvent->getDefaultFolderId())
);
}
/**
* @param $event \Thelia\Core\Event\UpdatePositionEvent
* @return null|Response
*/
protected function performAdditionalUpdatePositionAction($event)
{
if (null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
// Redirect to parent category list
$this->redirectToRoute(
'admin.folders.default',
array('parent' => $content->getDefaultFolderId())
);
}
return null;
}
/**
* @param $positionChangeMode
* @param $positionValue
* @return UpdatePositionEvent|void
*/
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
{
return new UpdatePositionEvent(
$this->getRequest()->get('content_id', null),
$positionChangeMode,
$positionValue
);
}
/**
* @return ContentToggleVisibilityEvent|void
*/
protected function createToggleVisibilityEvent()
{
return new ContentToggleVisibilityEvent($this->getExistingObject());
}
}

View File

@@ -0,0 +1,74 @@
<?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\Core\Event\Content;
/**
* Class ContentDeleteEvent
* @package Thelia\Core\Event\Content
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class ContentDeleteEvent extends ContentEvent
{
protected $content_id;
protected $folder_id;
function __construct($content_id)
{
$this->content_id = $content_id;
}
/**
* @param mixed $content_id
*
* @return $this
*/
public function setContentId($content_id)
{
$this->content_id = $content_id;
return $this;
}
/**
* @return mixed
*/
public function getContentId()
{
return $this->content_id;
}
public function setDefaultFolderId($folderid)
{
$this->folder_id = $folderid;
}
public function getDefaultFolderId()
{
return $this->folder_id;
}
}

View File

@@ -0,0 +1,35 @@
<?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\Core\Event\Content;
/**
* Class ContentToggleVisibilityEvent
* @package Thelia\Core\Event\Content
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class ContentToggleVisibilityEvent extends ContentEvent
{
}

View File

@@ -236,6 +236,7 @@ class Content extends BaseI18nLoop
->set("POSITION", $content->getPosition())
->set("DEFAULT_FOLDER", $content->getDefaultFolderId())
->set("URL", $content->getUrl($locale))
->set("VISIBLE", $content->getVisible())
;
$loopResult->addRow($loopResultRow);