From f15b96383c3d88637faa81e927c69485036d3326 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 10:20:59 +0200 Subject: [PATCH 01/74] cart template --- templates/default/cart.html | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 templates/default/cart.html diff --git a/templates/default/cart.html b/templates/default/cart.html new file mode 100644 index 000000000..8ab707f7b --- /dev/null +++ b/templates/default/cart.html @@ -0,0 +1,153 @@ +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+
+ +

Your Cart

+ + + +
+ + + + + + + + + + + + + + + + + + + + {loop type="cart" name="cartloop"} + + + + + + + + + + {/loop} + + + + + + + + + +
  + + Name + + + Price + + + Qty + + + Total +
+ + {assign "cart_count" $LOOP_COUNT} + {ifloop rel='product-image'} + {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} + Product #{$cart_count} + {/loop} + {/ifloop} + {elseloop rel="product-image"} + {images file='assets/img/product/1/118x85.png'}Product #{$LOOP_COUNT}{/images} + {/elseloop} + +

+ Product #{$LOOP_COUNT} +

+
+
+
Available :
+
In Stock
+
No.
+
{$REF}
+ {*
Select Size
+
Large
+
Select Delivery Date
+
Jan 2, 2013
+
Additional Option
+
Option 1
*} +
+
+ Remove +
+
$50.00
+ instead of $59.99 +
+
+ +
+
+ $100.00 +
 Total TTC +
+ $200.00 +
+
+ + Continue Shopping + +
+ +
+ + + +
+ + +{/block} \ No newline at end of file From b6bc6994fc007254bd8a9b64456a24471244303e Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 10:53:15 +0200 Subject: [PATCH 02/74] WIP : Install wizard --- .../Controller/Install/InstallController.php | 3 ++- core/lib/Thelia/Install/CheckPermission.php | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 40e6643db..75594868a 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -42,9 +42,10 @@ class InstallController extends BaseInstallController public function checkPermission() { + var_dump('step2'); //$this->verifyStep(2); - //$permission = new CheckPermission(); + $permission = new CheckPermission(); $this->getSession()->set("step", 2); return $this->render("step-2.html"); diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index db73330cf..e57185c36 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -31,9 +31,10 @@ namespace Thelia\Install; */ class CheckPermission extends BaseInstall { - const CONF = "const"; - const LOG = "log"; - const CACHE = "cache"; + + const DIR_CONF = 'local/config'; + const DIR_LOG = 'log'; + const DIR_CACHE = 'cache'; private $directories = array(); private $validation = array(); @@ -44,22 +45,22 @@ class CheckPermission extends BaseInstall $this->directories = array( - self::CONF => THELIA_ROOT . "local/config", - self::LOG => THELIA_ROOT . "log", - self::CACHE => THELIA_ROOT . "cache" + self::DIR_CONF => THELIA_ROOT . 'local/config', + self::DIR_LOG => THELIA_ROOT . 'DIR_LOG', + self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE' ); $this->validation = array( - self::CONF => array( - "text" => sprintf("config directory(%s)...", $this->directories[self::CONF]), + self::DIR_CONF => array( + "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]), "status" => true ), - self::LOG => array( - "text" => sprintf("cache directory(%s)...", $this->directories[self::LOG]), + self::DIR_LOG => array( + "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]), "status" => true ), - self::CACHE => array( - "text" => sprintf("log directory(%s)...", $this->directories[self::CACHE]), + self::DIR_CACHE => array( + "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]), "status" => true ) ); From 2857d0621c468820e2e05fb8bfdcacd3861bf2c7 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 11:14:23 +0200 Subject: [PATCH 03/74] cart page --- core/lib/Thelia/Core/Template/Loop/Cart.php | 12 +++++++++++- core/lib/Thelia/Model/CartItem.php | 12 ++++++++++++ core/lib/Thelia/Model/Product.php | 2 +- core/lib/Thelia/Model/ProductSaleElements.php | 4 ++-- templates/default/cart.html | 16 +++++++++++----- templates/default/product.html | 4 ++-- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index f65afdf40..17437387e 100755 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -13,6 +13,7 @@ use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\CountryQuery; class Cart extends BaseLoop { @@ -82,7 +83,6 @@ class Cart extends BaseLoop foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); - //$product->setLocale($this->request->getSession()->getLocale()); $loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable); @@ -92,6 +92,16 @@ class Cart extends BaseLoop $loopResultRow->set("QUANTITY", $cartItem->getQuantity()); $loopResultRow->set("PRICE", $cartItem->getPrice()); $loopResultRow->set("PRODUCT_ID", $product->getId()); + $loopResultRow->set("PRODUCT_URL", $product->getUrl($this->request->getSession()->getLang()->getLocale())) + ->set("PRICE", $cartItem->getPrice()) + ->set("PROMO_PRICE", $cartItem->getPromoPrice()) + ->set("TAXED_PRICE", $cartItem->getTaxedPrice( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + )) + ->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + )) + ->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0); $result->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index 5ef6048a5..f6a34011d 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -8,6 +8,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\CartItem as BaseCartItem; use Thelia\Model\ConfigQuery; use Thelia\Core\Event\CartEvent; +use Thelia\TaxEngine\Calculator; class CartItem extends BaseCartItem { @@ -64,4 +65,15 @@ class CartItem extends BaseCartItem return $this; } + public function getTaxedPrice(Country $country) + { + $taxCalculator = new Calculator(); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()), 2); + } + + public function getTaxedPromoPrice(Country $country) + { + $taxCalculator = new Calculator(); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()), 2); + } } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 06c4640d0..28951fb44 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -28,6 +28,6 @@ class Product extends BaseProduct public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()); + return round($taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()), 2); } } diff --git a/core/lib/Thelia/Model/ProductSaleElements.php b/core/lib/Thelia/Model/ProductSaleElements.php index 184e37d0a..6a95c37f3 100755 --- a/core/lib/Thelia/Model/ProductSaleElements.php +++ b/core/lib/Thelia/Model/ProductSaleElements.php @@ -32,12 +32,12 @@ class ProductSaleElements extends BaseProductSaleElements public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()), 2); } public function getTaxedPromoPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()), 2); } } diff --git a/templates/default/cart.html b/templates/default/cart.html index 8ab707f7b..e3107b34e 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -88,11 +88,17 @@
Option 1
*} - Remove + Remove -
$50.00
- instead of $59.99 + {if $IS_PROMO == 1} + {assign "real_price" $PROMO_TAXED_PRICE} +
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
+ instead of {currency attr="symbol"} {$TAXED_PRICE} + {else} + {assign "real_price" $TAXED_PRICE} +
{currency attr="symbol"} {$TAXED_PRICE}
+ {/if}
@@ -100,7 +106,7 @@
- $100.00 + {currency attr="symbol"} {$real_price * $QUANTITY} @@ -120,7 +126,7 @@ - Continue Shopping + Continue Shopping diff --git a/templates/default/product.html b/templates/default/product.html index 7c62eb740..f2b58d4ba 100644 --- a/templates/default/product.html +++ b/templates/default/product.html @@ -94,13 +94,13 @@ online_only : http://schema.org/OnlineOnly --> {if $IS_PROMO } - {loop name="productSaleElements_promo" type="product_sale_elements" product="{$ID}" limit="1"} + {loop name="productSaleElements_promo" type="product_sale_elements" product="{$ID}" limit="1" order="min_price"} {assign var="default_product_sale_elements" value="$ID"} {intl l="Special Price:"} {format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"} {intl l="Regular Price:"} {format_number number="{$TAXED_PRICE}"} {currency attr="symbol"} {/loop} {else} - {intl l="Special Price:"} {format_number number="{$BEST_TAXED_PRICE}"} {currency attr="symbol"} + {intl l="Special Price:"} {format_number number="{$TAXED_PRICE}"} {currency attr="symbol"} {/if} From e0a48df23eb860d38a477df68e0967627106ec9e Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 13:15:35 +0200 Subject: [PATCH 04/74] cart integration --- .../Thelia/Config/Resources/routing/front.xml | 6 + core/lib/Thelia/Core/Template/Loop/Cart.php | 2 + .../Smarty/Plugins/DataAccessFunctions.php | 10 +- core/lib/Thelia/Model/Cart.php | 25 +- core/lib/Thelia/Model/CartItem.php | 5 + templates/default/cart.html | 221 ++++++++++-------- templates/default/cart_billing.html | 141 +++++++++++ 7 files changed, 304 insertions(+), 106 deletions(-) create mode 100644 templates/default/cart_billing.html diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index adbb7d529..cea964153 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -97,6 +97,12 @@ Thelia\Controller\Front\DefaultController::noAction cart + + + Thelia\Controller\Front\DefaultController::noAction + cart_billing + + Thelia\Controller\Front\CartController::addItem diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index 17437387e..3c8724d68 100755 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -83,6 +83,7 @@ class Cart extends BaseLoop foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); + $productSaleElement = $cartItem->getProductSaleElements(); $loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable); @@ -93,6 +94,7 @@ class Cart extends BaseLoop $loopResultRow->set("PRICE", $cartItem->getPrice()); $loopResultRow->set("PRODUCT_ID", $product->getId()); $loopResultRow->set("PRODUCT_URL", $product->getUrl($this->request->getSession()->getLang()->getLocale())) + ->set("STOCK", $productSaleElement->getQuantity()) ->set("PRICE", $cartItem->getPrice()) ->set("PROMO_PRICE", $cartItem->getPromoPrice()) ->set("TAXED_PRICE", $cartItem->getTaxedPrice( diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 802dfcff2..cc99bfe50 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -31,6 +31,7 @@ use Thelia\Core\Template\ParserContext; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Model\CategoryQuery; use Thelia\Model\ContentQuery; +use Thelia\Model\CountryQuery; use Thelia\Model\CurrencyQuery; use Thelia\Model\FolderQuery; use Thelia\Model\Product; @@ -160,9 +161,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin $result = ""; switch($params["attr"]) { case "count_item": - $result = $cart->getCartItems()->count(); break; + case "total_price": + $result = $cart->getTotalAmount(); + break; + case "total_taxed_price": + $result = $cart->getTaxedAmount( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + ); + break; } return $result; diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index dcb65f88e..78e19daa4 100755 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -8,6 +8,7 @@ use Thelia\Model\Base\Cart as BaseCart; use Thelia\Model\ProductSaleElementsQuery; use Thelia\Model\ProductPriceQuery; use Thelia\Model\CartItemQuery; +use Thelia\TaxEngine\Calculator; class Cart extends BaseCart { @@ -72,9 +73,25 @@ class Cart extends BaseCart ; } - public function getTaxedAmount() + public function getTaxedAmount(Country $country) { + $taxCalculator = new Calculator(); + $total = 0; + + foreach($this->getCartItems() as $cartItem) { + $subtotal = $cartItem->getRealPrice(); + $subtotal -= $cartItem->getDiscount(); + /* we round it for the unit price, before the quantity factor */ + $subtotal = round($taxCalculator->load($cartItem->getProduct(), $country)->getTaxedPrice($subtotal), 2); + $subtotal *= $cartItem->getQuantity(); + + $total += $subtotal; + } + + $total -= $this->getDiscount(); + + return $total; } public function getTotalAmount() @@ -82,7 +99,11 @@ class Cart extends BaseCart $total = 0; foreach($this->getCartItems() as $cartItem) { - $total += $cartItem->getPrice()-$cartItem->getDiscount(); + $subtotal = $cartItem->getRealPrice(); + $subtotal -= $cartItem->getDiscount(); + $subtotal *= $cartItem->getQuantity(); + + $total += $subtotal; } $total -= $this->getDiscount(); diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index f6a34011d..a1fb3601a 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -65,6 +65,11 @@ class CartItem extends BaseCartItem return $this; } + public function getRealPrice() + { + return $this->getPromo() == 1 ? $this->getPromoPrice() : $this->getPrice(); + } + public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); diff --git a/templates/default/cart.html b/templates/default/cart.html index e3107b34e..6f91d8581 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -4,7 +4,7 @@ @@ -23,112 +23,117 @@ 4 Secure payment -
- - - - - - - - - - - - - - - - - - +
  - - Name - - - Price - - - Qty - - - Total -
+ + + + + + + + + + + + + + + + + - {loop type="cart" name="cartloop"} + {loop type="cart" name="cartloop"} - - - - - - - + + + + + + + - {/loop} + {/loop} - - - - - - - - -
  + + Name + + + Price + + + Qty + + + Total +
- - {assign "cart_count" $LOOP_COUNT} - {ifloop rel='product-image'} - {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} - Product #{$cart_count} - {/loop} - {/ifloop} - {elseloop rel="product-image"} - {images file='assets/img/product/1/118x85.png'}Product #{$LOOP_COUNT}{/images} - {/elseloop} - -

- Product #{$LOOP_COUNT} -

-
-
-
Available :
-
In Stock
-
No.
-
{$REF}
- {*
Select Size
-
Large
-
Select Delivery Date
-
Jan 2, 2013
-
Additional Option
-
Option 1
*} -
-
- Remove -
- {if $IS_PROMO == 1} - {assign "real_price" $PROMO_TAXED_PRICE} -
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
- instead of {currency attr="symbol"} {$TAXED_PRICE} - {else} - {assign "real_price" $TAXED_PRICE} -
{currency attr="symbol"} {$TAXED_PRICE}
- {/if} -
-
- -
-
- {currency attr="symbol"} {$real_price * $QUANTITY} -
+ + {assign "cart_count" $LOOP_COUNT} + {ifloop rel='product-image'} + {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} + Product #{$cart_count} + {/loop} + {/ifloop} + {elseloop rel="product-image"} + {images file='assets/img/product/1/118x85.png'}Product #{$cart_count}{/images} + {/elseloop} + +

+ Product #{$LOOP_COUNT} +

+
+
+
Available :
+
In Stock
+
No.
+
{$REF}
+ {*
Select Size
+
Large
+
Select Delivery Date
+
Jan 2, 2013
+
Additional Option
+
Option 1
*} +
+
+ Remove +
+ {if $IS_PROMO == 1} + {assign "real_price" $PROMO_TAXED_PRICE} +
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
+ instead of {currency attr="symbol"} {$TAXED_PRICE} + {else} + {assign "real_price" $TAXED_PRICE} +
{currency attr="symbol"} {$TAXED_PRICE}
+ {/if} +
+
+ + + + +
+
+ {currency attr="symbol"} {$real_price * $QUANTITY} +
 Total TTC -
- $200.00 -
-
+ + + +   + Total TTC + +
+ {currency attr="symbol"} {cart attr="total_taxed_price"} +
+ + + + - Continue Shopping - - + Continue Shopping + Proceed checkout @@ -154,6 +159,16 @@ +{/block} - +{block name="javascript-initialization"} + {/block} \ No newline at end of file diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html new file mode 100644 index 000000000..d44753e48 --- /dev/null +++ b/templates/default/cart_billing.html @@ -0,0 +1,141 @@ +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+
+ +

Your Cart

+ + + +
+
+
+ Add a new address + Chose your delivery address +
+
+ + + + {loop type="address" name="customer.addresses" customer="current"} + + + + + + + + {/loop} + + + +
+
+ +
+
Choose your delivery method
+
+
+ +
+
+ +
+
+
+ + Back + + +
+
+
+ + + +{/block} + +{block name="javascript-initialization"} + +{/block} \ No newline at end of file From c7b3aea7f08f6a0442ce0b0a8686e043e3121932 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 14:31:34 +0200 Subject: [PATCH 05/74] cart integration --- core/lib/Thelia/Core/Template/Element/LoopResult.php | 2 +- core/lib/Thelia/Core/Template/Loop/Feed.php | 11 ++++++++--- core/lib/Thelia/Module/DeliveryModuleInterface.php | 7 +++++-- local/modules/Colissimo/Colissimo.php | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php index f86ab203d..45b690fc0 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResult.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -37,7 +37,7 @@ class LoopResult implements \Iterator public function __construct($modelCollection = null) { $this->position = 0; - if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager) { + if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager || is_array($modelCollection)) { $this->modelCollection = $modelCollection; } } diff --git a/core/lib/Thelia/Core/Template/Loop/Feed.php b/core/lib/Thelia/Core/Template/Loop/Feed.php index 8e155a666..a40f84647 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feed.php +++ b/core/lib/Thelia/Core/Template/Loop/Feed.php @@ -73,9 +73,14 @@ class Feed extends BaseLoop $limit = min(count($items), $this->getLimit()); - $loopResult = new LoopResult(); - + $indexes = array(); for ($idx = 0; $idx < $limit; $idx++) { + $indexes[] = $idx; + } + + $loopResult = new LoopResult($query); + + foreach ($indexes as $idx) { $item = $items[$idx]; @@ -87,7 +92,7 @@ class Feed extends BaseLoop $date = $item->get_date('d/m/Y'); - $loopResultRow = new LoopResultRow(); + $loopResultRow = new LoopResultRow($loopResult, $item, $this->versionable, $this->timestampable, $this->countable); $loopResultRow->set("URL", $item->get_permalink()); $loopResultRow->set("TITLE", $item->get_title()); diff --git a/core/lib/Thelia/Module/DeliveryModuleInterface.php b/core/lib/Thelia/Module/DeliveryModuleInterface.php index ba218ac4d..72f8769bc 100644 --- a/core/lib/Thelia/Module/DeliveryModuleInterface.php +++ b/core/lib/Thelia/Module/DeliveryModuleInterface.php @@ -23,13 +23,16 @@ namespace Thelia\Module; +use Thelia\Model\Country; + interface DeliveryModuleInterface extends BaseModuleInterface { /** - * * calculate and return delivery price * + * @param Country $country + * * @return mixed */ - public function calculate($country = null); + public function calculate(Country $country); } diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php index 4d24cc059..2fe9cd0b9 100644 --- a/local/modules/Colissimo/Colissimo.php +++ b/local/modules/Colissimo/Colissimo.php @@ -25,6 +25,7 @@ namespace Colissimo; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; +use Thelia\Model\Country; use Thelia\Module\BaseModule; use Thelia\Module\DeliveryModuleInterface; @@ -57,10 +58,10 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface * * calculate and return delivery price * - * @param null $country + * @param Country $country * @return mixed */ - public function calculate($country = null) + public function calculate(Country $country) { // TODO: Implement calculate() method. return 2; From b151325e572c9c23a1940e9565462c2abe29ee6f Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 15:07:41 +0200 Subject: [PATCH 06/74] WIP : Install wizard : step 2 file permission --- .../Controller/Install/InstallController.php | 70 ++++++- core/lib/Thelia/Install/BaseInstall.php | 15 +- core/lib/Thelia/Install/CheckPermission.php | 183 ++++++++++++++---- templates/install/layout.tpl | 1 - templates/install/step-2.html | 15 +- 5 files changed, 232 insertions(+), 52 deletions(-) diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 75594868a..648ae843e 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -26,12 +26,14 @@ use Thelia\Install\CheckPermission; /** * Class InstallController + * * @package Thelia\Controller\Install - * @author Manuel Raynaud + * @author Manuel Raynaud + * @author Guillaume MOREL */ class InstallController extends BaseInstallController { - public function index() + public function indexAction() { //$this->verifyStep(1); @@ -40,57 +42,109 @@ class InstallController extends BaseInstallController return $this->render("index.html"); } - public function checkPermission() + /** + * Integration tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function checkPermissionAction() { + $args = array(); var_dump('step2'); //$this->verifyStep(2); - $permission = new CheckPermission(); + $checkPermission = new CheckPermission(true, $this->getTranslator()); + $args['isValid'] = $isValid = $checkPermission->exec(); + $args['validationMessages'] = $checkPermission->getValidationMessages(); $this->getSession()->set("step", 2); - return $this->render("step-2.html"); + + return $this->render("step-2.html", $args); } + /** + * Database connexion tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ public function databaseConnection() { + var_dump('step 3 bis'); + } + + /** + * Database connexion tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function databaseConnectionAction() + { + var_dump('step 3'); + exit(); //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 3); + return $this->render("step-3.html"); } - public function databaseSelection() + /** + * Database selection + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function databaseSelectionAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 4); + return $this->render("step-4.html"); } - public function generalInformation() + /** + * Set general informations + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function generalInformationAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 5); + return $this->render("step-5.html"); } - public function thanks() + /** + * Display Thanks page + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function thanksAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 6); + return $this->render("thanks.html"); } + /** + * Verify each steps and redirect if one step has already been passed + * + * @param int $step Step number + * + * @return bool + */ protected function verifyStep($step) { $session = $this->getSession(); diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php index 11b8d0999..86928236a 100644 --- a/core/lib/Thelia/Install/BaseInstall.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -25,15 +25,28 @@ use Thelia\Install\Exception\AlreadyInstallException; /** * Class BaseInstall + * * @author Manuel Raynaud */ abstract class BaseInstall { + /** @var bool If Installation wizard is launched by CLI */ + protected $isConsoleMode = true; + /** - * Verify if an installation already exists + * Constructor + * + * @param bool $verifyInstall Verify if an installation already exists */ public function __construct($verifyInstall = true) { + + // Check if install wizard is launched via CLI + if (php_sapi_name() == 'cli') { + $this->isConsoleMode = true; + } else { + $this->isConsoleMode = false; + } /* TODO : activate this part if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { throw new AlreadyInstallException("Thelia is already installed"); diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index e57185c36..d924bac35 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -23,57 +23,172 @@ namespace Thelia\Install; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Core\Translation\Translator; + /** * Class CheckPermission + * + * Take care of integration tests (files permissions) + * * @package Thelia\Install - * @author Manuel Raynaud + * @author Manuel Raynaud + * @author Guillaume MOREL */ class CheckPermission extends BaseInstall { - const DIR_CONF = 'local/config'; - const DIR_LOG = 'log'; - const DIR_CACHE = 'cache'; + const DIR_CONF = 'local/config'; + const DIR_LOG = 'log'; + const DIR_CACHE = 'cache'; - private $directories = array(); - private $validation = array(); - private $valid = true; + /** @var array Directory needed to be writable */ + protected $directoriesToBeWritable = array( + self::DIR_CONF, + self::DIR_LOG, + self::DIR_CACHE, + ); - public function __construct($verifyInstall = true) + protected $validationMessages = array(); + + /** @var bool If permissions are OK */ + protected $isValid = true; + + /** @var TranslatorInterface Translator Service */ + protected $translator = null; + + /** + * Constructor + * + * @param bool $verifyInstall If verify install + * @param Translator $translator Translator Service + * necessary for install wizard + */ + public function __construct($verifyInstall = true, Translator $translator = null) { + $this->translator = $translator; - - $this->directories = array( - self::DIR_CONF => THELIA_ROOT . 'local/config', - self::DIR_LOG => THELIA_ROOT . 'DIR_LOG', - self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE' - ); - - $this->validation = array( - self::DIR_CONF => array( - "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]), - "status" => true - ), - self::DIR_LOG => array( - "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]), - "status" => true - ), - self::DIR_CACHE => array( - "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]), - "status" => true - ) - ); + foreach ($this->directoriesToBeWritable as $directory) { + $this->validationMessages[$directory] = array( + 'text' => '', + 'hint' => '', + 'status' => true + ); + } parent::__construct($verifyInstall); } + /** + * Perform file permission check + * + * @return bool + */ public function exec() { - foreach ($this->directories as $key => $directory) { - if(is_writable($directory) === false) { - $this->valid = false; - $this->validation[$key]["status"] = false; + foreach ($this->directoriesToBeWritable as $directory) { + $fullDirectory = THELIA_ROOT . $directory; + $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, true); + if (is_writable($fullDirectory) === false) { + if (!$this->makeDirectoryWritable($fullDirectory)) { + $this->isValid = false; + $this->validationMessages[$directory]['status'] = false; + $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, false); + $this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory); + } } } + + return $this->isValid; } -} \ No newline at end of file + + /** + * Get validation messages + * + * @return array + */ + public function getValidationMessages() + { + return $this->validationMessages; + } + + /** + * Make a directory writable (recursively) + * + * @param string $directory path to directory + * + * @return bool + */ + protected function makeDirectoryWritable($directory) + { + chmod($directory, 0777); + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory) + ); + foreach ($iterator as $item) { + chmod($item, 0777); + } + + return (is_writable(THELIA_ROOT . $directory) === true); + } + + + + /** + * Get Translated text about the directory state + * + * @param string $directory Directory being checked + * @param bool $isValid If directory permission is valid + * + * @return string + */ + protected function getI18nText($directory, $isValid) + { + if ($this->translator !== null) { + if ($isValid) { + $sentence = 'Your directory %directory% is writable'; + } else { + $sentence = 'Your directory %directory% is not writable'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('Your directory %s needs to be writable', $directory); + } + + return $translatedText; + } + + /** + * Get Translated hint about the directory state + * + * @param string $directory Directory being checked + * + * @return string + */ + protected function getI18nHint($directory) + { + if ($this->translator !== null) { + $sentence = 'chmod 777 %directory% on your server with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('chmod 777 %s on your server with admin rights could help', $directory); + } + + return $translatedText; + } +} diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl index 4539ce32f..6b38292e2 100644 --- a/templates/install/layout.tpl +++ b/templates/install/layout.tpl @@ -38,7 +38,6 @@ - {intl l='Édité par OpenStudio'} - {intl l='Forum Thelia'} - {intl l='Contributions Thelia'} - {intl l='interface par Steaw-Webdesign'}

{module_include location='in_footer'} diff --git a/templates/install/step-2.html b/templates/install/step-2.html index fc24d25cb..a05267c7c 100644 --- a/templates/install/step-2.html +++ b/templates/install/step-2.html @@ -24,15 +24,14 @@
-

We will check some rights to files and directories...

+

{intl l="Checking directory permissions ..."}

    -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • + {foreach from=$validationMessages item=validationMessage} +
  • + {$validationMessage.text nofilter} + {if !$validationMessage.status} - {$validationMessage.hint nofilter}{/if} +
  • + {/foreach}
From bca2b58e416c9fb1d01aa55f9165d7f3151657bb Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 15:07:58 +0200 Subject: [PATCH 07/74] Merge master --- local/modules/Colissimo/Colissimo.php | 0 local/modules/Colissimo/Config/config.xml | 0 local/modules/Colissimo/Config/plugin.xml | 0 local/modules/Colissimo/Config/schema.xml | 0 local/modules/DebugBar/Config/config.xml | 0 local/modules/DebugBar/Config/plugin.xml | 0 local/modules/DebugBar/Config/schema.xml | 0 local/modules/DebugBar/DataCollector/PropelCollector.php | 0 local/modules/DebugBar/DebugBar.php | 0 local/modules/DebugBar/Listeners/DebugBarListeners.php | 0 local/modules/DebugBar/Smarty/Plugin/DebugBar.php | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 local/modules/Colissimo/Colissimo.php mode change 100644 => 100755 local/modules/Colissimo/Config/config.xml mode change 100644 => 100755 local/modules/Colissimo/Config/plugin.xml mode change 100644 => 100755 local/modules/Colissimo/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/Config/config.xml mode change 100644 => 100755 local/modules/DebugBar/Config/plugin.xml mode change 100644 => 100755 local/modules/DebugBar/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/DataCollector/PropelCollector.php mode change 100644 => 100755 local/modules/DebugBar/DebugBar.php mode change 100644 => 100755 local/modules/DebugBar/Listeners/DebugBarListeners.php mode change 100644 => 100755 local/modules/DebugBar/Smarty/Plugin/DebugBar.php diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/Colissimo/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/config.xml b/local/modules/DebugBar/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/plugin.xml b/local/modules/DebugBar/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/schema.xml b/local/modules/DebugBar/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DataCollector/PropelCollector.php b/local/modules/DebugBar/DataCollector/PropelCollector.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DebugBar.php b/local/modules/DebugBar/DebugBar.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Listeners/DebugBarListeners.php b/local/modules/DebugBar/Listeners/DebugBarListeners.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php old mode 100644 new mode 100755 From d8b5df416214f83de2f047f4c2aeeb35003a1530 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 15:24:08 +0200 Subject: [PATCH 08/74] delivery process --- .../Thelia/Core/Template/Loop/Delivery.php | 15 +++++++-- core/lib/Thelia/Module/BaseModule.php | 3 ++ install/insert.sql | 3 +- local/config/schema.xml | 3 +- templates/default/cart_billing.html | 31 ++++++++++++------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index a0e9ebb7a..b679e5061 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -22,9 +22,12 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Model\CountryQuery; +use Thelia\Module\BaseModule; /** * Class Delivery @@ -39,7 +42,7 @@ class Delivery extends BaseSpecificModule $collection = parent::getArgDefinitions(); $collection->addArgument( - Argument::createIntTypeArgument("country") + Argument::createIntTypeArgument("country", null, true) ); return $collection; @@ -50,6 +53,14 @@ class Delivery extends BaseSpecificModule $search = parent::exec($pagination); /* manage translations */ $locale = $this->configureI18nProcessing($search); + + $search->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL); + + $country = $this->getCountry(); + if(null !== $country) { + //@todo + } + /* perform search */ $deliveryModules = $this->search($search, $pagination); @@ -73,7 +84,7 @@ class Delivery extends BaseSpecificModule ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set('PRICE', $moduleInstance->calculate($this->getCountry())) + ->set('PRICE', $moduleInstance->calculate(CountryQuery::create()->findPk($country))) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 9d76e08f3..a13403482 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -28,6 +28,9 @@ use Symfony\Component\DependencyInjection\ContainerAware; abstract class BaseModule extends ContainerAware { + const CLASSIC_MODULE_TYPE = 1; + const DELIVERY_MODULE_TYPE = 2; + const PAYMENT_MODULE_TYPE = 3; public function __construct() { diff --git a/install/insert.sql b/install/insert.sql index 03fbc690c..a49dc7231 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -28,7 +28,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES -(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()); +(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()), +(2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW()); INSERT INTO `customer_title`(`id`, `by_default`, `position`, `created_at`, `updated_at`) VALUES (1, 1, 1, NOW(), NOW()), diff --git a/local/config/schema.xml b/local/config/schema.xml index 49a76ebed..186bdbfd6 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,4 +1,4 @@ - + @@ -80,6 +80,7 @@ + diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index d44753e48..8720bf696 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -48,18 +48,29 @@ @@ -83,18 +94,14 @@
Choose your delivery method
+ {loop type="delivery" name="deliveries" force_return="true"}
-
- -
+ {/loop}
From 785057c0be9fffd32221c6fdff4b0270ab39c535 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 15:42:25 +0200 Subject: [PATCH 09/74] add some information for OSX requirements --- Readme.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 791b61d1e..3481d508c 100755 --- a/Readme.md +++ b/Readme.md @@ -12,13 +12,34 @@ Here is the most recent developed code for the next major version (v2). You can Most part of the code can possibly change, a large part will be refactor soon, graphical setup does not exist yet. +Requirements +------------ + +* php 5.4 +* apache 2 +* mysql 5 + +If you use Mac OSX, they still don't use php 5.4 as default php version... There are many solutions for you : + +* use linux (the better one) +* use last MAMP version and put the php bin directory in your path and : + +```bash +$ vim ~/.bash_profile +then put this line : export PATH=/Applications/MAMP/bin/php/php5.4.x/bin/:$PATH +$ . .bash_profile +``` + +* configure a complete development environment : http://php-osx.liip.ch/ +* use a virtual machine with vagrant and puppet : https://puphpet.com/ + Installation ------------ ``` bash $ git clone --recursive https://github.com/thelia/thelia.git $ cd thelia -$ wget http://getcomposer.org/composer.phar +$ curl -sS https://getcomposer.org/installer | php $ php composer.phar install ``` From 1dcde3ff2ca5925fb0f9b247fbfae1646123ca91 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 15:47:32 +0200 Subject: [PATCH 10/74] fix typo --- Readme.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 3481d508c..c0c3ebef5 100755 --- a/Readme.md +++ b/Readme.md @@ -19,15 +19,13 @@ Requirements * apache 2 * mysql 5 -If you use Mac OSX, they still don't use php 5.4 as default php version... There are many solutions for you : +If you use Mac OSX, it still doesn't use php 5.4 as default php version... There are many solutions for you : -* use linux (the better one) -* use last MAMP version and put the php bin directory in your path and : +* use linux (the best one) +* use last MAMP version and put the php bin directory in your path : ```bash -$ vim ~/.bash_profile -then put this line : export PATH=/Applications/MAMP/bin/php/php5.4.x/bin/:$PATH -$ . .bash_profile +export PATH=/Applications/MAMP/bin/php/php5.4.x/bin/:$PATH ``` * configure a complete development environment : http://php-osx.liip.ch/ From 361e9e11260ecf4ddc5d4ef3aba33af5077b1086 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 16:12:04 +0200 Subject: [PATCH 11/74] delivery process --- .../Thelia/Core/Template/Loop/Delivery.php | 15 ++-- .../Template/Loop/ProductSaleElements.php | 2 +- .../Smarty/Plugins/DataAccessFunctions.php | 11 +++ install/insert.sql | 11 ++- templates/default/cart_billing.html | 69 ++++++++++++++++++- 5 files changed, 98 insertions(+), 10 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index b679e5061..dea302797 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -42,7 +42,7 @@ class Delivery extends BaseSpecificModule $collection = parent::getArgDefinitions(); $collection->addArgument( - Argument::createIntTypeArgument("country", null, true) + Argument::createIntTypeArgument("country") ); return $collection; @@ -56,9 +56,14 @@ class Delivery extends BaseSpecificModule $search->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL); - $country = $this->getCountry(); - if(null !== $country) { - //@todo + $countryId = $this->getCountry(); + if(null !== $countryId) { + $country = CountryQuery::create()->findPk($countryId); + if(null === $country) { + throw new \InvalidArgumentException('Cannot found country id: `' . $countryId . '` in delivery loop'); + } + } else { + $country = CountryQuery::create()->findOneByByDefault(1); } /* perform search */ @@ -84,7 +89,7 @@ class Delivery extends BaseSpecificModule ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set('PRICE', $moduleInstance->calculate(CountryQuery::create()->findPk($country))) + ->set('PRICE', $moduleInstance->calculate($country)) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php index 980ade454..e27626129 100755 --- a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php +++ b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php @@ -115,7 +115,7 @@ class ProductSaleElements extends BaseLoop $currencyId = $this->getCurrency(); if (null !== $currencyId) { - $currency = CurrencyQuery::create()->findOneById($currencyId); + $currency = CurrencyQuery::create()->findPk($currencyId); if (null === $currency) { throw new \InvalidArgumentException('Cannot found currency id: `' . $currency . '` in product_sale_elements loop'); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index cc99bfe50..bb220531c 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -155,6 +155,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin } } + public function countryDataAccess($params, $smarty) + { + $defaultCountry = CountryQuery::create()->findOneByByDefault(1); + + switch($params["attr"]) { + case "default": + return $defaultCountry->getId(); + } + } + public function cartDataAccess($params, $smarty) { $cart = $this->getCart($this->request); @@ -287,6 +297,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin new SmartyPluginDescriptor('function', 'content', $this, 'contentDataAccess'), new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'), new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'), + new SmartyPluginDescriptor('function', 'country', $this, 'countryDataAccess'), new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'), new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'), ); diff --git a/install/insert.sql b/install/insert.sql index 01d7fbce2..348e447c2 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -31,6 +31,11 @@ INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namesp (1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()), (2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW()); +INSERT INTO `thelia_2`.`module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES +('2', 'en_US', '72h delivery', NULL, NULL, NULL), +('2', 'fr_FR', 'Livraison par colissimo en 72h', NULL, NULL, NULL); + + INSERT INTO `customer_title`(`id`, `by_default`, `position`, `created_at`, `updated_at`) VALUES (1, 1, 1, NOW(), NOW()), (2, 0, 2, NOW(), NOW()), @@ -44,13 +49,13 @@ INSERT INTO `customer_title_i18n` (`id`, `locale`, `short`, `long`) VALUES (3, 'fr_FR', 'Mlle', 'Madamemoiselle'), (3, 'en_US', 'Miss', 'Miss'); -INSERT INTO `currency` (`id` ,`code` ,`symbol` ,`rate`, `position` ,`by_default` ,`created_at` ,`updated_at`) +INSERT INTO `currency` (`id`, `code`, `symbol`, `rate`, `position`, `by_default`, `created_at`, `updated_at`) VALUES -(1, 'EUR', '€', '1', 1, '1', NOW() , NOW()), +(1, 'EUR', '€', '1', 1, '1', NOW(), NOW()), (2, 'USD', '$', '1.26', 2, '0', NOW(), NOW()), (3, 'GBP', '£', '0.89', 3, '0', NOW(), NOW()); -INSERT INTO `currency_i18n` (`id` ,`locale` ,`name`) +INSERT INTO `currency_i18n` (`id`, `locale`, `name`) VALUES (1, 'fr_FR', 'Euro'), (1, 'en_US', 'Euro'), diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index 8720bf696..123596609 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -25,6 +25,73 @@
+ +
+
+ Add a new address + Chose your billing address +
+
+
  • - M. DUPONT Jean - Agency XY + {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY}
  • - street name of my business
    - 75000 - City, Country + {$ADDRESS1} + {if $ADDRESS2 != ""} +
    {$ADDRESS2} + {/if} + {if $ADDRESS3 != ""} +
    {$ADDRESS3} + {/if} +
    {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}
  • - +33 09 08 07 06 05 + {if $CELLPHONE != ""} + {$CELLPHONE} + {/if} + {if $PHONE != ""} +
    {$PHONE} + {/if}
