WIP : Upload management
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
|
||||
<form name="thelia.admin.category.creation" class="Thelia\Form\CategoryCreationForm"/>
|
||||
<form name="thelia.admin.category.modification" class="Thelia\Form\CategoryModificationForm"/>
|
||||
<form name="thelia.admin.category.picture.creation" class="Thelia\Form\CategoryPictureCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.product.creation" class="Thelia\Form\ProductCreationForm"/>
|
||||
<form name="thelia.admin.product.modification" class="Thelia\Form\ProductModificationForm"/>
|
||||
|
||||
@@ -100,6 +100,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::addRelatedContentAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.related-content.add" path="/admin/categories/related-picture/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::addRelatedPictureAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.related-content.delete" path="/admin/categories/related-content/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::deleteRelatedContentAction</default>
|
||||
</route>
|
||||
|
||||
@@ -27,6 +27,7 @@ use Thelia\Core\Event\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\CategoryCreateEvent;
|
||||
use Thelia\Form\CategoryPictureCreationForm;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Form\CategoryModificationForm;
|
||||
use Thelia\Form\CategoryCreationForm;
|
||||
@@ -306,6 +307,39 @@ class CategoryController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category pictures
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addRelatedPictureAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// $content_id = intval($this->getRequest()->get('content_id'));
|
||||
//
|
||||
// if ($content_id > 0) {
|
||||
//
|
||||
// $event = new CategoryAddContentEvent(
|
||||
// $this->getExistingObject(),
|
||||
// $content_id
|
||||
// );
|
||||
//
|
||||
// try {
|
||||
// $this->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $event);
|
||||
// }
|
||||
// catch (\Exception $ex) {
|
||||
// // Any error
|
||||
// return $this->errorPage($ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteRelatedContentAction() {
|
||||
|
||||
// Check current user authorization
|
||||
@@ -331,4 +365,30 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove
|
||||
* @return Symfony\Component\HttpFoundation\Response|void
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
var_dump('updateAction');
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
var_dump('getRequest', $this->getRequest()->files);
|
||||
// Create the form from the request
|
||||
$creationForm = new CategoryPictureCreationForm($this->getRequest());
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($creationForm, 'POST');
|
||||
var_dump('$form', $form);
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
var_dump('$data', $data);
|
||||
}
|
||||
|
||||
|
||||
return parent::updateAction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
100
core/lib/Thelia/Form/CategoryPictureCreationForm.php
Normal file
100
core/lib/Thelia/Form/CategoryPictureCreationForm.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Image;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class CategoryPictureCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
// ->add('alt')
|
||||
->add('file', 'file', array(
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
new Image(
|
||||
array(
|
||||
'minWidth' => 200,
|
||||
'maxWidth' => 400,
|
||||
'minHeight' => 200,
|
||||
'maxHeight' => 400,
|
||||
)
|
||||
)
|
||||
)))
|
||||
// ->add('category_id', 'model', array(
|
||||
// 'disabled' => false,
|
||||
// 'class' => 'Thelia\Model\ProductImage'
|
||||
// ))
|
||||
// ->add('position', 'integer', array(
|
||||
// 'constraints' => array(
|
||||
// new NotBlank()
|
||||
// )
|
||||
// ))
|
||||
->add('title', 'text', array(
|
||||
'constraints' => array(
|
||||
// new NotBlank()
|
||||
),
|
||||
// 'label' => Translator::getInstance()->trans('Category picture title *'),
|
||||
// 'label_attr' => array(
|
||||
// 'for' => 'title'
|
||||
// )
|
||||
))
|
||||
// ->add('description', 'text', array(
|
||||
// 'constraints' => array(
|
||||
// new NotBlank()
|
||||
// ),
|
||||
// 'label' => Translator::getInstance()->trans('Category picture description *'),
|
||||
// 'label_attr' => array(
|
||||
// 'for' => 'description'
|
||||
// )
|
||||
// ))
|
||||
// ->add('chapo', 'text', array(
|
||||
// 'constraints' => array(
|
||||
// new NotBlank()
|
||||
// ),
|
||||
// 'label' => Translator::getInstance()->trans('Category picture chapo *'),
|
||||
// 'label_attr' => array(
|
||||
// 'for' => 'chapo'
|
||||
// )
|
||||
// ))
|
||||
// ->add('postscriptum', 'text', array(
|
||||
// 'constraints' => array(
|
||||
// new NotBlank()
|
||||
// ),
|
||||
// 'label' => Translator::getInstance()->trans('Category picture postscriptum *'),
|
||||
// 'label_attr' => array(
|
||||
// 'for' => 'postscriptum'
|
||||
// )
|
||||
// ))
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_category_picture_creation';
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,48 @@ class CategoryImage extends BaseCategoryImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get picture absolute path
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getAbsolutePath()
|
||||
{
|
||||
return null === $this->file
|
||||
? null
|
||||
: $this->getUploadRootDir().'/'.$this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get picture web path
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getWebPath()
|
||||
{
|
||||
return null === $this->file
|
||||
? null
|
||||
: $this->getUploadDir().'/'.$this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* The absolute directory path where uploaded
|
||||
* documents should be saved
|
||||
* @return string
|
||||
*/
|
||||
protected function getUploadRootDir()
|
||||
{
|
||||
return __DIR__.'/../../../../../'.$this->getUploadDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rid of the __DIR__ so it doesn't screw up
|
||||
* when displaying uploaded doc/image in the view.
|
||||
* @return string
|
||||
*/
|
||||
protected function getUploadDir()
|
||||
{
|
||||
return 'local/media/images/category';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user