WIP : Upload management (upload+save+delete done) need to finish integration and add all image fields
This commit is contained in:
184
core/lib/Thelia/Core/Event/ImageCreateOrUpdateEvent.php
Executable file
184
core/lib/Thelia/Core/Event/ImageCreateOrUpdateEvent.php
Executable file
@@ -0,0 +1,184 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 9/18/13
|
||||
* Time: 3:56 PM
|
||||
*
|
||||
* Occurring when a Image list is saved
|
||||
*
|
||||
* @package Image
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ImageCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
CONST TYPE_PRODUCT = 'product';
|
||||
CONST TYPE_CATEGORY = 'category';
|
||||
CONST TYPE_CONTENT = 'content';
|
||||
CONST TYPE_FOLDER = 'folder';
|
||||
|
||||
/** @var array Images model to save */
|
||||
protected $modelImages = array();
|
||||
|
||||
/** @var array Images file to save */
|
||||
protected $uploadedFiles = array();
|
||||
|
||||
/** @var int Image parent id */
|
||||
protected $parentId = null;
|
||||
|
||||
/** @var string Image type */
|
||||
protected $imageType = null;
|
||||
|
||||
/** @var array Available image parent type */
|
||||
protected static $availableType = array(
|
||||
self::TYPE_PRODUCT,
|
||||
self::TYPE_CATEGORY,
|
||||
self::TYPE_CONTENT,
|
||||
self::TYPE_FOLDER,
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $pictureType Picture type
|
||||
* ex : ImageCreateOrUpdateEvent::TYPE_CATEGORY
|
||||
* @param int $parentId Image parent id
|
||||
*/
|
||||
public function __construct($pictureType, $parentId)
|
||||
{
|
||||
$this->imageType = $pictureType;
|
||||
$this->parentId = $parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Images to save
|
||||
*
|
||||
* @param array $images Thelia\Model\CategoryImage Array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setModelImages($images)
|
||||
{
|
||||
$this->modelImages = $images;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Images being saved
|
||||
*
|
||||
* @return array Array of Thelia\Model\CategoryImage
|
||||
*/
|
||||
public function getModelImages()
|
||||
{
|
||||
return $this->modelImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Images to save
|
||||
*
|
||||
* @param array $images Thelia\Model\CategoryImage Array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUploadedFiles($images)
|
||||
{
|
||||
$this->uploadedFiles = $images;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Images being saved
|
||||
*
|
||||
* @return array Array of Thelia\Model\CategoryImage
|
||||
*/
|
||||
public function getUploadedFiles()
|
||||
{
|
||||
return $this->uploadedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set picture type
|
||||
*
|
||||
* @param string $pictureType Picture type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImageType($pictureType)
|
||||
{
|
||||
$this->imageType = $pictureType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get picture type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImageType()
|
||||
{
|
||||
return $this->imageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all image parent type available
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableType()
|
||||
{
|
||||
return self::$availableType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image parent id
|
||||
*
|
||||
* @param int $parentId Image parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->parentId = $parentId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image parent id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->parentId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
82
core/lib/Thelia/Core/Event/ImageDeleteEvent.php
Executable file
82
core/lib/Thelia/Core/Event/ImageDeleteEvent.php
Executable file
@@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
|
||||
use Thelia\Model\CategoryImage;
|
||||
use Thelia\Model\ContentImage;
|
||||
use Thelia\Model\FolderImage;
|
||||
use Thelia\Model\ProductImage;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 9/18/13
|
||||
* Time: 3:56 PM
|
||||
*
|
||||
* Occurring when a Image is about to be deleted
|
||||
*
|
||||
* @package Image
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ImageDeleteEvent extends ActionEvent
|
||||
{
|
||||
/** @var CategoryImage|ProductImage|ContentImage|FolderImage Image about to be deleted */
|
||||
protected $imageToDelete = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CategoryImage|ProductImage|ContentImage|FolderImage $imageToDelete Image about to be deleted
|
||||
*/
|
||||
public function __construct($imageToDelete)
|
||||
{
|
||||
$this->imageToDelete = $imageToDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image about to be deleted
|
||||
*
|
||||
* @param CategoryImage|ProductImage|ContentImage|FolderImage $imageToDelete Image about to be deleted
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImageToDelete($imageToDelete)
|
||||
{
|
||||
$this->imageToDelete = $imageToDelete;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image about to be deleted
|
||||
*
|
||||
* @return CategoryImage|ProductImage|ContentImage|FolderImage
|
||||
*/
|
||||
public function getImageToDelete()
|
||||
{
|
||||
return $this->imageToDelete;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -234,6 +234,16 @@ final class TheliaEvents
|
||||
*/
|
||||
const IMAGE_CLEAR_CACHE = "action.clearImageCache";
|
||||
|
||||
/**
|
||||
* Save given images
|
||||
*/
|
||||
const IMAGE_SAVE = "action.saveImages";
|
||||
|
||||
/**
|
||||
* Delete given image
|
||||
*/
|
||||
const IMAGE_DELETE = "action.deleteImage";
|
||||
|
||||
/**
|
||||
* Sent when creating a Coupon
|
||||
*/
|
||||
|
||||
103
core/lib/Thelia/Core/Template/Smarty/Plugins/FlashMessage.php
Executable file
103
core/lib/Thelia/Core/Template/Smarty/Plugins/FlashMessage.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?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\Template\Smarty\Plugins;
|
||||
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Core\Template\Element\Exception\ElementNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 9/18/13
|
||||
* Time: 3:56 PM
|
||||
*
|
||||
* Plugin for smarty defining blocks allowing to get flash message
|
||||
* A flash message is a variable, array, object stored in session under the flashMessage key
|
||||
* ex $SESSION['flashMessage']['myKey']
|
||||
*
|
||||
* blocks :
|
||||
* - {flashMessage key="myKey"} ... {/flashMessage}
|
||||
*
|
||||
* Class Form
|
||||
*
|
||||
* @package Thelia\Core\Template\Smarty\Plugins
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*/
|
||||
class FlashMessage extends AbstractSmartyPlugin
|
||||
{
|
||||
|
||||
/** @var Request Request service */
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Request $request Request service
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FlashMessage
|
||||
* And clean session from this key
|
||||
*
|
||||
* @param array $params Block parameters
|
||||
* @param mixed $content Block content
|
||||
* @param \Smarty_Internal_Template $template Template
|
||||
* @param bool $repeat Control how many times
|
||||
* the block is displayed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFlashMessage($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
if ($repeat) {
|
||||
$key = $params['key'];
|
||||
$flashBag = $this->request->getSession()->get('flashMessage');
|
||||
$template->assign('value', $flashBag[$key]);
|
||||
|
||||
// Reset flash message (can be read once)
|
||||
unset($flashBag[$key]);
|
||||
$this->request->getSession()->set('flashMessage', $flashBag);
|
||||
} else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array an array of SmartyPluginDescriptor
|
||||
*/
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor("block", "flashMessage", $this, "getFlashMessage")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user