+ + + {loop type="address" name="customer.addresses" customer="current"} + + + + + + + + {/loop} + + + + + +
Add a new address @@ -98,7 +165,7 @@
{/loop} From 2309a2e7885a1f763291cc0429f1767ee94a87ac Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 16:29:09 +0200 Subject: [PATCH 12/74] remove script part of composer.json file --- composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/composer.json b/composer.json index 2d315bd3a..c8291305d 100755 --- a/composer.json +++ b/composer.json @@ -53,9 +53,5 @@ "": "local/modules/", "Thelia" : "core/lib/" } - }, - "scripts" : { - "post-update-cmd": "composer dump-autoload -o", - "post-install-cmd": "composer dump-autoload -o" } } From aa4e0636e8f270d4c3f79cba3d758bb4a9954822 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 16:31:13 +0200 Subject: [PATCH 13/74] use dump autoloader in all compser scripts --- Readme.md | 2 +- composer.lock | 2 +- reset_install.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index c0c3ebef5..ac0862dae 100755 --- a/Readme.md +++ b/Readme.md @@ -38,7 +38,7 @@ Installation $ git clone --recursive https://github.com/thelia/thelia.git $ cd thelia $ curl -sS https://getcomposer.org/installer | php -$ php composer.phar install +$ php composer.phar install --optimize-autoloader ``` Finish the installation using cli tools : diff --git a/composer.lock b/composer.lock index 61160ea49..acc232713 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "28dfdc7a840f9e70df422581f82a871f", + "hash": "6db52c20c300000aa218e3be92ef978e", "packages": [ { "name": "imagine/imagine", diff --git a/reset_install.sh b/reset_install.sh index 399156b67..380a80a5f 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -8,7 +8,7 @@ echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n" php Thelia cache:clear echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n" -composer install --prefer-dist +composer install --prefer-dist --optimize-autoloader cd local/config/ From bf3bc02f8b8c5e01bd810065fdc3ed2fa35848ed Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 16:46:12 +0200 Subject: [PATCH 14/74] fix fixture dependant unit test --- install/faker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install/faker.php b/install/faker.php index 66303f05a..11aad8651 100755 --- a/install/faker.php +++ b/install/faker.php @@ -189,7 +189,7 @@ try { $featureList = array(); for($i=0; $i<4; $i++) { $feature = new Thelia\Model\Feature(); - $feature->setVisible(rand(1, 10)>7 ? 0 : 1); + $feature->setVisible(1); $feature->setPosition($i); setI18n($faker, $feature); @@ -257,7 +257,7 @@ try { for($i=0; $i<4; $i++) { $folder = new Thelia\Model\Folder(); $folder->setParent(0); - $folder->setVisible(rand(1, 10)>7 ? 0 : 1); + $folder->setVisible(1); $folder->setPosition($i); setI18n($faker, $folder); @@ -270,7 +270,7 @@ try { for($j=1; $jsetParent($folder->getId()); - $subfolder->setVisible(rand(1, 10)>7 ? 0 : 1); + $subfolder->setVisible(1); $subfolder->setPosition($j); setI18n($faker, $subfolder); @@ -283,7 +283,7 @@ try { for($k=0; $kaddFolder($subfolder); - $content->setVisible(rand(1, 10)>7 ? 0 : 1); + $content->setVisible(1); $content->setPosition($k); setI18n($faker, $content); @@ -418,7 +418,7 @@ function createProduct($faker, $category, $position, $template, &$productIdList) $product = new Thelia\Model\Product(); $product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8)); $product->addCategory($category); - $product->setVisible(rand(1, 10)>7 ? 0 : 1); + $product->setVisible(1); $product->setPosition($position); $product->setTaxRuleId(1); $product->setTemplate($template); @@ -440,7 +440,7 @@ function createCategory($faker, $parent, $position, &$categoryIdList, $contentId { $category = new Thelia\Model\Category(); $category->setParent($parent); - $category->setVisible(rand(1, 10)>7 ? 0 : 1); + $category->setVisible(1); $category->setPosition($position); setI18n($faker, $category); From 035d9dd0e94fdcb992d72518bb8d7f9dd4da4582 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 16:57:08 +0200 Subject: [PATCH 15/74] add swiftmailer in composer --- composer.json | 3 ++- composer.lock | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c8291305d..4a3798384 100755 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "simplepie/simplepie": "dev-master", "imagine/imagine": "dev-master", - "symfony/icu": "1.0" + "symfony/icu": "1.0", + "swiftmailer/swiftmailer": "5.0.*" }, "require-dev" : { "phpunit/phpunit": "3.7.*", diff --git a/composer.lock b/composer.lock index acc232713..b0310c075 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "6db52c20c300000aa218e3be92ef978e", + "hash": "a40be01c82e68ba0c446dc204d2667da", "packages": [ { "name": "imagine/imagine", @@ -445,6 +445,55 @@ ], "time": "2013-07-02 16:38:47" }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "f3917ecef35a4e4d98b303eb9fee463bc983f379" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/f3917ecef35a4e4d98b303eb9fee463bc983f379", + "reference": "f3917ecef35a4e4d98b303eb9fee463bc983f379", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Chris Corbyn" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "mail", + "mailer" + ], + "time": "2013-08-30 12:35:21" + }, { "name": "symfony-cmf/routing", "version": "1.0.0", From cfc52c4e7fade57c5d5f5f157eab6a3c84de5cc9 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 18:15:09 +0200 Subject: [PATCH 16/74] Working : install wizard : type inference --- core/lib/Thelia/Controller/BaseController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 19e62a400..d5c54e991 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -31,6 +31,7 @@ use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Router; use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Translation\Translator; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; @@ -89,7 +90,7 @@ class BaseController extends ContainerAware * * return the Translator * - * @return mixed \Thelia\Core\Translation\Translator + * @return Translator */ public function getTranslator() { From 874c5f6cacc6a83e25b710ca4836c22f0d4e32db Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 18:20:15 +0200 Subject: [PATCH 17/74] integrate swiftMailer as mailer solution --- core/lib/Thelia/Config/Resources/config.xml | 4 + core/lib/Thelia/Controller/BaseController.php | 9 ++ .../Core/Event/MailTransporterEvent.php | 52 +++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 + core/lib/Thelia/Mailer/MailerFactory.php | 91 +++++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/MailTransporterEvent.php create mode 100644 core/lib/Thelia/Mailer/MailerFactory.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 691cf2198..bed490b4a 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -267,6 +267,10 @@ + + + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 19e62a400..8bf9aeec3 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -281,4 +281,13 @@ class BaseController extends ContainerAware $this->accessDenied(); } } + + /** + * @return \Swift_Mailer + */ + public function getMailer() + { + $mailer = $this->container->get('mailer'); + return $mailer->getSwiftMailer(); + } } diff --git a/core/lib/Thelia/Core/Event/MailTransporterEvent.php b/core/lib/Thelia/Core/Event/MailTransporterEvent.php new file mode 100644 index 000000000..d47ac693f --- /dev/null +++ b/core/lib/Thelia/Core/Event/MailTransporterEvent.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +/** + * Class MailTransporterEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ +class MailTransporterEvent extends ActionEvent { + /** + * @var \Swift_Transport + */ + protected $transporter; + + public function setMailerTransporter(\Swift_Transport $transporter) + { + $this->transporter = $transporter; + } + + public function getTransporter() + { + return $this->transporter; + } + + public function hasTransporter() + { + return null !== $this->transporter; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 2867762aa..242fde4e4 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -430,4 +430,9 @@ final class TheliaEvents const BEFORE_DELETEFEATURE_AV = "action.before_deleteFeatureAv"; const AFTER_DELETEFEATURE_AV = "action.after_deleteFeatureAv"; + /** + * sent when system find a mailer transporter. + */ + const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config'; + } diff --git a/core/lib/Thelia/Mailer/MailerFactory.php b/core/lib/Thelia/Mailer/MailerFactory.php new file mode 100644 index 000000000..5cd952270 --- /dev/null +++ b/core/lib/Thelia/Mailer/MailerFactory.php @@ -0,0 +1,91 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Mailer; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Thelia\Core\Event\MailTransporterEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\ConfigQuery; + + +/** + * Class MailerFactory + * @package Thelia\Mailer + * @author Manuel Raynaud + */ +class MailerFactory { + /** + * @var \Swift_Mailer + */ + protected $swiftMailer; + + protected $dispatcher; + + public function _construct(EventDispatcherInterface $dispatcher) + { + + $this->dispatcher = $dispatcher; + + $transporterEvent = new MailTransporterEvent(); + $this->dispatcher->dispatch(TheliaEvents::MAILTRANSPORTER_CONFIG, $transporterEvent); + + if($transporterEvent->hasTransporter()) { + $transporter = $transporterEvent->getTransporter(); + } else { + if (ConfigQuery::read("smtp.enabled")) { + $transporter = $this->configureSmtp(); + } else { + $transporter = \Swift_MailTransport::newInstance(); + } + } + + $this->swiftMailer = new \Swift_Mailer($transporter); + } + + private function configureSmtp() + { + $smtpTransporter = new \Swift_SmtpTransport(); + $smtpTransporter->setHost(Configquery::read('smtp.host', 'localhost')) + ->setPort(ConfigQuery::read('smtp.host')) + ->setEncryption(ConfigQuery::read('smtp.encryption')) + ->setUsername(ConfigQuery::read('smtp.username')) + ->setPassword(ConfigQuery::read('smtp.password')) + ->setAuthMode(ConfigQuery::read('smtp.authmode')) + ->setTimeout(ConfigQuery::read('smtp.timeout', 30)) + ->setSourceIp(ConfigQuery::read('smtp.sourceip')) + ; + return $smtpTransporter; + } + + public function send(\Swift_Mime_Message $message, &$failedRecipients = null) + { + $this->swiftMailer->send($message, $failedRecipients); + } + + public function getSwiftMailer() + { + return $this->swiftMailer; + } + + +} \ No newline at end of file From 67b6e5f07de74cfd019d3b5c32141067fde3c981 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Sep 2013 18:21:07 +0200 Subject: [PATCH 18/74] add some php doc --- core/lib/Thelia/Controller/BaseController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 8bf9aeec3..3c4c0a5bc 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -283,6 +283,9 @@ class BaseController extends ContainerAware } /** + * + * return an instance of \Swift_Mailer with good Transporter configured. + * * @return \Swift_Mailer */ public function getMailer() From afa9a46abf332ee2850996d2c078b9be8e253172 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 18:55:29 +0200 Subject: [PATCH 19/74] order delivery form --- core/lib/Thelia/Config/Resources/config.xml | 2 + .../Thelia/Config/Resources/routing/front.xml | 15 ++- .../Controller/Front/OrderController.php | 79 ++++++++++++++ core/lib/Thelia/Core/Event/OrderEvent.php | 101 ++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 9 +- .../Core/HttpFoundation/Session/Session.php | 20 ++-- core/lib/Thelia/Form/OrderDelivery.php | 94 ++++++++++++++++ templates/default/cart.html | 2 +- templates/default/cart_billing.html | 4 +- 9 files changed, 307 insertions(+), 19 deletions(-) create mode 100755 core/lib/Thelia/Controller/Front/OrderController.php create mode 100755 core/lib/Thelia/Core/Event/OrderEvent.php create mode 100755 core/lib/Thelia/Form/OrderDelivery.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 691cf2198..0eda0c37b 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -58,6 +58,8 @@ + + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index cea964153..a8b91a05d 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -98,11 +98,6 @@ cart - - Thelia\Controller\Front\DefaultController::noAction - cart_billing - - Thelia\Controller\Front\CartController::addItem @@ -117,6 +112,16 @@ cart + + Thelia\Controller\Front\DefaultController::noAction + cart_billing + + + + Thelia\Controller\Front\OrderController::deliver + cart_billing + + diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php new file mode 100755 index 000000000..0508b4dc9 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -0,0 +1,79 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Controller\Front; + +use Propel\Runtime\Exception\PropelException; +use Thelia\Form\Exception\FormValidationException; +use Thelia\Core\Event\OrderEvent; +use Thelia\Core\Event\TheliaEvents; +use Symfony\Component\HttpFoundation\Request; +use Thelia\Model\Order; + +class OrderController extends BaseFrontController +{ + /** + * set billing address + * set delivery address + * set delivery module + */ + public function deliver() + { + $orderEvent = $this->getOrderEvent(); + //$orderEvent->setBillingAddress($this->getRequest()->get("billing-address")); + $orderEvent->setDeliveryAddress($this->getRequest()->get("delivery-address")); + $orderEvent->setDeliveryModule($this->getRequest()->get("delivery-module")); + + try { + //$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_BILLING_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); + + $this->redirectSuccess(); + } catch (PropelException $e) { + $this->getParserContext()->setGeneralError($e->getMessage()); + } + + } + + protected function getOrderEvent() + { + $order = $this->getOrder($this->getRequest()); + + return new OrderEvent($order); + } + + public function getOrder(Request $request) + { + $session = $request->getSession(); + + if (null !== $order = $session->getOrder()) { + return $order; + } + + $order = new Order(); + + $session->setOrder($order); + + return $order; + } +} diff --git a/core/lib/Thelia/Core/Event/OrderEvent.php b/core/lib/Thelia/Core/Event/OrderEvent.php new file mode 100755 index 000000000..8b6762e99 --- /dev/null +++ b/core/lib/Thelia/Core/Event/OrderEvent.php @@ -0,0 +1,101 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Model\Address; +use Thelia\Model\AddressQuery; +use Thelia\Model\Module; +use Thelia\Model\Order; + +class OrderEvent extends ActionEvent +{ + protected $order = null; + protected $billingAddress = null; + protected $deliveryAddress = null; + protected $deliveryModule = null; + + /** + * @param Order $order + */ + public function __construct(Order $order) + { + $this->order = $order; + } + + /** + * @param Address $address + */ + public function setBillingAddress(Address $address) + { + $this->deliveryAddress = $address->getId(); + } + + /** + * @param Address $address + */ + public function setDeliveryAddress(Address $address) + { + $this->deliveryAddress = $address->getId(); + } + + /** + * @param Module $module + */ + public function setDeliveryModule(Module $module) + { + $this->deliveryModule = $module->getId(); + } + + /** + * @return null|Order + */ + public function getOrder() + { + return $this->order; + } + + /** + * @return array|mixed|Address + */ + public function getBillingAddress() + { + return AddressQuery::create()->findPk($this->billingAddress); + } + + /** + * @return array|mixed|Address + */ + public function getDeliveryAddress() + { + return AddressQuery::create()->findPk($this->deliveryAddress); + } + + /** + * @return array|mixed|Address + */ + public function getDeliveryModule() + { + return AddressQuery::create()->findPk($this->deliveryModule); + } +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 2867762aa..02256a360 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -218,13 +218,20 @@ final class TheliaEvents const CART_DELETEITEM = "action.deleteArticle"; + /** + * Order linked event + */ + const ORDER_SET_BILLING_ADDRESS = "action.order.setBillingAddress"; + const ORDER_SET_DELIVERY_ADDRESS = "action.order.setDeliveryAddress"; + const ORDER_SET_DELIVERY_MODULE = "action.order.setDeliveryModule"; + /** * Sent on image processing */ const IMAGE_PROCESS = "action.processImage"; /** - * Sent on cimage cache clear request + * Sent on image cache clear request */ const IMAGE_CLEAR_CACHE = "action.clearImageCache"; diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index e9e3d50bf..5edd007b3 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -29,6 +29,7 @@ use Thelia\Exception\InvalidCartException; use Thelia\Model\CartQuery; use Thelia\Model\Cart; use Thelia\Model\Currency; +use Thelia\Model\Order; use Thelia\Tools\URL; use Thelia\Model\Lang; @@ -43,6 +44,8 @@ use Thelia\Model\Lang; class Session extends BaseSession { /** + * @param bool $forceDefault + * * @return \Thelia\Model\Lang|null */ public function getLang($forceDefault = true) @@ -205,22 +208,19 @@ class Session extends BaseSession return $this; } - /** - * assign delivery id in session - * - * @param $delivery_id - * @return $this - */ - public function setDelivery($delivery_id) + // -- Order ------------------------------------------------------------------ + + + public function setOrder(Order $order) { - $this->set("thelia.delivery_id", $delivery_id); + $this->set("thelia.order", $order); return $this; } - public function getDelivery() + public function getOrder() { - return $this->get("thelia.delivery_id"); + return $this->get("thelia.order"); } diff --git a/core/lib/Thelia/Form/OrderDelivery.php b/core/lib/Thelia/Form/OrderDelivery.php new file mode 100755 index 000000000..d0ee0efb3 --- /dev/null +++ b/core/lib/Thelia/Form/OrderDelivery.php @@ -0,0 +1,94 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Model\AddressQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Translation\Translator; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; + +/** + * Class OrderDelivery + * @package Thelia\Form + * @author Etienne Roudeix + */ +class OrderDelivery extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("delivery-address", "integer", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyDeliveryAddress") + ) + )) + ) + )) + ->add("delivery-module", "integer", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyDeliveryModule") + ) + )) + ) + )); + } + + public function verifyDeliveryAddress($value, ExecutionContextInterface $context) + { + $address = AddressQuery::create() + ->findPk($value); + + if(null === $address) { + $context->addViolation("Address ID not found"); + } elseif($address->getCustomerId() !== $this->request->getSession()->getCustomerUser()->getId()) { + $context->addViolation("Address does not belong to you"); + } + } + + public function verifyDeliveryModule($value, ExecutionContextInterface $context) + { + $module = ModuleQuery::create() + ->filterByType(BaseModule::DELIVERY_MODULE_TYPE) + ->filterByActivate(1) + ->filterById($value) + ->find(); + + if(null === $module) { + $context->addViolation("Delivery module ID not found"); + } + } + + public function getName() + { + return "thelia_order_delivery"; + } +} \ No newline at end of file diff --git a/templates/default/cart.html b/templates/default/cart.html index 6f91d8581..483e34436 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -133,7 +133,7 @@ Continue Shopping - Proceed checkout + Proceed checkout diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index 123596609..45c6eadf1 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -24,7 +24,7 @@ 4 Secure payment
- +
@@ -164,7 +164,7 @@ {loop type="delivery" name="deliveries" force_return="true"}
From 2f41d4db6f15f88387638af4c70ff51f1ebf2945 Mon Sep 17 00:00:00 2001 From: franck Date: Mon, 16 Sep 2013 18:58:45 +0200 Subject: [PATCH 20/74] Started category management --- core/lib/Thelia/Action/Category.php | 262 +++---- core/lib/Thelia/Action/Config.php | 70 +- core/lib/Thelia/Action/Currency.php | 6 +- core/lib/Thelia/Action/Message.php | 4 +- core/lib/Thelia/Config/Resources/config.xml | 2 +- .../Thelia/Config/Resources/routing/admin.xml | 2 +- .../Admin/AbstractCrudController.php | 59 +- .../Admin/AttributeAvController.php | 2 +- .../Controller/Admin/AttributeController.php | 2 +- .../Controller/Admin/CategoryController.php | 419 ++++------- .../Controller/Admin/ConfigController.php | 2 +- .../Controller/Admin/CurrencyController.php | 2 +- .../Controller/Admin/FeatureAvController.php | 2 +- .../Controller/Admin/FeatureController.php | 2 +- .../Controller/Admin/TemplateController.php | 2 +- .../Thelia/Core/Event/CategoryCreateEvent.php | 20 +- .../Event/CategoryToggleVisibilityEvent.php | 28 + .../Thelia/Core/Event/CategoryUpdateEvent.php | 13 - core/lib/Thelia/Core/Event/TheliaEvents.php | 43 +- .../Core/Template/Loop/CategoryTree.php | 4 +- core/lib/Thelia/Form/CategoryCreationForm.php | 6 +- .../Thelia/Form/CategoryModificationForm.php | 8 +- core/lib/Thelia/Model/Category.php | 24 +- .../default/assets/less/thelia/thelia.less | 8 +- templates/admin/default/categories.html | 710 +++++++----------- templates/admin/default/category-edit.html | 243 +++--- templates/admin/default/currency-edit.html | 8 +- .../default/includes/catalog-breadcrumb.html | 4 +- templates/admin/default/message-edit.html | 12 +- templates/admin/default/orders.html | 6 +- templates/admin/default/variable-edit.html | 6 +- templates/admin/default/variables.html | 2 +- 32 files changed, 772 insertions(+), 1211 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index 297cd64da..a34f4a85e 100755 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -24,52 +24,88 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Thelia\Core\Event\TheliaEvents; -use Thelia\Model\Category as CategoryModel; + use Thelia\Model\CategoryQuery; +use Thelia\Model\Category as CategoryModel; -use Propel\Runtime\ActiveQuery\Criteria; -use Propel\Runtime\Propel; -use Thelia\Model\Map\CategoryTableMap; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\CategoryUpdateEvent; use Thelia\Core\Event\CategoryCreateEvent; use Thelia\Core\Event\CategoryDeleteEvent; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Event\UpdatePositionEvent; use Thelia\Core\Event\CategoryToggleVisibilityEvent; -use Thelia\Core\Event\CategoryChangePositionEvent; class Category extends BaseAction implements EventSubscriberInterface { + /** + * Create a new category entry + * + * @param CategoryCreateEvent $event + */ public function create(CategoryCreateEvent $event) { $category = new CategoryModel(); $category ->setDispatcher($this->getDispatcher()) - ->create( - $event->getTitle(), - $event->getParent(), - $event->getLocale() - ); + + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setParent($event->getParent()) + ->setVisible($event->getVisible()) + + ->save() + ; $event->setCategory($category); } - public function update(CategoryChangeEvent $event) + /** + * Change a category + * + * @param CategoryUpdateEvent $event + */ + public function update(CategoryUpdateEvent $event) { + $search = CategoryQuery::create(); + + if (null !== $category = CategoryQuery::create()->findPk($event->getCategoryId())) { + + $category + ->setDispatcher($this->getDispatcher()) + + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ->setChapo($event->getChapo()) + ->setPostscriptum($event->getPostscriptum()) + + ->setParent($event->getParent()) + ->setVisible($event->getVisible()) + + ->save(); + + $event->setCategory($category); + } } /** - * Delete a category + * Delete a category entry * - * @param ActionEvent $event + * @param CategoryDeleteEvent $event */ public function delete(CategoryDeleteEvent $event) { - $category = CategoryQuery::create()->findPk($event->getCategoryId()); + if (null !== $category = CategoryQuery::create()->findPk($event->getCategoryId())) { - if ($category !== null) { + $category + ->setDispatcher($this->getDispatcher()) + ->delete() + ; - $category->setDispatcher($this->getDispatcher())->delete(); + $event->setCategory($category); } } @@ -80,178 +116,48 @@ class Category extends BaseAction implements EventSubscriberInterface */ public function toggleVisibility(CategoryToggleVisibilityEvent $event) { - $category = CategoryQuery::create()->findPk($event->getCategoryId()); + $category = $event->getCategory(); - if ($category !== null) { - - $category - ->setDispatcher($this->getDispatcher()) - ->setVisible($category->getVisible() ? false : true) - ->save() + $category + ->setDispatcher($this->getDispatcher()) + ->setVisible($category->getVisible() ? false : true) + ->save() ; + } + + /** + * Changes position, selecting absolute ou relative change. + * + * @param CategoryChangePositionEvent $event + */ + public function updatePosition(UpdatePositionEvent $event) + { + if (null !== $category = CategoryQuery::create()->findPk($event->getObjectId())) { + + $category->setDispatcher($this->getDispatcher()); + + $mode = $event->getMode(); + + if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) + return $category->changeAbsolutePosition($event->getPosition()); + else if ($mode == UpdatePositionEvent::POSITION_UP) + return $category->movePositionUp(); + else if ($mode == UpdatePositionEvent::POSITION_DOWN) + return $category->movePositionDown(); } } /** - * Changes category position, selecting absolute ou relative change. - * - * @param CategoryChangePositionEvent $event - */ - public function changePosition(CategoryChangePositionEvent $event) - { - if ($event->getMode() == CategoryChangePositionEvent::POSITION_ABSOLUTE) - return $this->changeAbsolutePosition($event); - else - return $this->exchangePosition($event); - } - - /** - * Move up or down a category - * - * @param CategoryChangePositionEvent $event - */ - protected function exchangePosition(CategoryChangePositionEvent $event) - { - $category = CategoryQuery::create()->findPk($event->getCategoryId()); - - if ($category !== null) { - - // The current position of the category - $my_position = $category->getPosition(); - - // Find category to exchange position with - $search = CategoryQuery::create() - ->filterByParent($category->getParent()); - - // Up or down ? - if ($event->getMode() == CategoryChangePositionEvent::POSITION_UP) { - // Find the category immediately before me - $search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC); - } elseif ($event->getMode() == CategoryChangePositionEvent::POSITION_DOWN) { - // Find the category immediately after me - $search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC); - } else - - return; - - $result = $search->findOne(); - - // If we found the proper category, exchange their positions - if ($result) { - - $cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME); - - $cnx->beginTransaction(); - - try { - $category - ->setDispatcher($this->getDispatcher()) - ->setPosition($result->getPosition()) - ->save() - ; - - $result->setPosition($my_position)->save(); - - $cnx->commit(); - } catch (Exception $e) { - $cnx->rollback(); - } - } - } - } - - /** - * Changes category position - * - * @param CategoryChangePositionEvent $event - */ - protected function changeAbsolutePosition(CategoryChangePositionEvent $event) - { - $category = CategoryQuery::create()->findPk($event->getCategoryId()); - - if ($category !== null) { - - // The required position - $new_position = $event->getPosition(); - - // The current position - $current_position = $category->getPosition(); - - if ($new_position != null && $new_position > 0 && $new_position != $current_position) { - - // Find categories to offset - $search = CategoryQuery::create()->filterByParent($category->getParent()); - - if ($new_position > $current_position) { - // The new position is after the current position -> we will offset + 1 all categories located between us and the new position - $search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position)); - - $delta = -1; - } else { - // The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position - $search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1)); - - $delta = 1; - } - - $results = $search->find(); - - $cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME); - - $cnx->beginTransaction(); - - try { - foreach ($results as $result) { - $result->setPosition($result->getPosition() + $delta)->save($cnx); - } - - $category - ->setDispatcher($this->getDispatcher()) - ->setPosition($new_position) - ->save($cnx) - ; - - $cnx->commit(); - } catch (Exception $e) { - $cnx->rollback(); - } - } - } - } - - /** - * Returns an array of event names this subscriber listens to. - * - * The array keys are event names and the value can be: - * - * * The method name to call (priority defaults to 0) - * * An array composed of the method name to call and the priority - * * An array of arrays composed of the method names to call and respective - * priorities, or 0 if unset - * - * For instance: - * - * * array('eventName' => 'methodName') - * * array('eventName' => array('methodName', $priority)) - * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) - * - * @return array The event names to listen to - * - * @api + * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::CATEGORY_CREATE => array("create", 128), - TheliaEvents::CATEGORY_UPDATE => array("update", 128), - TheliaEvents::CATEGORY_DELETE => array("delete", 128), - + TheliaEvents::CATEGORY_CREATE => array("create", 128), + TheliaEvents::CATEGORY_UPDATE => array("update", 128), + TheliaEvents::CATEGORY_DELETE => array("delete", 128), TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128), - TheliaEvents::CATEGORY_CHANGE_POSITION => array("changePosition", 128), - - "action.updateCategoryPositionU" => array("changePositionUp", 128), - "action.updateCategoryPositionDown" => array("changePositionDown", 128), - "action.updateCategoryPosition" => array("changePosition", 128), + TheliaEvents::CATEGORY_UPDATE_POSITION => array("updatePosition", 128) ); } } diff --git a/core/lib/Thelia/Action/Config.php b/core/lib/Thelia/Action/Config.php index 83df28524..f8a7c027c 100644 --- a/core/lib/Thelia/Action/Config.php +++ b/core/lib/Thelia/Action/Config.php @@ -22,7 +22,6 @@ /*************************************************************************************/ namespace Thelia\Action; - use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Model\ConfigQuery; @@ -45,18 +44,9 @@ class Config extends BaseAction implements EventSubscriberInterface { $config = new ConfigModel(); - $config - ->setDispatcher($this->getDispatcher()) - - ->setName($event->getEventName()) - ->setValue($event->getValue()) - ->setLocale($event->getLocale()) - ->setTitle($event->getTitle()) - ->setHidden($event->getHidden()) - ->setSecured($event->getSecured()) - - ->save() - ; + $config->setDispatcher($this->getDispatcher())->setName($event->getEventName())->setValue($event->getValue()) + ->setLocale($event->getLocale())->setTitle($event->getTitle())->setHidden($event->getHidden()) + ->setSecured($event->getSecured())->save(); $event->setConfig($config); } @@ -70,18 +60,13 @@ class Config extends BaseAction implements EventSubscriberInterface { $search = ConfigQuery::create(); - if (null !== $config = $search->findOneById($event->getConfigId())) { + if (null !== $config = $search->findPk($event->getConfigId())) { if ($event->getValue() !== $config->getValue()) { - $config - ->setDispatcher($this->getDispatcher()) + $config->setDispatcher($this->getDispatcher())->setValue($event->getValue())->save(); - ->setValue($event->getValue()) - ->save() - ; - - $event->setConfig($config); + $event->setConfig($config); } } } @@ -95,23 +80,12 @@ class Config extends BaseAction implements EventSubscriberInterface { $search = ConfigQuery::create(); - if (null !== $config = ConfigQuery::create()->findOneById($event->getConfigId())) { + if (null !== $config = ConfigQuery::create()->findPk($event->getConfigId())) { - $config - ->setDispatcher($this->getDispatcher()) - - ->setName($event->getEventName()) - ->setValue($event->getValue()) - ->setHidden($event->getHidden()) - ->setSecured($event->getSecured()) - - ->setLocale($event->getLocale()) - ->setTitle($event->getTitle()) - ->setDescription($event->getDescription()) - ->setChapo($event->getChapo()) - ->setPostscriptum($event->getPostscriptum()) - - ->save(); + $config->setDispatcher($this->getDispatcher())->setName($event->getEventName())->setValue($event->getValue()) + ->setHidden($event->getHidden())->setSecured($event->getSecured())->setLocale($event->getLocale()) + ->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo()) + ->setPostscriptum($event->getPostscriptum())->save(); $event->setConfig($config); } @@ -125,14 +99,11 @@ class Config extends BaseAction implements EventSubscriberInterface public function delete(ConfigDeleteEvent $event) { - if (null !== ($config = ConfigQuery::create()->findOneById($event->getConfigId()))) { + if (null !== ($config = ConfigQuery::create()->findPk($event->getConfigId()))) { - if (! $config->getSecured()) { + if (!$config->getSecured()) { - $config - ->setDispatcher($this->getDispatcher()) - ->delete() - ; + $config->setDispatcher($this->getDispatcher())->delete(); $event->setConfig($config); } @@ -145,10 +116,15 @@ class Config extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::CONFIG_CREATE => array("create", 128), - TheliaEvents::CONFIG_SETVALUE => array("setValue", 128), - TheliaEvents::CONFIG_UPDATE => array("modify", 128), - TheliaEvents::CONFIG_DELETE => array("delete", 128), + TheliaEvents::CONFIG_CREATE => array( + "create", 128 + ), TheliaEvents::CONFIG_SETVALUE => array( + "setValue", 128 + ), TheliaEvents::CONFIG_UPDATE => array( + "modify", 128 + ), TheliaEvents::CONFIG_DELETE => array( + "delete", 128 + ), ); } } diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index 7908d1f0d..946fee375 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -71,7 +71,7 @@ class Currency extends BaseAction implements EventSubscriberInterface { $search = CurrencyQuery::create(); - if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) { + if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) { $currency ->setDispatcher($this->getDispatcher()) @@ -97,7 +97,7 @@ class Currency extends BaseAction implements EventSubscriberInterface { $search = CurrencyQuery::create(); - if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) { + if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) { if ($currency->getByDefault() != $event->getIsDefault()) { @@ -123,7 +123,7 @@ class Currency extends BaseAction implements EventSubscriberInterface public function delete(CurrencyDeleteEvent $event) { - if (null !== ($currency = CurrencyQuery::create()->findOneById($event->getCurrencyId()))) { + if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) { $currency ->setDispatcher($this->getDispatcher()) diff --git a/core/lib/Thelia/Action/Message.php b/core/lib/Thelia/Action/Message.php index faac35bf2..8918913fe 100644 --- a/core/lib/Thelia/Action/Message.php +++ b/core/lib/Thelia/Action/Message.php @@ -70,7 +70,7 @@ class Message extends BaseAction implements EventSubscriberInterface { $search = MessageQuery::create(); - if (null !== $message = MessageQuery::create()->findOneById($event->getMessageId())) { + if (null !== $message = MessageQuery::create()->findPk($event->getMessageId())) { $message ->setDispatcher($this->getDispatcher()) @@ -99,7 +99,7 @@ class Message extends BaseAction implements EventSubscriberInterface public function delete(MessageDeleteEvent $event) { - if (null !== ($message = MessageQuery::create()->findOneById($event->getMessageId()))) { + if (null !== ($message = MessageQuery::create()->findPk($event->getMessageId()))) { $message ->setDispatcher($this->getDispatcher()) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 691cf2198..0c0973db9 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -51,7 +51,7 @@ - + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index dc650d8d6..53c137988 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -85,7 +85,7 @@ - Thelia\Controller\Admin\CategoryController::toggleOnlineAction + Thelia\Controller\Admin\CategoryController::setToggleVisibilityAction diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index fad774023..5b7f8b60a 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -240,6 +240,17 @@ abstract class AbstractCrudController extends BaseAdminController return null; } + /** + * Put in this method post object position change processing if required. + * + * @param unknown $deleteEvent the delete event + * @return Response a response, or null to continue normal processing + */ + protected function performAdditionalUpdatePositionAction($positionChangeEvent) + { + return null; + } + /** * Return the current list order identifier, updating it in the same time. */ @@ -309,14 +320,18 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); } - $this->performAdditionalCreateAction($createEvent); + $response = $this->performAdditionalCreateAction($createEvent); - // Substitute _ID_ in the URL with the ID of the created object - $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl()); - - // Redirect to the success URL - $this->redirect($successUrl); + if ($response == null) { + // Substitute _ID_ in the URL with the ID of the created object + $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl()); + // Redirect to the success URL + $this->redirect($successUrl); + } + else { + return $response; + } } catch (FormValidationException $ex) { // Form cannot be validated @@ -396,16 +411,21 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } - $this->performAdditionalUpdateAction($changeEvent); + $response = $this->performAdditionalUpdateAction($changeEvent); - // If we have to stay on the same page, do not redirect to the succesUrl, - // just redirect to the edit page again. - if ($this->getRequest()->get('save_mode') == 'stay') { - $this->redirectToEditionTemplate($this->getRequest()); + if ($response == null) { + // If we have to stay on the same page, do not redirect to the succesUrl, + // just redirect to the edit page again. + if ($this->getRequest()->get('save_mode') == 'stay') { + $this->redirectToEditionTemplate($this->getRequest()); + } + + // Redirect to the success URL + $this->redirect($changeForm->getSuccessUrl()); + } + else { + return $response; } - - // Redirect to the success URL - $this->redirect($changeForm->getSuccessUrl()); } catch (FormValidationException $ex) { // Form cannot be validated @@ -452,7 +472,14 @@ abstract class AbstractCrudController extends BaseAdminController return $this->errorPage($ex); } - $this->redirectToListTemplate(); + $response = $this->performAdditionalUpdatePositionAction($event); + + if ($response == null) { + $this->redirectToListTemplate(); + } + else { + return $response; + } } /** @@ -475,7 +502,7 @@ abstract class AbstractCrudController extends BaseAdminController return $this->errorPage($ex); } - $this->redirectToRoute('admin.categories.default'); + $this->redirectToListTemplate(); } /** diff --git a/core/lib/Thelia/Controller/Admin/AttributeAvController.php b/core/lib/Thelia/Controller/Admin/AttributeAvController.php index b3afa687d..1ab12a081 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeAvController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeAvController.php @@ -33,7 +33,7 @@ use Thelia\Form\AttributeAvCreationForm; use Thelia\Core\Event\UpdatePositionEvent; /** - * Manages attributes-av sent by mail + * Manages attributes-av * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index 247b89632..48a65baa7 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -37,7 +37,7 @@ use Thelia\Core\Event\AttributeAvUpdateEvent; use Thelia\Core\Event\AttributeEvent; /** - * Manages attributes sent by mail + * Manages attributes * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index fba832ec8..15f620736 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -23,226 +23,160 @@ namespace Thelia\Controller\Admin; -use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\Event\CategoryCreateEvent; -use Thelia\Form\CategoryCreationForm; use Thelia\Core\Event\CategoryDeleteEvent; -use Thelia\Core\Event\CategoryUpdatePositionEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\CategoryUpdateEvent; +use Thelia\Core\Event\CategoryCreateEvent; use Thelia\Model\CategoryQuery; use Thelia\Form\CategoryModificationForm; +use Thelia\Form\CategoryCreationForm; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\CategoryToggleVisibilityEvent; -class CategoryController extends BaseAdminController +/** + * Manages categories + * + * @author Franck Allimant + */ +class CategoryController extends AbstractCrudController { - /** - * Render the categories list, ensuring the sort order is set. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - protected function renderList() - { - return $this->render('categories', $this->getTemplateArgs()); + public function __construct() { + parent::__construct( + 'category', + 'manual', + 'category_order', + + 'admin.categories.default', + 'admin.categories.create', + 'admin.categories.update', + 'admin.categories.delete', + + TheliaEvents::CATEGORY_CREATE, + TheliaEvents::CATEGORY_UPDATE, + TheliaEvents::CATEGORY_DELETE, + TheliaEvents::CATEGORY_TOGGLE_VISIBILITY, + TheliaEvents::CATEGORY_UPDATE_POSITION + ); } - protected function getTemplateArgs() - { - // Get the category ID - $category_id = $this->getRequest()->get('category_id', 0); + protected function getCreationForm() { + return new CategoryCreationForm($this->getRequest()); + } - // Find the current category order - $category_order = $this->getRequest()->get( - 'order', - $this->getSession()->get('admin.category_order', 'manual') + protected function getUpdateForm() { + return new CategoryModificationForm($this->getRequest()); + } + + protected function getCreationEvent($formData) { + $createEvent = new CategoryCreateEvent(); + + $createEvent + ->setTitle($formData['title']) + ->setLocale($formData["locale"]) + ->setParent($formData['parent']) + ->setVisible($formData['visible']) + ; + + return $createEvent; + } + + protected function getUpdateEvent($formData) { + $changeEvent = new CategoryUpdateEvent($formData['id']); + + // Create and dispatch the change event + $changeEvent + ->setLocale($formData['locale']) + ->setTitle($formData['title']) + ->setChapo($formData['chapo']) + ->setDescription($formData['description']) + ->setPostscriptum($formData['postscriptum']) + ->setVisible($formData['visible']) + ->setUrl($formData['url']) + ->setParent($formData['parent']) + ; + + return $changeEvent; + } + + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { + + return new UpdatePositionEvent( + $this->getRequest()->get('category_id', null), + $positionChangeMode, + $positionValue + ); + } + + protected function getDeleteEvent() { + return new CategoryDeleteEvent($this->getRequest()->get('category_id', 0)); + } + + protected function eventContainsObject($event) { + return $event->hasCategory(); + } + + protected function hydrateObjectForm($object) { + + // Prepare the data that will hydrate the form + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'chapo' => $object->getChapo(), + 'description' => $object->getDescription(), + 'postscriptum' => $object->getPostscriptum(), + 'visible' => $object->getVisible(), + 'url' => $object->getUrl($this->getCurrentEditionLocale()), + 'parent' => $object->getParent() ); - $args = array( - 'current_category_id' => $category_id, - 'category_order' => $category_order, + // Setup the object form + return new CategoryModificationForm($this->getRequest(), "form", $data); + } + + protected function getObjectFromEvent($event) { + return $event->hasCategory() ? $event->getCategory() : null; + } + + protected function getExistingObject() { + return CategoryQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('category_id', 0)); + } + + protected function getObjectLabel($object) { + return $object->getTitle(); + } + + protected function getObjectId($object) { + return $object->getId(); + } + + protected function renderListTemplate($currentOrder) { + return $this->render('categories', + array( + 'category_order' => $currentOrder, + 'category_id' => $this->getRequest()->get('category_id', 0) + ) + ); + } + + protected function renderEditionTemplate() { + return $this->render('category-edit', array('category_id' => $this->getRequest()->get('category_id', 0))); + } + + protected function redirectToEditionTemplate() { + $this->redirectToRoute( + "admin.categories.update", + array('category_id' => $this->getRequest()->get('category_id', 0)) ); - - // Store the current sort order in session - $this->getSession()->set('admin.category_order', $category_order); - - return $args; } - /** - * The default action is displaying the categories list. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function defaultAction() - { - if (null !== $response = $this->checkAuth("admin.categories.view")) return $response; - return $this->renderList(); - } - - /** - * Create a new category object - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function createAction() - { - // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.create")) return $response; - - $error_msg = false; - - // Create the Creation Form - $creationForm = new CategoryCreationForm($this->getRequest()); - - try { - - // Validate the form, create the CategoryCreation event and dispatch it. - $form = $this->validateForm($creationForm, "POST"); - - $data = $form->getData(); - - $createEvent = new CategoryCreateEvent( - $data["title"], - $data["parent"], - $data["locale"] - ); - - $this->dispatch(TheliaEvents::CATEGORY_CREATE, $createEvent); - - if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was created.")); - - $createdObject = $createEvent->getCategory(); - - // Log category creation - $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getTitle(), $createdObject->getId())); - - // Substitute _ID_ in the URL with the ID of the created object - $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); - - // Redirect to the success URL - $this->redirect($successUrl); - } catch (FormValidationException $ex) { - // Form cannot be validated - $error_msg = $this->createStandardFormValidationErrorMessage($ex); - } catch (\Exception $ex) { - // Any other error - $error_msg = $ex->getMessage(); - } - - $this->setupFormErrorContext("category creation", $error_msg, $creationForm, $ex); - - // At this point, the form has error, and should be redisplayed. - return $this->renderList(); - } - - /** - * Load a category object for modification, and display the edit template. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function changeAction() - { - // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - - // Load the category object - $category = CategoryQuery::create() - ->joinWithI18n($this->getCurrentEditionLocale()) - ->findOneById($this->getRequest()->get('category_id')); - - if ($category != null) { - - // Prepare the data that will hydrate the form - $data = array( - 'id' => $category->getId(), - 'locale' => $category->getLocale(), - 'title' => $category->getTitle(), - 'chapo' => $category->getChapo(), - 'description' => $category->getDescription(), - 'postscriptum' => $category->getPostscriptum(), - 'parent' => $category->getParent(), - 'visible' => $category->getVisible() ? true : false, - 'url' => $category->getUrl($this->getCurrentEditionLocale()) - // tbc !!! - ); - - // Setup the object form - $changeForm = new CategoryModificationForm($this->getRequest(), "form", $data); - - // Pass it to the parser - $this->getParserContext()->addForm($changeForm); - } - - // Render the edition template. - return $this->render('category-edit', $this->getTemplateArgs()); - } - - /** - * Save changes on a modified category object, and either go back to the category list, or stay on the edition page. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function saveChangeAction() - { - // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - - $error_msg = false; - - // Create the form from the request - $changeForm = new CategoryModificationForm($this->getRequest()); - - // Get the category ID - $category_id = $this->getRequest()->get('category_id'); - - try { - - // Check the form against constraints violations - $form = $this->validateForm($changeForm, "POST"); - - // Get the form field values - $data = $form->getData(); - - $changeEvent = new CategoryUpdateEvent($data['id']); - - // Create and dispatch the change event - $changeEvent - ->setCategoryName($data['name']) - ->setLocale($data["locale"]) - ->setSymbol($data['symbol']) - ->setCode($data['code']) - ->setRate($data['rate']) - ; - - $this->dispatch(TheliaEvents::CATEGORY_UPDATE, $changeEvent); - - if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was updated.")); - - // Log category modification - $changedObject = $changeEvent->getCategory(); - - $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getTitle(), $changedObject->getId())); - - // If we have to stay on the same page, do not redirect to the succesUrl, - // just redirect to the edit page again. - if ($this->getRequest()->get('save_mode') == 'stay') { - $this->redirectToRoute( - "admin.categories.update", - array('category_id' => $category_id) + protected function redirectToListTemplate() { + $this->redirectToRoute( + 'admin.categories.default', + array('category_id' => $this->getRequest()->get('category_id', 0)) ); - } - - // Redirect to the success URL - $this->redirect($changeForm->getSuccessUrl()); - } catch (FormValidationException $ex) { - // Form cannot be validated - $error_msg = $this->createStandardFormValidationErrorMessage($ex); - } catch (\Exception $ex) { - // Any other error - $error_msg = $ex->getMessage(); - } - - $this->setupFormErrorContext("category modification", $error_msg, $changeForm, $ex); - - // At this point, the form has errors, and should be redisplayed. - return $this->render('category-edit', array('category_id' => $category_id)); } /** @@ -253,74 +187,41 @@ class CategoryController extends BaseAdminController // Check current user authorization if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - $changeEvent = new CategoryUpdateEvent($this->getRequest()->get('category_id', 0)); - - // Create and dispatch the change event - $changeEvent->setIsDefault(true); + $event = new CategoryToggleVisibilityEvent($this->getExistingObject()); try { - $this->dispatch(TheliaEvents::CATEGORY_SET_DEFAULT, $changeEvent); + $this->dispatch(TheliaEvents::CATEGORY_TOGGLE_VISIBILITY, $event); } catch (\Exception $ex) { // Any error return $this->errorPage($ex); } - $this->redirectToRoute('admin.categories.default'); + // Ajax response -> no action + return $this->nullResponse(); } - /** - * Update categoryposition - */ - public function updatePositionAction() + protected function performAdditionalDeleteAction($deleteEvent) { - // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + // Redirect to parent category list + $this->redirectToRoute( + 'admin.categories.default', + array('category_id' => $deleteEvent->getCategory()->getParent()) + ); + } - try { - $mode = $this->getRequest()->get('mode', null); + protected function performAdditionalUpdatePositionAction($event) + { - if ($mode == 'up') - $mode = CategoryUpdatePositionEvent::POSITION_UP; - else if ($mode == 'down') - $mode = CategoryUpdatePositionEvent::POSITION_DOWN; - else - $mode = CategoryUpdatePositionEvent::POSITION_ABSOLUTE; + $category = CategoryQuery::create()->findPk($event->getObjectId()); - $position = $this->getRequest()->get('position', null); - - $event = new CategoryUpdatePositionEvent( - $this->getRequest()->get('category_id', null), - $mode, - $this->getRequest()->get('position', null) + if ($category != null) { + // Redirect to parent category list + $this->redirectToRoute( + 'admin.categories.default', + array('category_id' => $category->getParent()) ); - - $this->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $event); - } catch (\Exception $ex) { - // Any error - return $this->errorPage($ex); } - $this->redirectToRoute('admin.categories.default'); - } - - /** - * Delete a category object - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function deleteAction() - { - // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.delete")) return $response; - - // Get the category id, and dispatch the deleted request - $event = new CategoryDeleteEvent($this->getRequest()->get('category_id')); - - $this->dispatch(TheliaEvents::CATEGORY_DELETE, $event); - - if ($event->hasCategory()) - $this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $event->getCategory()->getTitle(), $event->getCategory()->getId())); - - $this->redirectToRoute('admin.categories.default'); + return null; } } diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index ff0e4bb39..8701710b0 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -33,7 +33,7 @@ use Thelia\Form\ConfigCreationForm; use Thelia\Core\Event\UpdatePositionEvent; /** - * Manages variables sent by mail + * Manages variables * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 4f3fdaaea..f0081d698 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -33,7 +33,7 @@ use Thelia\Form\CurrencyCreationForm; use Thelia\Core\Event\UpdatePositionEvent; /** - * Manages currencies sent by mail + * Manages currencies * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/FeatureAvController.php b/core/lib/Thelia/Controller/Admin/FeatureAvController.php index 25c7a5495..fc6571ccc 100644 --- a/core/lib/Thelia/Controller/Admin/FeatureAvController.php +++ b/core/lib/Thelia/Controller/Admin/FeatureAvController.php @@ -33,7 +33,7 @@ use Thelia\Form\FeatureAvCreationForm; use Thelia\Core\Event\UpdatePositionEvent; /** - * Manages features-av sent by mail + * Manages features-av * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/FeatureController.php b/core/lib/Thelia/Controller/Admin/FeatureController.php index 92cb89d33..f81f55919 100644 --- a/core/lib/Thelia/Controller/Admin/FeatureController.php +++ b/core/lib/Thelia/Controller/Admin/FeatureController.php @@ -37,7 +37,7 @@ use Thelia\Core\Event\FeatureAvUpdateEvent; use Thelia\Core\Event\FeatureEvent; /** - * Manages features sent by mail + * Manages features * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Controller/Admin/TemplateController.php b/core/lib/Thelia/Controller/Admin/TemplateController.php index 3685a359a..c9e30612c 100644 --- a/core/lib/Thelia/Controller/Admin/TemplateController.php +++ b/core/lib/Thelia/Controller/Admin/TemplateController.php @@ -41,7 +41,7 @@ use Thelia\Core\Event\TemplateAddFeatureEvent; use Thelia\Core\Event\TemplateDeleteFeatureEvent; /** - * Manages templates sent by mail + * Manages product templates * * @author Franck Allimant */ diff --git a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php index 5a687217c..41529019c 100644 --- a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php @@ -28,13 +28,7 @@ class CategoryCreateEvent extends CategoryEvent protected $title; protected $parent; protected $locale; - - public function __construct($title, $parent, $locale) - { - $this->title = $title; - $this->parent = $parent; - $this->locale = $locale; - } + protected $visible; public function getTitle() { @@ -71,4 +65,16 @@ class CategoryCreateEvent extends CategoryEvent return $this; } + + public function getVisible() + { + return $this->visible; + } + + public function setVisible($visible) + { + $this->visible = $visible; + + return $this; + } } diff --git a/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php new file mode 100644 index 000000000..f90378e38 --- /dev/null +++ b/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class CategoryToggleVisibilityEvent extends CategoryEvent +{ +} diff --git a/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php index 44e760549..f5f775a22 100644 --- a/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php @@ -32,7 +32,6 @@ class CategoryUpdateEvent extends CategoryCreateEvent protected $postscriptum; protected $url; - protected $visibility; protected $parent; public function __construct($category_id) @@ -100,18 +99,6 @@ class CategoryUpdateEvent extends CategoryCreateEvent return $this; } - public function getVisibility() - { - return $this->visibility; - } - - public function setVisibility($visibility) - { - $this->visibility = $visibility; - - return $this; - } - public function getParent() { return $this->parent; diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 2867762aa..a305f134a 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -145,50 +145,21 @@ final class TheliaEvents // -- END ADDRESS MANAGEMENT --------------------------------------------------------- - /** - * Sent once the category creation form has been successfully validated, and before category insertion in the database. - */ - const BEFORE_CREATECATEGORY = "action.before_createcategory"; + // -- Categories management ----------------------------------------------- - /** - * Create, change or delete a category - */ - const CATEGORY_CREATE = "action.createCategory"; - const CATEGORY_UPDATE = "action.updateCategory"; - const CATEGORY_DELETE = "action.deleteCategory"; - - /** - * Toggle category visibility - */ + const CATEGORY_CREATE = "action.createCategory"; + const CATEGORY_UPDATE = "action.updateCategory"; + const CATEGORY_DELETE = "action.deleteCategory"; const CATEGORY_TOGGLE_VISIBILITY = "action.toggleCategoryVisibility"; + const CATEGORY_UPDATE_POSITION = "action.updateCategoryPosition"; - /** - * Change category position - */ - const CATEGORY_CHANGE_POSITION = "action.updateCategoryPosition"; - - /** - * Sent just after a successful insert of a new category in the database. - */ + const BEFORE_CREATECATEGORY = "action.before_createcategory"; const AFTER_CREATECATEGORY = "action.after_createcategory"; - /** - * Sent befonre deleting a category - */ - const BEFORE_DELETECATEGORY = "action.before_deletecategory"; - /** - * Sent just after a successful delete of a category from the database. - */ + const BEFORE_DELETECATEGORY = "action.before_deletecategory"; const AFTER_DELETECATEGORY = "action.after_deletecategory"; - /** - * Sent just before a successful change of a category in the database. - */ const BEFORE_UPDATECATEGORY = "action.before_updateCategory"; - - /** - * Sent just after a successful change of a category in the database. - */ const AFTER_UPDATECATEGORY = "action.after_updateCategory"; /** diff --git a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php index afcd0410e..712767954 100755 --- a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php +++ b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php @@ -59,7 +59,7 @@ class CategoryTree extends BaseI18nLoop } // changement de rubrique - protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult) + protected function buildCategoryTree($parent, $visible, $level, $max_level, $exclude, LoopResult &$loopResult) { if ($level > $max_level) return; @@ -73,7 +73,7 @@ class CategoryTree extends BaseI18nLoop if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); - $search->filterById($exclude, Criteria::NOT_IN); + if ($exclude != null) $search->filterById($exclude, Criteria::NOT_IN); $search->orderByPosition(Criteria::ASC); diff --git a/core/lib/Thelia/Form/CategoryCreationForm.php b/core/lib/Thelia/Form/CategoryCreationForm.php index 5dce6a049..172b09ee6 100755 --- a/core/lib/Thelia/Form/CategoryCreationForm.php +++ b/core/lib/Thelia/Form/CategoryCreationForm.php @@ -39,7 +39,8 @@ class CategoryCreationForm extends BaseForm "for" => "title" ) )) - ->add("parent", "integer", array( + ->add("parent", "text", array( + "label" => Translator::getInstance()->trans("Parent category *"), "constraints" => array( new NotBlank() ) @@ -49,6 +50,9 @@ class CategoryCreationForm extends BaseForm new NotBlank() ) )) + ->add("visible", "integer", array( + "label" => Translator::getInstance()->trans("This category is online on the front office.") + )) ; } diff --git a/core/lib/Thelia/Form/CategoryModificationForm.php b/core/lib/Thelia/Form/CategoryModificationForm.php index d9de36d16..42b5893c1 100644 --- a/core/lib/Thelia/Form/CategoryModificationForm.php +++ b/core/lib/Thelia/Form/CategoryModificationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\GreaterThan; use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\NotBlank; class CategoryModificationForm extends CategoryCreationForm { @@ -36,12 +37,13 @@ class CategoryModificationForm extends CategoryCreationForm $this->formBuilder ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) - ->add("visible", "checkbox", array( - "label" => Translator::getInstance()->trans("This category is online on the front office.") + ->add("url", "text", array( + "label" => Translator::getInstance()->trans("Rewriten URL *"), + "constraints" => array(new NotBlank()) )) ; - // Add standard description fields + // Add standard description fields, excluding title and locale, which a re defined in parent class $this->addStandardDescFields(array('title', 'locale')); } diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index ced10c94b..5533eaf42 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -28,26 +28,6 @@ class Category extends BaseCategory return URL::getInstance()->retrieve('category', $this->getId(), $locale)->toString(); } - /** - * Create a new category. - * - * @param string $title the category title - * @param int $parent the ID of the parent category - * @param string $locale the locale of the title - */ - public function create($title, $parent, $locale) - { - $this - ->setLocale($locale) - ->setTitle($title) - ->setParent($parent) - ->setVisible(1) - ->setPosition($this->getNextPosition($parent)) - ; - - $this->save(); - } - /** * * count all products for current category and sub categories @@ -73,6 +53,8 @@ class Category extends BaseCategory public function preInsert(ConnectionInterface $con = null) { + $this->setPosition($this->getNextPosition($this->parent)); + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECATEGORY, new CategoryEvent($this)); return true; @@ -98,6 +80,8 @@ class Category extends BaseCategory public function preDelete(ConnectionInterface $con = null) { $this->dispatchEvent(TheliaEvents::BEFORE_DELETECATEGORY, new CategoryEvent($this)); + + return true; } public function postDelete(ConnectionInterface $con = null) diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index 50cd9bde6..6dc130918 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -34,7 +34,7 @@ .topbar { - background: url("@{imgDir}/top.jpg") repeat-x; + background: url("@{imgDir}/top.jpg") repeat-x; font-weight: bold; .version-info { @@ -202,7 +202,7 @@ border-bottom: 2px solid #A5CED8; margin-bottom: 0.5em; } - + // The action bar on the right .actions { text-align: right; @@ -217,6 +217,10 @@ text-transform: none; } } + + .inner-actions { + margin-top: 0.5em; + } } // The overall form container diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 6fe06f8bc..32b9e6cba 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -1,396 +1,260 @@ {extends file="admin-layout.tpl"} -{block name="page-title"}{intl l='Catalog'}{/block} +{block name="page-title"}{intl l='Categories'}{/block} -{block name="check-permissions"}admin.catalog.view{/block} +{block name="check-permissions"}admin.categories.view{/block} {block name="main-content"} -
-
+
- {include file="includes/catalog-breadcrumb.html"} +
- {module_include location='catalog_top'} + {include file="includes/catalog-breadcrumb.html"} -
-
-
- - - {module_include location='catalog_bottom'} - - + {module_include location='category_list_row'} - {* Adding a new Category *} + + + + + + + {/loop} + + {/ifloop} + + {elseloop rel="category_list"} + + + + + + {/elseloop} +
- {* display parent category name, and get current cat ID *} - {loop name="category_title" type="category" visible="*" id=$current_category_id} - {intl l="Categories in %cat" cat=$TITLE} - {$cat_id = $ID} - {/loop} - {elseloop rel="category_title"} - {intl l="Top level categories"} - {/elseloop} + {module_include location='categories_top'} - {module_include location='category_list_caption'} +
+
+
+ + + {module_include location='category_list_caption'} - {ifloop rel="category_list"} - - - + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} + + + + {/loop} + - + {ifloop rel="category_list"} + + + - + - {module_include location='category_list_header'} + - + {module_include location='category_list_header'} - + - - - + - - {loop name="category_list" type="category" visible="*" parent=$current_category_id order=$category_order backend_context="1" lang=$lang_id} - - + + + - + + {loop name="category_list" type="category" visible="*" parent=$category_id order=$category_order backend_context="1" lang=$lang_id} + + - - - {module_include location='category_list_row'} - - - - - - - - {/loop} - - {/ifloop} - - {elseloop rel="category_list"} - - - - - - {/elseloop} -
+ {* display parent category name, and get current cat ID *} + {loop name="category_title" type="category" visible="*" id=$category_id} + {intl l="Categories in %cat" cat=$TITLE} + {$cat_id = $ID} + {/loop} + {elseloop rel="category_title"} + {intl l="Top level categories"} + {/elseloop} - {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} - - - - {/loop} -
- {admin_sortable_header - current_order=$category_order - order='id' - reverse_order='id_reverse' - path={url path='/admin/catalog' id_category=$current_category_id} - label="{intl l='ID'}" - } -  
+ {admin_sortable_header + current_order=$category_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='ID'}" + } + - {admin_sortable_header - current_order=$category_order - order='alpha' - reverse_order='alpha_reverse' - path={url path='/admin/catalog' id_category=$current_category_id} - label="{intl l='Category title'}" - } -   + {admin_sortable_header + current_order=$category_order + order='alpha' + reverse_order='alpha_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Category title'}" + } + - {admin_sortable_header - current_order=$category_order - order='visible' - reverse_order='visible_reverse' - path={url path='/admin/catalog' id_category=$current_category_id} - label="{intl l='Online'}" - } - - {admin_sortable_header - current_order=$category_order - order='manual' - reverse_order='manual_reverse' - path={url path='/admin/catalog' id_category=$current_category_id} - label="{intl l='Position'}" - } - + {admin_sortable_header + current_order=$category_order + order='visible' + reverse_order='visible_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Online'}" + } + {intl l='Actions'}
+ {admin_sortable_header + current_order=$category_order + order='manual' + reverse_order='manual_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Position'}" + } +
{$ID}{intl l='Actions'}
- {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - {$TITLE} - {/loop} -
{$ID} - - {$TITLE} - - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} -
- -
- {/loop} - - {elseloop rel="can_change"} -
- -
- {/elseloop} -
- {admin_position_block - permission="admin.categories.edit" - path={url path='admin/category/update-position' category_id=$ID} - url_parameter="category_id" - in_place_edit_class="categoryPositionChange" - position=$POSITION - id=$ID - } - -
- - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"} - - {/loop} -
-
-
- {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} - {intl l="This category has no sub-categories. To create a new one, click the + button above."} - {/loop} - - {elseloop rel="can_create"} - {intl l="This category has no sub-categories."} - {/elseloop} -
-
-
-
-
- -
-
-
- - - - {ifloop rel="product_list"} - - - - - - - - - - - - - - - - {loop name="product_list" type="product" category=$current_category_id order="manual"} - - - - - - - - {module_include location='product_list_row'} - - - - - - - - {/loop} - - {/ifloop} + - {elseloop rel="product_list"} - - - - - - {/elseloop} -
- {* display parent category name *} - {loop name="category_title" type="category" visible="*" id=$current_category_id} - {intl l="Products in %cat" cat=$TITLE} - {/loop} - - {elseloop rel="category_title"} - {intl l="Top level Products"} - {/elseloop} - - {module_include location='product_list_caption'} - - - - -
- {admin_sortable_header - current_order=$product_order - order='id' - reverse_order='id_reverse' - path={url path='/admin/product' category_id=$current_category_id} - label="{intl l='ID'}" - } - -   - {admin_sortable_header - current_order=$product_order - order='ref' - reverse_order='ref_reverse' - path={url path='/admin/product' category_id=$current_category_id} - label="{intl l='Reference'}" - } - - {admin_sortable_header - current_order=$product_order - order='alpha' - reverse_order='alpha_reverse' - path={url path='/admin/product' category_id=$current_category_id} - label="{intl l='Product title'}" - } - - {module_include location='product_list_header'} - - - {admin_sortable_header - current_order=$product_order - order='visible' - reverse_order='visible_reverse' - path={url path='/admin/product' category_id=$current_category_id} - label="{intl l='Online'}" - } - - {admin_sortable_header - current_order=$product_order - order='manual' - reverse_order='manual_reverse' - path={url path='/admin/product' category_id=$current_category_id} - label="{intl l='Position'}" - } -  
{$ID} - {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - - {$TITLE} - - {/loop} - - {$REF}{$TITLE} - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"} -
- -
- {/loop} - - {elseloop rel="can_change"} -
- -
- {/elseloop} -
- {admin_position_block - permission="admin.product.edit" - path={url path='admin/product' category_id=$ID} - url_parameter="product_id" - in_place_edit_class="productPositionChange" - position=$POSITION - id=$ID - } - -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.edit"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.delete"} - +
+ {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} + {$TITLE} {/loop} - -
{intl l="This category doesn't have any products. To add a new product, click the + button above."}
-
-
-
+
+ + {$TITLE} + + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} +
+ +
+ {/loop} - {form name="thelia.admin.category.creation"} + {elseloop rel="can_change"} +
+ +
+ {/elseloop} +
+ {admin_position_block + permission="admin.categories.edit" + path={url path='admin/categories/update-position' category_id=$ID} + url_parameter="category_id" + in_place_edit_class="categoryPositionChange" + position=$POSITION + id=$ID + } + +
+ + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} + + {/loop} + + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"} + + {/loop} +
+
+
+ {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} + {intl l="This category has no sub-categories. To create a new one, click the + button above."} + {/loop} + + {elseloop rel="can_create"} + {intl l="This category has no sub-categories."} + {/elseloop} +
+
+
+
+
+ + {module_include location='categories_bottom'} + +
+
+ + + {* Adding a new category *} + + {form name="thelia.admin.category.creation"} {* Capture the dialog body, to pass it to the generic dialog *} {capture "category_creation_dialog"} {form_hidden_fields form=$form} - {form_field form=$form field='success_url'} - {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} - - {/form_field} + {form_field form=$form field='success_url'} + {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} + + {/form_field} - {form_field form=$form field='parent'} - - {/form_field} + {form_field form=$form field='parent'} + + {/form_field} - {form_field form=$form field='title'} -
- + {form_field form=$form field='title'} +
+ + {loop type="lang" name="default-lang" default_only="1"} +
+ + $TITLE +
- {loop type="lang" name="default-lang" default_only="1"} +
{intl l='Enter here the category name in the default language (%title)' title="$TITLE"}
-
- - $TITLE -
+ {* Switch edition to the current locale *} + -
{intl l='Enter here the category name in the default language (%title)' title="$TITLE"}
+ {form_field form=$form field='locale'} + + {/form_field} + {/loop} +
+ {/form_field} - {* Switch edition to the current locale *} - - - {form_field form=$form field='locale'} - - {/form_field} - {/loop} -
- {/form_field} + {form_field form=$form field='visible'} +
+
+ +
+
+ {/form_field} {module_include location='category_create_form'} - {/capture} + {/capture} - {include - file = "includes/generic-create-dialog.html" + {include + file = "includes/generic-create-dialog.html" - dialog_id = "add_category_dialog" - dialog_title = {intl l="Create a new category"} - dialog_body = {$smarty.capture.category_creation_dialog nofilter} + dialog_id = "category_creation_dialog" + dialog_title = {intl l="Create a new category"} + dialog_body = {$smarty.capture.category_creation_dialog nofilter} - dialog_ok_label = {intl l="Create this category"} - dialog_cancel_label = {intl l="Cancel"} + dialog_ok_label = {intl l="Create this category"} - form_action = {url path='/admin/categories/create'} - form_enctype = {form_enctype form=$form} - form_error_message = $form_error_message - } + form_action = {url path='/admin/categories/create'} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } {/form} - {* Delete category confirmation dialog *} + + {* Delete confirmation dialog *} {capture "category_delete_dialog"} - - + {module_include location='category_delete_form'} @@ -399,9 +263,9 @@ {include file = "includes/generic-confirm-dialog.html" - dialog_id = "delete_category_dialog" - dialog_title = {intl l="Delete a category"} - dialog_message = {intl l="Do you really want to delete this category, and all its contents ?"} + dialog_id = "category_delete_dialog" + dialog_title = {intl l="Delete category"} + dialog_message = {intl l="Do you really want to delete this category and all its content ?"} form_action = {url path='/admin/categories/delete'} form_content = {$smarty.capture.category_delete_dialog nofilter} @@ -410,108 +274,76 @@ {block name="javascript-initialization"} - {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} - - {/javascripts} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} - {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'} - - {/javascripts} + {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'} + + {/javascripts} - + {/block} \ No newline at end of file diff --git a/templates/admin/default/category-edit.html b/templates/admin/default/category-edit.html index e01849475..9fa9e18e4 100755 --- a/templates/admin/default/category-edit.html +++ b/templates/admin/default/category-edit.html @@ -11,7 +11,7 @@ {include file="includes/catalog-breadcrumb.html"}
- {loop name="category_edit" type="category" visible="*" id="{$current_category_id}" backend_context="1" lang="$edit_language_id"} + {loop name="category_edit" type="category" visible="*" id="{$category_id}" backend_context="1" lang="$edit_language_id"}
@@ -25,189 +25,126 @@
- +
+
-
- -
+
-
-
-
+
- {include file="includes/inner-form-toolbar.html" close_url="{url path='admin/catalog/category/edit' category_id=$current_category_id}"} +
-
-
-
- + {form name="thelia.admin.category.modification"} + -
- -
-
+ {include file="includes/inner-form-toolbar.html" close_url="{url path='/admin/categories' category_id=$category_id}"} -
- + {* Be sure to get the category ID, even if the form could not be validated *} + -
- -
-
+ {form_hidden_fields form=$form} -
- + {form_field form=$form field='success_url'} + + {/form_field} -
- + {form_field form=$form field='locale'} + + {/form_field} -
-
+ {if $form_error}
{$form_error_message}
{/if} -
- + {include file="includes/standard-description-form-fields.html"} -
- -
-
+ {form_field form=$form field='url'} +
+ -
- + +
+ {/form_field} -
- -
{intl l="The rewritten URL to the category page. Click \"Use Default\" button to use the default URL. Use only digits, letters, - and _ characters."}
-
-
+
+
+ {form_field form=$form field='parent'} +
-
-
+ -
-
-
-   -
-

