Merge Master

This commit is contained in:
touffies
2013-10-07 11:50:20 +02:00
69 changed files with 1560 additions and 11105 deletions

View File

@@ -0,0 +1,306 @@
<?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\Controller\Admin;
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\Address\AddressEvent;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\AddressCreateForm;
use Thelia\Form\AddressUpdateForm;
use Thelia\Model\AddressQuery;
use Thelia\Model\CustomerQuery;
/**
* Class AddressController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AddressController extends AbstractCrudController
{
public function __construct()
{
parent::__construct(
'address',
null,
null,
'admin.customer.update.view',
'admin.address.create',
'admin.address.update',
'admin.address.delete',
TheliaEvents::ADDRESS_CREATE,
TheliaEvents::ADDRESS_UPDATE,
TheliaEvents::ADDRESS_DELETE,
null,
null
);
}
public function useAddressAction()
{
if (null !== $response = $this->checkAuth("admin.customer.update")) return $response;
$address_id = $this->getRequest()->request->get('address_id');
try {
$address = AddressQuery::create()->findPk($address_id);
if (null === $address) {
throw new \InvalidArgumentException(sprintf('%d address does not exists', $address_id));
}
$addressEvent = new AddressEvent($address);
$this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent);
$this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId()));
} catch(\Exception $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage()));
}
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
}
/**
* Return the creation form for this object
*/
protected function getCreationForm()
{
return new AddressCreateForm($this->getRequest());
}
/**
* Return the update form for this object
*/
protected function getUpdateForm()
{
return new AddressUpdateForm($this->getRequest());
}
/**
* Hydrate the update form for this object, before passing it to the update template
*
* @param \Thelia\Model\Address $object
*/
protected function hydrateObjectForm($object)
{
$data = array(
"label" => $object->getLabel(),
"title" => $object->getTitleId(),
"firstname" => $object->getFirstname(),
"lastname" => $object->getLastname(),
"address1" => $object->getAddress1(),
"address2" => $object->getAddress2(),
"address3" => $object->getAddress3(),
"zipcode" => $object->getZipcode(),
"city" => $object->getCity(),
"country" => $object->getCountryId(),
"cellphone" => $object->getCellphone(),
"phone" => $object->getPhone(),
"company" => $object->getCompany()
);
return new AddressUpdateForm($this->getRequest(), "form", $data);
}
/**
* Creates the creation event with the provided form data
*
* @param unknown $formData
*/
protected function getCreationEvent($formData)
{
$event = $this->getCreateOrUpdateEvent($formData);
$customer = CustomerQuery::create()->findPk($this->getRequest()->get("customer_id"));
$event->setCustomer($customer);
return $event;
}
/**
* Creates the update event with the provided form data
*
* @param unknown $formData
*/
protected function getUpdateEvent($formData)
{
$event = $this->getCreateOrUpdateEvent($formData);
$event->setAddress($this->getExistingObject());
return $event;
}
protected function getCreateOrUpdateEvent($formData)
{
$event = new AddressCreateOrUpdateEvent(
$formData["label"],
$formData["title"],
$formData["firstname"],
$formData["lastname"],
$formData["address1"],
$formData["address2"],
$formData["address3"],
$formData["zipcode"],
$formData["city"],
$formData["country"],
$formData["cellphone"],
$formData["phone"],
$formData["company"],
$formData["is_default"]
);
return $event;
}
/**
* Creates the delete event with the provided form data
*/
protected function getDeleteEvent()
{
return new AddressEvent($this->getExistingObject());
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*
* @param unknown $event
*/
protected function eventContainsObject($event)
{
return null !== $event->getAddress();
}
/**
* Get the created object from an event.
*
* @param unknown $createEvent
*/
protected function getObjectFromEvent($event)
{
return null;
}
/**
* Load an existing object from the database
*/
protected function getExistingObject()
{
return AddressQuery::create()->findPk($this->getRequest()->get('address_id'));
}
/**
* Returns the object label form the object event (name, title, etc.)
*
* @param unknown $object
*/
protected function getObjectLabel($object)
{
return $object->getLabel();
}
/**
* Returns the object ID from the object
*
* @param unknown $object
*/
protected function getObjectId($object)
{
return $object->getId();
}
/**
* Render the main list template
*
* @param unknown $currentOrder, if any, null otherwise.
*/
protected function renderListTemplate($currentOrder)
{
// TODO: Implement renderListTemplate() method.
}
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
return $this->render('ajax/address-update-modal', array(
"address_id" => $this->getRequest()->get('address_id'),
"customer_id" => $this->getExistingObject()->getCustomerId()
));
}
/**
* Redirect to the edition template
*/
protected function redirectToEditionTemplate()
{
$address = $this->getExistingObject();
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
}
/**
* Redirect to the list template
*/
protected function redirectToListTemplate()
{
// TODO: Implement redirectToListTemplate() method.
}
/**
* Put in this method post object delete processing if required.
*
* @param \Thelia\Core\Event\AddressEvent $deleteEvent the delete event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalDeleteAction($deleteEvent)
{
$address = $deleteEvent->getAddress();
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
}
/**
* Put in this method post object creation processing if required.
*
* @param AddressCreateOrUpdateEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
{
$this->redirectToEditionTemplate();
}
protected function performAdditionalUpdateAction($event)
{
$this->redirectToEditionTemplate();
}
}

View File

@@ -51,7 +51,7 @@ class BaseAdminController extends BaseController
/**
* Helper to append a message to the admin log.
*
* @param unknown $message
* @param string $message
*/
public function adminLogAppend($message)
{
@@ -187,12 +187,12 @@ class BaseAdminController extends BaseController
/**
* @return a ParserInterface instance parser
*/
protected function getParser()
protected function getParser($template = null)
{
$parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used
$parser->setTemplate(ConfigQuery::read('base_admin_template', 'admin/default'));
$parser->setTemplate($template ?: ConfigQuery::read('base_admin_template', 'admin/default'));
return $parser;
}
@@ -246,9 +246,9 @@ class BaseAdminController extends BaseController
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
*/
public function redirectToRoute($routeId, $urlParameters = array())
public function redirectToRoute($routeId, $urlParameters = array(), $routeParameters = array())
{
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters), $urlParameters));
}
/**
@@ -378,10 +378,12 @@ class BaseAdminController extends BaseController
* Render the given template, and returns the result as a string.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @param array $args the template arguments
* @param null $templateDir
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderRaw($templateName, $args = array())
protected function renderRaw($templateName, $args = array(), $templateDir = null)
{
// Add the template standard extension
@@ -417,7 +419,7 @@ class BaseAdminController extends BaseController
// Render the template.
try {
$data = $this->getParser()->render($templateName, $args);
$data = $this->getParser($templateDir)->render($templateName, $args);
return $data;
} catch (AuthenticationException $ex) {

View File

@@ -22,13 +22,17 @@
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Form\Form;
use Thelia\Core\Event\Address\AddressEvent;
use Thelia\Core\Event\Customer\CustomerAddressEvent;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CustomerModification;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\AddressQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator;
@@ -53,6 +57,8 @@ class CustomerController extends BaseAdminController
));
}
/**
* update customer action
*

View File

@@ -23,10 +23,13 @@
namespace Thelia\Controller\Admin;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Core\Event\Order\OrderAddressEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\PdfEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\OrderUpdateAddress;
use Thelia\Model\ConfigQuery;
use Thelia\Model\Base\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery;
@@ -193,4 +196,52 @@ class OrderController extends BaseAdminController
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
}
public function generateInvoicePdf($order_id)
{
return $this->generatePdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice'));
}
public function generateDeliveryPdf($order_id)
{
return $this->generatePdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery'));
}
protected function generatePdf($order_id, $fileName)
{
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
$html = $this->renderRaw(
$fileName,
array(
'order_id' => $order_id
),
ConfigQuery::read('pdf_template', 'pdf')
);
$order = OrderQuery::create()->findPk($order_id);
try {
$pdfEvent = new PdfEvent($html);
$this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent);
if($pdfEvent->hasPdf()) {
return Response::create($pdfEvent->getPdf(), 200,
array(
'Content-type' => "application/pdf",
'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', $order->getRef()),
));
}
} catch (\Exception $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d with message "%s"', $order_id, $e->getMessage()));
}
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", array(
'order_id' => $order_id
))));
}
}