{intl l='Category created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}}

-
-
-
-
+ +
+ {/form_field} +
+ +
+ {form_field form=$form field='visible'} +
+ +
+ +
+
+ {/form_field} +
+
-
-
- - -
- -
-
-
- -
-
- - -
- -
-
-
-
- -
- - -
- +   +
+

{intl l='Category created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}

-
+
-
-
-
+ + {/form} +
+
-
-

Images

-
+
+ klljkmk +
-
-

Documents

-
+
+
-
-

Modules

-
+
+
-
-
- - {/loop} +
+
+
+
+
+ {/loop}
@@ -217,10 +154,6 @@ + + + \ No newline at end of file diff --git a/web/install/header.php b/web/install/header.php new file mode 100644 index 000000000..983fa51ce --- /dev/null +++ b/web/install/header.php @@ -0,0 +1,59 @@ +. */ +/* */ +/*************************************************************************************/ +session_start(); +include 'bootstrap.php'; +?> + + + + Installation + + + + + +
+
+
+
+
Version undefined
+
+
+
+
+
+
+
+
+
+

Thelia installation wizard

+
+
    +
  • 1Welcome
  • +
  • 2Checking permissions
  • +
  • 3Database connection
  • +
  • 4Database selection
  • +
  • 5General information
  • +
  • 6Thanks
  • +
+
\ No newline at end of file diff --git a/web/install/index.php b/web/install/index.php new file mode 100644 index 000000000..884ca11b7 --- /dev/null +++ b/web/install/index.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ +?> + +
+

+Welcome in the Thelia installation wizard. +

+

+We will guide you throughout this process to install any application on your system. +

+
+ + \ No newline at end of file diff --git a/web/install/permission.php b/web/install/permission.php new file mode 100644 index 000000000..fca995457 --- /dev/null +++ b/web/install/permission.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ +?> +getContainer()->get('thelia.translator')); +$isValid = $checkPermission->exec(); +$validationMessage = $checkPermission->getValidationMessages(); +$_SESSION['install']['return_step'] = 'permission.php'; +$_SESSION['install']['continue'] = $isValid; +$_SESSION['install']['current_step'] = 'permission.php'; +$_SESSION['install']['step'] = 2; +?> +
+

Checking permissions

+
    + $data): ?> +
  • + + +
  • + +
+ +
+
+ + Continue + + refresh + +
+ \ No newline at end of file diff --git a/web/install/script.js b/web/install/script.js new file mode 100644 index 000000000..b26e7612e --- /dev/null +++ b/web/install/script.js @@ -0,0 +1,1999 @@ +/** + * bootstrap.js v3.0.0 by @fat and @mdo + * Copyright 2013 Twitter Inc. + * http://www.apache.org/licenses/LICENSE-2.0 + */ +if (!jQuery) { throw new Error("Bootstrap requires jQuery") } + +/* ======================================================================== + * Bootstrap: transition.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#transitions + * ======================================================================== + * Copyright 2013 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) + // ============================================================ + + function transitionEnd() { + var el = document.createElement('bootstrap') + + var transEndEventNames = { + 'WebkitTransition' : 'webkitTransitionEnd' + , 'MozTransition' : 'transitionend' + , 'OTransition' : 'oTransitionEnd otransitionend' + , 'transition' : 'transitionend' + } + + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + return { end: transEndEventNames[name] } + } + } + } + + // http://blog.alexmaccaw.com/css-transitions + $.fn.emulateTransitionEnd = function (duration) { + var called = false, $el = this + $(this).one($.support.transition.end, function () { called = true }) + var callback = function () { if (!called) $($el).trigger($.support.transition.end) } + setTimeout(callback, duration) + return this + } + + $(function () { + $.support.transition = transitionEnd() + }) + +}(window.jQuery); + +/* ======================================================================== + * Bootstrap: alert.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#alerts + * ======================================================================== + * Copyright 2013 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // ALERT CLASS DEFINITION + // ====================== + + var dismiss = '[data-dismiss="alert"]' + var Alert = function (el) { + $(el).on('click', dismiss, this.close) + } + + Alert.prototype.close = function (e) { + var $this = $(this) + var selector = $this.attr('data-target') + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } + + var $parent = $(selector) + + if (e) e.preventDefault() + + if (!$parent.length) { + $parent = $this.hasClass('alert') ? $this : $this.parent() + } + + $parent.trigger(e = $.Event('close.bs.alert')) + + if (e.isDefaultPrevented()) return + + $parent.removeClass('in') + + function removeElement() { + $parent.trigger('closed.bs.alert').remove() + } + + $.support.transition && $parent.hasClass('fade') ? + $parent + .one($.support.transition.end, removeElement) + .emulateTransitionEnd(150) : + removeElement() + } + + + // ALERT PLUGIN DEFINITION + // ======================= + + var old = $.fn.alert + + $.fn.alert = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.alert') + + if (!data) $this.data('bs.alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } + + $.fn.alert.Constructor = Alert + + + // ALERT NO CONFLICT + // ================= + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + + // ALERT DATA-API + // ============== + + $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + +}(window.jQuery); + +/* ======================================================================== + * Bootstrap: button.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#buttons + * ======================================================================== + * Copyright 2013 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // BUTTON PUBLIC CLASS DEFINITION + // ============================== + + var Button = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + } + + Button.DEFAULTS = { + loadingText: 'loading...' + } + + Button.prototype.setState = function (state) { + var d = 'disabled' + var $el = this.$element + var val = $el.is('input') ? 'val' : 'html' + var data = $el.data() + + state = state + 'Text' + + if (!data.resetText) $el.data('resetText', $el[val]()) + + $el[val](data[state] || this.options[state]) + + // push to event loop to allow forms to submit + setTimeout(function () { + state == 'loadingText' ? + $el.addClass(d).attr(d, d) : + $el.removeClass(d).removeAttr(d); + }, 0) + } + + Button.prototype.toggle = function () { + var $parent = this.$element.closest('[data-toggle="buttons"]') + + if ($parent.length) { + var $input = this.$element.find('input') + .prop('checked', !this.$element.hasClass('active')) + .trigger('change') + if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active') + } + + this.$element.toggleClass('active') + } + + + // BUTTON PLUGIN DEFINITION + // ======================== + + var old = $.fn.button + + $.fn.button = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.button') + var options = typeof option == 'object' && option + + if (!data) $this.data('bs.button', (data = new Button(this, options))) + + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } + + $.fn.button.Constructor = Button + + + // BUTTON NO CONFLICT + // ================== + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + + // BUTTON DATA-API + // =============== + + $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + $btn.button('toggle') + e.preventDefault() + }) + +}(window.jQuery); + +/* ======================================================================== + * Bootstrap: carousel.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#carousel + * ======================================================================== + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // CAROUSEL CLASS DEFINITION + // ========================= + + var Carousel = function (element, options) { + this.$element = $(element) + this.$indicators = this.$element.find('.carousel-indicators') + this.options = options + this.paused = + this.sliding = + this.interval = + this.$active = + this.$items = null + + this.options.pause == 'hover' && this.$element + .on('mouseenter', $.proxy(this.pause, this)) + .on('mouseleave', $.proxy(this.cycle, this)) + } + + Carousel.DEFAULTS = { + interval: 5000 + , pause: 'hover' + , wrap: true + } + + Carousel.prototype.cycle = function (e) { + e || (this.paused = false) + + this.interval && clearInterval(this.interval) + + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + + return this + } + + Carousel.prototype.getActiveIndex = function () { + this.$active = this.$element.find('.item.active') + this.$items = this.$active.parent().children() + + return this.$items.index(this.$active) + } + + Carousel.prototype.to = function (pos) { + var that = this + var activeIndex = this.getActiveIndex() + + if (pos > (this.$items.length - 1) || pos < 0) return + + if (this.sliding) return this.$element.one('slid', function () { that.to(pos) }) + if (activeIndex == pos) return this.pause().cycle() + + return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) + } + + Carousel.prototype.pause = function (e) { + e || (this.paused = true) + + if (this.$element.find('.next, .prev').length && $.support.transition.end) { + this.$element.trigger($.support.transition.end) + this.cycle(true) + } + + this.interval = clearInterval(this.interval) + + return this + } + + Carousel.prototype.next = function () { + if (this.sliding) return + return this.slide('next') + } + + Carousel.prototype.prev = function () { + if (this.sliding) return + return this.slide('prev') + } + + Carousel.prototype.slide = function (type, next) { + var $active = this.$element.find('.item.active') + var $next = next || $active[type]() + var isCycling = this.interval + var direction = type == 'next' ? 'left' : 'right' + var fallback = type == 'next' ? 'first' : 'last' + var that = this + + if (!$next.length) { + if (!this.options.wrap) return + $next = this.$element.find('.item')[fallback]() + } + + this.sliding = true + + isCycling && this.pause() + + var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction }) + + if ($next.hasClass('active')) return + + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + this.$element.one('slid', function () { + var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) + $nextIndicator && $nextIndicator.addClass('active') + }) + } + + if ($.support.transition && this.$element.hasClass('slide')) { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return + $next.addClass(type) + $next[0].offsetWidth // force reflow + $active.addClass(direction) + $next.addClass(direction) + $active + .one($.support.transition.end, function () { + $next.removeClass([type, direction].join(' ')).addClass('active') + $active.removeClass(['active', direction].join(' ')) + that.sliding = false + setTimeout(function () { that.$element.trigger('slid') }, 0) + }) + .emulateTransitionEnd(600) + } else { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return + $active.removeClass('active') + $next.addClass('active') + this.sliding = false + this.$element.trigger('slid') + } + + isCycling && this.cycle() + + return this + } + + + // CAROUSEL PLUGIN DEFINITION + // ========================== + + var old = $.fn.carousel + + $.fn.carousel = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.carousel') + var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) + var action = typeof option == 'string' ? option : options.slide + + if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) + if (typeof option == 'number') data.to(option) + else if (action) data[action]() + else if (options.interval) data.pause().cycle() + }) + } + + $.fn.carousel.Constructor = Carousel + + + // CAROUSEL NO CONFLICT + // ==================== + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + + + // CAROUSEL DATA-API + // ================= + + $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { + var $this = $(this), href + var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 + var options = $.extend({}, $target.data(), $this.data()) + var slideIndex = $this.attr('data-slide-to') + if (slideIndex) options.interval = false + + $target.carousel(options) + + if (slideIndex = $this.attr('data-slide-to')) { + $target.data('bs.carousel').to(slideIndex) + } + + e.preventDefault() + }) + + $(window).on('load', function () { + $('[data-ride="carousel"]').each(function () { + var $carousel = $(this) + $carousel.carousel($carousel.data()) + }) + }) + +}(window.jQuery); + +/* ======================================================================== + * Bootstrap: collapse.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#collapse + * ======================================================================== + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // COLLAPSE PUBLIC CLASS DEFINITION + // ================================ + + var Collapse = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Collapse.DEFAULTS, options) + this.transitioning = null + + if (this.options.parent) this.$parent = $(this.options.parent) + if (this.options.toggle) this.toggle() + } + + Collapse.DEFAULTS = { + toggle: true + } + + Collapse.prototype.dimension = function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } + + Collapse.prototype.show = function () { + if (this.transitioning || this.$element.hasClass('in')) return + + var startEvent = $.Event('show.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + var actives = this.$parent && this.$parent.find('> .panel > .in') + + if (actives && actives.length) { + var hasData = actives.data('bs.collapse') + if (hasData && hasData.transitioning) return + actives.collapse('hide') + hasData || actives.data('bs.collapse', null) + } + + var dimension = this.dimension() + + this.$element + .removeClass('collapse') + .addClass('collapsing') + [dimension](0) + + this.transitioning = 1 + + var complete = function () { + this.$element + .removeClass('collapsing') + .addClass('in') + [dimension]('auto') + this.transitioning = 0 + this.$element.trigger('shown.bs.collapse') + } + + if (!$.support.transition) return complete.call(this) + + var scrollSize = $.camelCase(['scroll', dimension].join('-')) + + this.$element + .one($.support.transition.end, $.proxy(complete, this)) + .emulateTransitionEnd(350) + [dimension](this.$element[0][scrollSize]) + } + + Collapse.prototype.hide = function () { + if (this.transitioning || !this.$element.hasClass('in')) return + + var startEvent = $.Event('hide.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + var dimension = this.dimension() + + this.$element + [dimension](this.$element[dimension]()) + [0].offsetHeight + + this.$element + .addClass('collapsing') + .removeClass('collapse') + .removeClass('in') + + this.transitioning = 1 + + var complete = function () { + this.transitioning = 0 + this.$element + .trigger('hidden.bs.collapse') + .removeClass('collapsing') + .addClass('collapse') + } + + if (!$.support.transition) return complete.call(this) + + this.$element + [dimension](0) + .one($.support.transition.end, $.proxy(complete, this)) + .emulateTransitionEnd(350) + } + + Collapse.prototype.toggle = function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } + + + // COLLAPSE PLUGIN DEFINITION + // ========================== + + var old = $.fn.collapse + + $.fn.collapse = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.collapse') + var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) + + if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) + if (typeof option == 'string') data[option]() + }) + } + + $.fn.collapse.Constructor = Collapse + + + // COLLAPSE NO CONFLICT + // ==================== + + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + // COLLAPSE DATA-API + // ================= + + $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) { + var $this = $(this), href + var target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 + var $target = $(target) + var data = $target.data('bs.collapse') + var option = data ? 'toggle' : $this.data() + var parent = $this.attr('data-parent') + var $parent = parent && $(parent) + + if (!data || !data.transitioning) { + if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed') + $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed') + } + + $target.collapse(option) + }) + +}(window.jQuery); + +/* ======================================================================== + * Bootstrap: dropdown.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#dropdowns + * ======================================================================== + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ + + ++function ($) { "use strict"; + + // DROPDOWN CLASS DEFINITION + // ========================= + + var backdrop = '.dropdown-backdrop' + var toggle = '[data-toggle=dropdown]' + var Dropdown = function (element) { + var $el = $(element).on('click.bs.dropdown', this.toggle) + } + + Dropdown.prototype.toggle = function (e) { + var $this = $(this) + + if ($this.is('.disabled, :disabled')) return + + var $parent = getParent($this) + var isActive = $parent.hasClass('open') + + clearMenus() + + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we we use a backdrop because click events don't delegate + $(' @@ -251,7 +412,7 @@ {/form} - {* Delete confirmation dialog *} + {* Delete category confirmation dialog *} {capture "category_delete_dialog"} @@ -270,6 +431,26 @@ form_action = {url path='/admin/categories/delete'} form_content = {$smarty.capture.category_delete_dialog nofilter} } + + {* Delete product confirmation dialog *} + + {capture "product_delete_dialog"} + + + {module_include location='product_delete_form'} + + {/capture} + + {include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "product_delete_dialog" + dialog_title = {intl l="Delete product"} + dialog_message = {intl l="Do you really want to delete this product ?"} + + form_action = {url path='/admin/products/delete'} + form_content = {$smarty.capture.product_delete_dialog nofilter} + } {/block} {block name="javascript-initialization"} @@ -290,6 +471,11 @@ $('#category_delete_id').val($(this).data('id')); }); + // Set proper product ID in delete from + $('a.product-delete').click(function(ev) { + $('#product_delete_id').val($(this).data('id')); + }); + // JS stuff for creation form {include file = "includes/generic-js-dialog.html" From c8baa38fed2dafeddc2adcbe1da761793ddcda4c Mon Sep 17 00:00:00 2001 From: franck Date: Tue, 17 Sep 2013 17:31:22 +0200 Subject: [PATCH 50/74] Added missing files... --- core/lib/Thelia/Action/Product.php | 199 ++++++++++ .../Controller/Admin/ProductController.php | 350 ++++++++++++++++++ .../Core/Event/ProductAddContentEvent.php | 48 +++ .../Thelia/Core/Event/ProductCreateEvent.php | 80 ++++ .../Core/Event/ProductDeleteContentEvent.php | 48 +++ .../Thelia/Core/Event/ProductDeleteEvent.php | 44 +++ core/lib/Thelia/Core/Event/ProductEvent.php | 54 +++ .../Event/ProductToggleVisibilityEvent.php | 28 ++ .../Thelia/Core/Event/ProductUpdateEvent.php | 113 ++++++ .../Thelia/Form/ProductModificationForm.php | 64 ++++ core/lib/Thelia/Model/Product.php | 21 +- 11 files changed, 1042 insertions(+), 7 deletions(-) create mode 100644 core/lib/Thelia/Action/Product.php create mode 100644 core/lib/Thelia/Controller/Admin/ProductController.php create mode 100644 core/lib/Thelia/Core/Event/ProductAddContentEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductCreateEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductDeleteContentEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductDeleteEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductToggleVisibilityEvent.php create mode 100644 core/lib/Thelia/Core/Event/ProductUpdateEvent.php create mode 100644 core/lib/Thelia/Form/ProductModificationForm.php diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php new file mode 100644 index 000000000..d2deb7688 --- /dev/null +++ b/core/lib/Thelia/Action/Product.php @@ -0,0 +1,199 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +use Thelia\Model\ProductQuery; +use Thelia\Model\Product as ProductModel; + +use Thelia\Core\Event\TheliaEvents; + +use Thelia\Core\Event\ProductUpdateEvent; +use Thelia\Core\Event\ProductCreateEvent; +use Thelia\Core\Event\ProductDeleteEvent; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\ProductToggleVisibilityEvent; +use Thelia\Core\Event\ProductAddContentEvent; +use Thelia\Core\Event\ProductDeleteContentEvent; +use Thelia\Model\ProductAssociatedContent; +use Thelia\Model\ProductAssociatedContentQuery; + +class Product extends BaseAction implements EventSubscriberInterface +{ + /** + * Create a new product entry + * + * @param ProductCreateEvent $event + */ + public function create(ProductCreateEvent $event) + { + $product = new ProductModel(); + + $product + ->setDispatcher($this->getDispatcher()) + + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setParent($event->getParent()) + ->setVisible($event->getVisible()) + + ->save() + ; + + $event->setProduct($product); + } + + /** + * Change a product + * + * @param ProductUpdateEvent $event + */ + public function update(ProductUpdateEvent $event) + { + $search = ProductQuery::create(); + + if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) { + + $product + ->setDispatcher($this->getDispatcher()) + + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ->setChapo($event->getChapo()) + ->setPostscriptum($event->getPostscriptum()) + + ->setParent($event->getParent()) + ->setVisible($event->getVisible()) + + ->save(); + + $event->setProduct($product); + } + } + + /** + * Delete a product entry + * + * @param ProductDeleteEvent $event + */ + public function delete(ProductDeleteEvent $event) + { + if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) { + + $product + ->setDispatcher($this->getDispatcher()) + ->delete() + ; + + $event->setProduct($product); + } + } + + /** + * Toggle product visibility. No form used here + * + * @param ActionEvent $event + */ + public function toggleVisibility(ProductToggleVisibilityEvent $event) + { + $product = $event->getProduct(); + + $product + ->setDispatcher($this->getDispatcher()) + ->setVisible($product->getVisible() ? false : true) + ->save() + ; + } + + /** + * Changes position, selecting absolute ou relative change. + * + * @param ProductChangePositionEvent $event + */ + public function updatePosition(UpdatePositionEvent $event) + { + if (null !== $product = ProductQuery::create()->findPk($event->getObjectId())) { + + $product->setDispatcher($this->getDispatcher()); + + $mode = $event->getMode(); + + if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) + return $product->changeAbsolutePosition($event->getPosition()); + else if ($mode == UpdatePositionEvent::POSITION_UP) + return $product->movePositionUp(); + else if ($mode == UpdatePositionEvent::POSITION_DOWN) + return $product->movePositionDown(); + } + } + + public function addContent(ProductAddContentEvent $event) { + + if (ProductAssociatedContentQuery::create() + ->filterByContentId($event->getContentId()) + ->filterByProduct($event->getProduct())->count() <= 0) { + + $content = new ProductAssociatedContent(); + + $content + ->setProduct($event->getProduct()) + ->setContentId($event->getContentId()) + ->save() + ; + } + } + + public function removeContent(ProductDeleteContentEvent $event) { + + $content = ProductAssociatedContentQuery::create() + ->filterByContentId($event->getContentId()) + ->filterByProduct($event->getProduct())->findOne() + ; + + if ($content !== null) $content->delete(); + } + + + /** + * {@inheritDoc} + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::PRODUCT_CREATE => array("create", 128), + TheliaEvents::PRODUCT_UPDATE => array("update", 128), + TheliaEvents::PRODUCT_DELETE => array("delete", 128), + TheliaEvents::PRODUCT_TOGGLE_VISIBILITY => array("toggleVisibility", 128), + + TheliaEvents::PRODUCT_UPDATE_POSITION => array("updatePosition", 128), + + TheliaEvents::PRODUCT_ADD_CONTENT => array("addContent", 128), + TheliaEvents::PRODUCT_REMOVE_CONTENT => array("removeContent", 128), + + ); + } +} diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php new file mode 100644 index 000000000..e1b651e60 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -0,0 +1,350 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +use Thelia\Core\Event\ProductDeleteEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\ProductUpdateEvent; +use Thelia\Core\Event\ProductCreateEvent; +use Thelia\Model\ProductQuery; +use Thelia\Form\ProductModificationForm; +use Thelia\Form\ProductCreationForm; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\ProductToggleVisibilityEvent; +use Thelia\Core\Event\ProductDeleteContentEvent; +use Thelia\Core\Event\ProductAddContentEvent; +use Thelia\Model\ProductAssociatedContent; +use Thelia\Model\FolderQuery; +use Thelia\Model\ContentQuery; +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Model\ProductAssociatedContentQuery; + +/** + * Manages products + * + * @author Franck Allimant + */ +class ProductController extends AbstractCrudController +{ + public function __construct() + { + parent::__construct( + 'product', + 'manual', + 'product_order', + + 'admin.products.default', + 'admin.products.create', + 'admin.products.update', + 'admin.products.delete', + + TheliaEvents::PRODUCT_CREATE, + TheliaEvents::PRODUCT_UPDATE, + TheliaEvents::PRODUCT_DELETE, + + TheliaEvents::PRODUCT_TOGGLE_VISIBILITY, + TheliaEvents::PRODUCT_UPDATE_POSITION + ); + } + + protected function getCreationForm() + { + return new ProductCreationForm($this->getRequest()); + } + + protected function getUpdateForm() + { + return new ProductModificationForm($this->getRequest()); + } + + protected function getCreationEvent($formData) + { + $createEvent = new ProductCreateEvent(); + + $createEvent + ->setTitle($formData['title']) + ->setLocale($formData["locale"]) + ->setParent($formData['parent']) + ->setVisible($formData['visible']) + ; + + return $createEvent; + } + + protected function getUpdateEvent($formData) + { + $changeEvent = new ProductUpdateEvent($formData['id']); + + // Create and dispatch the change event + $changeEvent + ->setLocale($formData['locale']) + ->setTitle($formData['title']) + ->setChapo($formData['chapo']) + ->setDescription($formData['description']) + ->setPostscriptum($formData['postscriptum']) + ->setVisible($formData['visible']) + ->setUrl($formData['url']) + ->setParent($formData['parent']) + ; + + return $changeEvent; + } + + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { + return new UpdatePositionEvent( + $this->getRequest()->get('product_id', null), + $positionChangeMode, + $positionValue + ); + } + + protected function getDeleteEvent() + { + return new ProductDeleteEvent($this->getRequest()->get('product_id', 0)); + } + + protected function eventContainsObject($event) + { + return $event->hasProduct(); + } + + protected function hydrateObjectForm($object) + { + // Prepare the data that will hydrate the form + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'chapo' => $object->getChapo(), + 'description' => $object->getDescription(), + 'postscriptum' => $object->getPostscriptum(), + 'visible' => $object->getVisible(), + 'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()), + 'parent' => $object->getParent() + ); + + // Setup the object form + return new ProductModificationForm($this->getRequest(), "form", $data); + } + + protected function getObjectFromEvent($event) + { + return $event->hasProduct() ? $event->getProduct() : null; + } + + protected function getExistingObject() + { + return ProductQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('product_id', 0)); + } + + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + protected function getObjectId($object) + { + return $object->getId(); + } + + protected function getEditionArguments() + { + return array( + 'product_id' => $this->getRequest()->get('product_id', 0), + 'folder_id' => $this->getRequest()->get('folder_id', 0), + 'current_tab' => $this->getRequest()->get('current_tab', 'general') + ); + } + + protected function renderListTemplate($currentOrder) + { + $this->getListOrderFromSession('product', 'product_order', 'manual'); + + return $this->render('categories', + array( + 'product_order' => $currentOrder, + 'product_id' => $this->getRequest()->get('product_id', 0) + )); + } + + protected function redirectToListTemplate() + { + // Redirect to the product default category list + $product = $this->getExistingObject(); + + $this->redirectToRoute( + 'admin.products.default', + array('category_id' => $product != null ? $product->getDefaultCategory() : 0) + ); + } + + protected function renderEditionTemplate() + { + return $this->render('product-edit', $this->getEditionArguments()); + } + + protected function redirectToEditionTemplate() + { + $this->redirectToRoute("admin.products.update", $this->getEditionArguments()); + } + + /** + * Online status toggle product + */ + public function setToggleVisibilityAction() + { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + + $event = new ProductToggleVisibilityEvent($this->getExistingObject()); + + try { + $this->dispatch(TheliaEvents::PRODUCT_TOGGLE_VISIBILITY, $event); + } catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + // Ajax response -> no action + return $this->nullResponse(); + } + + protected function performAdditionalDeleteAction($deleteEvent) + { + // Redirect to parent product list + $this->redirectToRoute( + 'admin.products.default', + array('category_id' => $deleteEvent->getProduct()->getDefaultCategory()) + ); + } + + protected function performAdditionalUpdateAction($updateEvent) + { + if ($this->getRequest()->get('save_mode') != 'stay') { + + // Redirect to parent product list + $this->redirectToRoute( + 'admin.categories.default', + array('category_id' => $product->getDefaultCategory()) + ); + } + } + + protected function performAdditionalUpdatePositionAction($event) + { + $product = ProductQuery::create()->findPk($event->getObjectId()); + + if ($product != null) { + // Redirect to parent product list + $this->redirectToRoute( + 'admin.categories.default', + array('category_id' => $product->getDefaultCategory()) + ); + } + + return null; + } + + public function getAvailableRelatedContentAction($productId, $folderId) + { + $result = array(); + + $folders = FolderQuery::create()->filterById($folderId)->find(); + + if ($folders !== null) { + + $list = ContentQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->filterByFolder($folders, Criteria::IN) + ->filterById(ProductAssociatedContentQuery::create()->select('content_id')->findByProductId($productId), Criteria::NOT_IN) + ->find(); + ; + + if ($list !== null) { + foreach($list as $item) { + $result[] = array('id' => $item->getId(), 'title' => $item->getTitle()); + } + } + } + + return $this->jsonResponse(json_encode($result)); + } + + public function addRelatedContentAction() + { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + + $content_id = intval($this->getRequest()->get('content_id')); + + if ($content_id > 0) { + + $event = new ProductAddContentEvent( + $this->getExistingObject(), + $content_id + ); + + try { + $this->dispatch(TheliaEvents::PRODUCT_ADD_CONTENT, $event); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + } + + $this->redirectToEditionTemplate(); + } + + public function deleteRelatedContentAction() + { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + + $content_id = intval($this->getRequest()->get('content_id')); + + if ($content_id > 0) { + + $event = new ProductDeleteContentEvent( + $this->getExistingObject(), + $content_id + ); + + try { + $this->dispatch(TheliaEvents::PRODUCT_REMOVE_CONTENT, $event); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + } + + $this->redirectToEditionTemplate(); + } +} diff --git a/core/lib/Thelia/Core/Event/ProductAddContentEvent.php b/core/lib/Thelia/Core/Event/ProductAddContentEvent.php new file mode 100644 index 000000000..8cd648753 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductAddContentEvent.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Model\Product; + +class ProductAddContentEvent extends ProductEvent +{ + protected $content_id; + + public function __construct(Product $product, $content_id) + { + parent::__construct($product); + + $this->content_id = $content_id; + } + + public function getContentId() + { + return $this->content_id; + } + + public function setContentId($content_id) + { + $this->content_id = $content_id; + } +} diff --git a/core/lib/Thelia/Core/Event/ProductCreateEvent.php b/core/lib/Thelia/Core/Event/ProductCreateEvent.php new file mode 100644 index 000000000..51be86e25 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductCreateEvent.php @@ -0,0 +1,80 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class ProductCreateEvent extends ProductEvent +{ + protected $title; + protected $parent; + protected $locale; + protected $visible; + + public function getTitle() + { + return $this->title; + } + + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } + + public function getLocale() + { + return $this->locale; + } + + public function setLocale($locale) + { + $this->locale = $locale; + + return $this; + } + + public function getVisible() + { + return $this->visible; + } + + public function setVisible($visible) + { + $this->visible = $visible; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/ProductDeleteContentEvent.php b/core/lib/Thelia/Core/Event/ProductDeleteContentEvent.php new file mode 100644 index 000000000..f3cdbda1f --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductDeleteContentEvent.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Model\Product; + +class ProductDeleteContentEvent extends ProductEvent +{ + protected $content_id; + + public function __construct(Product $product, $content_id) + { + parent::__construct($product); + + $this->content_id = $content_id; + } + + public function getContentId() + { + return $this->content_id; + } + + public function setContentId($content_id) + { + $this->content_id = $content_id; + } +} diff --git a/core/lib/Thelia/Core/Event/ProductDeleteEvent.php b/core/lib/Thelia/Core/Event/ProductDeleteEvent.php new file mode 100644 index 000000000..43273887c --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductDeleteEvent.php @@ -0,0 +1,44 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class ProductDeleteEvent extends ProductEvent +{ + public function __construct($product_id) + { + $this->product_id = $product_id; + } + + public function getProductId() + { + return $this->product_id; + } + + public function setProductId($product_id) + { + $this->product_id = $product_id; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/ProductEvent.php b/core/lib/Thelia/Core/Event/ProductEvent.php new file mode 100644 index 000000000..6decd8101 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductEvent.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Model\Product; +use Thelia\Core\Event\ActionEvent; + +class ProductEvent extends ActionEvent +{ + public $product = null; + + public function __construct(Product $product = null) + { + $this->product = $product; + } + + public function hasProduct() + { + return ! is_null($this->product); + } + + public function getProduct() + { + return $this->product; + } + + public function setProduct(Product $product) + { + $this->product = $product; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/ProductToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/ProductToggleVisibilityEvent.php new file mode 100644 index 000000000..732cfac76 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductToggleVisibilityEvent.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class ProductToggleVisibilityEvent extends ProductEvent +{ +} diff --git a/core/lib/Thelia/Core/Event/ProductUpdateEvent.php b/core/lib/Thelia/Core/Event/ProductUpdateEvent.php new file mode 100644 index 000000000..8ade33c74 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductUpdateEvent.php @@ -0,0 +1,113 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class ProductUpdateEvent extends ProductCreateEvent +{ + protected $product_id; + + protected $chapo; + protected $description; + protected $postscriptum; + + protected $url; + protected $parent; + + public function __construct($product_id) + { + $this->product_id = $product_id; + } + + public function getProductId() + { + return $this->product_id; + } + + public function setProductId($product_id) + { + $this->product_id = $product_id; + + return $this; + } + + public function getChapo() + { + return $this->chapo; + } + + public function setChapo($chapo) + { + $this->chapo = $chapo; + + return $this; + } + + public function getDescription() + { + return $this->description; + } + + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + public function getPostscriptum() + { + return $this->postscriptum; + } + + public function setPostscriptum($postscriptum) + { + $this->postscriptum = $postscriptum; + + return $this; + } + + public function getUrl() + { + return $this->url; + } + + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } +} diff --git a/core/lib/Thelia/Form/ProductModificationForm.php b/core/lib/Thelia/Form/ProductModificationForm.php new file mode 100644 index 000000000..dbda15eaa --- /dev/null +++ b/core/lib/Thelia/Form/ProductModificationForm.php @@ -0,0 +1,64 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\GreaterThan; +use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\NotBlank; + +class ProductModificationForm extends ProductCreationForm +{ + use StandardDescriptionFieldsTrait; + + protected function buildForm() + { + parent::buildForm(true); + + $this->formBuilder + ->add("id", "integer", array( + "label" => Translator::getInstance()->trans("Prodcut ID *"), + "label_attr" => array("for" => "product_id_field"), + "constraints" => array(new GreaterThan(array('value' => 0))) + + )) + ->add("template_id", "integer", array( + "label" => Translator::getInstance()->trans("Product template"), + "label_attr" => array("for" => "product_template_field") + + )) + ->add("url", "text", array( + "label" => Translator::getInstance()->trans("Rewriten URL *"), + "constraints" => array(new NotBlank()), + "label_attr" => array("for" => "rewriten_url_field") + )) + ; + + // Add standard description fields, excluding title and locale, which a re defined in parent class + $this->addStandardDescFields(array('title', 'locale')); + } + + public function getName() + { + return "thelia_product_modification"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index c770379b9..87b414dd9 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -46,7 +46,8 @@ class Product extends BaseProduct /** * @return the current default category for this product */ - public function getDefaultCategory() { + public function getDefaultCategory() + { // Find default category $default_category = ProductCategoryQuery::create() ->filterByProductId($this->getId()) @@ -61,8 +62,8 @@ class Product extends BaseProduct * * @param integer $categoryId the new default category id */ - public function setDefaultCategory($categoryId) { - + public function setDefaultCategory($categoryId) + { // Unset previous category ProductCategoryQuery::create() ->filterByProductId($this->getId()) @@ -85,11 +86,17 @@ class Product extends BaseProduct /** * Calculate next position relative to our default category */ - protected function addCriteriaToPositionQuery($query) { - - // TODO: Find the default category for this product, - // and generate the position relative to this category + protected function addCriteriaToPositionQuery($query) + { + // Retrourver les produits qui ont la même categorie par defaut + $produits = ProductCategoryQuery::create() + ->filterByCategory($this->getDefaultCategory()) + ->filterByDefaultCategory(true) + ->select('product_id') + ->find(); + // Filtrer la requete sur ces produits + if ($produits != null) $query->filterById($produits); } /** From 82c7cdeb4483f383115791ba33b5add7978e1c29 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 17:39:12 +0200 Subject: [PATCH 51/74] Working : Content : fix loop giving no elements --- core/lib/Thelia/Core/Template/Loop/Product.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index d0d8dc5b7..489587a71 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -175,14 +175,17 @@ class Product extends BaseI18nLoop if (!is_null($category) ||!is_null($categoryDefault)) { - $categories = array(); - if (!is_null($category)) { - $categories = array_merge($categories, CategoryQuery::create()->filterById($category, Criteria::IN)->find()); + $categoryIds = array(); + if (!is_array($category)) { + $category = array(); } - if (!is_null($categoryDefault)) { - $categories = array_merge($categories, CategoryQuery::create()->filterById($categoryDefault, Criteria::IN)->find()); + if (!is_array($categoryDefault)) { + $categoryDefault = array(); } + $categoryIds = array_merge($categoryIds, $category, $categoryDefault); + $categories =CategoryQuery::create()->filterById($categoryIds, Criteria::IN)->find(); + $depth = $this->getDepth(); if (null !== $depth) { @@ -549,12 +552,12 @@ class Product extends BaseI18nLoop $search->addDescendingOrderByColumn('real_lowest_price'); break; case "manual": - if(null === $category || count($category) != 1) + if(null === $categoryIds || count($categoryIds) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single category argument'); $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": - if(null === $category || count($category) != 1) + if(null === $categoryIds || count($categoryIds) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single category argument'); $search->orderByPosition(Criteria::DESC); break; From c99e7a91b93eec96e8a8fb0cd7c8f97536e73138 Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 17 Sep 2013 17:43:19 +0200 Subject: [PATCH 52/74] Working : Content : fix loop giving no elements --- .../lib/Thelia/Core/Template/Loop/Content.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 4ac061c3f..a29cb2e60 100755 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -102,15 +102,16 @@ class Content extends BaseI18nLoop if (!is_null($folder) || !is_null($folderDefault)) { - $folders = array(); - if (!is_null($folder)) { - $folders = array_merge($folders, FolderQuery::create()->filterById($folder, Criteria::IN)->find()); - } - - if (!is_null($folderDefault)) { - $folders = array_merge(FolderQuery::create()->filterById($folderDefault, Criteria::IN)->find()); + $foldersIds = array(); + if (!is_array($folder)) { + $folder = array(); + } + if (!is_array($folderDefault)) { + $folderDefault = array(); } + $foldersIds = array_merge($foldersIds, $folder, $folderDefault); + $folders =FolderQuery::create()->filterById($foldersIds, Criteria::IN)->find(); $depth = $this->getDepth(); @@ -175,12 +176,12 @@ class Content extends BaseI18nLoop $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual": - if(null === $folder || count($folder) != 1) + if(null === $foldersIds || count($foldersIds) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single folder argument'); $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": - if(null === $folder || count($folder) != 1) + if(null === $foldersIds || count($foldersIds) != 1) throw new \InvalidArgumentException('Manual order cannot be set without single folder argument'); $search->orderByPosition(Criteria::DESC); break; From 50212c55cf50a55f702b863fec3d5cac3fb83f59 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 17:50:05 +0200 Subject: [PATCH 53/74] remove old model classes: --- core/lib/Thelia/Model/Rewriting.php | 9 -------- core/lib/Thelia/Model/RewritingQuery.php | 20 ---------------- .../Thelia/Model/Tools/UrlRewritingTrait.php | 23 ++++++++++++++++++- 3 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 core/lib/Thelia/Model/Rewriting.php delete mode 100644 core/lib/Thelia/Model/RewritingQuery.php diff --git a/core/lib/Thelia/Model/Rewriting.php b/core/lib/Thelia/Model/Rewriting.php deleted file mode 100644 index 8d6f75fab..000000000 --- a/core/lib/Thelia/Model/Rewriting.php +++ /dev/null @@ -1,9 +0,0 @@ -generateRewritenUrl($this->getRewritenUrlViewName(), $this->getId(), $locale, $this->getTitle()); + // Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe + + $this->setLocale($locale); + // Replace all weird characters with dashes + $string = preg_replace('/[^\w\-~_\.]+/u', '-', $this->getTitle()); + + // Only allow one dash separator at a time (and make string lowercase) + $cleanString = mb_strtolower(preg_replace('/--+/u', '-', $string), 'UTF-8'); + + $urlFilePart = $cleanString . ".html"; + + // TODO : + // check if URL url already exists, and add a numeric suffix, or the like + try{ + URL::getInstance()->resolve($urlFilePart); + } catch (UrlRewritingException $e) { + + } + // insert the URL in the rewriting table + //URL::getInstance()->generateRewritenUrl($this->getRewritenUrlViewName(), $this->getId(), $locale, $this->getTitle()); } /** From ecf4412fbd0e8d0a296fc3df41572a5aef6976b3 Mon Sep 17 00:00:00 2001 From: franck Date: Tue, 17 Sep 2013 18:38:49 +0200 Subject: [PATCH 54/74] Changed getDefaultCategory in getDefaultCategoryId --- core/lib/Thelia/Model/Product.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 87b414dd9..541668ddb 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -9,6 +9,7 @@ use Thelia\TaxEngine\Calculator; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\ProductEvent; +use Propel\Runtime\ActiveQuery\Criteria; class Product extends BaseProduct { @@ -46,7 +47,7 @@ class Product extends BaseProduct /** * @return the current default category for this product */ - public function getDefaultCategory() + public function getDefaultCategoryId() { // Find default category $default_category = ProductCategoryQuery::create() @@ -54,7 +55,7 @@ class Product extends BaseProduct ->filterByDefaultCategory(true) ->findOne(); - return $default_category; + return $default_category == null ? 0 : $default_category->getCategoryId(); } /** @@ -88,15 +89,15 @@ class Product extends BaseProduct */ protected function addCriteriaToPositionQuery($query) { - // Retrourver les produits qui ont la même categorie par defaut + // Find products in the same category $produits = ProductCategoryQuery::create() - ->filterByCategory($this->getDefaultCategory()) + ->filterByCategoryId($this->getDefaultCategoryId()) ->filterByDefaultCategory(true) ->select('product_id') ->find(); // Filtrer la requete sur ces produits - if ($produits != null) $query->filterById($produits); + if ($produits != null) $query->filterById($produits, Criteria::IN); } /** From 60d09dc76e86c96f7690815850f7db727a848aaa Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 19:11:44 +0200 Subject: [PATCH 55/74] refactor rewrriten method name --- core/lib/Thelia/Model/Category.php | 4 +- core/lib/Thelia/Model/Content.php | 4 +- core/lib/Thelia/Model/Folder.php | 4 +- core/lib/Thelia/Model/Product.php | 4 +- core/lib/Thelia/Model/RewritingUrl.php | 17 +++++ .../Thelia/Model/Tools/UrlRewritingTrait.php | 63 +++++++++++++++---- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 042864de0..91b32eec7 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -28,7 +28,7 @@ class Category extends BaseCategory /** * {@inheritDoc} */ - protected function getRewritenUrlViewName() { + protected function getRewrittenUrlViewName() { return 'category'; } @@ -69,7 +69,7 @@ class Category extends BaseCategory { $this->setPosition($this->getNextPosition()); - $this->generateRewritenUrl($this->getLocale()); + $this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::BEFORE_CREATECATEGORY, new CategoryEvent($this)); diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 79660f93a..d626bfb10 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -17,7 +17,7 @@ class Content extends BaseContent /** * {@inheritDoc} */ - protected function getRewritenUrlViewName() { + protected function getRewrittenUrlViewName() { return 'content'; } @@ -37,7 +37,7 @@ class Content extends BaseContent { $this->setPosition($this->getNextPosition()); - $this->generateRewritenUrl($this->getLocale()); + $this->generateRewrittenUrl($this->getLocale()); return true; } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 1e73e7e23..318edb7ac 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -17,7 +17,7 @@ class Folder extends BaseFolder /** * {@inheritDoc} */ - protected function getRewritenUrlViewName() { + protected function getRewrittenUrlViewName() { return 'folder'; } @@ -67,7 +67,7 @@ class Folder extends BaseFolder { $this->setPosition($this->getNextPosition()); - $this->generateRewritenUrl($this->getLocale()); + $this->generateRewrittenUrl($this->getLocale()); return true; } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 87b414dd9..d227cc9a2 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -21,7 +21,7 @@ class Product extends BaseProduct /** * {@inheritDoc} */ - protected function getRewritenUrlViewName() { + protected function getRewrittenUrlViewName() { return 'product'; } @@ -106,7 +106,7 @@ class Product extends BaseProduct { $this->setPosition($this->getNextPosition()); - $this->generateRewritenUrl($this->getLocale()); + $this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this)); diff --git a/core/lib/Thelia/Model/RewritingUrl.php b/core/lib/Thelia/Model/RewritingUrl.php index 58dde9388..9dd826d01 100644 --- a/core/lib/Thelia/Model/RewritingUrl.php +++ b/core/lib/Thelia/Model/RewritingUrl.php @@ -2,8 +2,25 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\RewritingUrl as BaseRewritingUrl; +use Thelia\Model\RewritingUrlQuery; class RewritingUrl extends BaseRewritingUrl { + public function preSave(ConnectionInterface $con = null) + { + if($this->getRedirected() == 0) { + //check if rewriting url alredy exists and put redirect to 1 + RewritingUrlQuery::create() + ->filterByView($this->getView()) + ->filterByViewId($this->getViewId()) + ->filterByViewLocale($this->getViewLocale()) + ->update(array( + "redirect" => 1 + )); + } + + return true; + } } diff --git a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php index f50da56d5..c9154a0db 100644 --- a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php +++ b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php @@ -24,7 +24,8 @@ namespace Thelia\Model\Tools; use Thelia\Exception\UrlRewritingException; -use Thelia\Model\Rewriting; +use Thelia\Model\RewritingUrlQuery; +use Thelia\Model\RewritingUrl; use Thelia\Tools\URL; /** * A trait for managing Rewriten URLs from model classes @@ -34,7 +35,7 @@ trait UrlRewritingTrait { /** * @returns string the view name of the rewriten object (e.g., 'category', 'product') */ - protected abstract function getRewritenUrlViewName(); + protected abstract function getRewrittenUrlViewName(); /** * Get the object URL for the given locale, rewriten if rewriting is enabled. @@ -43,7 +44,7 @@ trait UrlRewritingTrait { */ public function getUrl($locale) { - return URL::getInstance()->retrieve($this->getRewritenUrlViewName(), $this->getId(), $locale)->toString(); + return URL::getInstance()->retrieve($this->getRewrittenUrlViewName(), $this->getId(), $locale)->toString(); } /** @@ -51,13 +52,22 @@ trait UrlRewritingTrait { * * @param string $locale a valid locale (e.g. en_US) */ - public function generateRewritenUrl($locale) + public function generateRewrittenUrl($locale) { + if ($this->isNew()) { + throw new \RuntimeException(sprintf('Object %s must be save before generating url', $this->getRewrittenUrlViewName())); + } // Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe $this->setLocale($locale); + + $title = $this->getTitle(); + + if (null === $title) { + throw new \RuntimeException(sprintf('Impossible to generate url if title does not exists for the locale %s', $locale)); + } // Replace all weird characters with dashes - $string = preg_replace('/[^\w\-~_\.]+/u', '-', $this->getTitle()); + $string = preg_replace('/[^\w\-~_\.]+/u', '-', $title); // Only allow one dash separator at a time (and make string lowercase) $cleanString = mb_strtolower(preg_replace('/--+/u', '-', $string), 'UTF-8'); @@ -67,30 +77,59 @@ trait UrlRewritingTrait { // TODO : // check if URL url already exists, and add a numeric suffix, or the like try{ - URL::getInstance()->resolve($urlFilePart); + $i=0; + while(URL::getInstance()->resolve($urlFilePart)) { + $i++; + $urlFilePart = sprintf("%s-%d.html",$cleanString, $i); + } } catch (UrlRewritingException $e) { - + $rewritingUrl = new RewritingUrl(); + $rewritingUrl->setUrl($urlFilePart) + ->setView($this->getRewrittenUrlViewName()) + ->setViewId($this->getId()) + ->setViewLocale($locale) + ->setRedirected(0) + ->save() + ; } - // insert the URL in the rewriting table - //URL::getInstance()->generateRewritenUrl($this->getRewritenUrlViewName(), $this->getId(), $locale, $this->getTitle()); + + return $urlFilePart; + } /** * return the rewriten URL for the given locale * * @param string $locale a valid locale (e.g. en_US) + * @return null */ - public function getRewritenUrl($locale) + public function getRewrittenUrl($locale) { - return "fake url - TODO"; + $rewritingUrl = RewritingUrlQuery::create() + ->filterByViewLocale($locale) + ->filterByView($this->getRewrittenUrlViewName()) + ->filterByViewId($this->getId()) + ->filterByRedirected(0) + ->findOne() + ; + + if($rewritingUrl) { + $url = $rewritingUrl->getUrl(); + } else { + $url = null; + } + + return $url; } /** * Set the rewriten URL for the given locale * * @param string $locale a valid locale (e.g. en_US) + * @param $url the wanted url + * @return $this */ - public function setRewritenUrl($locale, $url) + public function setRewrittenUrl($locale, $url) { // TODO - code me ! From e1e383707b04f59ee33eb80fdb0b86e0b23bbf49 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 19:19:52 +0200 Subject: [PATCH 56/74] template is not mandatory in product table. --- core/lib/Thelia/Model/Base/ProductQuery.php | 4 +- core/lib/Thelia/Model/Base/Template.php | 9 +- core/lib/Thelia/Model/Base/TemplateQuery.php | 4 +- core/lib/Thelia/Model/Category.php | 3 +- core/lib/Thelia/Model/Content.php | 7 +- core/lib/Thelia/Model/Folder.php | 6 +- core/lib/Thelia/Model/Map/ProductTableMap.php | 2 +- .../Model/Map/ProductVersionTableMap.php | 2 +- core/lib/Thelia/Model/Product.php | 3 +- install/thelia.sql | 4 +- local/config/schema.xml | 2398 ++++++++--------- 11 files changed, 1225 insertions(+), 1217 deletions(-) diff --git a/core/lib/Thelia/Model/Base/ProductQuery.php b/core/lib/Thelia/Model/Base/ProductQuery.php index 9b1710f03..9c3b0759c 100644 --- a/core/lib/Thelia/Model/Base/ProductQuery.php +++ b/core/lib/Thelia/Model/Base/ProductQuery.php @@ -857,7 +857,7 @@ abstract class ProductQuery extends ModelCriteria * * @return ChildProductQuery The current query, for fluid interface */ - public function joinTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinTemplate($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('Template'); @@ -892,7 +892,7 @@ abstract class ProductQuery extends ModelCriteria * * @return \Thelia\Model\TemplateQuery A secondary query class using the current class as primary query */ - public function useTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useTemplateQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this ->joinTemplate($relationAlias, $joinType) diff --git a/core/lib/Thelia/Model/Base/Template.php b/core/lib/Thelia/Model/Base/Template.php index 77efa7ba0..08bb0f3a0 100644 --- a/core/lib/Thelia/Model/Base/Template.php +++ b/core/lib/Thelia/Model/Base/Template.php @@ -864,9 +864,10 @@ abstract class Template implements ActiveRecordInterface if ($this->productsScheduledForDeletion !== null) { if (!$this->productsScheduledForDeletion->isEmpty()) { - \Thelia\Model\ProductQuery::create() - ->filterByPrimaryKeys($this->productsScheduledForDeletion->getPrimaryKeys(false)) - ->delete($con); + foreach ($this->productsScheduledForDeletion as $product) { + // need to save related object because we set the relation to null + $product->save($con); + } $this->productsScheduledForDeletion = null; } } @@ -1553,7 +1554,7 @@ abstract class Template implements ActiveRecordInterface $this->productsScheduledForDeletion = clone $this->collProducts; $this->productsScheduledForDeletion->clear(); } - $this->productsScheduledForDeletion[]= clone $product; + $this->productsScheduledForDeletion[]= $product; $product->setTemplate(null); } diff --git a/core/lib/Thelia/Model/Base/TemplateQuery.php b/core/lib/Thelia/Model/Base/TemplateQuery.php index 506d7d943..98c588dd8 100644 --- a/core/lib/Thelia/Model/Base/TemplateQuery.php +++ b/core/lib/Thelia/Model/Base/TemplateQuery.php @@ -395,7 +395,7 @@ abstract class TemplateQuery extends ModelCriteria * * @return ChildTemplateQuery The current query, for fluid interface */ - public function joinProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinProduct($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('Product'); @@ -430,7 +430,7 @@ abstract class TemplateQuery extends ModelCriteria * * @return \Thelia\Model\ProductQuery A secondary query class using the current class as primary query */ - public function useProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useProductQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this ->joinProduct($relationAlias, $joinType) diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 91b32eec7..204896674 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -69,8 +69,6 @@ class Category extends BaseCategory { $this->setPosition($this->getNextPosition()); - $this->generateRewrittenUrl($this->getLocale()); - $this->dispatchEvent(TheliaEvents::BEFORE_CREATECATEGORY, new CategoryEvent($this)); return true; @@ -81,6 +79,7 @@ class Category extends BaseCategory */ public function postInsert(ConnectionInterface $con = null) { + //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATECATEGORY, new CategoryEvent($this)); } diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index d626bfb10..4d9cf9f3a 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -37,8 +37,11 @@ class Content extends BaseContent { $this->setPosition($this->getNextPosition()); - $this->generateRewrittenUrl($this->getLocale()); - return true; } + + public function postInsert(ConnectionInterface $con = null) + { + //$this->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 318edb7ac..e32505d9d 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -67,8 +67,12 @@ class Folder extends BaseFolder { $this->setPosition($this->getNextPosition()); - $this->generateRewrittenUrl($this->getLocale()); return true; } + + public function postInsert(ConnectionInterface $con = null) + { + //$this->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/Map/ProductTableMap.php b/core/lib/Thelia/Model/Map/ProductTableMap.php index 17c4585f0..59ac236ac 100644 --- a/core/lib/Thelia/Model/Map/ProductTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductTableMap.php @@ -189,7 +189,7 @@ class ProductTableMap extends TableMap $this->addColumn('REF', 'Ref', 'VARCHAR', true, 255, null); $this->addColumn('VISIBLE', 'Visible', 'TINYINT', true, null, 0); $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); - $this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null); + $this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0); diff --git a/core/lib/Thelia/Model/Map/ProductVersionTableMap.php b/core/lib/Thelia/Model/Map/ProductVersionTableMap.php index 4e84b4db8..14d38a764 100644 --- a/core/lib/Thelia/Model/Map/ProductVersionTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductVersionTableMap.php @@ -180,7 +180,7 @@ class ProductVersionTableMap extends TableMap $this->addColumn('REF', 'Ref', 'VARCHAR', true, 255, null); $this->addColumn('VISIBLE', 'Visible', 'TINYINT', true, null, 0); $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); - $this->addColumn('TEMPLATE_ID', 'TemplateId', 'INTEGER', true, null, null); + $this->addColumn('TEMPLATE_ID', 'TemplateId', 'INTEGER', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); $this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0); diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 2be99958c..be534298e 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -107,7 +107,7 @@ class Product extends BaseProduct { $this->setPosition($this->getNextPosition()); - $this->generateRewrittenUrl($this->getLocale()); + $this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this)); @@ -119,6 +119,7 @@ class Product extends BaseProduct */ public function postInsert(ConnectionInterface $con = null) { + //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this)); } diff --git a/install/thelia.sql b/install/thelia.sql index 3dc5d0454..b49840d9b 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -36,7 +36,7 @@ CREATE TABLE `product` `ref` VARCHAR(255) NOT NULL, `visible` TINYINT DEFAULT 0 NOT NULL, `position` INTEGER NOT NULL, - `template_id` INTEGER NOT NULL, + `template_id` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, `version` INTEGER DEFAULT 0, @@ -2167,7 +2167,7 @@ CREATE TABLE `product_version` `ref` VARCHAR(255) NOT NULL, `visible` TINYINT DEFAULT 0 NOT NULL, `position` INTEGER NOT NULL, - `template_id` INTEGER NOT NULL, + `template_id` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, `version` INTEGER DEFAULT 0 NOT NULL, diff --git a/local/config/schema.xml b/local/config/schema.xml index a43cfda56..86e313cdf 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,1199 +1,1199 @@ - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - -
-
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + +
+
From 0d1c6cf8cbeeb048626d86a95dbbe20bb7d7e1be Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 19:47:10 +0200 Subject: [PATCH 57/74] postage + invoice step --- core/lib/Thelia/Action/Order.php | 3 +- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Config/Resources/routing/front.xml | 5 + .../Controller/Front/BaseFrontController.php | 10 ++ .../Controller/Front/OrderController.php | 76 ++++++++++- core/lib/Thelia/Core/Event/OrderEvent.php | 51 +++++-- .../lib/Thelia/Core/Template/Loop/Address.php | 22 ++- .../Core/Template/Loop/BaseSpecificModule.php | 3 +- .../lib/Thelia/Core/Template/Loop/Country.php | 2 +- .../Thelia/Core/Template/Loop/Delivery.php | 2 +- .../lib/Thelia/Core/Template/Loop/Payment.php | 84 ++++++++++++ .../Smarty/Plugins/DataAccessFunctions.php | 14 +- core/lib/Thelia/Form/OrderPayment.php | 94 +++++++++++++ core/lib/Thelia/Model/Order.php | 2 +- .../Thelia/Module/DeliveryModuleInterface.php | 2 +- local/modules/Colissimo/Colissimo.php | 2 +- templates/default/order_delivery.html | 2 +- templates/default/order_invoice.html | 128 +++++++++++++++--- 18 files changed, 455 insertions(+), 48 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Loop/Payment.php create mode 100755 core/lib/Thelia/Form/OrderPayment.php diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index a0d98265e..15266fac1 100755 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -61,9 +61,8 @@ class Order extends BaseAction implements EventSubscriberInterface { $order = $event->getOrder(); - $deliveryAddress = $event->getDeliveryAddress(); - $order->setDeliveryModuleId($event->getDeliveryModule()); + $order->setPostage($event->getPostage()); $event->setOrder($order); } diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 41e49d7d7..326f52145 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -64,6 +64,7 @@
+ diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index e702a1938..c1e153af0 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -122,6 +122,11 @@ order_delivery + + Thelia\Controller\Front\OrderController::pay + order_invoice + + Thelia\Controller\Front\DefaultController::noAction order_invoice diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 69ea8553d..74e918b2d 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -65,4 +65,14 @@ class BaseFrontController extends BaseController $this->redirectToRoute("cart.view"); } } + + protected function checkValidDelivery() + { + $order = $this->getSession()->getOrder(); + if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId()) { + $this->redirectToRoute("order.delivery"); + } + + + } } diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php index 393f71ebd..75fa91b36 100755 --- a/core/lib/Thelia/Controller/Front/OrderController.php +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -28,9 +28,12 @@ use Thelia\Core\Event\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Symfony\Component\HttpFoundation\Request; use Thelia\Form\OrderDelivery; +use Thelia\Form\OrderPayment; use Thelia\Log\Tlog; use Thelia\Model\AddressQuery; use Thelia\Model\AreaDeliveryModuleQuery; +use Thelia\Model\CountryQuery; +use Thelia\Model\ModuleQuery; use Thelia\Model\Order; /** @@ -41,7 +44,6 @@ use Thelia\Model\Order; class OrderController extends BaseFrontController { /** - * set billing address * set delivery address * set delivery module */ @@ -59,14 +61,16 @@ class OrderController extends BaseFrontController $deliveryAddressId = $form->get("delivery-address")->getData(); $deliveryModuleId = $form->get("delivery-module")->getData(); + $deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId); + $deliveryModule = ModuleQuery::create()->findPk($deliveryModuleId); - /* check that the delivery address belong to the current customer */ + /* check that the delivery address belongs to the current customer */ $deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId); if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) { - throw new \Exception("Address does not belong to the current customer"); + throw new \Exception("Delivery address does not belong to the current customer"); } - /* check that the delivery module fetch the delivery address area */ + /* check that the delivery module fetches the delivery address area */ if(AreaDeliveryModuleQuery::create() ->filterByAreaId($deliveryAddress->getCountry()->getAreaId()) ->filterByDeliveryModuleId($deliveryModuleId) @@ -74,10 +78,18 @@ class OrderController extends BaseFrontController throw new \Exception("Delivery module cannot be use with selected delivery address"); } + /* try to get postage amount */ + $moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace()); + if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) { + throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode())); + } + $moduleInstance = $moduleReflection->newInstance(); + $postage = $moduleInstance->getPostage($deliveryAddress->getCountry()); $orderEvent = $this->getOrderEvent(); $orderEvent->setDeliveryAddress($deliveryAddressId); $orderEvent->setDeliveryModule($deliveryModuleId); + $orderEvent->setPostage($postage); $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); @@ -105,6 +117,62 @@ class OrderController extends BaseFrontController } + /** + * set invoice address + * set payment module + */ + public function pay() + { + $this->checkAuth(); + $this->checkCartNotEmpty(); + $this->checkValidDelivery(); + + $message = false; + + $orderPayment = new OrderPayment($this->getRequest()); + + try { + $form = $this->validateForm($orderPayment, "post"); + + $deliveryAddressId = $form->get("delivery-address")->getData(); + $deliveryModuleId = $form->get("delivery-module")->getData(); + + /* check that the invoice address belongs to the current customer */ + $deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId); + if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) { + throw new \Exception("Invoice address does not belong to the current customer"); + } + + $orderEvent = $this->getOrderEvent(); + $orderEvent->setInvoiceAddress($deliveryAddressId); + $orderEvent->setPaymentModule($deliveryModuleId); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); + + $this->redirectToRoute("order.invoice"); + + } catch (FormValidationException $e) { + $message = sprintf("Please check your input: %s", $e->getMessage()); + } catch (PropelException $e) { + $this->getParserContext()->setGeneralError($e->getMessage()); + } catch (\Exception $e) { + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); + } + + if ($message !== false) { + Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage())); + + $orderPayment->setErrorMessage($message); + + $this->getParserContext() + ->addForm($orderPayment) + ->setGeneralError($message) + ; + } + + } + protected function getOrderEvent() { $order = $this->getOrder($this->getRequest()); diff --git a/core/lib/Thelia/Core/Event/OrderEvent.php b/core/lib/Thelia/Core/Event/OrderEvent.php index 6c2b5ff4b..349fd53a1 100755 --- a/core/lib/Thelia/Core/Event/OrderEvent.php +++ b/core/lib/Thelia/Core/Event/OrderEvent.php @@ -23,17 +23,16 @@ namespace Thelia\Core\Event; -use Thelia\Model\Address; -use Thelia\Model\AddressQuery; -use Thelia\Model\Module; use Thelia\Model\Order; class OrderEvent extends ActionEvent { protected $order = null; - protected $billingAddress = null; + protected $invoiceAddress = null; protected $deliveryAddress = null; protected $deliveryModule = null; + protected $paymentModule = null; + protected $postage = null; /** * @param Order $order @@ -54,7 +53,7 @@ class OrderEvent extends ActionEvent /** * @param $address */ - public function setBillingAddress($address) + public function setInvoiceAddress($address) { $this->deliveryAddress = $address; } @@ -75,6 +74,22 @@ class OrderEvent extends ActionEvent $this->deliveryModule = $module; } + /** + * @param $module + */ + public function setPaymentModule($module) + { + $this->paymentModule = $module; + } + + /** + * @param $postage + */ + public function setPostage($postage) + { + $this->postage = $postage; + } + /** * @return null|Order */ @@ -84,15 +99,15 @@ class OrderEvent extends ActionEvent } /** - * @return array|mixed|Address + * @return null|int */ - public function getBillingAddress() + public function getInvoiceAddress() { - return $this->billingAddress; + return $this->invoiceAddress; } /** - * @return array|mixed|Address + * @return null|int */ public function getDeliveryAddress() { @@ -100,10 +115,26 @@ class OrderEvent extends ActionEvent } /** - * @return array|mixed|Address + * @return null|int */ public function getDeliveryModule() { return $this->deliveryModule; } + + /** + * @return null|int + */ + public function getPaymentModule() + { + return $this->paymentModule; + } + + /** + * @return null|int + */ + public function getPostage() + { + return $this->postage; + } } diff --git a/core/lib/Thelia/Core/Template/Loop/Address.php b/core/lib/Thelia/Core/Template/Loop/Address.php index 1321592f4..9ca4352e9 100755 --- a/core/lib/Thelia/Core/Template/Loop/Address.php +++ b/core/lib/Thelia/Core/Template/Loop/Address.php @@ -54,7 +54,13 @@ class Address extends BaseLoop protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createIntListTypeArgument('id'), + new Argument( + 'id', + new TypeCollection( + new Type\IntListType(), + new Type\EnumType(array('*', 'any')) + ) + ), new Argument( 'customer', new TypeCollection( @@ -63,8 +69,14 @@ class Address extends BaseLoop ), 'current' ), - Argument::createBooleanTypeArgument('default'), - Argument::createIntListTypeArgument('exclude') + Argument::createBooleanOrBothTypeArgument('default'), + new Argument( + 'exclude', + new TypeCollection( + new Type\IntListType(), + new Type\EnumType(array('none')) + ) + ) ); } @@ -79,7 +91,7 @@ class Address extends BaseLoop $id = $this->getId(); - if (null !== $id) { + if (null !== $id && !in_array($id, array('*', 'any'))) { $search->filterById($id, Criteria::IN); } @@ -106,7 +118,7 @@ class Address extends BaseLoop $exclude = $this->getExclude(); - if (!is_null($exclude)) { + if (null !== $exclude && 'none' !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } diff --git a/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php b/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php index 2aaa173dc..6f5f23707 100644 --- a/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php +++ b/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php @@ -29,7 +29,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Model\ModuleQuery; /** - * Class Delivery * @package Thelia\Core\Template\Loop * @author Manuel Raynaud */ @@ -93,6 +92,8 @@ class BaseSpecificModule extends BaseI18nLoop { $search = ModuleQuery::create(); + $search->filterByActivate(1); + if (null !== $id = $this->getId()) { $search->filterById($id); } diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index f14b97efc..3a05b684a 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -87,7 +87,7 @@ class Country extends BaseI18nLoop if (true === $withArea) { $search->filterByAreaId(null, Criteria::ISNOTNULL); - } elseif (false == $withArea) { + } elseif (false === $withArea) { $search->filterByAreaId(null, Criteria::ISNULL); } diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index dea302797..5d33d398d 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -89,7 +89,7 @@ class Delivery extends BaseSpecificModule ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set('PRICE', $moduleInstance->calculate($country)) + ->set('POSTAGE', $moduleInstance->getPostage($country)) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Loop/Payment.php b/core/lib/Thelia/Core/Template/Loop/Payment.php new file mode 100644 index 000000000..542ffb590 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Payment.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Module\BaseModule; + +/** + * Class Payment + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class Payment extends BaseSpecificModule +{ + + public function getArgDefinitions() + { + $collection = parent::getArgDefinitions(); + + return $collection; + } + + public function exec(&$pagination) + { + $search = parent::exec($pagination); + /* manage translations */ + $locale = $this->configureI18nProcessing($search); + + $search->filterByType(BaseModule::PAYMENT_MODULE_TYPE, Criteria::EQUAL); + + /* perform search */ + $paymentModules = $this->search($search, $pagination); + + $loopResult = new LoopResult($paymentModules); + + foreach ($paymentModules as $paymentModule) { + $loopResultRow = new LoopResultRow($loopResult, $paymentModule, $this->versionable, $this->timestampable, $this->countable); + + $moduleReflection = new \ReflectionClass($paymentModule->getFullNamespace()); + if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) { + throw new \RuntimeException(sprintf("payment module %s is not a Thelia\Module\PaymentModuleInterface", $paymentModule->getCode())); + } + $moduleInstance = $moduleReflection->newInstance(); + + $moduleInstance->setRequest($this->request); + $moduleInstance->setDispatcher($this->dispatcher); + + $loopResultRow + ->set('ID', $paymentModule->getId()) + ->set('TITLE', $paymentModule->getVirtualColumn('i18n_TITLE')) + ->set('CHAPO', $paymentModule->getVirtualColumn('i18n_CHAPO')) + ->set('DESCRIPTION', $paymentModule->getVirtualColumn('i18n_DESCRIPTION')) + ->set('POSTSCRIPTUM', $paymentModule->getVirtualColumn('i18n_POSTSCRIPTUM')) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 41341f789..ffad52785 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -188,7 +188,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin public function orderDataAccess($params, &$smarty) { - return $this->dataAccess("Order", $params, $this->request->getSession()->getOrder()); + $order = $this->request->getSession()->getOrder(); + $attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr')); + switch($attribute) { + case 'postage': + return $order->getPostage(); + case 'delivery_address': + return $order->chosenDeliveryAddress; + } + + throw new \InvalidArgumentException(sprintf("%s has no '%s' attribute", 'Order', $attribute)); } /** @@ -196,6 +205,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin * * @param $params * @param $smarty + * + * @return string */ public function langDataAccess($params, $smarty) { @@ -294,6 +305,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin */ public function getPluginDescriptors() { + return array( new SmartyPluginDescriptor('function', 'admin', $this, 'adminDataAccess'), new SmartyPluginDescriptor('function', 'customer', $this, 'customerDataAccess'), diff --git a/core/lib/Thelia/Form/OrderPayment.php b/core/lib/Thelia/Form/OrderPayment.php new file mode 100755 index 000000000..d3ebe4daf --- /dev/null +++ b/core/lib/Thelia/Form/OrderPayment.php @@ -0,0 +1,94 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Model\AddressQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Translation\Translator; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; + +/** + * Class OrderPayment + * @package Thelia\Form + * @author Etienne Roudeix + */ +class OrderPayment extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("invoice-address", "integer", array( + "required" => true, + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyInvoiceAddress") + ) + )) + ) + )) + ->add("payment-module", "integer", array( + "required" => true, + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyPaymentModule") + ) + )) + ) + )); + } + + public function verifyInvoiceAddress($value, ExecutionContextInterface $context) + { + $address = AddressQuery::create() + ->findPk($value); + + if(null === $address) { + $context->addViolation("Address ID not found"); + } + } + + public function verifyPaymentModule($value, ExecutionContextInterface $context) + { + $module = ModuleQuery::create() + ->filterByType(BaseModule::PAYMENT_MODULE_TYPE) + ->filterByActivate(1) + ->filterById($value) + ->find(); + + if(null === $module) { + $context->addViolation("Payment module ID not found"); + } + } + + public function getName() + { + return "thelia_order_payment"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index 2bc014d27..e2eb43971 100755 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -7,7 +7,7 @@ use Thelia\Model\Base\Order as BaseOrder; class Order extends BaseOrder { public $chosenDeliveryAddress = null; - public $chosenInvoiceModule = null; + public $chosenInvoiceAddress = null; /** * calculate the total amount diff --git a/core/lib/Thelia/Module/DeliveryModuleInterface.php b/core/lib/Thelia/Module/DeliveryModuleInterface.php index 72f8769bc..17b000d4f 100644 --- a/core/lib/Thelia/Module/DeliveryModuleInterface.php +++ b/core/lib/Thelia/Module/DeliveryModuleInterface.php @@ -34,5 +34,5 @@ interface DeliveryModuleInterface extends BaseModuleInterface * * @return mixed */ - public function calculate(Country $country); + public function getPostage(Country $country); } diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php index 2fe9cd0b9..14ad36b0d 100755 --- a/local/modules/Colissimo/Colissimo.php +++ b/local/modules/Colissimo/Colissimo.php @@ -61,7 +61,7 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface * @param Country $country * @return mixed */ - public function calculate(Country $country) + public function getPostage(Country $country) { // TODO: Implement calculate() method. return 2; diff --git a/templates/default/order_delivery.html b/templates/default/order_delivery.html index d72cfedf2..46a5be64e 100644 --- a/templates/default/order_delivery.html +++ b/templates/default/order_delivery.html @@ -128,7 +128,7 @@ {form_field form=$form field='delivery-module'} {/form_field} - {$TITLE} / {currency attr="symbol"} {$PRICE} + {$TITLE} / {currency attr="symbol"} {$POSTAGE}
{/loop} diff --git a/templates/default/order_invoice.html b/templates/default/order_invoice.html index 2b76454e9..033c46838 100644 --- a/templates/default/order_invoice.html +++ b/templates/default/order_invoice.html @@ -25,12 +25,19 @@ - + {form name="thelia.order.payment"} + + + + {form_hidden_fields form=$form} + + {if $form_error}
{$form_error_message}
{/if} + @@ -123,7 +130,7 @@ @@ -151,32 +158,105 @@
+ {loop type="address" name="delivery-address" id="{order attr="delivery_address"}"}
Delivery address
- M. DUPONT Jean - Agency XY + {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY}
- street name of my business
- 75000 - City, Country + {$ADDRESS1}
+ {if $ADDRESS2 != ""} + {$ADDRESS2}
+ {/if} + {if $ADDRESS3 != ""} + {$ADDRESS3}
+ {/if} + {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}
+ {/loop}
+ + {form_field form=$form field='invoice-address'} +
Billing address
+ + {if $error} + {$message} + {/if} +
- M. DUPONT Jean - Agency XY -
- street name of my business
- 75000 - City, Country -
- Change address + +
Shipping Tax
- {order attr="postage"} + {currency attr="symbol"} {order attr="postage"}
+ + {loop type="address" name="invoice-address" default="{if !$error && $value}*{else}true{/if}" id="{if !$error && $value}{$value}{else}*{/if}"} + + + + + + + {if !$error} + + + + {/if} + + {/loop} + + {loop type="address" name="invoice-address" default="{if !$error && $value}*{else}false{/if}" exclude="{if !$error && $value}{$value}{else}none{/if}"} + + + + + + + {/loop} + +
+ {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY} +
+ {$ADDRESS1}
+ {if $ADDRESS2 != ""} + {$ADDRESS2}
+ {/if} + {if $ADDRESS3 != ""} + {$ADDRESS3}
+ {/if} + {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop} +
+
+ +
+ Change address +
+ {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY} +
+ {$ADDRESS1}
+ {if $ADDRESS2 != ""} + {$ADDRESS2}
+ {/if} + {if $ADDRESS3 != ""} + {$ADDRESS3}
+ {/if} + {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop} +
+
+ +
+
+
+ {/form_field}
Choose your payment method
@@ -195,10 +275,12 @@
- Back - + Back + + {/form} + @@ -209,8 +291,16 @@ {block name="javascript-initialization"} {/block} \ No newline at end of file From 347e5e5089f7305b7dae2eab222795cfca40e557 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 19:52:20 +0200 Subject: [PATCH 58/74] fix postage display --- templates/default/order_invoice.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/default/order_invoice.html b/templates/default/order_invoice.html index 033c46838..865fdb267 100644 --- a/templates/default/order_invoice.html +++ b/templates/default/order_invoice.html @@ -149,7 +149,7 @@ Total TTC
- {currency attr="symbol"} {cart attr="total_taxed_price"} + {currency attr="symbol"} {{cart attr="total_taxed_price"} + {order attr="postage"}}
From 03375a65b3cd7d385d6435e8d773cac41accc33a Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 20:07:50 +0200 Subject: [PATCH 59/74] payment loop --- core/lib/Thelia/Config/Resources/config.xml | 1 + templates/default/order_invoice.html | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 326f52145..c0199652d 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -24,6 +24,7 @@ + diff --git a/templates/default/order_invoice.html b/templates/default/order_invoice.html index 865fdb267..b08283c6c 100644 --- a/templates/default/order_invoice.html +++ b/templates/default/order_invoice.html @@ -258,11 +258,15 @@ {/form_field} + {form_field form=$form field='payment-module'} +
Choose your payment method
    - $value) { ?> + + {loop type="payment" name="payments" force_return="true"} +
  • - + + {/loop} +
+ {/form_field} + Back From da7f9e07c407f3d70f2aea053270bebbddb1ea80 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:15:28 +0200 Subject: [PATCH 60/74] create test for UrlRewritingTrait --- core/lib/Thelia/Model/RewritingUrl.php | 12 +-- .../Thelia/Model/Tools/UrlRewritingTrait.php | 9 +- .../Tests/Rewriting/ProductRewriteTest.php | 88 +++++++++++++++++++ 3 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php diff --git a/core/lib/Thelia/Model/RewritingUrl.php b/core/lib/Thelia/Model/RewritingUrl.php index 9dd826d01..a13777c41 100644 --- a/core/lib/Thelia/Model/RewritingUrl.php +++ b/core/lib/Thelia/Model/RewritingUrl.php @@ -2,25 +2,25 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\RewritingUrl as BaseRewritingUrl; use Thelia\Model\RewritingUrlQuery; class RewritingUrl extends BaseRewritingUrl { - public function preSave(ConnectionInterface $con = null) + public function postInsert(ConnectionInterface $con = null) { - if($this->getRedirected() == 0) { - //check if rewriting url alredy exists and put redirect to 1 + if(null !== $this->getRedirected()) { + //check if rewriting url alredy exists and put redirect to the new one RewritingUrlQuery::create() ->filterByView($this->getView()) ->filterByViewId($this->getViewId()) ->filterByViewLocale($this->getViewLocale()) + ->filterByRedirected($this->getId(), Criteria::NOT_IN) ->update(array( - "redirect" => 1 + "Redirected" => $this->getId() )); } - - return true; } } diff --git a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php index c9154a0db..1b9087626 100644 --- a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php +++ b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php @@ -55,17 +55,13 @@ trait UrlRewritingTrait { public function generateRewrittenUrl($locale) { if ($this->isNew()) { - throw new \RuntimeException(sprintf('Object %s must be save before generating url', $this->getRewrittenUrlViewName())); + throw new \RuntimeException(sprintf('Object %s must be saved before generating url', $this->getRewrittenUrlViewName())); } // Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe $this->setLocale($locale); - $title = $this->getTitle(); - - if (null === $title) { - throw new \RuntimeException(sprintf('Impossible to generate url if title does not exists for the locale %s', $locale)); - } + $title = $this->getTitle() ?: $this->getRef(); // Replace all weird characters with dashes $string = preg_replace('/[^\w\-~_\.]+/u', '-', $title); @@ -88,7 +84,6 @@ trait UrlRewritingTrait { ->setView($this->getRewrittenUrlViewName()) ->setViewId($this->getId()) ->setViewLocale($locale) - ->setRedirected(0) ->save() ; } diff --git a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php new file mode 100644 index 000000000..c38773814 --- /dev/null +++ b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php @@ -0,0 +1,88 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Rewriting; +use Thelia\Model\Product; +use Thelia\Model\ProductQuery; + + +/** + * Class ProductRewriteTest + * @package Thelia\Tests\Rewriting + * @author Manuel Raynaud + */ +class ProductRewriteTest extends \PHPUnit_Framework_TestCase +{ + protected static $productId; + + public static function setUpBeforeClass() + { + $product = new Product(); + $product->setRef(sprintf("TestRewrittenProduct%s",uniqid())) + ->setPosition(1) + ->setVisible(1) + ->setLocale('en_US') + ->setTitle('My english super Title') + ->setLocale('fr_FR') + ->setTitle('Mon super titre en français') + ->save(); + + self::$productId = $product->getId(); + } + + /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl + */ + public function testFrenchRewrittenUrl() + { + $product = ProductQuery::create()->findPk(self::$productId); + + $rewrittenUrl = $product->generateRewrittenUrl('fr_FR'); + $this->assertNotNull($rewrittenUrl, "rewritten url can not be null"); + $this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl); + //mon-super-titre-en-français-2.html + } + + /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl + */ + public function testEnglishRewrittenUrl() + { + $product = ProductQuery::create()->findPk(self::$productId); + + $rewrittenUrl = $product->generateRewrittenUrl('en_US'); + $this->assertNotNull($rewrittenUrl, "rewritten url can not be null"); + $this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Object product must be saved before generating url + */ + public function testOnNotSavedProduct() + { + $product = new Product(); + + $product->generateRewrittenUrl('fr_FR'); + } +} \ No newline at end of file From f068539e79ef1fd42213579fa52aa27782b171b0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:16:51 +0200 Subject: [PATCH 61/74] add covers annotation in ProductRewriteTest --- core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php index c38773814..b6601289d 100644 --- a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php +++ b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php @@ -76,6 +76,7 @@ class ProductRewriteTest extends \PHPUnit_Framework_TestCase } /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl * @expectedException \RuntimeException * @expectedExceptionMessage Object product must be saved before generating url */ From 1e15142283019420d75c4aa622bddfa766f23170 Mon Sep 17 00:00:00 2001 From: franck Date: Tue, 17 Sep 2013 20:18:53 +0200 Subject: [PATCH 62/74] Added product creation --- core/lib/Thelia/Model/Product.php | 48 +++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 541668ddb..ef000e820 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -10,6 +10,8 @@ use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\ProductEvent; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\Propel; +use Thelia\Model\Map\ProductTableMap; class Product extends BaseProduct { @@ -19,6 +21,8 @@ class Product extends BaseProduct use \Thelia\Model\Tools\UrlRewritingTrait; + protected $defaultCategory = null; + /** * {@inheritDoc} */ @@ -45,7 +49,7 @@ class Product extends BaseProduct } /** - * @return the current default category for this product + * @return the current default category ID for this product */ public function getDefaultCategoryId() { @@ -84,6 +88,42 @@ class Product extends BaseProduct return $this; } + /** + * Create a new product, along with the default category ID + * + * @param int $defaultCategoryId the default category ID of this product + */ + public function create($defaultCategoryId) { + + $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME); + + $con->beginTransaction(); + + try { + // Create the product + $this->save($con); + + // Add the default category + $pc = new ProductCategory(); + + $pc + ->setProduct($this) + ->setCategoryId($defaultCategoryId) + ->setDefaultCategory(true) + ->save($con) + ; + + // Store all the stuff ! + $con->commit(); + } + catch(PropelException $ex) { + + $con->rollback(); + + throw $ex; + } + } + /** * Calculate next position relative to our default category */ @@ -105,8 +145,6 @@ class Product extends BaseProduct */ public function preInsert(ConnectionInterface $con = null) { - $this->setPosition($this->getNextPosition()); - $this->generateRewritenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this)); @@ -119,6 +157,10 @@ class Product extends BaseProduct */ public function postInsert(ConnectionInterface $con = null) { + $this->setPosition($this->getNextPosition()); + + $this->save(); + $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this)); } From e4b36098c75b6e2a70f9a7836a7707692a07f04b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:29:09 +0200 Subject: [PATCH 63/74] fix typo and remove url generation in postInsert model --- core/lib/Thelia/Controller/Admin/CategoryController.php | 2 +- core/lib/Thelia/Controller/Admin/ProductController.php | 2 +- core/lib/Thelia/Model/Category.php | 1 - core/lib/Thelia/Model/Content.php | 5 ----- core/lib/Thelia/Model/Folder.php | 5 ----- core/lib/Thelia/Model/FolderI18n.php | 6 ++++++ core/lib/Thelia/Model/Product.php | 1 - core/lib/Thelia/Model/ProductI18n.php | 6 ++++++ 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 8c74c31ec..4d0d15ef1 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -133,7 +133,7 @@ class CategoryController extends AbstractCrudController 'description' => $object->getDescription(), 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), - 'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()), + 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), 'parent' => $object->getParent() ); diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index e1b651e60..b167922e0 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -141,7 +141,7 @@ class ProductController extends AbstractCrudController 'description' => $object->getDescription(), 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), - 'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()), + 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), 'parent' => $object->getParent() ); diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 204896674..347a0f7f7 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -79,7 +79,6 @@ class Category extends BaseCategory */ public function postInsert(ConnectionInterface $con = null) { - //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATECATEGORY, new CategoryEvent($this)); } diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 4d9cf9f3a..10ed2afe3 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -39,9 +39,4 @@ class Content extends BaseContent return true; } - - public function postInsert(ConnectionInterface $con = null) - { - //$this->generateRewrittenUrl($this->getLocale()); - } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index e32505d9d..f9006fbd7 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -70,9 +70,4 @@ class Folder extends BaseFolder return true; } - - public function postInsert(ConnectionInterface $con = null) - { - //$this->generateRewrittenUrl($this->getLocale()); - } } diff --git a/core/lib/Thelia/Model/FolderI18n.php b/core/lib/Thelia/Model/FolderI18n.php index d1044452b..7ede39502 100755 --- a/core/lib/Thelia/Model/FolderI18n.php +++ b/core/lib/Thelia/Model/FolderI18n.php @@ -2,8 +2,14 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\FolderI18n as BaseFolderI18n; class FolderI18n extends BaseFolderI18n { + public function postInsert(ConnectionInterface $con = null) + { + $folder = $this->getFolder(); + $folder->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index be534298e..fbac7c71a 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -119,7 +119,6 @@ class Product extends BaseProduct */ public function postInsert(ConnectionInterface $con = null) { - //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this)); } diff --git a/core/lib/Thelia/Model/ProductI18n.php b/core/lib/Thelia/Model/ProductI18n.php index 7507bceb1..6ec3ac4a3 100755 --- a/core/lib/Thelia/Model/ProductI18n.php +++ b/core/lib/Thelia/Model/ProductI18n.php @@ -2,8 +2,14 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\ProductI18n as BaseProductI18n; class ProductI18n extends BaseProductI18n { + public function postInsert(ConnectionInterface $con = null) + { + $product = $this->getProduct(); + $product->generateRewrittenUrl($this->getLocale()); + } } From 294c48f8abd5e48090a4dc32fa18eb7679f70904 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 20:32:51 +0200 Subject: [PATCH 64/74] fix content faker --- install/faker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install/faker.php b/install/faker.php index 3d48fc0e1..eed6db11a 100755 --- a/install/faker.php +++ b/install/faker.php @@ -281,7 +281,7 @@ try { $folder = new Thelia\Model\Folder(); $folder->setParent(0); $folder->setVisible(1); - $folder->setPosition($i); + $folder->setPosition($i+1); setI18n($faker, $folder); $folder->save(); @@ -294,11 +294,11 @@ try { $document->setFolderId($folder->getId()); generate_document($document, 1, 'folder', $folder->getId()); - for($j=1; $jsetParent($folder->getId()); $subfolder->setVisible(1); - $subfolder->setPosition($j); + $subfolder->setPosition($j+1); setI18n($faker, $subfolder); $subfolder->save(); @@ -311,7 +311,7 @@ try { $document->setFolderId($folder->getId()); generate_document($document, 1, 'folder', $subfolder->getId()); - for($k=0; $kaddFolder($subfolder); @@ -320,8 +320,8 @@ try { $collection->prepend($contentFolders[0]->setDefaultFolder(1)); $content->setContentFolders($collection); - $content->setVisible(rand(1, 10)>7 ? 0 : 1); - $content->setPosition($k); + $content->setVisible(1); + $content->setPosition($k+1); setI18n($faker, $content); $content->save(); From 5a64654ce53f40ba52f2da99f2113427a43d03f5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:45:29 +0200 Subject: [PATCH 65/74] move url generation to I18n entity --- core/lib/Thelia/Model/CategoryI18n.php | 7 ++++++- core/lib/Thelia/Model/ContentI18n.php | 7 ++++++- core/lib/Thelia/Model/Folder.php | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Model/CategoryI18n.php b/core/lib/Thelia/Model/CategoryI18n.php index bb4e7b3f3..de3e38663 100755 --- a/core/lib/Thelia/Model/CategoryI18n.php +++ b/core/lib/Thelia/Model/CategoryI18n.php @@ -2,8 +2,13 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\CategoryI18n as BaseCategoryI18n; class CategoryI18n extends BaseCategoryI18n { - + public function postInsert(ConnectionInterface $con = null) + { + $category = $this->getCategory(); + $category->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/ContentI18n.php b/core/lib/Thelia/Model/ContentI18n.php index 5b29d894f..11713d57b 100755 --- a/core/lib/Thelia/Model/ContentI18n.php +++ b/core/lib/Thelia/Model/ContentI18n.php @@ -2,8 +2,13 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\ContentI18n as BaseContentI18n; class ContentI18n extends BaseContentI18n { - + public function postInsert(ConnectionInterface $con = null) + { + $content = $this->getContent(); + $content->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index f9006fbd7..8cbe00ce0 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -67,7 +67,6 @@ class Folder extends BaseFolder { $this->setPosition($this->getNextPosition()); - return true; } } From 48e2be57c6ade1fdc743ee38e8536e20c387f923 Mon Sep 17 00:00:00 2001 From: franck Date: Wed, 18 Sep 2013 01:24:37 +0200 Subject: [PATCH 66/74] Fixed some unit tests --- core/lib/Thelia/Core/Template/Loop/Image.php | 9 ++- .../lib/Thelia/Core/Template/Loop/TaxRule.php | 9 ++- .../Core/Template/Element/BaseLoopTestor.php | 5 +- .../Tests/Core/Template/Loop/DocumentTest.php | 13 ++-- .../Tests/Core/Template/Loop/ImageTest.php | 13 ++-- .../Tests/Core/Template/Loop/ProductTest.php | 3 +- .../Tests/Core/Template/Loop/TaxRuleTest.php | 60 +++++++++++++++++++ .../Thelia/Tests/TaxEngine/CalculatorTest.php | 2 +- 8 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php diff --git a/core/lib/Thelia/Core/Template/Loop/Image.php b/core/lib/Thelia/Core/Template/Loop/Image.php index c85d41fc7..8d0c99400 100755 --- a/core/lib/Thelia/Core/Template/Loop/Image.php +++ b/core/lib/Thelia/Core/Template/Loop/Image.php @@ -175,7 +175,7 @@ class Image extends BaseI18nLoop $source_id = $this->getSourceId(); $id = $this->getId(); - //echo "source = ".$this->getSource()."source_id=$source_id, id=$id
"; + //echo "source = ".$this->getSourceId()."source_id=$source_id, id=$id
"; if (is_null($source_id) && is_null($id)) { throw new \InvalidArgumentException("If 'source' argument is specified, 'id' or 'source_id' argument should be specified"); @@ -214,6 +214,7 @@ class Image extends BaseI18nLoop */ public function exec(&$pagination) { + // Select the proper query to use, and get the object type $object_type = $object_id = null; @@ -262,13 +263,14 @@ class Image extends BaseI18nLoop } - //echo "sql=".$search->toString(); + // echo "sql=".$search->toString(); $results = $this->search($search, $pagination); $loopResult = new LoopResult($results); foreach ($results as $result) { + // Create image processing event $event = new ImageEvent($this->request); @@ -315,7 +317,8 @@ class Image extends BaseI18nLoop ; $loopResult->addRow($loopResultRow); - } catch (\Exception $ex) { + } + catch (\Exception $ex) { // Ignore the result and log an error Tlog::getInstance()->addError("Failed to process image in image loop: ", $this->args); } diff --git a/core/lib/Thelia/Core/Template/Loop/TaxRule.php b/core/lib/Thelia/Core/Template/Loop/TaxRule.php index a8ba3bf4a..5851f631d 100644 --- a/core/lib/Thelia/Core/Template/Loop/TaxRule.php +++ b/core/lib/Thelia/Core/Template/Loop/TaxRule.php @@ -31,11 +31,9 @@ use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\Argument; -use Thelia\Model\Base\CategoryQuery; -use Thelia\Model\Base\ProductCategoryQuery; -use Thelia\Model\Base\TaxRuleQuery; use Thelia\Type\TypeCollection; use Thelia\Type; +use Thelia\Model\TaxRuleQuery; /** * @@ -57,7 +55,8 @@ class TaxRule extends BaseI18nLoop { return new ArgumentCollection( Argument::createIntListTypeArgument('id'), - new Argument( + Argument::createIntListTypeArgument('exclude'), + new Argument( 'order', new TypeCollection( new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse')) @@ -77,7 +76,7 @@ class TaxRule extends BaseI18nLoop $search = TaxRuleQuery::create(); /* manage translations */ - $locale = $this->configureI18nProcessing($search, 'TITLE', 'DESCRIPTION'); + $locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION')); $id = $this->getId(); diff --git a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php index 2b31d265a..eb271d4c1 100755 --- a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php +++ b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php @@ -132,7 +132,7 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn); } - public function baseTestSearchById($id) + public function baseTestSearchById($id, $other_args = array()) { $this->instance->initializeArgs(array_merge( $this->getMandatoryArguments(), @@ -140,7 +140,8 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase "type" => "foo", "name" => "foo", "id" => $id, - ) + ), + $other_args )); $dummy = null; diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php index 04e41b6f8..2b7019879 100644 --- a/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php @@ -58,32 +58,27 @@ class DocumentTest extends BaseLoopTestor { $document = ProductDocumentQuery::create()->findOne(); - $this->baseTestSearchById($document->getId()); + $this->baseTestSearchById($document->getId(), array('source' => 'product')); } public function testSearchByFolderId() { $document = FolderDocumentQuery::create()->findOne(); - $this->baseTestSearchById($document->getId()); + $this->baseTestSearchById($document->getId(), array('source' => 'folder')); } public function testSearchByContentId() { $document = ContentDocumentQuery::create()->findOne(); - $this->baseTestSearchById($document->getId()); + $this->baseTestSearchById($document->getId(), array('source' => 'content')); } public function testSearchByCategoryId() { $document = CategoryDocumentQuery::create()->findOne(); - $this->baseTestSearchById($document->getId()); - } - - public function testSearchLimit() - { - $this->baseTestSearchWithLimit(1); + $this->baseTestSearchById($document->getId(), array('source' => 'category')); } } diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php index 3d2517c0a..ba4bfadc5 100644 --- a/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php @@ -58,32 +58,27 @@ class ImageTest extends BaseLoopTestor { $image = ProductImageQuery::create()->findOne(); - $this->baseTestSearchById($image->getId()); + $this->baseTestSearchById($image->getId(), array('source' => 'product')); } public function testSearchByFolderId() { $image = FolderImageQuery::create()->findOne(); - $this->baseTestSearchById($image->getId()); + $this->baseTestSearchById($image->getId(), array('source' => 'folder')); } public function testSearchByContentId() { $image = ContentImageQuery::create()->findOne(); - $this->baseTestSearchById($image->getId()); + $this->baseTestSearchById($image->getId(), array('source' => 'content')); } public function testSearchByCategoryId() { $image = CategoryImageQuery::create()->findOne(); - $this->baseTestSearchById($image->getId()); - } - - public function testSearchLimit() - { - $this->baseTestSearchWithLimit(1); + $this->baseTestSearchById($image->getId(), array('source' => 'category')); } } diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php index 1b307c5b5..07e179cbd 100755 --- a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php @@ -27,6 +27,7 @@ use Thelia\Model\ProductQuery; use Thelia\Tests\Core\Template\Element\BaseLoopTestor; use Thelia\Core\Template\Loop\Product; +use Propel\Runtime\ActiveQuery\Criteria; /** * @@ -52,7 +53,7 @@ class ProductTest extends BaseLoopTestor public function testSearchById() { - $product = ProductQuery::create()->findOne(); + $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne(); $this->baseTestSearchById($product->getId()); } diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php new file mode 100644 index 000000000..20523bfa5 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php @@ -0,0 +1,60 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\TaxRule; +use Thelia\Model\TaxRuleQuery; + +/** + * + * @author Etienne Roudeix + * + */ +class TaxRuleTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\TaxRule'; + } + + public function getTestedInstance() + { + return new TaxRule($this->container); + } + + public function getMandatoryArguments() + { + return array(); + } + + public function testSearchById() + { + $tr = TaxRuleQuery::create()->findOne(); + + $this->baseTestSearchById($tr->getId()); + } + +} diff --git a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php index e0443c5ba..502b14c7e 100755 --- a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php +++ b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php @@ -78,7 +78,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase public function testLoad() { - $productQuery = ProductQuery::create()->findOneById(1); + $productQuery = ProductQuery::create()->findOne(); $countryQuery = CountryQuery::create()->findOneById(64); $calculator = new Calculator(); From 8f95fe1b8b9f06f721de6c08aa58d81fff4ae9ba Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Sep 2013 08:25:20 +0200 Subject: [PATCH 67/74] remove all tables before inserting tables creation --- core/lib/Thelia/Command/ReloadDatabaseCommand.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/lib/Thelia/Command/ReloadDatabaseCommand.php b/core/lib/Thelia/Command/ReloadDatabaseCommand.php index 70fab56d9..311b20552 100644 --- a/core/lib/Thelia/Command/ReloadDatabaseCommand.php +++ b/core/lib/Thelia/Command/ReloadDatabaseCommand.php @@ -54,6 +54,13 @@ class ReloadDatabaseCommand extends BaseModuleGenerate $connection = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME); $connection = $connection->getWrappedConnection(); + $tables = $connection->query("SHOW TABLES"); + $connection->query("SET FOREIGN_KEY_CHECKS = 0"); + foreach($tables as $table) { + $connection->query(sprintf("DROP TABLE `%s`", $table[0])); + } + $connection->query("SET FOREIGN_KEY_CHECKS = 1"); + $database = new Database($connection); $output->writeln(array( '', From bb246b320509fa2f3e8bcabf957277fcc901d6f5 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 18 Sep 2013 08:55:12 +0200 Subject: [PATCH 68/74] fix test --- core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php | 2 +- local/modules/Colissimo/Config/schema.xml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100755 local/modules/Colissimo/Config/schema.xml diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php index 20523bfa5..fa24d72ee 100644 --- a/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php @@ -54,7 +54,7 @@ class TaxRuleTest extends BaseLoopTestor { $tr = TaxRuleQuery::create()->findOne(); - $this->baseTestSearchById($tr->getId()); + $this->baseTestSearchById($tr->getId(), array('force_return' => true)); } } diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml deleted file mode 100755 index a4e2315b0..000000000 --- a/local/modules/Colissimo/Config/schema.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - From f32f16e833e3def5427b0399872177bd7211e075 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 18 Sep 2013 09:17:49 +0200 Subject: [PATCH 69/74] fix product without pse in loop --- core/lib/Thelia/Core/Template/Loop/Product.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 4a401d464..7c71e542b 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -597,14 +597,16 @@ class Product extends BaseI18nLoop $loopResult = new LoopResult($products); + $taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic + foreach ($products as $product) { $loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable); $price = $product->getRealLowestPrice(); - $taxedPrice = $product->getTaxedPrice( - CountryQuery::create()->findOneById(64) // @TODO : make it magic + $taxedPrice = null === $price ? null : $product->getTaxedPrice( + $taxCountry ); // Find previous and next product, in the default category. From 387c0d00c30b1d0f8e8a62f115ae3d8e52d5d39d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Sep 2013 09:34:48 +0200 Subject: [PATCH 70/74] test if cache directory exists before launching debug bar --- core/lib/Thelia/Install/CheckPermission.php | 2 + .../DebugBar/Smarty/Plugin/DebugBar.php | 12 ++- web/.htaccess | 0 web/install/bdd.php | 0 web/install/bootstrap.php | 0 web/install/config.php | 0 web/install/connection.php | 0 web/install/end.php | 0 web/install/fd33fd0-6fda040.ico | Bin web/install/footer.php | 0 web/install/header.php | 0 web/install/index.php | 0 web/install/permission.php | 0 web/install/script.js | 0 web/install/styles.css | 0 web/test_to_remove/datas_coupon_edit.json | 85 ------------------ 16 files changed, 12 insertions(+), 87 deletions(-) mode change 100644 => 100755 web/.htaccess mode change 100644 => 100755 web/install/bdd.php mode change 100644 => 100755 web/install/bootstrap.php mode change 100644 => 100755 web/install/config.php mode change 100644 => 100755 web/install/connection.php mode change 100644 => 100755 web/install/end.php mode change 100644 => 100755 web/install/fd33fd0-6fda040.ico mode change 100644 => 100755 web/install/footer.php mode change 100644 => 100755 web/install/header.php mode change 100644 => 100755 web/install/index.php mode change 100644 => 100755 web/install/permission.php mode change 100644 => 100755 web/install/script.js mode change 100644 => 100755 web/install/styles.css delete mode 100755 web/test_to_remove/datas_coupon_edit.json diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index d07b8ed83..15317211b 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -44,12 +44,14 @@ class CheckPermission extends BaseInstall const DIR_CONF = 'local/config'; const DIR_LOG = 'log'; const DIR_CACHE = 'cache'; + const DIR_WEB = 'web'; /** @var array Directory needed to be writable */ protected $directoriesToBeWritable = array( self::DIR_CONF, self::DIR_LOG, self::DIR_CACHE, + self::DIR_WEB, ); /** @var array Minimum server configuration necessary */ diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php index 0cd1abee9..9f3cc8386 100755 --- a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php +++ b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php @@ -71,7 +71,11 @@ class DebugBar extends AbstractSmartyPlugin } } - file_put_contents($cssFile, $assetCss->dump()); + if(!file_exists(THELIA_WEB_DIR . "/cache")) { + @mkdir(THELIA_WEB_DIR . "/cache"); + } + + @file_put_contents($cssFile, $assetCss->dump()); } $render = sprintf('', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE)); } @@ -96,7 +100,11 @@ class DebugBar extends AbstractSmartyPlugin } } - file_put_contents($cacheFile, $assetJs->dump()); + if(!file_exists(THELIA_WEB_DIR . "/cache")) { + @mkdir(THELIA_WEB_DIR . "/cache"); + } + + @file_put_contents($cacheFile, $assetJs->dump()); } $render = sprintf('', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE)); diff --git a/web/.htaccess b/web/.htaccess old mode 100644 new mode 100755 diff --git a/web/install/bdd.php b/web/install/bdd.php old mode 100644 new mode 100755 diff --git a/web/install/bootstrap.php b/web/install/bootstrap.php old mode 100644 new mode 100755 diff --git a/web/install/config.php b/web/install/config.php old mode 100644 new mode 100755 diff --git a/web/install/connection.php b/web/install/connection.php old mode 100644 new mode 100755 diff --git a/web/install/end.php b/web/install/end.php old mode 100644 new mode 100755 diff --git a/web/install/fd33fd0-6fda040.ico b/web/install/fd33fd0-6fda040.ico old mode 100644 new mode 100755 diff --git a/web/install/footer.php b/web/install/footer.php old mode 100644 new mode 100755 diff --git a/web/install/header.php b/web/install/header.php old mode 100644 new mode 100755 diff --git a/web/install/index.php b/web/install/index.php old mode 100644 new mode 100755 diff --git a/web/install/permission.php b/web/install/permission.php old mode 100644 new mode 100755 diff --git a/web/install/script.js b/web/install/script.js old mode 100644 new mode 100755 diff --git a/web/install/styles.css b/web/install/styles.css old mode 100644 new mode 100755 diff --git a/web/test_to_remove/datas_coupon_edit.json b/web/test_to_remove/datas_coupon_edit.json deleted file mode 100755 index d64345682..000000000 --- a/web/test_to_remove/datas_coupon_edit.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "breadcrumb" : [ - { - "url" : "0", - "display" : "Racine", - "edit" : "", - "browse" : "" - } - ], - "categories" : [ - { - "id" : "1", - "ligne" : "1", - "classement" : "1", - "titre" : "Boyaux", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "18", - "ligne" : "1", - "classement" : "2", - "titre" : "Epices \/ condiments", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "100", - "ligne" : "1", - "classement" : "3", - "titre" : "Emballage", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "194", - "ligne" : "1", - "classement" : "4", - "titre" : "Petits mat\u00e9riels", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "355", - "ligne" : "1", - "classement" : "5", - "titre" : "Materiel de cuisine", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "426", - "ligne" : "0", - "classement" : "6", - "titre" : "Bacs", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "458", - "ligne" : "1", - "classement" : "7", - "titre" : "Hygi\u00e8ne & entretien", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "592", - "ligne" : "1", - "classement" : "8", - "titre" : "Art de la table", - "langue_courante" : true, - "parent" : 0 - }, - { - "id" : "601", - "ligne" : "1", - "classement" : "9", - "titre" : "Mat\u00e9riels", - "langue_courante" : true, - "parent" : 0 - } - ], - "products":[] -} \ No newline at end of file From a041273b80c66811337978a9b5052f4d69c64ab2 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Sep 2013 10:34:31 +0200 Subject: [PATCH 71/74] remove unused classes --- core/lib/Thelia/Model/AttributeCategory.php | 9 - .../Thelia/Model/AttributeCategoryQuery.php | 20 - .../Model/Map/AttributeCategoryTableMap.php | 449 ------------------ .../Model/Map/FeatureCategoryTableMap.php | 449 ------------------ 4 files changed, 927 deletions(-) delete mode 100755 core/lib/Thelia/Model/AttributeCategory.php delete mode 100755 core/lib/Thelia/Model/AttributeCategoryQuery.php delete mode 100644 core/lib/Thelia/Model/Map/AttributeCategoryTableMap.php delete mode 100644 core/lib/Thelia/Model/Map/FeatureCategoryTableMap.php diff --git a/core/lib/Thelia/Model/AttributeCategory.php b/core/lib/Thelia/Model/AttributeCategory.php deleted file mode 100755 index ef1341e08..000000000 --- a/core/lib/Thelia/Model/AttributeCategory.php +++ /dev/null @@ -1,9 +0,0 @@ - array('Id', 'CategoryId', 'AttributeId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'categoryId', 'attributeId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AttributeCategoryTableMap::ID, AttributeCategoryTableMap::CATEGORY_ID, AttributeCategoryTableMap::ATTRIBUTE_ID, AttributeCategoryTableMap::CREATED_AT, AttributeCategoryTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'CATEGORY_ID', 'ATTRIBUTE_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'category_id', 'attribute_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) - ); - - /** - * holds an array of keys for quick access to the fieldnames array - * - * first dimension keys are the type constants - * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 - */ - protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'CategoryId' => 1, 'AttributeId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'categoryId' => 1, 'attributeId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(AttributeCategoryTableMap::ID => 0, AttributeCategoryTableMap::CATEGORY_ID => 1, AttributeCategoryTableMap::ATTRIBUTE_ID => 2, AttributeCategoryTableMap::CREATED_AT => 3, AttributeCategoryTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CATEGORY_ID' => 1, 'ATTRIBUTE_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'category_id' => 1, 'attribute_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) - ); - - /** - * Initialize the table attributes and columns - * Relations are not initialized by this method since they are lazy loaded - * - * @return void - * @throws PropelException - */ - public function initialize() - { - // attributes - $this->setName('attribute_category'); - $this->setPhpName('AttributeCategory'); - $this->setClassName('\\Thelia\\Model\\AttributeCategory'); - $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(true); - $this->setIsCrossRef(true); - // columns - $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addForeignKey('CATEGORY_ID', 'CategoryId', 'INTEGER', 'category', 'ID', true, null, null); - $this->addForeignKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER', 'attribute', 'ID', true, null, null); - $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); - $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); - } // initialize() - - /** - * Build the RelationMap objects for this table relationships - */ - public function buildRelations() - { - $this->addRelation('Category', '\\Thelia\\Model\\Category', RelationMap::MANY_TO_ONE, array('category_id' => 'id', ), 'CASCADE', 'RESTRICT'); - $this->addRelation('Attribute', '\\Thelia\\Model\\Attribute', RelationMap::MANY_TO_ONE, array('attribute_id' => 'id', ), 'CASCADE', 'RESTRICT'); - } // buildRelations() - - /** - * - * Gets the list of behaviors registered for this table - * - * @return array Associative array (name => parameters) of behaviors - */ - public function getBehaviors() - { - return array( - 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), - ); - } // getBehaviors() - - /** - * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. - * - * For tables with a single-column primary key, that simple pkey value will be returned. For tables with - * a multi-column primary key, a serialize()d version of the primary key will be returned. - * - * @param array $row resultset row. - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM - */ - public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - // If the PK cannot be derived from the row, return NULL. - if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { - return null; - } - - return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - } - - /** - * Retrieves the primary key from the DB resultset row - * For tables with a single-column primary key, that simple pkey value will be returned. For tables with - * a multi-column primary key, an array of the primary key columns will be returned. - * - * @param array $row resultset row. - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM - * - * @return mixed The primary key of the row - */ - public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - - return (int) $row[ - $indexType == TableMap::TYPE_NUM - ? 0 + $offset - : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) - ]; - } - - /** - * The class that the tableMap will make instances of. - * - * If $withPrefix is true, the returned path - * uses a dot-path notation which is translated into a path - * relative to a location on the PHP include_path. - * (e.g. path.to.MyClass -> 'path/to/MyClass.php') - * - * @param boolean $withPrefix Whether or not to return the path with the class name - * @return string path.to.ClassName - */ - public static function getOMClass($withPrefix = true) - { - return $withPrefix ? AttributeCategoryTableMap::CLASS_DEFAULT : AttributeCategoryTableMap::OM_CLASS; - } - - /** - * Populates an object of the default type or an object that inherit from the default. - * - * @param array $row row returned by DataFetcher->fetch(). - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). - One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - * @return array (AttributeCategory object, last column rank) - */ - public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - $key = AttributeCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = AttributeCategoryTableMap::getInstanceFromPool($key))) { - // We no longer rehydrate the object, since this can cause data loss. - // See http://www.propelorm.org/ticket/509 - // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + AttributeCategoryTableMap::NUM_HYDRATE_COLUMNS; - } else { - $cls = AttributeCategoryTableMap::OM_CLASS; - $obj = new $cls(); - $col = $obj->hydrate($row, $offset, false, $indexType); - AttributeCategoryTableMap::addInstanceToPool($obj, $key); - } - - return array($obj, $col); - } - - /** - * The returned array will contain objects of the default type or - * objects that inherit from the default. - * - * @param DataFetcherInterface $dataFetcher - * @return array - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function populateObjects(DataFetcherInterface $dataFetcher) - { - $results = array(); - - // set the class once to avoid overhead in the loop - $cls = static::getOMClass(false); - // populate the object(s) - while ($row = $dataFetcher->fetch()) { - $key = AttributeCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = AttributeCategoryTableMap::getInstanceFromPool($key))) { - // We no longer rehydrate the object, since this can cause data loss. - // See http://www.propelorm.org/ticket/509 - // $obj->hydrate($row, 0, true); // rehydrate - $results[] = $obj; - } else { - $obj = new $cls(); - $obj->hydrate($row); - $results[] = $obj; - AttributeCategoryTableMap::addInstanceToPool($obj, $key); - } // if key exists - } - - return $results; - } - /** - * Add all the columns needed to create a new object. - * - * Note: any columns that were marked with lazyLoad="true" in the - * XML schema will not be added to the select list and only loaded - * on demand. - * - * @param Criteria $criteria object containing the columns to add. - * @param string $alias optional table alias - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function addSelectColumns(Criteria $criteria, $alias = null) - { - if (null === $alias) { - $criteria->addSelectColumn(AttributeCategoryTableMap::ID); - $criteria->addSelectColumn(AttributeCategoryTableMap::CATEGORY_ID); - $criteria->addSelectColumn(AttributeCategoryTableMap::ATTRIBUTE_ID); - $criteria->addSelectColumn(AttributeCategoryTableMap::CREATED_AT); - $criteria->addSelectColumn(AttributeCategoryTableMap::UPDATED_AT); - } else { - $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.CATEGORY_ID'); - $criteria->addSelectColumn($alias . '.ATTRIBUTE_ID'); - $criteria->addSelectColumn($alias . '.CREATED_AT'); - $criteria->addSelectColumn($alias . '.UPDATED_AT'); - } - } - - /** - * Returns the TableMap related to this object. - * This method is not needed for general use but a specific application could have a need. - * @return TableMap - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function getTableMap() - { - return Propel::getServiceContainer()->getDatabaseMap(AttributeCategoryTableMap::DATABASE_NAME)->getTable(AttributeCategoryTableMap::TABLE_NAME); - } - - /** - * Add a TableMap instance to the database for this tableMap class. - */ - public static function buildTableMap() - { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(AttributeCategoryTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(AttributeCategoryTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new AttributeCategoryTableMap()); - } - } - - /** - * Performs a DELETE on the database, given a AttributeCategory or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or AttributeCategory object or primary key or array of primary keys - * which is used to create the DELETE statement - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows - * if supported by native driver or if emulated using Propel. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function doDelete($values, ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - if ($values instanceof Criteria) { - // rename for clarity - $criteria = $values; - } elseif ($values instanceof \Thelia\Model\AttributeCategory) { // it's a model object - // create criteria based on pk values - $criteria = $values->buildPkeyCriteria(); - } else { // it's a primary key, or an array of pks - $criteria = new Criteria(AttributeCategoryTableMap::DATABASE_NAME); - $criteria->add(AttributeCategoryTableMap::ID, (array) $values, Criteria::IN); - } - - $query = AttributeCategoryQuery::create()->mergeWith($criteria); - - if ($values instanceof Criteria) { AttributeCategoryTableMap::clearInstancePool(); - } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { AttributeCategoryTableMap::removeInstanceFromPool($singleval); - } - } - - return $query->delete($con); - } - - /** - * Deletes all rows from the attribute_category table. - * - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). - */ - public static function doDeleteAll(ConnectionInterface $con = null) - { - return AttributeCategoryQuery::create()->doDeleteAll($con); - } - - /** - * Performs an INSERT on the database, given a AttributeCategory or Criteria object. - * - * @param mixed $criteria Criteria or AttributeCategory object containing data that is used to create the INSERT statement. - * @param ConnectionInterface $con the ConnectionInterface connection to use - * @return mixed The new primary key. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function doInsert($criteria, ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - if ($criteria instanceof Criteria) { - $criteria = clone $criteria; // rename for clarity - } else { - $criteria = $criteria->buildCriteria(); // build Criteria from AttributeCategory object - } - - if ($criteria->containsKey(AttributeCategoryTableMap::ID) && $criteria->keyContainsValue(AttributeCategoryTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.AttributeCategoryTableMap::ID.')'); - } - - - // Set the correct dbName - $query = AttributeCategoryQuery::create()->mergeWith($criteria); - - try { - // use transaction because $criteria could contain info - // for more than one table (I guess, conceivably) - $con->beginTransaction(); - $pk = $query->doInsert($con); - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $pk; - } - -} // AttributeCategoryTableMap -// This is the static code needed to register the TableMap for this table with the main Propel class. -// -AttributeCategoryTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/FeatureCategoryTableMap.php b/core/lib/Thelia/Model/Map/FeatureCategoryTableMap.php deleted file mode 100644 index 3e20805b6..000000000 --- a/core/lib/Thelia/Model/Map/FeatureCategoryTableMap.php +++ /dev/null @@ -1,449 +0,0 @@ - array('Id', 'FeatureId', 'CategoryId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'featureId', 'categoryId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(FeatureCategoryTableMap::ID, FeatureCategoryTableMap::FEATURE_ID, FeatureCategoryTableMap::CATEGORY_ID, FeatureCategoryTableMap::CREATED_AT, FeatureCategoryTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'FEATURE_ID', 'CATEGORY_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'feature_id', 'category_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) - ); - - /** - * holds an array of keys for quick access to the fieldnames array - * - * first dimension keys are the type constants - * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 - */ - protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'FeatureId' => 1, 'CategoryId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'featureId' => 1, 'categoryId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(FeatureCategoryTableMap::ID => 0, FeatureCategoryTableMap::FEATURE_ID => 1, FeatureCategoryTableMap::CATEGORY_ID => 2, FeatureCategoryTableMap::CREATED_AT => 3, FeatureCategoryTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'FEATURE_ID' => 1, 'CATEGORY_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'feature_id' => 1, 'category_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) - ); - - /** - * Initialize the table attributes and columns - * Relations are not initialized by this method since they are lazy loaded - * - * @return void - * @throws PropelException - */ - public function initialize() - { - // attributes - $this->setName('feature_category'); - $this->setPhpName('FeatureCategory'); - $this->setClassName('\\Thelia\\Model\\FeatureCategory'); - $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(true); - $this->setIsCrossRef(true); - // columns - $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addForeignKey('FEATURE_ID', 'FeatureId', 'INTEGER', 'feature', 'ID', true, null, null); - $this->addForeignKey('CATEGORY_ID', 'CategoryId', 'INTEGER', 'category', 'ID', true, null, null); - $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); - $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); - } // initialize() - - /** - * Build the RelationMap objects for this table relationships - */ - public function buildRelations() - { - $this->addRelation('Category', '\\Thelia\\Model\\Category', RelationMap::MANY_TO_ONE, array('category_id' => 'id', ), 'CASCADE', 'RESTRICT'); - $this->addRelation('Feature', '\\Thelia\\Model\\Feature', RelationMap::MANY_TO_ONE, array('feature_id' => 'id', ), 'CASCADE', 'RESTRICT'); - } // buildRelations() - - /** - * - * Gets the list of behaviors registered for this table - * - * @return array Associative array (name => parameters) of behaviors - */ - public function getBehaviors() - { - return array( - 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), - ); - } // getBehaviors() - - /** - * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. - * - * For tables with a single-column primary key, that simple pkey value will be returned. For tables with - * a multi-column primary key, a serialize()d version of the primary key will be returned. - * - * @param array $row resultset row. - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM - */ - public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - // If the PK cannot be derived from the row, return NULL. - if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { - return null; - } - - return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - } - - /** - * Retrieves the primary key from the DB resultset row - * For tables with a single-column primary key, that simple pkey value will be returned. For tables with - * a multi-column primary key, an array of the primary key columns will be returned. - * - * @param array $row resultset row. - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM - * - * @return mixed The primary key of the row - */ - public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - - return (int) $row[ - $indexType == TableMap::TYPE_NUM - ? 0 + $offset - : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) - ]; - } - - /** - * The class that the tableMap will make instances of. - * - * If $withPrefix is true, the returned path - * uses a dot-path notation which is translated into a path - * relative to a location on the PHP include_path. - * (e.g. path.to.MyClass -> 'path/to/MyClass.php') - * - * @param boolean $withPrefix Whether or not to return the path with the class name - * @return string path.to.ClassName - */ - public static function getOMClass($withPrefix = true) - { - return $withPrefix ? FeatureCategoryTableMap::CLASS_DEFAULT : FeatureCategoryTableMap::OM_CLASS; - } - - /** - * Populates an object of the default type or an object that inherit from the default. - * - * @param array $row row returned by DataFetcher->fetch(). - * @param int $offset The 0-based offset for reading from the resultset row. - * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). - One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - * @return array (FeatureCategory object, last column rank) - */ - public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - $key = FeatureCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = FeatureCategoryTableMap::getInstanceFromPool($key))) { - // We no longer rehydrate the object, since this can cause data loss. - // See http://www.propelorm.org/ticket/509 - // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + FeatureCategoryTableMap::NUM_HYDRATE_COLUMNS; - } else { - $cls = FeatureCategoryTableMap::OM_CLASS; - $obj = new $cls(); - $col = $obj->hydrate($row, $offset, false, $indexType); - FeatureCategoryTableMap::addInstanceToPool($obj, $key); - } - - return array($obj, $col); - } - - /** - * The returned array will contain objects of the default type or - * objects that inherit from the default. - * - * @param DataFetcherInterface $dataFetcher - * @return array - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function populateObjects(DataFetcherInterface $dataFetcher) - { - $results = array(); - - // set the class once to avoid overhead in the loop - $cls = static::getOMClass(false); - // populate the object(s) - while ($row = $dataFetcher->fetch()) { - $key = FeatureCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = FeatureCategoryTableMap::getInstanceFromPool($key))) { - // We no longer rehydrate the object, since this can cause data loss. - // See http://www.propelorm.org/ticket/509 - // $obj->hydrate($row, 0, true); // rehydrate - $results[] = $obj; - } else { - $obj = new $cls(); - $obj->hydrate($row); - $results[] = $obj; - FeatureCategoryTableMap::addInstanceToPool($obj, $key); - } // if key exists - } - - return $results; - } - /** - * Add all the columns needed to create a new object. - * - * Note: any columns that were marked with lazyLoad="true" in the - * XML schema will not be added to the select list and only loaded - * on demand. - * - * @param Criteria $criteria object containing the columns to add. - * @param string $alias optional table alias - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function addSelectColumns(Criteria $criteria, $alias = null) - { - if (null === $alias) { - $criteria->addSelectColumn(FeatureCategoryTableMap::ID); - $criteria->addSelectColumn(FeatureCategoryTableMap::FEATURE_ID); - $criteria->addSelectColumn(FeatureCategoryTableMap::CATEGORY_ID); - $criteria->addSelectColumn(FeatureCategoryTableMap::CREATED_AT); - $criteria->addSelectColumn(FeatureCategoryTableMap::UPDATED_AT); - } else { - $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.FEATURE_ID'); - $criteria->addSelectColumn($alias . '.CATEGORY_ID'); - $criteria->addSelectColumn($alias . '.CREATED_AT'); - $criteria->addSelectColumn($alias . '.UPDATED_AT'); - } - } - - /** - * Returns the TableMap related to this object. - * This method is not needed for general use but a specific application could have a need. - * @return TableMap - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function getTableMap() - { - return Propel::getServiceContainer()->getDatabaseMap(FeatureCategoryTableMap::DATABASE_NAME)->getTable(FeatureCategoryTableMap::TABLE_NAME); - } - - /** - * Add a TableMap instance to the database for this tableMap class. - */ - public static function buildTableMap() - { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(FeatureCategoryTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(FeatureCategoryTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new FeatureCategoryTableMap()); - } - } - - /** - * Performs a DELETE on the database, given a FeatureCategory or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or FeatureCategory object or primary key or array of primary keys - * which is used to create the DELETE statement - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows - * if supported by native driver or if emulated using Propel. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function doDelete($values, ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - if ($values instanceof Criteria) { - // rename for clarity - $criteria = $values; - } elseif ($values instanceof \Thelia\Model\FeatureCategory) { // it's a model object - // create criteria based on pk values - $criteria = $values->buildPkeyCriteria(); - } else { // it's a primary key, or an array of pks - $criteria = new Criteria(FeatureCategoryTableMap::DATABASE_NAME); - $criteria->add(FeatureCategoryTableMap::ID, (array) $values, Criteria::IN); - } - - $query = FeatureCategoryQuery::create()->mergeWith($criteria); - - if ($values instanceof Criteria) { FeatureCategoryTableMap::clearInstancePool(); - } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { FeatureCategoryTableMap::removeInstanceFromPool($singleval); - } - } - - return $query->delete($con); - } - - /** - * Deletes all rows from the feature_category table. - * - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). - */ - public static function doDeleteAll(ConnectionInterface $con = null) - { - return FeatureCategoryQuery::create()->doDeleteAll($con); - } - - /** - * Performs an INSERT on the database, given a FeatureCategory or Criteria object. - * - * @param mixed $criteria Criteria or FeatureCategory object containing data that is used to create the INSERT statement. - * @param ConnectionInterface $con the ConnectionInterface connection to use - * @return mixed The new primary key. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function doInsert($criteria, ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - if ($criteria instanceof Criteria) { - $criteria = clone $criteria; // rename for clarity - } else { - $criteria = $criteria->buildCriteria(); // build Criteria from FeatureCategory object - } - - if ($criteria->containsKey(FeatureCategoryTableMap::ID) && $criteria->keyContainsValue(FeatureCategoryTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.FeatureCategoryTableMap::ID.')'); - } - - - // Set the correct dbName - $query = FeatureCategoryQuery::create()->mergeWith($criteria); - - try { - // use transaction because $criteria could contain info - // for more than one table (I guess, conceivably) - $con->beginTransaction(); - $pk = $query->doInsert($con); - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $pk; - } - -} // FeatureCategoryTableMap -// This is the static code needed to register the TableMap for this table with the main Propel class. -// -FeatureCategoryTableMap::buildTableMap(); From e7fa896866c75349a8ae93b845638060ba167dc8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Sep 2013 10:52:07 +0200 Subject: [PATCH 72/74] remove unused classes --- .../Thelia/Model/Base/AttributeCategory.php | 1495 ----------------- .../Model/Base/AttributeCategoryQuery.php | 759 --------- .../lib/Thelia/Model/Base/FeatureCategory.php | 1495 ----------------- .../Model/Base/FeatureCategoryQuery.php | 759 --------- core/lib/Thelia/Model/FeatureCategory.php | 9 - .../lib/Thelia/Model/FeatureCategoryQuery.php | 20 - 6 files changed, 4537 deletions(-) delete mode 100644 core/lib/Thelia/Model/Base/AttributeCategory.php delete mode 100644 core/lib/Thelia/Model/Base/AttributeCategoryQuery.php delete mode 100644 core/lib/Thelia/Model/Base/FeatureCategory.php delete mode 100644 core/lib/Thelia/Model/Base/FeatureCategoryQuery.php delete mode 100755 core/lib/Thelia/Model/FeatureCategory.php delete mode 100755 core/lib/Thelia/Model/FeatureCategoryQuery.php diff --git a/core/lib/Thelia/Model/Base/AttributeCategory.php b/core/lib/Thelia/Model/Base/AttributeCategory.php deleted file mode 100644 index da702559a..000000000 --- a/core/lib/Thelia/Model/Base/AttributeCategory.php +++ /dev/null @@ -1,1495 +0,0 @@ -modifiedColumns); - } - - /** - * Has specified column been modified? - * - * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID - * @return boolean True if $col has been modified. - */ - public function isColumnModified($col) - { - return in_array($col, $this->modifiedColumns); - } - - /** - * Get the columns that have been modified in this object. - * @return array A unique list of the modified column names for this object. - */ - public function getModifiedColumns() - { - return array_unique($this->modifiedColumns); - } - - /** - * Returns whether the object has ever been saved. This will - * be false, if the object was retrieved from storage or was created - * and then saved. - * - * @return true, if the object has never been persisted. - */ - public function isNew() - { - return $this->new; - } - - /** - * Setter for the isNew attribute. This method will be called - * by Propel-generated children and objects. - * - * @param boolean $b the state of the object. - */ - public function setNew($b) - { - $this->new = (Boolean) $b; - } - - /** - * Whether this object has been deleted. - * @return boolean The deleted state of this object. - */ - public function isDeleted() - { - return $this->deleted; - } - - /** - * Specify whether this object has been deleted. - * @param boolean $b The deleted state of this object. - * @return void - */ - public function setDeleted($b) - { - $this->deleted = (Boolean) $b; - } - - /** - * Sets the modified state for the object to be false. - * @param string $col If supplied, only the specified column is reset. - * @return void - */ - public function resetModified($col = null) - { - if (null !== $col) { - while (false !== ($offset = array_search($col, $this->modifiedColumns))) { - array_splice($this->modifiedColumns, $offset, 1); - } - } else { - $this->modifiedColumns = array(); - } - } - - /** - * Compares this with another AttributeCategory instance. If - * obj is an instance of AttributeCategory, delegates to - * equals(AttributeCategory). Otherwise, returns false. - * - * @param obj The object to compare to. - * @return Whether equal to the object specified. - */ - public function equals($obj) - { - $thisclazz = get_class($this); - if (!is_object($obj) || !($obj instanceof $thisclazz)) { - return false; - } - - if ($this === $obj) { - return true; - } - - if (null === $this->getPrimaryKey() - || null === $obj->getPrimaryKey()) { - return false; - } - - return $this->getPrimaryKey() === $obj->getPrimaryKey(); - } - - /** - * If the primary key is not null, return the hashcode of the - * primary key. Otherwise, return the hash code of the object. - * - * @return int Hashcode - */ - public function hashCode() - { - if (null !== $this->getPrimaryKey()) { - return crc32(serialize($this->getPrimaryKey())); - } - - return crc32(serialize(clone $this)); - } - - /** - * Get the associative array of the virtual columns in this object - * - * @param string $name The virtual column name - * - * @return array - */ - public function getVirtualColumns() - { - return $this->virtualColumns; - } - - /** - * Checks the existence of a virtual column in this object - * - * @return boolean - */ - public function hasVirtualColumn($name) - { - return array_key_exists($name, $this->virtualColumns); - } - - /** - * Get the value of a virtual column in this object - * - * @return mixed - */ - public function getVirtualColumn($name) - { - if (!$this->hasVirtualColumn($name)) { - throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); - } - - return $this->virtualColumns[$name]; - } - - /** - * Set the value of a virtual column in this object - * - * @param string $name The virtual column name - * @param mixed $value The value to give to the virtual column - * - * @return AttributeCategory The current object, for fluid interface - */ - public function setVirtualColumn($name, $value) - { - $this->virtualColumns[$name] = $value; - - return $this; - } - - /** - * Logs a message using Propel::log(). - * - * @param string $msg - * @param int $priority One of the Propel::LOG_* logging levels - * @return boolean - */ - protected function log($msg, $priority = Propel::LOG_INFO) - { - return Propel::log(get_class($this) . ': ' . $msg, $priority); - } - - /** - * Populate the current object from a string, using a given parser format - * - * $book = new Book(); - * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); - * - * - * @param mixed $parser A AbstractParser instance, - * or a format name ('XML', 'YAML', 'JSON', 'CSV') - * @param string $data The source data to import from - * - * @return AttributeCategory The current object, for fluid interface - */ - public function importFrom($parser, $data) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - return $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); - } - - /** - * Export the current object properties to a string, using a given parser format - * - * $book = BookQuery::create()->findPk(9012); - * echo $book->exportTo('JSON'); - * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); - * - * - * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') - * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. - * @return string The exported data - */ - public function exportTo($parser, $includeLazyLoadColumns = true) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); - } - - /** - * Clean up internal collections prior to serializing - * Avoids recursive loops that turn into segmentation faults when serializing - */ - public function __sleep() - { - $this->clearAllReferences(); - - return array_keys(get_object_vars($this)); - } - - /** - * Get the [id] column value. - * - * @return int - */ - public function getId() - { - - return $this->id; - } - - /** - * Get the [category_id] column value. - * - * @return int - */ - public function getCategoryId() - { - - return $this->category_id; - } - - /** - * Get the [attribute_id] column value. - * - * @return int - */ - public function getAttributeId() - { - - return $this->attribute_id; - } - - /** - * Get the [optionally formatted] temporal [created_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getCreatedAt($format = NULL) - { - if ($format === null) { - return $this->created_at; - } else { - return $this->created_at !== null ? $this->created_at->format($format) : null; - } - } - - /** - * Get the [optionally formatted] temporal [updated_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getUpdatedAt($format = NULL) - { - if ($format === null) { - return $this->updated_at; - } else { - return $this->updated_at !== null ? $this->updated_at->format($format) : null; - } - } - - /** - * Set the value of [id] column. - * - * @param int $v new value - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - */ - public function setId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->id !== $v) { - $this->id = $v; - $this->modifiedColumns[] = AttributeCategoryTableMap::ID; - } - - - return $this; - } // setId() - - /** - * Set the value of [category_id] column. - * - * @param int $v new value - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - */ - public function setCategoryId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->category_id !== $v) { - $this->category_id = $v; - $this->modifiedColumns[] = AttributeCategoryTableMap::CATEGORY_ID; - } - - if ($this->aCategory !== null && $this->aCategory->getId() !== $v) { - $this->aCategory = null; - } - - - return $this; - } // setCategoryId() - - /** - * Set the value of [attribute_id] column. - * - * @param int $v new value - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - */ - public function setAttributeId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->attribute_id !== $v) { - $this->attribute_id = $v; - $this->modifiedColumns[] = AttributeCategoryTableMap::ATTRIBUTE_ID; - } - - if ($this->aAttribute !== null && $this->aAttribute->getId() !== $v) { - $this->aAttribute = null; - } - - - return $this; - } // setAttributeId() - - /** - * Sets the value of [created_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - */ - public function setCreatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->created_at !== null || $dt !== null) { - if ($dt !== $this->created_at) { - $this->created_at = $dt; - $this->modifiedColumns[] = AttributeCategoryTableMap::CREATED_AT; - } - } // if either are not null - - - return $this; - } // setCreatedAt() - - /** - * Sets the value of [updated_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - */ - public function setUpdatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->updated_at !== null || $dt !== null) { - if ($dt !== $this->updated_at) { - $this->updated_at = $dt; - $this->modifiedColumns[] = AttributeCategoryTableMap::UPDATED_AT; - } - } // if either are not null - - - return $this; - } // setUpdatedAt() - - /** - * Indicates whether the columns in this object are only set to default values. - * - * This method can be used in conjunction with isModified() to indicate whether an object is both - * modified _and_ has some values set which are non-default. - * - * @return boolean Whether the columns in this object are only been set with default values. - */ - public function hasOnlyDefaultValues() - { - // otherwise, everything was equal, so return TRUE - return true; - } // hasOnlyDefaultValues() - - /** - * Hydrates (populates) the object variables with values from the database resultset. - * - * An offset (0-based "start column") is specified so that objects can be hydrated - * with a subset of the columns in the resultset rows. This is needed, for example, - * for results of JOIN queries where the resultset row includes columns from two or - * more tables. - * - * @param array $row The row returned by DataFetcher->fetch(). - * @param int $startcol 0-based offset column which indicates which restultset column to start with. - * @param boolean $rehydrate Whether this object is being re-hydrated from the database. - * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). - One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * - * @return int next starting column - * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. - */ - public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) - { - try { - - - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : AttributeCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - $this->id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AttributeCategoryTableMap::translateFieldName('CategoryId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->category_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AttributeCategoryTableMap::translateFieldName('AttributeId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->attribute_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $this->resetModified(); - - $this->setNew(false); - - if ($rehydrate) { - $this->ensureConsistency(); - } - - return $startcol + 5; // 5 = AttributeCategoryTableMap::NUM_HYDRATE_COLUMNS. - - } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\AttributeCategory object", 0, $e); - } - } - - /** - * Checks and repairs the internal consistency of the object. - * - * This method is executed after an already-instantiated object is re-hydrated - * from the database. It exists to check any foreign keys to make sure that - * the objects related to the current object are correct based on foreign key. - * - * You can override this method in the stub class, but you should always invoke - * the base method from the overridden method (i.e. parent::ensureConsistency()), - * in case your model changes. - * - * @throws PropelException - */ - public function ensureConsistency() - { - if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) { - $this->aCategory = null; - } - if ($this->aAttribute !== null && $this->attribute_id !== $this->aAttribute->getId()) { - $this->aAttribute = null; - } - } // ensureConsistency - - /** - * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. - * - * This will only work if the object has been saved and has a valid primary key set. - * - * @param boolean $deep (optional) Whether to also de-associated any related objects. - * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. - * @return void - * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db - */ - public function reload($deep = false, ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("Cannot reload a deleted object."); - } - - if ($this->isNew()) { - throw new PropelException("Cannot reload an unsaved object."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - // We don't need to alter the object instance pool; we're just modifying this instance - // already in the pool. - - $dataFetcher = ChildAttributeCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); - $row = $dataFetcher->fetch(); - $dataFetcher->close(); - if (!$row) { - throw new PropelException('Cannot find matching row in the database to reload object values.'); - } - $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate - - if ($deep) { // also de-associate any related objects? - - $this->aCategory = null; - $this->aAttribute = null; - } // if (deep) - } - - /** - * Removes this object from datastore and sets delete attribute. - * - * @param ConnectionInterface $con - * @return void - * @throws PropelException - * @see AttributeCategory::setDeleted() - * @see AttributeCategory::isDeleted() - */ - public function delete(ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("This object has already been deleted."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - try { - $deleteQuery = ChildAttributeCategoryQuery::create() - ->filterByPrimaryKey($this->getPrimaryKey()); - $ret = $this->preDelete($con); - if ($ret) { - $deleteQuery->delete($con); - $this->postDelete($con); - $con->commit(); - $this->setDeleted(true); - } else { - $con->commit(); - } - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * Persists this object to the database. - * - * If the object is new, it inserts it; otherwise an update is performed. - * All modified related objects will also be persisted in the doSave() - * method. This method wraps all precipitate database operations in a - * single transaction. - * - * @param ConnectionInterface $con - * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. - * @throws PropelException - * @see doSave() - */ - public function save(ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("You cannot save an object that has been deleted."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - $isInsert = $this->isNew(); - try { - $ret = $this->preSave($con); - if ($isInsert) { - $ret = $ret && $this->preInsert($con); - // timestampable behavior - if (!$this->isColumnModified(AttributeCategoryTableMap::CREATED_AT)) { - $this->setCreatedAt(time()); - } - if (!$this->isColumnModified(AttributeCategoryTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } else { - $ret = $ret && $this->preUpdate($con); - // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(AttributeCategoryTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } - if ($ret) { - $affectedRows = $this->doSave($con); - if ($isInsert) { - $this->postInsert($con); - } else { - $this->postUpdate($con); - } - $this->postSave($con); - AttributeCategoryTableMap::addInstanceToPool($this); - } else { - $affectedRows = 0; - } - $con->commit(); - - return $affectedRows; - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * Performs the work of inserting or updating the row in the database. - * - * If the object is new, it inserts it; otherwise an update is performed. - * All related objects are also updated in this method. - * - * @param ConnectionInterface $con - * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. - * @throws PropelException - * @see save() - */ - protected function doSave(ConnectionInterface $con) - { - $affectedRows = 0; // initialize var to track total num of affected rows - if (!$this->alreadyInSave) { - $this->alreadyInSave = true; - - // We call the save method on the following object(s) if they - // were passed to this object by their corresponding set - // method. This object relates to these object(s) by a - // foreign key reference. - - if ($this->aCategory !== null) { - if ($this->aCategory->isModified() || $this->aCategory->isNew()) { - $affectedRows += $this->aCategory->save($con); - } - $this->setCategory($this->aCategory); - } - - if ($this->aAttribute !== null) { - if ($this->aAttribute->isModified() || $this->aAttribute->isNew()) { - $affectedRows += $this->aAttribute->save($con); - } - $this->setAttribute($this->aAttribute); - } - - if ($this->isNew() || $this->isModified()) { - // persist changes - if ($this->isNew()) { - $this->doInsert($con); - } else { - $this->doUpdate($con); - } - $affectedRows += 1; - $this->resetModified(); - } - - $this->alreadyInSave = false; - - } - - return $affectedRows; - } // doSave() - - /** - * Insert the row in the database. - * - * @param ConnectionInterface $con - * - * @throws PropelException - * @see doSave() - */ - protected function doInsert(ConnectionInterface $con) - { - $modifiedColumns = array(); - $index = 0; - - $this->modifiedColumns[] = AttributeCategoryTableMap::ID; - if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeCategoryTableMap::ID . ')'); - } - - // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(AttributeCategoryTableMap::ID)) { - $modifiedColumns[':p' . $index++] = 'ID'; - } - if ($this->isColumnModified(AttributeCategoryTableMap::CATEGORY_ID)) { - $modifiedColumns[':p' . $index++] = 'CATEGORY_ID'; - } - if ($this->isColumnModified(AttributeCategoryTableMap::ATTRIBUTE_ID)) { - $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_ID'; - } - if ($this->isColumnModified(AttributeCategoryTableMap::CREATED_AT)) { - $modifiedColumns[':p' . $index++] = 'CREATED_AT'; - } - if ($this->isColumnModified(AttributeCategoryTableMap::UPDATED_AT)) { - $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; - } - - $sql = sprintf( - 'INSERT INTO attribute_category (%s) VALUES (%s)', - implode(', ', $modifiedColumns), - implode(', ', array_keys($modifiedColumns)) - ); - - try { - $stmt = $con->prepare($sql); - foreach ($modifiedColumns as $identifier => $columnName) { - switch ($columnName) { - case 'ID': - $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); - break; - case 'CATEGORY_ID': - $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT); - break; - case 'ATTRIBUTE_ID': - $stmt->bindValue($identifier, $this->attribute_id, PDO::PARAM_INT); - break; - case 'CREATED_AT': - $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); - break; - case 'UPDATED_AT': - $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); - break; - } - } - $stmt->execute(); - } catch (Exception $e) { - Propel::log($e->getMessage(), Propel::LOG_ERR); - throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); - } - - try { - $pk = $con->lastInsertId(); - } catch (Exception $e) { - throw new PropelException('Unable to get autoincrement id.', 0, $e); - } - $this->setId($pk); - - $this->setNew(false); - } - - /** - * Update the row in the database. - * - * @param ConnectionInterface $con - * - * @return Integer Number of updated rows - * @see doSave() - */ - protected function doUpdate(ConnectionInterface $con) - { - $selectCriteria = $this->buildPkeyCriteria(); - $valuesCriteria = $this->buildCriteria(); - - return $selectCriteria->doUpdate($valuesCriteria, $con); - } - - /** - * Retrieves a field from the object by name passed in as a string. - * - * @param string $name name - * @param string $type The type of fieldname the $name is of: - * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @return mixed Value of field. - */ - public function getByName($name, $type = TableMap::TYPE_PHPNAME) - { - $pos = AttributeCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); - $field = $this->getByPosition($pos); - - return $field; - } - - /** - * Retrieves a field from the object by Position as specified in the xml schema. - * Zero-based. - * - * @param int $pos position in xml schema - * @return mixed Value of field at $pos - */ - public function getByPosition($pos) - { - switch ($pos) { - case 0: - return $this->getId(); - break; - case 1: - return $this->getCategoryId(); - break; - case 2: - return $this->getAttributeId(); - break; - case 3: - return $this->getCreatedAt(); - break; - case 4: - return $this->getUpdatedAt(); - break; - default: - return null; - break; - } // switch() - } - - /** - * Exports the object as an array. - * - * You can specify the key type of the array by passing one of the class - * type constants. - * - * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. - * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion - * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. - * - * @return array an associative array containing the field names (as keys) and field values - */ - public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) - { - if (isset($alreadyDumpedObjects['AttributeCategory'][$this->getPrimaryKey()])) { - return '*RECURSION*'; - } - $alreadyDumpedObjects['AttributeCategory'][$this->getPrimaryKey()] = true; - $keys = AttributeCategoryTableMap::getFieldNames($keyType); - $result = array( - $keys[0] => $this->getId(), - $keys[1] => $this->getCategoryId(), - $keys[2] => $this->getAttributeId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), - ); - $virtualColumns = $this->virtualColumns; - foreach($virtualColumns as $key => $virtualColumn) - { - $result[$key] = $virtualColumn; - } - - if ($includeForeignObjects) { - if (null !== $this->aCategory) { - $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); - } - if (null !== $this->aAttribute) { - $result['Attribute'] = $this->aAttribute->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); - } - } - - return $result; - } - - /** - * Sets a field from the object by name passed in as a string. - * - * @param string $name - * @param mixed $value field value - * @param string $type The type of fieldname the $name is of: - * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @return void - */ - public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) - { - $pos = AttributeCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); - - return $this->setByPosition($pos, $value); - } - - /** - * Sets a field from the object by Position as specified in the xml schema. - * Zero-based. - * - * @param int $pos position in xml schema - * @param mixed $value field value - * @return void - */ - public function setByPosition($pos, $value) - { - switch ($pos) { - case 0: - $this->setId($value); - break; - case 1: - $this->setCategoryId($value); - break; - case 2: - $this->setAttributeId($value); - break; - case 3: - $this->setCreatedAt($value); - break; - case 4: - $this->setUpdatedAt($value); - break; - } // switch() - } - - /** - * Populates the object using an array. - * - * This is particularly useful when populating an object from one of the - * request arrays (e.g. $_POST). This method goes through the column - * names, checking to see whether a matching key exists in populated - * array. If so the setByName() method is called for that column. - * - * You can specify the key type of the array by additionally passing one - * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * The default key type is the column's TableMap::TYPE_PHPNAME. - * - * @param array $arr An array to populate the object from. - * @param string $keyType The type of keys the array uses. - * @return void - */ - public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) - { - $keys = AttributeCategoryTableMap::getFieldNames($keyType); - - if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setCategoryId($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setAttributeId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); - } - - /** - * Build a Criteria object containing the values of all modified columns in this object. - * - * @return Criteria The Criteria object containing all modified values. - */ - public function buildCriteria() - { - $criteria = new Criteria(AttributeCategoryTableMap::DATABASE_NAME); - - if ($this->isColumnModified(AttributeCategoryTableMap::ID)) $criteria->add(AttributeCategoryTableMap::ID, $this->id); - if ($this->isColumnModified(AttributeCategoryTableMap::CATEGORY_ID)) $criteria->add(AttributeCategoryTableMap::CATEGORY_ID, $this->category_id); - if ($this->isColumnModified(AttributeCategoryTableMap::ATTRIBUTE_ID)) $criteria->add(AttributeCategoryTableMap::ATTRIBUTE_ID, $this->attribute_id); - if ($this->isColumnModified(AttributeCategoryTableMap::CREATED_AT)) $criteria->add(AttributeCategoryTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(AttributeCategoryTableMap::UPDATED_AT)) $criteria->add(AttributeCategoryTableMap::UPDATED_AT, $this->updated_at); - - return $criteria; - } - - /** - * Builds a Criteria object containing the primary key for this object. - * - * Unlike buildCriteria() this method includes the primary key values regardless - * of whether or not they have been modified. - * - * @return Criteria The Criteria object containing value(s) for primary key(s). - */ - public function buildPkeyCriteria() - { - $criteria = new Criteria(AttributeCategoryTableMap::DATABASE_NAME); - $criteria->add(AttributeCategoryTableMap::ID, $this->id); - - return $criteria; - } - - /** - * Returns the primary key for this object (row). - * @return int - */ - public function getPrimaryKey() - { - return $this->getId(); - } - - /** - * Generic method to set the primary key (id column). - * - * @param int $key Primary key. - * @return void - */ - public function setPrimaryKey($key) - { - $this->setId($key); - } - - /** - * Returns true if the primary key for this object is null. - * @return boolean - */ - public function isPrimaryKeyNull() - { - - return null === $this->getId(); - } - - /** - * Sets contents of passed object to values from current object. - * - * If desired, this method can also make copies of all associated (fkey referrers) - * objects. - * - * @param object $copyObj An object of \Thelia\Model\AttributeCategory (or compatible) type. - * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. - * @throws PropelException - */ - public function copyInto($copyObj, $deepCopy = false, $makeNew = true) - { - $copyObj->setCategoryId($this->getCategoryId()); - $copyObj->setAttributeId($this->getAttributeId()); - $copyObj->setCreatedAt($this->getCreatedAt()); - $copyObj->setUpdatedAt($this->getUpdatedAt()); - if ($makeNew) { - $copyObj->setNew(true); - $copyObj->setId(NULL); // this is a auto-increment column, so set to default value - } - } - - /** - * Makes a copy of this object that will be inserted as a new row in table when saved. - * It creates a new object filling in the simple attributes, but skipping any primary - * keys that are defined for the table. - * - * If desired, this method can also make copies of all associated (fkey referrers) - * objects. - * - * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\AttributeCategory Clone of current object. - * @throws PropelException - */ - public function copy($deepCopy = false) - { - // we use get_class(), because this might be a subclass - $clazz = get_class($this); - $copyObj = new $clazz(); - $this->copyInto($copyObj, $deepCopy); - - return $copyObj; - } - - /** - * Declares an association between this object and a ChildCategory object. - * - * @param ChildCategory $v - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - * @throws PropelException - */ - public function setCategory(ChildCategory $v = null) - { - if ($v === null) { - $this->setCategoryId(NULL); - } else { - $this->setCategoryId($v->getId()); - } - - $this->aCategory = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildCategory object, it will not be re-added. - if ($v !== null) { - $v->addAttributeCategory($this); - } - - - return $this; - } - - - /** - * Get the associated ChildCategory object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildCategory The associated ChildCategory object. - * @throws PropelException - */ - public function getCategory(ConnectionInterface $con = null) - { - if ($this->aCategory === null && ($this->category_id !== null)) { - $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con); - /* The following can be used additionally to - guarantee the related object contains a reference - to this object. This level of coupling may, however, be - undesirable since it could result in an only partially populated collection - in the referenced object. - $this->aCategory->addAttributeCategories($this); - */ - } - - return $this->aCategory; - } - - /** - * Declares an association between this object and a ChildAttribute object. - * - * @param ChildAttribute $v - * @return \Thelia\Model\AttributeCategory The current object (for fluent API support) - * @throws PropelException - */ - public function setAttribute(ChildAttribute $v = null) - { - if ($v === null) { - $this->setAttributeId(NULL); - } else { - $this->setAttributeId($v->getId()); - } - - $this->aAttribute = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildAttribute object, it will not be re-added. - if ($v !== null) { - $v->addAttributeCategory($this); - } - - - return $this; - } - - - /** - * Get the associated ChildAttribute object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildAttribute The associated ChildAttribute object. - * @throws PropelException - */ - public function getAttribute(ConnectionInterface $con = null) - { - if ($this->aAttribute === null && ($this->attribute_id !== null)) { - $this->aAttribute = ChildAttributeQuery::create()->findPk($this->attribute_id, $con); - /* The following can be used additionally to - guarantee the related object contains a reference - to this object. This level of coupling may, however, be - undesirable since it could result in an only partially populated collection - in the referenced object. - $this->aAttribute->addAttributeCategories($this); - */ - } - - return $this->aAttribute; - } - - /** - * Clears the current object and sets all attributes to their default values - */ - public function clear() - { - $this->id = null; - $this->category_id = null; - $this->attribute_id = null; - $this->created_at = null; - $this->updated_at = null; - $this->alreadyInSave = false; - $this->clearAllReferences(); - $this->resetModified(); - $this->setNew(true); - $this->setDeleted(false); - } - - /** - * Resets all references to other model objects or collections of model objects. - * - * This method is a user-space workaround for PHP's inability to garbage collect - * objects with circular references (even in PHP 5.3). This is currently necessary - * when using Propel in certain daemon or large-volume/high-memory operations. - * - * @param boolean $deep Whether to also clear the references on all referrer objects. - */ - public function clearAllReferences($deep = false) - { - if ($deep) { - } // if ($deep) - - $this->aCategory = null; - $this->aAttribute = null; - } - - /** - * Return the string representation of this object - * - * @return string - */ - public function __toString() - { - return (string) $this->exportTo(AttributeCategoryTableMap::DEFAULT_STRING_FORMAT); - } - - // timestampable behavior - - /** - * Mark the current object so that the update date doesn't get updated during next save - * - * @return ChildAttributeCategory The current object (for fluent API support) - */ - public function keepUpdateDateUnchanged() - { - $this->modifiedColumns[] = AttributeCategoryTableMap::UPDATED_AT; - - return $this; - } - - /** - * Code to be run before persisting the object - * @param ConnectionInterface $con - * @return boolean - */ - public function preSave(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after persisting the object - * @param ConnectionInterface $con - */ - public function postSave(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before inserting to database - * @param ConnectionInterface $con - * @return boolean - */ - public function preInsert(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after inserting to database - * @param ConnectionInterface $con - */ - public function postInsert(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before updating the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preUpdate(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after updating the object in database - * @param ConnectionInterface $con - */ - public function postUpdate(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before deleting the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preDelete(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after deleting the object in database - * @param ConnectionInterface $con - */ - public function postDelete(ConnectionInterface $con = null) - { - - } - - - /** - * Derived method to catches calls to undefined methods. - * - * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). - * Allows to define default __call() behavior if you overwrite __call() - * - * @param string $name - * @param mixed $params - * - * @return array|string - */ - public function __call($name, $params) - { - if (0 === strpos($name, 'get')) { - $virtualColumn = substr($name, 3); - if ($this->hasVirtualColumn($virtualColumn)) { - return $this->getVirtualColumn($virtualColumn); - } - - $virtualColumn = lcfirst($virtualColumn); - if ($this->hasVirtualColumn($virtualColumn)) { - return $this->getVirtualColumn($virtualColumn); - } - } - - if (0 === strpos($name, 'from')) { - $format = substr($name, 4); - - return $this->importFrom($format, reset($params)); - } - - if (0 === strpos($name, 'to')) { - $format = substr($name, 2); - $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; - - return $this->exportTo($format, $includeLazyLoadColumns); - } - - throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); - } - -} diff --git a/core/lib/Thelia/Model/Base/AttributeCategoryQuery.php b/core/lib/Thelia/Model/Base/AttributeCategoryQuery.php deleted file mode 100644 index d325d2037..000000000 --- a/core/lib/Thelia/Model/Base/AttributeCategoryQuery.php +++ /dev/null @@ -1,759 +0,0 @@ -setModelAlias($modelAlias); - } - if ($criteria instanceof Criteria) { - $query->mergeWith($criteria); - } - - return $query; - } - - /** - * Find object by primary key. - * Propel uses the instance pool to skip the database if the object exists. - * Go fast if the query is untouched. - * - * - * $obj = $c->findPk(12, $con); - * - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con an optional connection object - * - * @return ChildAttributeCategory|array|mixed the result, formatted by the current formatter - */ - public function findPk($key, $con = null) - { - if ($key === null) { - return null; - } - if ((null !== ($obj = AttributeCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { - // the object is already in the instance pool - return $obj; - } - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - $this->basePreSelect($con); - if ($this->formatter || $this->modelAlias || $this->with || $this->select - || $this->selectColumns || $this->asColumns || $this->selectModifiers - || $this->map || $this->having || $this->joins) { - return $this->findPkComplex($key, $con); - } else { - return $this->findPkSimple($key, $con); - } - } - - /** - * Find object by primary key using raw SQL to go fast. - * Bypass doSelect() and the object formatter by using generated code. - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con A connection object - * - * @return ChildAttributeCategory A model object, or null if the key is not found - */ - protected function findPkSimple($key, $con) - { - $sql = 'SELECT ID, CATEGORY_ID, ATTRIBUTE_ID, CREATED_AT, UPDATED_AT FROM attribute_category WHERE ID = :p0'; - try { - $stmt = $con->prepare($sql); - $stmt->bindValue(':p0', $key, PDO::PARAM_INT); - $stmt->execute(); - } catch (Exception $e) { - Propel::log($e->getMessage(), Propel::LOG_ERR); - throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); - } - $obj = null; - if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildAttributeCategory(); - $obj->hydrate($row); - AttributeCategoryTableMap::addInstanceToPool($obj, (string) $key); - } - $stmt->closeCursor(); - - return $obj; - } - - /** - * Find object by primary key. - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con A connection object - * - * @return ChildAttributeCategory|array|mixed the result, formatted by the current formatter - */ - protected function findPkComplex($key, $con) - { - // As the query uses a PK condition, no limit(1) is necessary. - $criteria = $this->isKeepQuery() ? clone $this : $this; - $dataFetcher = $criteria - ->filterByPrimaryKey($key) - ->doSelect($con); - - return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); - } - - /** - * Find objects by primary key - * - * $objs = $c->findPks(array(12, 56, 832), $con); - * - * @param array $keys Primary keys to use for the query - * @param ConnectionInterface $con an optional connection object - * - * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter - */ - public function findPks($keys, $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); - } - $this->basePreSelect($con); - $criteria = $this->isKeepQuery() ? clone $this : $this; - $dataFetcher = $criteria - ->filterByPrimaryKeys($keys) - ->doSelect($con); - - return $criteria->getFormatter()->init($criteria)->format($dataFetcher); - } - - /** - * Filter the query by primary key - * - * @param mixed $key Primary key to use for the query - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByPrimaryKey($key) - { - - return $this->addUsingAlias(AttributeCategoryTableMap::ID, $key, Criteria::EQUAL); - } - - /** - * Filter the query by a list of primary keys - * - * @param array $keys The list of primary key to use for the query - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByPrimaryKeys($keys) - { - - return $this->addUsingAlias(AttributeCategoryTableMap::ID, $keys, Criteria::IN); - } - - /** - * Filter the query on the id column - * - * Example usage: - * - * $query->filterById(1234); // WHERE id = 1234 - * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) - * $query->filterById(array('min' => 12)); // WHERE id > 12 - * - * - * @param mixed $id The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterById($id = null, $comparison = null) - { - if (is_array($id)) { - $useMinMax = false; - if (isset($id['min'])) { - $this->addUsingAlias(AttributeCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($id['max'])) { - $this->addUsingAlias(AttributeCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AttributeCategoryTableMap::ID, $id, $comparison); - } - - /** - * Filter the query on the category_id column - * - * Example usage: - * - * $query->filterByCategoryId(1234); // WHERE category_id = 1234 - * $query->filterByCategoryId(array(12, 34)); // WHERE category_id IN (12, 34) - * $query->filterByCategoryId(array('min' => 12)); // WHERE category_id > 12 - * - * - * @see filterByCategory() - * - * @param mixed $categoryId The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByCategoryId($categoryId = null, $comparison = null) - { - if (is_array($categoryId)) { - $useMinMax = false; - if (isset($categoryId['min'])) { - $this->addUsingAlias(AttributeCategoryTableMap::CATEGORY_ID, $categoryId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($categoryId['max'])) { - $this->addUsingAlias(AttributeCategoryTableMap::CATEGORY_ID, $categoryId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AttributeCategoryTableMap::CATEGORY_ID, $categoryId, $comparison); - } - - /** - * Filter the query on the attribute_id column - * - * Example usage: - * - * $query->filterByAttributeId(1234); // WHERE attribute_id = 1234 - * $query->filterByAttributeId(array(12, 34)); // WHERE attribute_id IN (12, 34) - * $query->filterByAttributeId(array('min' => 12)); // WHERE attribute_id > 12 - * - * - * @see filterByAttribute() - * - * @param mixed $attributeId The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByAttributeId($attributeId = null, $comparison = null) - { - if (is_array($attributeId)) { - $useMinMax = false; - if (isset($attributeId['min'])) { - $this->addUsingAlias(AttributeCategoryTableMap::ATTRIBUTE_ID, $attributeId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($attributeId['max'])) { - $this->addUsingAlias(AttributeCategoryTableMap::ATTRIBUTE_ID, $attributeId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AttributeCategoryTableMap::ATTRIBUTE_ID, $attributeId, $comparison); - } - - /** - * Filter the query on the created_at column - * - * Example usage: - * - * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' - * - * - * @param mixed $createdAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByCreatedAt($createdAt = null, $comparison = null) - { - if (is_array($createdAt)) { - $useMinMax = false; - if (isset($createdAt['min'])) { - $this->addUsingAlias(AttributeCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($createdAt['max'])) { - $this->addUsingAlias(AttributeCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AttributeCategoryTableMap::CREATED_AT, $createdAt, $comparison); - } - - /** - * Filter the query on the updated_at column - * - * Example usage: - * - * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' - * - * - * @param mixed $updatedAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByUpdatedAt($updatedAt = null, $comparison = null) - { - if (is_array($updatedAt)) { - $useMinMax = false; - if (isset($updatedAt['min'])) { - $this->addUsingAlias(AttributeCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($updatedAt['max'])) { - $this->addUsingAlias(AttributeCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AttributeCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); - } - - /** - * Filter the query by a related \Thelia\Model\Category object - * - * @param \Thelia\Model\Category|ObjectCollection $category The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByCategory($category, $comparison = null) - { - if ($category instanceof \Thelia\Model\Category) { - return $this - ->addUsingAlias(AttributeCategoryTableMap::CATEGORY_ID, $category->getId(), $comparison); - } elseif ($category instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(AttributeCategoryTableMap::CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByCategory() only accepts arguments of type \Thelia\Model\Category or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Category relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function joinCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Category'); - - // create a ModelJoin object for this join - $join = new ModelJoin(); - $join->setJoinType($joinType); - $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); - if ($previousJoin = $this->getPreviousJoin()) { - $join->setPreviousJoin($previousJoin); - } - - // add the ModelJoin to the current object - if ($relationAlias) { - $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); - $this->addJoinObject($join, $relationAlias); - } else { - $this->addJoinObject($join, 'Category'); - } - - return $this; - } - - /** - * Use the Category relation Category object - * - * @see useQuery() - * - * @param string $relationAlias optional alias for the relation, - * to be used as main alias in the secondary query - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return \Thelia\Model\CategoryQuery A secondary query class using the current class as primary query - */ - public function useCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Category', '\Thelia\Model\CategoryQuery'); - } - - /** - * Filter the query by a related \Thelia\Model\Attribute object - * - * @param \Thelia\Model\Attribute|ObjectCollection $attribute The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function filterByAttribute($attribute, $comparison = null) - { - if ($attribute instanceof \Thelia\Model\Attribute) { - return $this - ->addUsingAlias(AttributeCategoryTableMap::ATTRIBUTE_ID, $attribute->getId(), $comparison); - } elseif ($attribute instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(AttributeCategoryTableMap::ATTRIBUTE_ID, $attribute->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByAttribute() only accepts arguments of type \Thelia\Model\Attribute or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Attribute relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function joinAttribute($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Attribute'); - - // create a ModelJoin object for this join - $join = new ModelJoin(); - $join->setJoinType($joinType); - $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); - if ($previousJoin = $this->getPreviousJoin()) { - $join->setPreviousJoin($previousJoin); - } - - // add the ModelJoin to the current object - if ($relationAlias) { - $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); - $this->addJoinObject($join, $relationAlias); - } else { - $this->addJoinObject($join, 'Attribute'); - } - - return $this; - } - - /** - * Use the Attribute relation Attribute object - * - * @see useQuery() - * - * @param string $relationAlias optional alias for the relation, - * to be used as main alias in the secondary query - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return \Thelia\Model\AttributeQuery A secondary query class using the current class as primary query - */ - public function useAttributeQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinAttribute($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Attribute', '\Thelia\Model\AttributeQuery'); - } - - /** - * Exclude object from result - * - * @param ChildAttributeCategory $attributeCategory Object to remove from the list of results - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function prune($attributeCategory = null) - { - if ($attributeCategory) { - $this->addUsingAlias(AttributeCategoryTableMap::ID, $attributeCategory->getId(), Criteria::NOT_EQUAL); - } - - return $this; - } - - /** - * Deletes all rows from the attribute_category table. - * - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). - */ - public function doDeleteAll(ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - $affectedRows = 0; // initialize var to track total num of affected rows - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - $affectedRows += parent::doDeleteAll($con); - // Because this db requires some delete cascade/set null emulation, we have to - // clear the cached instance *after* the emulation has happened (since - // instances get re-added by the select statement contained therein). - AttributeCategoryTableMap::clearInstancePool(); - AttributeCategoryTableMap::clearRelatedInstancePool(); - - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $affectedRows; - } - - /** - * Performs a DELETE on the database, given a ChildAttributeCategory or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or ChildAttributeCategory object or primary key or array of primary keys - * which is used to create the DELETE statement - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows - * if supported by native driver or if emulated using Propel. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public function delete(ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(AttributeCategoryTableMap::DATABASE_NAME); - } - - $criteria = $this; - - // Set the correct dbName - $criteria->setDbName(AttributeCategoryTableMap::DATABASE_NAME); - - $affectedRows = 0; // initialize var to track total num of affected rows - - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - - - AttributeCategoryTableMap::removeInstanceFromPool($criteria); - - $affectedRows += ModelCriteria::delete($con); - AttributeCategoryTableMap::clearRelatedInstancePool(); - $con->commit(); - - return $affectedRows; - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - } - - // timestampable behavior - - /** - * Filter by the latest updated - * - * @param int $nbDays Maximum age of the latest update in days - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function recentlyUpdated($nbDays = 7) - { - return $this->addUsingAlias(AttributeCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Filter by the latest created - * - * @param int $nbDays Maximum age of in days - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function recentlyCreated($nbDays = 7) - { - return $this->addUsingAlias(AttributeCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Order by update date desc - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function lastUpdatedFirst() - { - return $this->addDescendingOrderByColumn(AttributeCategoryTableMap::UPDATED_AT); - } - - /** - * Order by update date asc - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function firstUpdatedFirst() - { - return $this->addAscendingOrderByColumn(AttributeCategoryTableMap::UPDATED_AT); - } - - /** - * Order by create date desc - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function lastCreatedFirst() - { - return $this->addDescendingOrderByColumn(AttributeCategoryTableMap::CREATED_AT); - } - - /** - * Order by create date asc - * - * @return ChildAttributeCategoryQuery The current query, for fluid interface - */ - public function firstCreatedFirst() - { - return $this->addAscendingOrderByColumn(AttributeCategoryTableMap::CREATED_AT); - } - -} // AttributeCategoryQuery diff --git a/core/lib/Thelia/Model/Base/FeatureCategory.php b/core/lib/Thelia/Model/Base/FeatureCategory.php deleted file mode 100644 index 035e077d2..000000000 --- a/core/lib/Thelia/Model/Base/FeatureCategory.php +++ /dev/null @@ -1,1495 +0,0 @@ -modifiedColumns); - } - - /** - * Has specified column been modified? - * - * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID - * @return boolean True if $col has been modified. - */ - public function isColumnModified($col) - { - return in_array($col, $this->modifiedColumns); - } - - /** - * Get the columns that have been modified in this object. - * @return array A unique list of the modified column names for this object. - */ - public function getModifiedColumns() - { - return array_unique($this->modifiedColumns); - } - - /** - * Returns whether the object has ever been saved. This will - * be false, if the object was retrieved from storage or was created - * and then saved. - * - * @return true, if the object has never been persisted. - */ - public function isNew() - { - return $this->new; - } - - /** - * Setter for the isNew attribute. This method will be called - * by Propel-generated children and objects. - * - * @param boolean $b the state of the object. - */ - public function setNew($b) - { - $this->new = (Boolean) $b; - } - - /** - * Whether this object has been deleted. - * @return boolean The deleted state of this object. - */ - public function isDeleted() - { - return $this->deleted; - } - - /** - * Specify whether this object has been deleted. - * @param boolean $b The deleted state of this object. - * @return void - */ - public function setDeleted($b) - { - $this->deleted = (Boolean) $b; - } - - /** - * Sets the modified state for the object to be false. - * @param string $col If supplied, only the specified column is reset. - * @return void - */ - public function resetModified($col = null) - { - if (null !== $col) { - while (false !== ($offset = array_search($col, $this->modifiedColumns))) { - array_splice($this->modifiedColumns, $offset, 1); - } - } else { - $this->modifiedColumns = array(); - } - } - - /** - * Compares this with another FeatureCategory instance. If - * obj is an instance of FeatureCategory, delegates to - * equals(FeatureCategory). Otherwise, returns false. - * - * @param obj The object to compare to. - * @return Whether equal to the object specified. - */ - public function equals($obj) - { - $thisclazz = get_class($this); - if (!is_object($obj) || !($obj instanceof $thisclazz)) { - return false; - } - - if ($this === $obj) { - return true; - } - - if (null === $this->getPrimaryKey() - || null === $obj->getPrimaryKey()) { - return false; - } - - return $this->getPrimaryKey() === $obj->getPrimaryKey(); - } - - /** - * If the primary key is not null, return the hashcode of the - * primary key. Otherwise, return the hash code of the object. - * - * @return int Hashcode - */ - public function hashCode() - { - if (null !== $this->getPrimaryKey()) { - return crc32(serialize($this->getPrimaryKey())); - } - - return crc32(serialize(clone $this)); - } - - /** - * Get the associative array of the virtual columns in this object - * - * @param string $name The virtual column name - * - * @return array - */ - public function getVirtualColumns() - { - return $this->virtualColumns; - } - - /** - * Checks the existence of a virtual column in this object - * - * @return boolean - */ - public function hasVirtualColumn($name) - { - return array_key_exists($name, $this->virtualColumns); - } - - /** - * Get the value of a virtual column in this object - * - * @return mixed - */ - public function getVirtualColumn($name) - { - if (!$this->hasVirtualColumn($name)) { - throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); - } - - return $this->virtualColumns[$name]; - } - - /** - * Set the value of a virtual column in this object - * - * @param string $name The virtual column name - * @param mixed $value The value to give to the virtual column - * - * @return FeatureCategory The current object, for fluid interface - */ - public function setVirtualColumn($name, $value) - { - $this->virtualColumns[$name] = $value; - - return $this; - } - - /** - * Logs a message using Propel::log(). - * - * @param string $msg - * @param int $priority One of the Propel::LOG_* logging levels - * @return boolean - */ - protected function log($msg, $priority = Propel::LOG_INFO) - { - return Propel::log(get_class($this) . ': ' . $msg, $priority); - } - - /** - * Populate the current object from a string, using a given parser format - * - * $book = new Book(); - * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); - * - * - * @param mixed $parser A AbstractParser instance, - * or a format name ('XML', 'YAML', 'JSON', 'CSV') - * @param string $data The source data to import from - * - * @return FeatureCategory The current object, for fluid interface - */ - public function importFrom($parser, $data) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - return $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); - } - - /** - * Export the current object properties to a string, using a given parser format - * - * $book = BookQuery::create()->findPk(9012); - * echo $book->exportTo('JSON'); - * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); - * - * - * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') - * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. - * @return string The exported data - */ - public function exportTo($parser, $includeLazyLoadColumns = true) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); - } - - /** - * Clean up internal collections prior to serializing - * Avoids recursive loops that turn into segmentation faults when serializing - */ - public function __sleep() - { - $this->clearAllReferences(); - - return array_keys(get_object_vars($this)); - } - - /** - * Get the [id] column value. - * - * @return int - */ - public function getId() - { - - return $this->id; - } - - /** - * Get the [feature_id] column value. - * - * @return int - */ - public function getFeatureId() - { - - return $this->feature_id; - } - - /** - * Get the [category_id] column value. - * - * @return int - */ - public function getCategoryId() - { - - return $this->category_id; - } - - /** - * Get the [optionally formatted] temporal [created_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getCreatedAt($format = NULL) - { - if ($format === null) { - return $this->created_at; - } else { - return $this->created_at !== null ? $this->created_at->format($format) : null; - } - } - - /** - * Get the [optionally formatted] temporal [updated_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getUpdatedAt($format = NULL) - { - if ($format === null) { - return $this->updated_at; - } else { - return $this->updated_at !== null ? $this->updated_at->format($format) : null; - } - } - - /** - * Set the value of [id] column. - * - * @param int $v new value - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - */ - public function setId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->id !== $v) { - $this->id = $v; - $this->modifiedColumns[] = FeatureCategoryTableMap::ID; - } - - - return $this; - } // setId() - - /** - * Set the value of [feature_id] column. - * - * @param int $v new value - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - */ - public function setFeatureId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->feature_id !== $v) { - $this->feature_id = $v; - $this->modifiedColumns[] = FeatureCategoryTableMap::FEATURE_ID; - } - - if ($this->aFeature !== null && $this->aFeature->getId() !== $v) { - $this->aFeature = null; - } - - - return $this; - } // setFeatureId() - - /** - * Set the value of [category_id] column. - * - * @param int $v new value - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - */ - public function setCategoryId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->category_id !== $v) { - $this->category_id = $v; - $this->modifiedColumns[] = FeatureCategoryTableMap::CATEGORY_ID; - } - - if ($this->aCategory !== null && $this->aCategory->getId() !== $v) { - $this->aCategory = null; - } - - - return $this; - } // setCategoryId() - - /** - * Sets the value of [created_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - */ - public function setCreatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->created_at !== null || $dt !== null) { - if ($dt !== $this->created_at) { - $this->created_at = $dt; - $this->modifiedColumns[] = FeatureCategoryTableMap::CREATED_AT; - } - } // if either are not null - - - return $this; - } // setCreatedAt() - - /** - * Sets the value of [updated_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - */ - public function setUpdatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->updated_at !== null || $dt !== null) { - if ($dt !== $this->updated_at) { - $this->updated_at = $dt; - $this->modifiedColumns[] = FeatureCategoryTableMap::UPDATED_AT; - } - } // if either are not null - - - return $this; - } // setUpdatedAt() - - /** - * Indicates whether the columns in this object are only set to default values. - * - * This method can be used in conjunction with isModified() to indicate whether an object is both - * modified _and_ has some values set which are non-default. - * - * @return boolean Whether the columns in this object are only been set with default values. - */ - public function hasOnlyDefaultValues() - { - // otherwise, everything was equal, so return TRUE - return true; - } // hasOnlyDefaultValues() - - /** - * Hydrates (populates) the object variables with values from the database resultset. - * - * An offset (0-based "start column") is specified so that objects can be hydrated - * with a subset of the columns in the resultset rows. This is needed, for example, - * for results of JOIN queries where the resultset row includes columns from two or - * more tables. - * - * @param array $row The row returned by DataFetcher->fetch(). - * @param int $startcol 0-based offset column which indicates which restultset column to start with. - * @param boolean $rehydrate Whether this object is being re-hydrated from the database. - * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). - One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * - * @return int next starting column - * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. - */ - public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) - { - try { - - - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : FeatureCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - $this->id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : FeatureCategoryTableMap::translateFieldName('FeatureId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->feature_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : FeatureCategoryTableMap::translateFieldName('CategoryId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->category_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FeatureCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FeatureCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $this->resetModified(); - - $this->setNew(false); - - if ($rehydrate) { - $this->ensureConsistency(); - } - - return $startcol + 5; // 5 = FeatureCategoryTableMap::NUM_HYDRATE_COLUMNS. - - } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\FeatureCategory object", 0, $e); - } - } - - /** - * Checks and repairs the internal consistency of the object. - * - * This method is executed after an already-instantiated object is re-hydrated - * from the database. It exists to check any foreign keys to make sure that - * the objects related to the current object are correct based on foreign key. - * - * You can override this method in the stub class, but you should always invoke - * the base method from the overridden method (i.e. parent::ensureConsistency()), - * in case your model changes. - * - * @throws PropelException - */ - public function ensureConsistency() - { - if ($this->aFeature !== null && $this->feature_id !== $this->aFeature->getId()) { - $this->aFeature = null; - } - if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) { - $this->aCategory = null; - } - } // ensureConsistency - - /** - * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. - * - * This will only work if the object has been saved and has a valid primary key set. - * - * @param boolean $deep (optional) Whether to also de-associated any related objects. - * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. - * @return void - * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db - */ - public function reload($deep = false, ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("Cannot reload a deleted object."); - } - - if ($this->isNew()) { - throw new PropelException("Cannot reload an unsaved object."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - // We don't need to alter the object instance pool; we're just modifying this instance - // already in the pool. - - $dataFetcher = ChildFeatureCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); - $row = $dataFetcher->fetch(); - $dataFetcher->close(); - if (!$row) { - throw new PropelException('Cannot find matching row in the database to reload object values.'); - } - $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate - - if ($deep) { // also de-associate any related objects? - - $this->aCategory = null; - $this->aFeature = null; - } // if (deep) - } - - /** - * Removes this object from datastore and sets delete attribute. - * - * @param ConnectionInterface $con - * @return void - * @throws PropelException - * @see FeatureCategory::setDeleted() - * @see FeatureCategory::isDeleted() - */ - public function delete(ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("This object has already been deleted."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - try { - $deleteQuery = ChildFeatureCategoryQuery::create() - ->filterByPrimaryKey($this->getPrimaryKey()); - $ret = $this->preDelete($con); - if ($ret) { - $deleteQuery->delete($con); - $this->postDelete($con); - $con->commit(); - $this->setDeleted(true); - } else { - $con->commit(); - } - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * Persists this object to the database. - * - * If the object is new, it inserts it; otherwise an update is performed. - * All modified related objects will also be persisted in the doSave() - * method. This method wraps all precipitate database operations in a - * single transaction. - * - * @param ConnectionInterface $con - * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. - * @throws PropelException - * @see doSave() - */ - public function save(ConnectionInterface $con = null) - { - if ($this->isDeleted()) { - throw new PropelException("You cannot save an object that has been deleted."); - } - - if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - $isInsert = $this->isNew(); - try { - $ret = $this->preSave($con); - if ($isInsert) { - $ret = $ret && $this->preInsert($con); - // timestampable behavior - if (!$this->isColumnModified(FeatureCategoryTableMap::CREATED_AT)) { - $this->setCreatedAt(time()); - } - if (!$this->isColumnModified(FeatureCategoryTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } else { - $ret = $ret && $this->preUpdate($con); - // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(FeatureCategoryTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } - if ($ret) { - $affectedRows = $this->doSave($con); - if ($isInsert) { - $this->postInsert($con); - } else { - $this->postUpdate($con); - } - $this->postSave($con); - FeatureCategoryTableMap::addInstanceToPool($this); - } else { - $affectedRows = 0; - } - $con->commit(); - - return $affectedRows; - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * Performs the work of inserting or updating the row in the database. - * - * If the object is new, it inserts it; otherwise an update is performed. - * All related objects are also updated in this method. - * - * @param ConnectionInterface $con - * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. - * @throws PropelException - * @see save() - */ - protected function doSave(ConnectionInterface $con) - { - $affectedRows = 0; // initialize var to track total num of affected rows - if (!$this->alreadyInSave) { - $this->alreadyInSave = true; - - // We call the save method on the following object(s) if they - // were passed to this object by their corresponding set - // method. This object relates to these object(s) by a - // foreign key reference. - - if ($this->aCategory !== null) { - if ($this->aCategory->isModified() || $this->aCategory->isNew()) { - $affectedRows += $this->aCategory->save($con); - } - $this->setCategory($this->aCategory); - } - - if ($this->aFeature !== null) { - if ($this->aFeature->isModified() || $this->aFeature->isNew()) { - $affectedRows += $this->aFeature->save($con); - } - $this->setFeature($this->aFeature); - } - - if ($this->isNew() || $this->isModified()) { - // persist changes - if ($this->isNew()) { - $this->doInsert($con); - } else { - $this->doUpdate($con); - } - $affectedRows += 1; - $this->resetModified(); - } - - $this->alreadyInSave = false; - - } - - return $affectedRows; - } // doSave() - - /** - * Insert the row in the database. - * - * @param ConnectionInterface $con - * - * @throws PropelException - * @see doSave() - */ - protected function doInsert(ConnectionInterface $con) - { - $modifiedColumns = array(); - $index = 0; - - $this->modifiedColumns[] = FeatureCategoryTableMap::ID; - if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureCategoryTableMap::ID . ')'); - } - - // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(FeatureCategoryTableMap::ID)) { - $modifiedColumns[':p' . $index++] = 'ID'; - } - if ($this->isColumnModified(FeatureCategoryTableMap::FEATURE_ID)) { - $modifiedColumns[':p' . $index++] = 'FEATURE_ID'; - } - if ($this->isColumnModified(FeatureCategoryTableMap::CATEGORY_ID)) { - $modifiedColumns[':p' . $index++] = 'CATEGORY_ID'; - } - if ($this->isColumnModified(FeatureCategoryTableMap::CREATED_AT)) { - $modifiedColumns[':p' . $index++] = 'CREATED_AT'; - } - if ($this->isColumnModified(FeatureCategoryTableMap::UPDATED_AT)) { - $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; - } - - $sql = sprintf( - 'INSERT INTO feature_category (%s) VALUES (%s)', - implode(', ', $modifiedColumns), - implode(', ', array_keys($modifiedColumns)) - ); - - try { - $stmt = $con->prepare($sql); - foreach ($modifiedColumns as $identifier => $columnName) { - switch ($columnName) { - case 'ID': - $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); - break; - case 'FEATURE_ID': - $stmt->bindValue($identifier, $this->feature_id, PDO::PARAM_INT); - break; - case 'CATEGORY_ID': - $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT); - break; - case 'CREATED_AT': - $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); - break; - case 'UPDATED_AT': - $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); - break; - } - } - $stmt->execute(); - } catch (Exception $e) { - Propel::log($e->getMessage(), Propel::LOG_ERR); - throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); - } - - try { - $pk = $con->lastInsertId(); - } catch (Exception $e) { - throw new PropelException('Unable to get autoincrement id.', 0, $e); - } - $this->setId($pk); - - $this->setNew(false); - } - - /** - * Update the row in the database. - * - * @param ConnectionInterface $con - * - * @return Integer Number of updated rows - * @see doSave() - */ - protected function doUpdate(ConnectionInterface $con) - { - $selectCriteria = $this->buildPkeyCriteria(); - $valuesCriteria = $this->buildCriteria(); - - return $selectCriteria->doUpdate($valuesCriteria, $con); - } - - /** - * Retrieves a field from the object by name passed in as a string. - * - * @param string $name name - * @param string $type The type of fieldname the $name is of: - * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @return mixed Value of field. - */ - public function getByName($name, $type = TableMap::TYPE_PHPNAME) - { - $pos = FeatureCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); - $field = $this->getByPosition($pos); - - return $field; - } - - /** - * Retrieves a field from the object by Position as specified in the xml schema. - * Zero-based. - * - * @param int $pos position in xml schema - * @return mixed Value of field at $pos - */ - public function getByPosition($pos) - { - switch ($pos) { - case 0: - return $this->getId(); - break; - case 1: - return $this->getFeatureId(); - break; - case 2: - return $this->getCategoryId(); - break; - case 3: - return $this->getCreatedAt(); - break; - case 4: - return $this->getUpdatedAt(); - break; - default: - return null; - break; - } // switch() - } - - /** - * Exports the object as an array. - * - * You can specify the key type of the array by passing one of the class - * type constants. - * - * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. - * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion - * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. - * - * @return array an associative array containing the field names (as keys) and field values - */ - public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) - { - if (isset($alreadyDumpedObjects['FeatureCategory'][$this->getPrimaryKey()])) { - return '*RECURSION*'; - } - $alreadyDumpedObjects['FeatureCategory'][$this->getPrimaryKey()] = true; - $keys = FeatureCategoryTableMap::getFieldNames($keyType); - $result = array( - $keys[0] => $this->getId(), - $keys[1] => $this->getFeatureId(), - $keys[2] => $this->getCategoryId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), - ); - $virtualColumns = $this->virtualColumns; - foreach($virtualColumns as $key => $virtualColumn) - { - $result[$key] = $virtualColumn; - } - - if ($includeForeignObjects) { - if (null !== $this->aCategory) { - $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); - } - if (null !== $this->aFeature) { - $result['Feature'] = $this->aFeature->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); - } - } - - return $result; - } - - /** - * Sets a field from the object by name passed in as a string. - * - * @param string $name - * @param mixed $value field value - * @param string $type The type of fieldname the $name is of: - * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @return void - */ - public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) - { - $pos = FeatureCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); - - return $this->setByPosition($pos, $value); - } - - /** - * Sets a field from the object by Position as specified in the xml schema. - * Zero-based. - * - * @param int $pos position in xml schema - * @param mixed $value field value - * @return void - */ - public function setByPosition($pos, $value) - { - switch ($pos) { - case 0: - $this->setId($value); - break; - case 1: - $this->setFeatureId($value); - break; - case 2: - $this->setCategoryId($value); - break; - case 3: - $this->setCreatedAt($value); - break; - case 4: - $this->setUpdatedAt($value); - break; - } // switch() - } - - /** - * Populates the object using an array. - * - * This is particularly useful when populating an object from one of the - * request arrays (e.g. $_POST). This method goes through the column - * names, checking to see whether a matching key exists in populated - * array. If so the setByName() method is called for that column. - * - * You can specify the key type of the array by additionally passing one - * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * The default key type is the column's TableMap::TYPE_PHPNAME. - * - * @param array $arr An array to populate the object from. - * @param string $keyType The type of keys the array uses. - * @return void - */ - public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) - { - $keys = FeatureCategoryTableMap::getFieldNames($keyType); - - if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setFeatureId($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setCategoryId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); - } - - /** - * Build a Criteria object containing the values of all modified columns in this object. - * - * @return Criteria The Criteria object containing all modified values. - */ - public function buildCriteria() - { - $criteria = new Criteria(FeatureCategoryTableMap::DATABASE_NAME); - - if ($this->isColumnModified(FeatureCategoryTableMap::ID)) $criteria->add(FeatureCategoryTableMap::ID, $this->id); - if ($this->isColumnModified(FeatureCategoryTableMap::FEATURE_ID)) $criteria->add(FeatureCategoryTableMap::FEATURE_ID, $this->feature_id); - if ($this->isColumnModified(FeatureCategoryTableMap::CATEGORY_ID)) $criteria->add(FeatureCategoryTableMap::CATEGORY_ID, $this->category_id); - if ($this->isColumnModified(FeatureCategoryTableMap::CREATED_AT)) $criteria->add(FeatureCategoryTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(FeatureCategoryTableMap::UPDATED_AT)) $criteria->add(FeatureCategoryTableMap::UPDATED_AT, $this->updated_at); - - return $criteria; - } - - /** - * Builds a Criteria object containing the primary key for this object. - * - * Unlike buildCriteria() this method includes the primary key values regardless - * of whether or not they have been modified. - * - * @return Criteria The Criteria object containing value(s) for primary key(s). - */ - public function buildPkeyCriteria() - { - $criteria = new Criteria(FeatureCategoryTableMap::DATABASE_NAME); - $criteria->add(FeatureCategoryTableMap::ID, $this->id); - - return $criteria; - } - - /** - * Returns the primary key for this object (row). - * @return int - */ - public function getPrimaryKey() - { - return $this->getId(); - } - - /** - * Generic method to set the primary key (id column). - * - * @param int $key Primary key. - * @return void - */ - public function setPrimaryKey($key) - { - $this->setId($key); - } - - /** - * Returns true if the primary key for this object is null. - * @return boolean - */ - public function isPrimaryKeyNull() - { - - return null === $this->getId(); - } - - /** - * Sets contents of passed object to values from current object. - * - * If desired, this method can also make copies of all associated (fkey referrers) - * objects. - * - * @param object $copyObj An object of \Thelia\Model\FeatureCategory (or compatible) type. - * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. - * @throws PropelException - */ - public function copyInto($copyObj, $deepCopy = false, $makeNew = true) - { - $copyObj->setFeatureId($this->getFeatureId()); - $copyObj->setCategoryId($this->getCategoryId()); - $copyObj->setCreatedAt($this->getCreatedAt()); - $copyObj->setUpdatedAt($this->getUpdatedAt()); - if ($makeNew) { - $copyObj->setNew(true); - $copyObj->setId(NULL); // this is a auto-increment column, so set to default value - } - } - - /** - * Makes a copy of this object that will be inserted as a new row in table when saved. - * It creates a new object filling in the simple attributes, but skipping any primary - * keys that are defined for the table. - * - * If desired, this method can also make copies of all associated (fkey referrers) - * objects. - * - * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\FeatureCategory Clone of current object. - * @throws PropelException - */ - public function copy($deepCopy = false) - { - // we use get_class(), because this might be a subclass - $clazz = get_class($this); - $copyObj = new $clazz(); - $this->copyInto($copyObj, $deepCopy); - - return $copyObj; - } - - /** - * Declares an association between this object and a ChildCategory object. - * - * @param ChildCategory $v - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - * @throws PropelException - */ - public function setCategory(ChildCategory $v = null) - { - if ($v === null) { - $this->setCategoryId(NULL); - } else { - $this->setCategoryId($v->getId()); - } - - $this->aCategory = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildCategory object, it will not be re-added. - if ($v !== null) { - $v->addFeatureCategory($this); - } - - - return $this; - } - - - /** - * Get the associated ChildCategory object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildCategory The associated ChildCategory object. - * @throws PropelException - */ - public function getCategory(ConnectionInterface $con = null) - { - if ($this->aCategory === null && ($this->category_id !== null)) { - $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con); - /* The following can be used additionally to - guarantee the related object contains a reference - to this object. This level of coupling may, however, be - undesirable since it could result in an only partially populated collection - in the referenced object. - $this->aCategory->addFeatureCategories($this); - */ - } - - return $this->aCategory; - } - - /** - * Declares an association between this object and a ChildFeature object. - * - * @param ChildFeature $v - * @return \Thelia\Model\FeatureCategory The current object (for fluent API support) - * @throws PropelException - */ - public function setFeature(ChildFeature $v = null) - { - if ($v === null) { - $this->setFeatureId(NULL); - } else { - $this->setFeatureId($v->getId()); - } - - $this->aFeature = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildFeature object, it will not be re-added. - if ($v !== null) { - $v->addFeatureCategory($this); - } - - - return $this; - } - - - /** - * Get the associated ChildFeature object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildFeature The associated ChildFeature object. - * @throws PropelException - */ - public function getFeature(ConnectionInterface $con = null) - { - if ($this->aFeature === null && ($this->feature_id !== null)) { - $this->aFeature = ChildFeatureQuery::create()->findPk($this->feature_id, $con); - /* The following can be used additionally to - guarantee the related object contains a reference - to this object. This level of coupling may, however, be - undesirable since it could result in an only partially populated collection - in the referenced object. - $this->aFeature->addFeatureCategories($this); - */ - } - - return $this->aFeature; - } - - /** - * Clears the current object and sets all attributes to their default values - */ - public function clear() - { - $this->id = null; - $this->feature_id = null; - $this->category_id = null; - $this->created_at = null; - $this->updated_at = null; - $this->alreadyInSave = false; - $this->clearAllReferences(); - $this->resetModified(); - $this->setNew(true); - $this->setDeleted(false); - } - - /** - * Resets all references to other model objects or collections of model objects. - * - * This method is a user-space workaround for PHP's inability to garbage collect - * objects with circular references (even in PHP 5.3). This is currently necessary - * when using Propel in certain daemon or large-volume/high-memory operations. - * - * @param boolean $deep Whether to also clear the references on all referrer objects. - */ - public function clearAllReferences($deep = false) - { - if ($deep) { - } // if ($deep) - - $this->aCategory = null; - $this->aFeature = null; - } - - /** - * Return the string representation of this object - * - * @return string - */ - public function __toString() - { - return (string) $this->exportTo(FeatureCategoryTableMap::DEFAULT_STRING_FORMAT); - } - - // timestampable behavior - - /** - * Mark the current object so that the update date doesn't get updated during next save - * - * @return ChildFeatureCategory The current object (for fluent API support) - */ - public function keepUpdateDateUnchanged() - { - $this->modifiedColumns[] = FeatureCategoryTableMap::UPDATED_AT; - - return $this; - } - - /** - * Code to be run before persisting the object - * @param ConnectionInterface $con - * @return boolean - */ - public function preSave(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after persisting the object - * @param ConnectionInterface $con - */ - public function postSave(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before inserting to database - * @param ConnectionInterface $con - * @return boolean - */ - public function preInsert(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after inserting to database - * @param ConnectionInterface $con - */ - public function postInsert(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before updating the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preUpdate(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after updating the object in database - * @param ConnectionInterface $con - */ - public function postUpdate(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before deleting the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preDelete(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after deleting the object in database - * @param ConnectionInterface $con - */ - public function postDelete(ConnectionInterface $con = null) - { - - } - - - /** - * Derived method to catches calls to undefined methods. - * - * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). - * Allows to define default __call() behavior if you overwrite __call() - * - * @param string $name - * @param mixed $params - * - * @return array|string - */ - public function __call($name, $params) - { - if (0 === strpos($name, 'get')) { - $virtualColumn = substr($name, 3); - if ($this->hasVirtualColumn($virtualColumn)) { - return $this->getVirtualColumn($virtualColumn); - } - - $virtualColumn = lcfirst($virtualColumn); - if ($this->hasVirtualColumn($virtualColumn)) { - return $this->getVirtualColumn($virtualColumn); - } - } - - if (0 === strpos($name, 'from')) { - $format = substr($name, 4); - - return $this->importFrom($format, reset($params)); - } - - if (0 === strpos($name, 'to')) { - $format = substr($name, 2); - $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; - - return $this->exportTo($format, $includeLazyLoadColumns); - } - - throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); - } - -} diff --git a/core/lib/Thelia/Model/Base/FeatureCategoryQuery.php b/core/lib/Thelia/Model/Base/FeatureCategoryQuery.php deleted file mode 100644 index b9c9a67be..000000000 --- a/core/lib/Thelia/Model/Base/FeatureCategoryQuery.php +++ /dev/null @@ -1,759 +0,0 @@ -setModelAlias($modelAlias); - } - if ($criteria instanceof Criteria) { - $query->mergeWith($criteria); - } - - return $query; - } - - /** - * Find object by primary key. - * Propel uses the instance pool to skip the database if the object exists. - * Go fast if the query is untouched. - * - * - * $obj = $c->findPk(12, $con); - * - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con an optional connection object - * - * @return ChildFeatureCategory|array|mixed the result, formatted by the current formatter - */ - public function findPk($key, $con = null) - { - if ($key === null) { - return null; - } - if ((null !== ($obj = FeatureCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { - // the object is already in the instance pool - return $obj; - } - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - $this->basePreSelect($con); - if ($this->formatter || $this->modelAlias || $this->with || $this->select - || $this->selectColumns || $this->asColumns || $this->selectModifiers - || $this->map || $this->having || $this->joins) { - return $this->findPkComplex($key, $con); - } else { - return $this->findPkSimple($key, $con); - } - } - - /** - * Find object by primary key using raw SQL to go fast. - * Bypass doSelect() and the object formatter by using generated code. - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con A connection object - * - * @return ChildFeatureCategory A model object, or null if the key is not found - */ - protected function findPkSimple($key, $con) - { - $sql = 'SELECT ID, FEATURE_ID, CATEGORY_ID, CREATED_AT, UPDATED_AT FROM feature_category WHERE ID = :p0'; - try { - $stmt = $con->prepare($sql); - $stmt->bindValue(':p0', $key, PDO::PARAM_INT); - $stmt->execute(); - } catch (Exception $e) { - Propel::log($e->getMessage(), Propel::LOG_ERR); - throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); - } - $obj = null; - if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildFeatureCategory(); - $obj->hydrate($row); - FeatureCategoryTableMap::addInstanceToPool($obj, (string) $key); - } - $stmt->closeCursor(); - - return $obj; - } - - /** - * Find object by primary key. - * - * @param mixed $key Primary key to use for the query - * @param ConnectionInterface $con A connection object - * - * @return ChildFeatureCategory|array|mixed the result, formatted by the current formatter - */ - protected function findPkComplex($key, $con) - { - // As the query uses a PK condition, no limit(1) is necessary. - $criteria = $this->isKeepQuery() ? clone $this : $this; - $dataFetcher = $criteria - ->filterByPrimaryKey($key) - ->doSelect($con); - - return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); - } - - /** - * Find objects by primary key - * - * $objs = $c->findPks(array(12, 56, 832), $con); - * - * @param array $keys Primary keys to use for the query - * @param ConnectionInterface $con an optional connection object - * - * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter - */ - public function findPks($keys, $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); - } - $this->basePreSelect($con); - $criteria = $this->isKeepQuery() ? clone $this : $this; - $dataFetcher = $criteria - ->filterByPrimaryKeys($keys) - ->doSelect($con); - - return $criteria->getFormatter()->init($criteria)->format($dataFetcher); - } - - /** - * Filter the query by primary key - * - * @param mixed $key Primary key to use for the query - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByPrimaryKey($key) - { - - return $this->addUsingAlias(FeatureCategoryTableMap::ID, $key, Criteria::EQUAL); - } - - /** - * Filter the query by a list of primary keys - * - * @param array $keys The list of primary key to use for the query - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByPrimaryKeys($keys) - { - - return $this->addUsingAlias(FeatureCategoryTableMap::ID, $keys, Criteria::IN); - } - - /** - * Filter the query on the id column - * - * Example usage: - * - * $query->filterById(1234); // WHERE id = 1234 - * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) - * $query->filterById(array('min' => 12)); // WHERE id > 12 - * - * - * @param mixed $id The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterById($id = null, $comparison = null) - { - if (is_array($id)) { - $useMinMax = false; - if (isset($id['min'])) { - $this->addUsingAlias(FeatureCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($id['max'])) { - $this->addUsingAlias(FeatureCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(FeatureCategoryTableMap::ID, $id, $comparison); - } - - /** - * Filter the query on the feature_id column - * - * Example usage: - * - * $query->filterByFeatureId(1234); // WHERE feature_id = 1234 - * $query->filterByFeatureId(array(12, 34)); // WHERE feature_id IN (12, 34) - * $query->filterByFeatureId(array('min' => 12)); // WHERE feature_id > 12 - * - * - * @see filterByFeature() - * - * @param mixed $featureId The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByFeatureId($featureId = null, $comparison = null) - { - if (is_array($featureId)) { - $useMinMax = false; - if (isset($featureId['min'])) { - $this->addUsingAlias(FeatureCategoryTableMap::FEATURE_ID, $featureId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($featureId['max'])) { - $this->addUsingAlias(FeatureCategoryTableMap::FEATURE_ID, $featureId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(FeatureCategoryTableMap::FEATURE_ID, $featureId, $comparison); - } - - /** - * Filter the query on the category_id column - * - * Example usage: - * - * $query->filterByCategoryId(1234); // WHERE category_id = 1234 - * $query->filterByCategoryId(array(12, 34)); // WHERE category_id IN (12, 34) - * $query->filterByCategoryId(array('min' => 12)); // WHERE category_id > 12 - * - * - * @see filterByCategory() - * - * @param mixed $categoryId The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByCategoryId($categoryId = null, $comparison = null) - { - if (is_array($categoryId)) { - $useMinMax = false; - if (isset($categoryId['min'])) { - $this->addUsingAlias(FeatureCategoryTableMap::CATEGORY_ID, $categoryId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($categoryId['max'])) { - $this->addUsingAlias(FeatureCategoryTableMap::CATEGORY_ID, $categoryId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(FeatureCategoryTableMap::CATEGORY_ID, $categoryId, $comparison); - } - - /** - * Filter the query on the created_at column - * - * Example usage: - * - * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' - * - * - * @param mixed $createdAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByCreatedAt($createdAt = null, $comparison = null) - { - if (is_array($createdAt)) { - $useMinMax = false; - if (isset($createdAt['min'])) { - $this->addUsingAlias(FeatureCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($createdAt['max'])) { - $this->addUsingAlias(FeatureCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(FeatureCategoryTableMap::CREATED_AT, $createdAt, $comparison); - } - - /** - * Filter the query on the updated_at column - * - * Example usage: - * - * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' - * - * - * @param mixed $updatedAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByUpdatedAt($updatedAt = null, $comparison = null) - { - if (is_array($updatedAt)) { - $useMinMax = false; - if (isset($updatedAt['min'])) { - $this->addUsingAlias(FeatureCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($updatedAt['max'])) { - $this->addUsingAlias(FeatureCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(FeatureCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); - } - - /** - * Filter the query by a related \Thelia\Model\Category object - * - * @param \Thelia\Model\Category|ObjectCollection $category The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByCategory($category, $comparison = null) - { - if ($category instanceof \Thelia\Model\Category) { - return $this - ->addUsingAlias(FeatureCategoryTableMap::CATEGORY_ID, $category->getId(), $comparison); - } elseif ($category instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(FeatureCategoryTableMap::CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByCategory() only accepts arguments of type \Thelia\Model\Category or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Category relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function joinCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Category'); - - // create a ModelJoin object for this join - $join = new ModelJoin(); - $join->setJoinType($joinType); - $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); - if ($previousJoin = $this->getPreviousJoin()) { - $join->setPreviousJoin($previousJoin); - } - - // add the ModelJoin to the current object - if ($relationAlias) { - $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); - $this->addJoinObject($join, $relationAlias); - } else { - $this->addJoinObject($join, 'Category'); - } - - return $this; - } - - /** - * Use the Category relation Category object - * - * @see useQuery() - * - * @param string $relationAlias optional alias for the relation, - * to be used as main alias in the secondary query - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return \Thelia\Model\CategoryQuery A secondary query class using the current class as primary query - */ - public function useCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Category', '\Thelia\Model\CategoryQuery'); - } - - /** - * Filter the query by a related \Thelia\Model\Feature object - * - * @param \Thelia\Model\Feature|ObjectCollection $feature The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function filterByFeature($feature, $comparison = null) - { - if ($feature instanceof \Thelia\Model\Feature) { - return $this - ->addUsingAlias(FeatureCategoryTableMap::FEATURE_ID, $feature->getId(), $comparison); - } elseif ($feature instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(FeatureCategoryTableMap::FEATURE_ID, $feature->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByFeature() only accepts arguments of type \Thelia\Model\Feature or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Feature relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function joinFeature($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Feature'); - - // create a ModelJoin object for this join - $join = new ModelJoin(); - $join->setJoinType($joinType); - $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); - if ($previousJoin = $this->getPreviousJoin()) { - $join->setPreviousJoin($previousJoin); - } - - // add the ModelJoin to the current object - if ($relationAlias) { - $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); - $this->addJoinObject($join, $relationAlias); - } else { - $this->addJoinObject($join, 'Feature'); - } - - return $this; - } - - /** - * Use the Feature relation Feature object - * - * @see useQuery() - * - * @param string $relationAlias optional alias for the relation, - * to be used as main alias in the secondary query - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return \Thelia\Model\FeatureQuery A secondary query class using the current class as primary query - */ - public function useFeatureQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinFeature($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Feature', '\Thelia\Model\FeatureQuery'); - } - - /** - * Exclude object from result - * - * @param ChildFeatureCategory $featureCategory Object to remove from the list of results - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function prune($featureCategory = null) - { - if ($featureCategory) { - $this->addUsingAlias(FeatureCategoryTableMap::ID, $featureCategory->getId(), Criteria::NOT_EQUAL); - } - - return $this; - } - - /** - * Deletes all rows from the feature_category table. - * - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). - */ - public function doDeleteAll(ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - $affectedRows = 0; // initialize var to track total num of affected rows - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - $affectedRows += parent::doDeleteAll($con); - // Because this db requires some delete cascade/set null emulation, we have to - // clear the cached instance *after* the emulation has happened (since - // instances get re-added by the select statement contained therein). - FeatureCategoryTableMap::clearInstancePool(); - FeatureCategoryTableMap::clearRelatedInstancePool(); - - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $affectedRows; - } - - /** - * Performs a DELETE on the database, given a ChildFeatureCategory or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or ChildFeatureCategory object or primary key or array of primary keys - * which is used to create the DELETE statement - * @param ConnectionInterface $con the connection to use - * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows - * if supported by native driver or if emulated using Propel. - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public function delete(ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(FeatureCategoryTableMap::DATABASE_NAME); - } - - $criteria = $this; - - // Set the correct dbName - $criteria->setDbName(FeatureCategoryTableMap::DATABASE_NAME); - - $affectedRows = 0; // initialize var to track total num of affected rows - - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - - - FeatureCategoryTableMap::removeInstanceFromPool($criteria); - - $affectedRows += ModelCriteria::delete($con); - FeatureCategoryTableMap::clearRelatedInstancePool(); - $con->commit(); - - return $affectedRows; - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - } - - // timestampable behavior - - /** - * Filter by the latest updated - * - * @param int $nbDays Maximum age of the latest update in days - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function recentlyUpdated($nbDays = 7) - { - return $this->addUsingAlias(FeatureCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Filter by the latest created - * - * @param int $nbDays Maximum age of in days - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function recentlyCreated($nbDays = 7) - { - return $this->addUsingAlias(FeatureCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Order by update date desc - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function lastUpdatedFirst() - { - return $this->addDescendingOrderByColumn(FeatureCategoryTableMap::UPDATED_AT); - } - - /** - * Order by update date asc - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function firstUpdatedFirst() - { - return $this->addAscendingOrderByColumn(FeatureCategoryTableMap::UPDATED_AT); - } - - /** - * Order by create date desc - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function lastCreatedFirst() - { - return $this->addDescendingOrderByColumn(FeatureCategoryTableMap::CREATED_AT); - } - - /** - * Order by create date asc - * - * @return ChildFeatureCategoryQuery The current query, for fluid interface - */ - public function firstCreatedFirst() - { - return $this->addAscendingOrderByColumn(FeatureCategoryTableMap::CREATED_AT); - } - -} // FeatureCategoryQuery diff --git a/core/lib/Thelia/Model/FeatureCategory.php b/core/lib/Thelia/Model/FeatureCategory.php deleted file mode 100755 index 62852f3ee..000000000 --- a/core/lib/Thelia/Model/FeatureCategory.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Wed, 18 Sep 2013 10:54:22 +0200 Subject: [PATCH 73/74] remove unused classes --- core/lib/Thelia/Model/CouponRule.php | 9 --------- core/lib/Thelia/Model/CouponRuleQuery.php | 20 -------------------- 2 files changed, 29 deletions(-) delete mode 100755 core/lib/Thelia/Model/CouponRule.php delete mode 100755 core/lib/Thelia/Model/CouponRuleQuery.php diff --git a/core/lib/Thelia/Model/CouponRule.php b/core/lib/Thelia/Model/CouponRule.php deleted file mode 100755 index 14c84deb2..000000000 --- a/core/lib/Thelia/Model/CouponRule.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Wed, 18 Sep 2013 11:07:15 +0200 Subject: [PATCH 74/74] rtrime rewritten url --- core/lib/Thelia/Model/Tools/UrlRewritingTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php index 1b9087626..182dbcaf3 100644 --- a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php +++ b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php @@ -68,7 +68,7 @@ trait UrlRewritingTrait { // Only allow one dash separator at a time (and make string lowercase) $cleanString = mb_strtolower(preg_replace('/--+/u', '-', $string), 'UTF-8'); - $urlFilePart = $cleanString . ".html"; + $urlFilePart = rtrim($cleanString, '.-~_') . ".html"; // TODO : // check if URL url already exists, and add a numeric suffix, or the like