From d1d9892ae8b851c42c1588c396c53765bd91e68c Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 12 Sep 2013 22:10:51 +0200 Subject: [PATCH 01/13] absoluteUrl prevetn duplicate parameters in generated URL --- core/lib/Thelia/Tools/URL.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 05084c0c1..650cb9de1 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -140,8 +140,14 @@ class URL if (! is_null($parameters)) { foreach ($parameters as $name => $value) { + + // Remove this parameter from base URL to prevent duplicate parameters + $base = preg_replace('/([?&])'.$name.'=([^&])*(&|$)/', '$1', $base); + $queryString .= sprintf("%s=%s&", urlencode($name), urlencode($value)); } + + $base = rtrim($base, '&'); } $sepChar = strstr($base, '?') === false ? '?' : '&'; From 6a66a3f99ac0a10e5bdf6db8b752c0c02bdaa9fa Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:16:29 +0200 Subject: [PATCH 02/13] Fixed duplication parameter check regexp --- core/lib/Thelia/Tools/URL.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 650cb9de1..5dc6c20c9 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -146,8 +146,6 @@ class URL $queryString .= sprintf("%s=%s&", urlencode($name), urlencode($value)); } - - $base = rtrim($base, '&'); } $sepChar = strstr($base, '?') === false ? '?' : '&'; From 316043d93a9e9231a31280112560814bb7a9f527 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:18:19 +0200 Subject: [PATCH 03/13] Fixed action column alignment --- .../default/assets/less/thelia/tables.less | 7 +++ templates/admin/default/attribute-edit.html | 22 ++++--- templates/admin/default/attributes.html | 62 ++++++++++++++++++- templates/admin/default/categories.html | 2 +- templates/admin/default/currencies.html | 2 +- templates/admin/default/customers.html | 24 +++---- .../default/includes/inner-form-toolbar.html | 2 +- .../standard-description-form-fields.html | 8 +-- .../default/includes/thelia_news_feed.html | 3 +- templates/admin/default/orders.html | 14 ++--- 10 files changed, 111 insertions(+), 35 deletions(-) diff --git a/templates/admin/default/assets/less/thelia/tables.less b/templates/admin/default/assets/less/thelia/tables.less index d8b3a9e4e..5997840a8 100755 --- a/templates/admin/default/assets/less/thelia/tables.less +++ b/templates/admin/default/assets/less/thelia/tables.less @@ -55,6 +55,13 @@ .table-left-aligned { th, td { text-align: left; + + &.text-center { + text-align: center; + } + &.text-right { + text-align: right; + } } select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input { diff --git a/templates/admin/default/attribute-edit.html b/templates/admin/default/attribute-edit.html index 1b290f222..882edd60c 100644 --- a/templates/admin/default/attribute-edit.html +++ b/templates/admin/default/attribute-edit.html @@ -37,6 +37,10 @@

{intl l='Attribute information'}

+ {form_field form=$form field='id'} + + {/form_field} + {* Be sure to get the attribute ID, even if the form could not be validated *} @@ -52,7 +56,7 @@ {if $form_error}
{$form_error_message}
{/if} - {include file="includes/standard-description-form-fields.html"} + {include file="includes/standard-description-form-fields.html" form=$form}
@@ -79,9 +83,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='id' reverse_order='id_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l='ID'}" } @@ -89,9 +94,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='alpha' reverse_order='alpha_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l='Value'}" } @@ -99,9 +105,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='manual' reverse_order='manual_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l="Position"}" } @@ -114,12 +121,13 @@ - {loop name="list" type="attribute_availability" attribute=$attribute_id backend_context="1" lang=$edit_language_id order=$order} + {loop name="list" type="attribute_availability" attribute=$attribute_id backend_context="1" lang=$edit_language_id order=$attributeav_order} {$ID} - + {* FIXME : integrate this in the encolsing form to provide standard form processing *} + @@ -151,7 +159,7 @@
- {intl l="No product attribute has been created yet. Click the + button to create one."} + {intl l="No value has been created yet. Click the + button to create one."}
diff --git a/templates/admin/default/attributes.html b/templates/admin/default/attributes.html index eab4996ac..57fd9c256 100644 --- a/templates/admin/default/attributes.html +++ b/templates/admin/default/attributes.html @@ -97,6 +97,17 @@ {module_include location='attributes_table_row'} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.attributes.change"} + + {/loop} +
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.attributes.change"} @@ -213,10 +224,51 @@ dialog_title = {intl l="Delete attribute"} dialog_message = {intl l="Do you really want to delete this attribute ? It will be removed from all product templates."} - form_action = {url path='/admin/configuration/attributes/delete'} + form_action = {url path='/admin/configuration/attributes/remove_from-all-templates' attribute_id=$ID} form_content = {$smarty.capture.delete_dialog nofilter} } + +{* Add to all dialog *} + +{capture "add_to_all_dialog"} + + + {module_include location='attribute_add_to_all_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "add_to_all_dialog" + dialog_title = {intl l="Add to all product templates"} + dialog_message = {intl l="Do you really want to add this attribute to all product templates ?"} + + form_action = {url path='/admin/configuration/attributes/add-to-all-templates'} + form_content = {$smarty.capture.add_to_all_dialog nofilter} +} + +{* Remove from all dialog *} + +{capture "remove_from_all_dialog"} + + + {module_include location='attribute_add_to_all_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "remove_from_all_dialog" + dialog_title = {intl l="Remove from all product templates"} + dialog_message = {intl l="Do you really want to remove this attribute from all product templates ? You'll loose all product related data for this attribute."} + + form_action = {url path='/admin/configuration/attributes/remove-from-all-templates'} + form_content = {$smarty.capture.remove_from_all_dialog nofilter} +} + {/block} {block name="javascript-initialization"} @@ -233,6 +285,14 @@ $('#attribute_delete_id').val($(this).data('id')); }); + $('a.attribute-add-to-all').click(function(ev) { + $('#attribute_add_to_all_id').val($(this).data('id')); + }); + + $('a.attribute-remove-from-all').click(function(ev) { + $('#attribute_remove_from_all_id').val($(this).data('id')); + }); + // JS stuff for creation form {include file = "includes/generic-js-dialog.html" diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 0423bcc66..6fe06f8bc 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -82,7 +82,7 @@ } - {intl l='Actions'} + {intl l='Actions'} diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index 72bf01e75..fe4cfe882 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -111,7 +111,7 @@ {module_include location='currencies_table_header'} - {intl l='Actions'} + {intl l='Actions'} diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index 799115bf3..72179f667 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -11,9 +11,9 @@
- + @@ -58,7 +58,7 @@ {intl l='order amount'} - {intl l='Actions'} + {intl l='Actions'} @@ -154,23 +154,23 @@ {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} {/form_field} - + {form_field form=$form field='company'}
{/form_field} - - {form_field form=$form field='title'} + + {form_field form=$form field='title'}
- + +
{/form_field} @@ -191,13 +191,13 @@ {form_field form=$form field='address1'}
- +
{form_field form=$form field='address2'} - {/form_field} + {/form_field}
@@ -237,8 +237,8 @@
- {/form_field} - + {/form_field} + {/capture} {include diff --git a/templates/admin/default/includes/inner-form-toolbar.html b/templates/admin/default/includes/inner-form-toolbar.html index 518c204e3..c142cbdd7 100755 --- a/templates/admin/default/includes/inner-form-toolbar.html +++ b/templates/admin/default/includes/inner-form-toolbar.html @@ -12,7 +12,7 @@
{/form_field} @@ -25,7 +25,7 @@ {intl l="The détailed description."} - +
{/form_field} @@ -36,6 +36,6 @@ {intl l="A short post-description information"} - +
{/form_field} \ No newline at end of file diff --git a/templates/admin/default/includes/thelia_news_feed.html b/templates/admin/default/includes/thelia_news_feed.html index 6b9d2b5a9..09b3af020 100755 --- a/templates/admin/default/includes/thelia_news_feed.html +++ b/templates/admin/default/includes/thelia_news_feed.html @@ -4,7 +4,8 @@

{$DATE}

{$TITLE|strip_tags nofilter}

-

{$DESCRIPTION|strip_tags|truncate:250:"...":true nofilter}

+ {* we use unescape:"htmlall" to unescape var before truncate, to prevent a cut in the middel of an HTML entity, eg &ea... *} +

{$DESCRIPTION|strip_tags|unescape:"htmlall"|truncate:250:"...":true nofilter}

{intl l='Lire la suite »'}

{/loop} diff --git a/templates/admin/default/orders.html b/templates/admin/default/orders.html index 947c615a3..4f9c6ecf8 100644 --- a/templates/admin/default/orders.html +++ b/templates/admin/default/orders.html @@ -17,7 +17,7 @@ {module_include location='orders_top'}
-
+
- + {module_include location='orders_table_header'} - + - + @@ -116,7 +116,7 @@ - + - +
@@ -36,14 +36,14 @@
{intl l="Name"} {intl l="Amount"} {intl l="Status"}{intl l="Actions"}{intl l="Actions"}
01230450123045
-
+
From ca7d1f7c85de546fb754ac97b95070d4bd26d613 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:19:53 +0200 Subject: [PATCH 04/13] Finished attributes management --- core/lib/Thelia/Action/Attribute.php | 24 +++ .../Thelia/Config/Resources/routing/admin.xml | 8 + .../Admin/AbstractCrudController.php | 74 +++++--- .../Admin/AttributeAvController.php | 60 +++--- .../Controller/Admin/AttributeController.php | 171 +++++++++++++++--- .../Controller/Admin/BaseAdminController.php | 33 +++- .../Controller/Admin/ConfigController.php | 1 + .../Controller/Admin/CurrencyController.php | 1 + .../Controller/Admin/MessageController.php | 52 ++++-- core/lib/Thelia/Core/Event/TheliaEvents.php | 3 + .../Template/Loop/AttributeAvailability.php | 8 +- .../Smarty/Plugins/AdminUtilities.php | 5 +- .../Core/Template/Smarty/Plugins/Form.php | 80 +++++--- .../Template/Smarty/Plugins/UrlGenerator.php | 1 + .../Thelia/Form/AttributeModificationForm.php | 2 + 15 files changed, 406 insertions(+), 117 deletions(-) diff --git a/core/lib/Thelia/Action/Attribute.php b/core/lib/Thelia/Action/Attribute.php index 8524f6054..2877ca388 100644 --- a/core/lib/Thelia/Action/Attribute.php +++ b/core/lib/Thelia/Action/Attribute.php @@ -37,6 +37,8 @@ use Thelia\Model\ConfigQuery; use Thelia\Model\AttributeAv; use Thelia\Model\AttributeAvQuery; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\CategoryEvent; +use Thelia\Core\Event\AttributeEvent; class Attribute extends BaseAction implements EventSubscriberInterface { @@ -133,6 +135,24 @@ class Attribute extends BaseAction implements EventSubscriberInterface } } + public function addToAllTemplates(AttributeEvent $event) + { + $templates = ProductTemplateAttributeQuery::create()->find(); + + foreach($templates as $template) { + $pat = new ProductTemplateAttribute(); + + $pat->setTemplate($template->getId()) + ->setAttributeId($event->getAttribute()->getId()) + ->save(); + } + } + + public function removeFromAllTemplates(AttributeEvent $event) + { + // Delete this attribute from all product templates + ProductTemplateAttributeQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete(); + } /** * {@inheritDoc} @@ -144,6 +164,10 @@ class Attribute extends BaseAction implements EventSubscriberInterface TheliaEvents::ATTRIBUTE_UPDATE => array("update", 128), TheliaEvents::ATTRIBUTE_DELETE => array("delete", 128), TheliaEvents::ATTRIBUTE_UPDATE_POSITION => array("updatePosition", 128), + + TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES => array("removeFromAllTemplates", 128), + TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES => array("addToAllTemplates", 128), + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c76e70eda..c16ee05bd 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -236,6 +236,14 @@ Thelia\Controller\Admin\AttributeController::updatePositionAction + + Thelia\Controller\Admin\AttributeController::removeFromAllTemplates + + + + Thelia\Controller\Admin\AttributeController::addToAllTemplates + + Thelia\Controller\Admin\AttributeAvController::createAction diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index 1dcbca01f..31f9ba72a 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -38,6 +38,7 @@ abstract class AbstractCrudController extends BaseAdminController // List ordering protected $defaultListOrder; + protected $orderRequestParameterName; // Permissions protected $viewPermissionIdentifier; @@ -74,6 +75,7 @@ abstract class AbstractCrudController extends BaseAdminController $objectName, $defaultListOrder = null, + $orderRequestParameterName = null, $viewPermissionIdentifier, $createPermissionIdentifier, @@ -89,8 +91,9 @@ abstract class AbstractCrudController extends BaseAdminController $this->objectName = $objectName; $this->defaultListOrder = $defaultListOrder; + $this->orderRequestParameterName = $orderRequestParameterName; - $this->viewPermissionIdentifier = $viewPermissionIdentifier; + $this->viewPermissionIdentifier = $viewPermissionIdentifier; $this->createPermissionIdentifier = $createPermissionIdentifier; $this->updatePermissionIdentifier = $updatePermissionIdentifier; $this->deletePermissionIdentifier = $deletePermissionIdentifier; @@ -194,36 +197,56 @@ abstract class AbstractCrudController extends BaseAdminController protected abstract function redirectToListTemplate(); - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { throw new \LogicException ("Position Update is not supported for this object"); } - protected function createToggleVisibilityEvent() { - + protected function createToggleVisibilityEvent() + { throw new \LogicException ("Toggle Visibility is not supported for this object"); } + /** + * Put in this method post object creation processing if required. + * + * @param unknown $createdObject the created object + */ + protected function performAdditionalCreateAction($createdObject) + { + // Nothing to do + } + + /** + * Put in this method post object update processing if required. + * + * @param unknown $updatedObject the updated object + */ + protected function performAdditionalUpdateAction($updatedObject) + { + // Nothing to do + } + + /** + * Put in this method post object delete processing if required. + * + * @param unknown $deletedObject the deleted object + */ + protected function performAdditionalDeleteAction($deletedObject) + { + // Nothing to do + } + /** * Return the current list order identifier, updating it in the same time. */ - protected function getCurrentListOrder($update_session = true) { - - $order = null; - - if ($this->defaultListOrder) { - - $orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $this->objectName); - - // Find the current order - $order = $this->getRequest()->get( - 'order', - $this->getSession()->get($orderSessionIdentifier, $this->defaultListOrder) - ); - - if ($update_session) $this->getSession()->set($orderSessionIdentifier, $order); - } - - return $order; + protected function getCurrentListOrder($update_session = true) + { + return $this->getListOrderFromSession( + $this->objectName, + $this->orderRequestParameterName, + $this->defaultListOrder + ); } /** @@ -283,6 +306,8 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); } + $this->performAdditionalCreateAction($createdObject); + // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl()); @@ -317,7 +342,7 @@ abstract class AbstractCrudController extends BaseAdminController if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; // Load the object - $object = $this->getExistingObject($this->getRequest()); + $object = $this->getExistingObject(); if ($object != null) { @@ -368,6 +393,8 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } + $this->performAdditionalUpdateAction($changedObject); + // 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') { @@ -467,6 +494,7 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend( sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject))); } + $this->performAdditionalDeleteAction($deletedObject); $this->redirectToListTemplate(); } diff --git a/core/lib/Thelia/Controller/Admin/AttributeAvController.php b/core/lib/Thelia/Controller/Admin/AttributeAvController.php index b7118b53a..b3afa687d 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeAvController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeAvController.php @@ -39,10 +39,12 @@ use Thelia\Core\Event\UpdatePositionEvent; */ class AttributeAvController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( - 'attribute', + 'attributeav', 'manual', + 'order', 'admin.configuration.attributes-av.view', 'admin.configuration.attributes-av.create', @@ -57,15 +59,18 @@ class AttributeAvController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new AttributeAvCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new AttributeAvModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new AttributeAvCreateEvent(); $createEvent @@ -77,8 +82,8 @@ class AttributeAvController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { - + protected function getUpdateEvent($formData) + { $changeEvent = new AttributeAvUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,8 +98,8 @@ class AttributeAvController extends AbstractCrudController return $changeEvent; } - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { - + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { return new UpdatePositionEvent( $this->getRequest()->get('attributeav_id', null), $positionChangeMode, @@ -102,16 +107,18 @@ class AttributeAvController extends AbstractCrudController ); } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasAttributeAv(); } - protected function hydrateObjectForm($object) { - + protected function hydrateObjectForm($object) + { $data = array( 'id' => $object->getId(), 'locale' => $object->getLocale(), @@ -125,32 +132,38 @@ class AttributeAvController extends AbstractCrudController return new AttributeAvModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasAttributeAv() ? $event->getAttributeAv() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return AttributeAvQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('attributeav_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getTitle(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function getViewArguments() { + protected function getViewArguments() + { return array( 'attribute_id' => $this->getRequest()->get('attribute_id'), 'order' => $this->getCurrentListOrder() ); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { // We always return to the attribute edition form return $this->render( 'attribute-edit', @@ -158,12 +171,14 @@ class AttributeAvController extends AbstractCrudController ); } - protected function renderEditionTemplate() { + protected function renderEditionTemplate() + { // We always return to the attribute edition form return $this->render('attribute-edit', $this->getViewArguments()); } - protected function redirectToEditionTemplate() { + protected function redirectToEditionTemplate() + { // We always return to the attribute edition form $this->redirectToRoute( "admin.configuration.attributes.update", @@ -171,7 +186,8 @@ class AttributeAvController extends AbstractCrudController ); } - protected function redirectToListTemplate() { + protected function redirectToListTemplate() + { $this->redirectToRoute( "admin.configuration.attributes.update", $this->getViewArguments() diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index f6b76c0df..0ae181900 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -31,6 +31,10 @@ use Thelia\Model\AttributeQuery; use Thelia\Form\AttributeModificationForm; use Thelia\Form\AttributeCreationForm; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Model\AttributeAv; +use Thelia\Model\AttributeAvQuery; +use Thelia\Core\Event\AttributeAvUpdateEvent; +use Thelia\Core\Event\AttributeEvent; /** * Manages attributes sent by mail @@ -39,10 +43,12 @@ use Thelia\Core\Event\UpdatePositionEvent; */ class AttributeController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( 'attribute', 'manual', + 'order', 'admin.configuration.attributes.view', 'admin.configuration.attributes.create', @@ -57,15 +63,18 @@ class AttributeController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new AttributeCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new AttributeModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new AttributeCreateEvent(); $createEvent @@ -77,8 +86,8 @@ class AttributeController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { - + protected function getUpdateEvent($formData) + { $changeEvent = new AttributeUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,8 +102,31 @@ class AttributeController extends AbstractCrudController return $changeEvent; } - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { + /** + * Process the attributes values (fix it in future version to integrate it in the attribute form as a collection) + * + * @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction() + */ + protected function performAdditionalUpdateAction($updatedObject) + { + $attr_values = $this->getRequest()->get('attribute_values', null); + if ($attr_values !== null) { + + foreach($attr_values as $id => $value) { + + $event = new AttributeAvUpdateEvent($id); + + $event->setTitle($value); + $event->setLocale($this->getCurrentEditionLocale()); + + $this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event); + } + } + } + + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { return new UpdatePositionEvent( $this->getRequest()->get('attribute_id', null), $positionChangeMode, @@ -102,15 +134,18 @@ class AttributeController extends AbstractCrudController ); } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new AttributeDeleteEvent($this->getRequest()->get('attribute_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasAttribute(); } - protected function hydrateObjectForm($object) { + protected function hydrateObjectForm($object) + { $data = array( 'id' => $object->getId(), @@ -121,44 +156,132 @@ class AttributeController extends AbstractCrudController 'postscriptum' => $object->getPostscriptum() ); + // Setup attributes values + /* + * FIXME : doesn't work. "We get a This form should not contain extra fields." error + $attr_av_list = AttributeAvQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->filterByAttributeId($object->getId()) + ->find(); + + $attr_array = array(); + + foreach($attr_av_list as $attr_av) { + $attr_array[$attr_av->getId()] = $attr_av->getTitle(); + } + + $data['attribute_values'] = $attr_array; + */ + // Setup the object form return new AttributeModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasAttribute() ? $event->getAttribute() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return AttributeQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('attribute_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getTitle(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { return $this->render('attributes', array('order' => $currentOrder)); } - protected function renderEditionTemplate() { - return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id'))); - } - - protected function redirectToEditionTemplate() { - $this->redirectToRoute( - "admin.configuration.attributes.update", - array('attribute_id' => $this->getRequest()->get('attribute_id')) + protected function renderEditionTemplate() + { + return $this->render( + 'attribute-edit', + array( + 'attribute_id' => $this->getRequest()->get('attribute_id'), + 'attributeav_order' => $this->getAttributeAvListOrder() + ) ); } - protected function redirectToListTemplate() { + protected function redirectToEditionTemplate() + { + $this->redirectToRoute( + "admin.configuration.attributes.update", + array( + 'attribute_id' => $this->getRequest()->get('attribute_id'), + 'attributeav_order' => $this->getAttributeAvListOrder() + ) + ); + } + + protected function redirectToListTemplate() + { $this->redirectToRoute('admin.configuration.attributes.default'); } + + /** + * Get the Attribute value list order. + * + * @return string the current list order + */ + protected function getAttributeAvListOrder() + { + return $this->getListOrderFromSession( + 'attributeav', + 'attributeav_order', + 'manual' + ); + } + + /** + * Add or Remove from all product templates + */ + protected function addRemoveFromAllTemplates($eventType) + { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response; + + try { + if (null !== $object = $this->getExistingObject()) { + + $event = new AttributeEvent($object); + + $this->dispatch($eventType, $event); + } + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToListTemplate(); + } + + /** + * Remove from all product templates + */ + public function removeFromAllTemplates() + { + return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES); + } + + /** + * Add to all product templates + */ + public function addToAllTemplates() + { + return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 4fb8bf31e..6471dda81 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -97,7 +97,7 @@ class BaseAdminController extends BaseController protected function errorPage($message) { if ($message instanceof \Exception) { - $message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage())); + $message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage())); } return $this->render('general_error', array( @@ -273,6 +273,35 @@ class BaseAdminController extends BaseController return $this->getCurrentEditionLang()->getLocale(); } + + /** + * Return the current list order identifier for a given object name, + * updating in using the current request. + * + * @param unknown $objectName the object name (e.g. 'attribute', 'message') + * @param unknown $requestParameterName the name of the request parameter that defines the list order + * @param unknown $defaultListOrder the default order to use, if none is defined + * @param string $updateSession if true, the session will be updated with the current order. + * + * @return String the current liste order. + */ + protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true) { + + $order = $defaultListOrder; + + $orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $objectName); + + // Find the current order + $order = $this->getRequest()->get( + $requestParameterName, + $this->getSession()->get($orderSessionIdentifier, $defaultListOrder) + ); + + if ($updateSession) $this->getSession()->set($orderSessionIdentifier, $order); + + return $order; + } + /** * Render the given template, and returns the result as an Http Response. * @@ -314,7 +343,7 @@ class BaseAdminController extends BaseController 'edit_language_id' => $edition_language->getId(), 'edit_language_locale' => $edition_language->getLocale(), - 'current_url' => htmlspecialchars($this->getRequest()->getUri()) + 'current_url' => $this->getRequest()->getUri() )); // Update the current edition language in session diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index ee88e99e0..ff0e4bb39 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -43,6 +43,7 @@ class ConfigController extends AbstractCrudController parent::__construct( 'variable', 'name', + 'order', 'admin.configuration.variables.view', 'admin.configuration.variables.create', diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 2df950984..4f3fdaaea 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -43,6 +43,7 @@ class CurrencyController extends AbstractCrudController parent::__construct( 'currency', 'manual', + 'order', 'admin.configuration.currencies.view', 'admin.configuration.currencies.create', diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index f87218116..a55c9deca 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -37,10 +37,12 @@ use Thelia\Form\MessageCreationForm; */ class MessageController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( 'message', - null, + null, // no sort order change + null, // no sort order change 'admin.configuration.messages.view', 'admin.configuration.messages.create', @@ -55,15 +57,18 @@ class MessageController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new MessageCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new MessageModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new MessageCreateEvent(); $createEvent @@ -76,7 +81,8 @@ class MessageController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { + protected function getUpdateEvent($formData) + { $changeEvent = new MessageUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,16 +99,18 @@ class MessageController extends AbstractCrudController return $changeEvent; } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new MessageDeleteEvent($this->getRequest()->get('message_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasMessage(); } - protected function hydrateObjectForm($object) { - + protected function hydrateObjectForm($object) + { // Prepare the data that will hydrate the form $data = array( 'id' => $object->getId(), @@ -119,40 +127,48 @@ class MessageController extends AbstractCrudController return new MessageModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasMessage() ? $event->getMessage() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return MessageQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('message_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getName(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { return $this->render('messages'); } - protected function renderEditionTemplate() { + protected function renderEditionTemplate() + { return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id'))); } - protected function redirectToEditionTemplate() { + protected function redirectToEditionTemplate() + { $this->redirectToRoute( "admin.configuration.messages.update", array('message_id' => $this->getRequest()->get('message_id')) ); } - protected function redirectToListTemplate() { + protected function redirectToListTemplate() + { $this->redirectToRoute('admin.configuration.messages.default'); } } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 78d84b758..97e140eb6 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -369,6 +369,9 @@ final class TheliaEvents const ATTRIBUTE_DELETE = "action.deleteAttribute"; const ATTRIBUTE_UPDATE_POSITION = "action.updateAttributePosition"; + const ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES = "action.addAttributeToAllTemplate"; + const ATTRIBUTE_ADD_TO_ALL_TEMPLATES = "action.removeAttributeFromAllTemplate"; + const BEFORE_CREATEATTRIBUTE = "action.before_createAttribute"; const AFTER_CREATEATTRIBUTE = "action.after_createAttribute"; diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php index 1d94e889e..e9a7d9eb8 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php @@ -59,7 +59,7 @@ class AttributeAvailability extends BaseI18nLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) + new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse')) ), 'manual' ) @@ -100,6 +100,12 @@ class AttributeAvailability extends BaseI18nLoop foreach ($orders as $order) { switch ($order) { + case 'id': + $search->orderById(Criteria::ASC); + break; + case 'id_reverse': + $search->orderById(Criteria::DESC); + break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 5608fc168..a56bbff1c 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -106,6 +106,9 @@ class AdminUtilities extends AbstractSmartyPlugin // The column label $label = $this->getParam($params, 'label'); + // The request parameter + $request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order'); + if ($current_order == $order) { $icon = 'up'; $order_change = $reverse_order; @@ -121,7 +124,7 @@ class AdminUtilities extends AbstractSmartyPlugin else $output = ''; - return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label); + return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), $label); } /** diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 9ae840019..2d5324644 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -112,6 +112,37 @@ class Form extends AbstractSmartyPlugin } } + protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars) + { + $template->assign("name", $fieldName); + + $template->assign("value", $fieldValue); + + // If Checkbox input type + if ($fieldVars['checked'] !== null) { + $this->renderFormFieldCheckBox($template, $formFieldView['checked']); + } + + $template->assign("label", $fieldVars["label"]); + $template->assign("label_attr", $fieldVars["label_attr"]); + + $errors = $fieldVars["errors"]; + + $template->assign("error", empty($errors) ? false : true); + + if (! empty($errors)) { + $this->assignFieldErrorVars($template, $errors); + } + + $attr = array(); + + foreach ($fieldVars["attr"] as $key => $value) { + $attr[] = sprintf('%s="%s"', $key, $value); + } + + $template->assign("attr", implode(" ", $attr)); + } + public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { @@ -120,32 +151,29 @@ class Form extends AbstractSmartyPlugin $template->assign("options", $formFieldView->vars); - $template->assign("name", $formFieldView->vars["full_name"]); - $template->assign("value", $formFieldView->vars["value"]); + $value = $formFieldView->vars["value"]; +/* FIXME: doesnt work. We got "This form should not contain extra fields." error. + // We have a collection + if (is_array($value)) { - // If Checkbox input type - if ($formFieldView->vars['checked'] !== null) { - $this->renderFormFieldCheckBox($template, $formFieldView); + $key = $this->getParam($params, 'value_key'); + + if ($key != null) { + + if (isset($value[$key])) { + + $name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); + $val = $value[$key]; + + $this->assignFieldValues($template, $name, $val, $formFieldView->vars); + } + } } - - $template->assign("label", $formFieldView->vars["label"]); - $template->assign("label_attr", $formFieldView->vars["label_attr"]); - - $errors = $formFieldView->vars["errors"]; - - $template->assign("error", empty($errors) ? false : true); - - if (! empty($errors)) { - $this->assignFieldErrorVars($template, $errors); + else { + $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars); } - - $attr = array(); - - foreach ($formFieldView->vars["attr"] as $key => $value) { - $attr[] = sprintf('%s="%s"', $key, $value); - } - - $template->assign("attr", implode(" ", $attr)); +*/ + $this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars); $formFieldView->setRendered(); } else { @@ -275,12 +303,12 @@ class Form extends AbstractSmartyPlugin * @param \Smarty_Internal_Template $template * @param $formFieldView */ - public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $formFieldView) + public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $isChecked) { $template->assign("value", 0); - if ($formFieldView->vars['checked']) { + if ($isChecked) { $template->assign("value", 1); } - $template->assign("value", $formFieldView->vars['checked']); + $template->assign("value", $isChecked); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 905c5bb5b..56c853d00 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -54,6 +54,7 @@ class UrlGenerator extends AbstractSmartyPlugin $url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target'))); if ($target != null) $url .= '#'.$target; + return $url; } diff --git a/core/lib/Thelia/Form/AttributeModificationForm.php b/core/lib/Thelia/Form/AttributeModificationForm.php index 62b0b707a..45dab7b28 100644 --- a/core/lib/Thelia/Form/AttributeModificationForm.php +++ b/core/lib/Thelia/Form/AttributeModificationForm.php @@ -43,10 +43,12 @@ class AttributeModificationForm extends AttributeCreationForm ) ) )) +/* FIXME: doesn't work ->add('attribute_values', 'collection', array( 'type' => 'text', 'options' => array('required' => false) )) +*/ ; // Add standard description fields From 275b20ac7751e2330fc0816e45d51453a01a49b6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 10:17:45 +0200 Subject: [PATCH 05/13] allow to make an address as default on update action --- core/lib/Thelia/Action/Address.php | 4 ++++ .../Thelia/Config/Resources/routing/front.xml | 7 ++++++- .../Controller/Front/AddressController.php | 18 +++++++----------- .../Controller/Front/BaseFrontController.php | 7 +++++++ .../Core/Event/AddressCreateOrUpdateEvent.php | 18 +++++++++++++++++- core/lib/Thelia/Form/AddressCreateForm.php | 10 ++++++++-- core/lib/Thelia/Model/Address.php | 14 ++++++++++++++ templates/default/account.html | 3 ++- templates/default/register.html | 4 ++-- 9 files changed, 67 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 278f71a5b..27d46a4b7 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -73,6 +73,10 @@ class Address extends BaseAction implements EventSubscriberInterface ->save() ; + if($event->getIsDefault()) { + $addressModel->makeItDefault(); + } + $event->setAddress($addressModel); } diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index c50fd97b9..c30e576b9 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -59,7 +59,12 @@ - + + Thelia\Controller\Front\DefaultController::noAction + address + + + Thelia\Controller\Front\AddressController::createAction address diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 5f3fb4799..c4a40d951 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -46,14 +46,13 @@ class AddressController extends BaseFrontController */ public function generateModalAction($address_id) { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied(); - } - + $this->checkAuth(); $this->checkXmlHttpRequest(); } + + /** * Create controller. * Check if customer is logged in @@ -62,9 +61,7 @@ class AddressController extends BaseFrontController */ public function createAction() { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied() - } + $this->checkAuth(); $addressCreate = new AddressCreateForm($this->getRequest()); @@ -98,11 +95,9 @@ class AddressController extends BaseFrontController public function updateAction() { + $this->checkAuth(); $request = $this->getRequest(); - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->redirectToRoute("home"); - } if (null === $address_id = $request->get("address_id")) { $this->redirectToRoute("home"); @@ -164,7 +159,8 @@ class AddressController extends BaseFrontController $form->get("country")->getData(), $form->get("cellphone")->getData(), $form->get("phone")->getData(), - $form->get("company")->getData() + $form->get("company")->getData(), + $form->get("is_default")->getData() ); } } diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index cf83e865d..1c4a13977 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -50,4 +50,11 @@ class BaseFrontController extends BaseController { $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters)); } + + public function checkAuth() + { + if($this->getSecurityContext()->hasCustomerUser() === false) { + $this->redirectToRoute("customer.login.view"); + } + } } diff --git a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php index af69ae0b4..01e615ff6 100644 --- a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php @@ -108,7 +108,12 @@ class AddressCreateOrUpdateEvent extends ActionEvent */ protected $address; - public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company) + /** + * @var int + */ + protected $isDefault; + + public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company, $isDefault = 0) { $this->address1 = $address1; $this->address2 = $address2; @@ -123,6 +128,7 @@ class AddressCreateOrUpdateEvent extends ActionEvent $this->phone = $phone; $this->title = $title; $this->zipcode = $zipcode; + $this->isDefault = $isDefault; } /** @@ -229,6 +235,16 @@ class AddressCreateOrUpdateEvent extends ActionEvent return $this->zipcode; } + /** + * @return int + */ + public function getIsDefault() + { + return $this->isDefault; + } + + + /** * @param \Thelia\Model\Customer $customer */ diff --git a/core/lib/Thelia/Form/AddressCreateForm.php b/core/lib/Thelia/Form/AddressCreateForm.php index ed1750047..483366a1f 100644 --- a/core/lib/Thelia/Form/AddressCreateForm.php +++ b/core/lib/Thelia/Form/AddressCreateForm.php @@ -60,7 +60,7 @@ class AddressCreateForm extends BaseForm "constraints" => array( new NotBlank() ), - "label" => Translator::getInstance()->trans("Address label *"), + "label" => Translator::getInstance()->trans("Address label"), "label_attr" => array( "for" => "label_create" ), @@ -154,11 +154,17 @@ class AddressCreateForm extends BaseForm ) )) ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Compagny"), + "label" => Translator::getInstance()->trans("Company"), "label_attr" => array( "for" => "company_create" ) )) + ->add("is_default", "integer", array( + "label" => Translator::getInstance()->trans("Make this address has my primary address"), + "label_attr" => array( + "for" => "default_address" + ) + )) ; } diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index dbd334ba2..9c2a390b5 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -7,10 +7,24 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Address as BaseAddress; +use Thelia\Model\AddressQuery; class Address extends BaseAddress { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + /** + * put the the current address as default one + */ + public function makeItDefault() + { + + AddressQuery::create()->filterByCustomerId($this->getCustomerId()) + ->update(array('isDefault' => '0')); + + $this->setIsDefault(1); + $this->save(); + } + /** * Code to be run before inserting to database * @param ConnectionInterface $con diff --git a/templates/default/account.html b/templates/default/account.html index c7edeb449..b67d6424c 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -1,3 +1,4 @@ +{check_auth context="front" roles="CUSTOMER" login_tpl="login"} {extends file="layout.tpl"} {block name="breadcrumb"} @@ -74,7 +75,7 @@
- {intl l="Add a new address"} + {intl l="Add a new address"} {loop type="address" name="customer.addresses"} diff --git a/templates/default/register.html b/templates/default/register.html index 7100737bc..a3448932b 100644 --- a/templates/default/register.html +++ b/templates/default/register.html @@ -96,7 +96,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error} @@ -109,7 +109,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error} From 2d8656e45b0dea6aa8254285e8d601faa1556f16 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 10:55:45 +0200 Subject: [PATCH 06/13] allow to create a new address --- core/lib/Thelia/Action/Address.php | 58 ++++--- core/lib/Thelia/Model/Address.php | 2 +- templates/default/address.html | 247 +++++++++++++++++++++++++++++ 3 files changed, 283 insertions(+), 24 deletions(-) create mode 100644 templates/default/address.html diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 27d46a4b7..0aee9a6f5 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -22,10 +22,13 @@ /*************************************************************************************/ namespace Thelia\Action; +use Propel\Runtime\Exception\PropelException; +use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\AddressCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Address as AddressModel; +use Thelia\Model\Map\AddressTableMap; /** * Class Address @@ -52,32 +55,41 @@ class Address extends BaseAction implements EventSubscriberInterface protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { $addressModel->setDispatcher($this->getDispatcher()); + $con = Propel::getWriteConnection(AddressTableMap::DATABASE_NAME); + $con->beginTransaction(); + try { + if ($addressModel->isNew()) { + $addressModel->setLabel($event->getLabel()); + } - if ($addressModel->isNew()) { - $addressModel->setLabel($event->getLabel()); + $addressModel + ->setTitleId($event->getTitle()) + ->setFirstname($event->getFirstname()) + ->setLastname($event->getLastname()) + ->setAddress1($event->getAddress1()) + ->setAddress2($event->getAddress2()) + ->setAddress3($event->getAddress3()) + ->setZipcode($event->getZipcode()) + ->setCity($event->getCity()) + ->setCountryId($event->getCountry()) + ->setCellphone($event->getCellphone()) + ->setPhone($event->getPhone()) + ->setCompany($event->getCompany()) + ->save() + ; + + if($event->getIsDefault()) { + $addressModel->makeItDefault(); + } + + $event->setAddress($addressModel); + $con->commit(); + + } catch(PropelException $e) { + $con->rollback(); + throw $e; } - $addressModel - ->setTitleId($event->getTitle()) - ->setFirstname($event->getFirstname()) - ->setLastname($event->getLastname()) - ->setAddress1($event->getAddress1()) - ->setAddress2($event->getAddress2()) - ->setAddress3($event->getAddress3()) - ->setZipcode($event->getZipcode()) - ->setCity($event->getCity()) - ->setCountryId($event->getCountry()) - ->setCellphone($event->getCellphone()) - ->setPhone($event->getPhone()) - ->setCompany($event->getCompany()) - ->save() - ; - - if($event->getIsDefault()) { - $addressModel->makeItDefault(); - } - - $event->setAddress($addressModel); } /** diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index 9c2a390b5..8c9bd4552 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -19,7 +19,7 @@ class Address extends BaseAddress { { AddressQuery::create()->filterByCustomerId($this->getCustomerId()) - ->update(array('isDefault' => '0')); + ->update(array('IsDefault' => '0')); $this->setIsDefault(1); $this->save(); diff --git a/templates/default/address.html b/templates/default/address.html new file mode 100644 index 000000000..086a2b5ba --- /dev/null +++ b/templates/default/address.html @@ -0,0 +1,247 @@ +{check_auth context="front" roles="CUSTOMER" login_tpl="login"} +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+ +
+ +

{intl l="Create New Address"}

+ {form name="thelia.address.create"} +
+ {form_field form=$form field='success_url'} + {* the url the user is redirected to on login success *} + {/form_field} + + {form_field form=$form field='error_message'} + {* the url the user is redirected to on login success *} + {/form_field} + {form_hidden_fields form=$form} + {if $form_error}
{$form_error_message}
{/if} +
+
+ {intl l="Address"} +
+ +
+ {form_field form=$form field="label"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="title"} +
+ +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + + {form_field form=$form field="firstname"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + + {form_field form=$form field="lastname"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="address1"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="address2"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="zipcode"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="city"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="country"} +
+ +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + + {form_field form=$form field="phone"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="cellphone"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} +
+
+ + {form_field form=$form field="is_default"} +
+
+
+ +
+
+
+ + {/form_field} + +
+
+ +
+
+ + + {/form} +
+ +
+{/block} \ No newline at end of file From ddf175f361542c335ed84b109c1445403a099771 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 11:31:12 +0200 Subject: [PATCH 07/13] allow update customer address in front tempalte --- .../Thelia/Config/Resources/routing/front.xml | 11 +- .../Controller/Front/AddressController.php | 26 +- templates/default/account.html | 2 +- templates/default/address-update.html | 250 ++++++++++++++++++ templates/default/address.html | 4 +- 5 files changed, 277 insertions(+), 16 deletions(-) create mode 100644 templates/default/address-update.html diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index c30e576b9..da3c1bdb7 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -69,13 +69,14 @@ address - - Thelia\Controller\Front\DefaultController::noAction - address-edit + + Thelia\Controller\Front\AddressController::updateViewAction + address-update - - Thelia\Controller\Front\AddressController::updateAction + + Thelia\Controller\Front\AddressController::processUpdateAction + address-update diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index c4a40d951..33fa67069 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -27,7 +27,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; use Thelia\Form\AddressUpdateForm; use Thelia\Form\Exception\FormValidationException; -use Thelia\Model\Base\AddressQuery; +use Thelia\Model\AddressQuery; use Thelia\Model\Customer; use Thelia\Tools\URL; @@ -93,18 +93,28 @@ class AddressController extends BaseFrontController } } - public function updateAction() + public function updateViewAction($address_id) + { + $this->checkAuth(); + + $customer = $this->getSecurityContext()->getCustomerUser(); + $address = AddressQuery::create()->findPk($address_id); + + if(!$address || $customer->getId() != $address->getCustomerId()) { + $this->redirectToRoute("home"); + } + + $this->getParserContext()->set("address_id", $address_id); + } + + public function processUpdateAction($address_id) { $this->checkAuth(); $request = $this->getRequest(); - - if (null === $address_id = $request->get("address_id")) { - $this->redirectToRoute("home"); - } - $addressUpdate = new AddressUpdateForm($request); + try { $customer = $this->getSecurityContext()->getCustomerUser(); @@ -131,7 +141,7 @@ class AddressController extends BaseFrontController } catch (\Exception $e) { $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); } - + $this->getParserContext()->set("address_id", $address_id); if ($message !== false) { \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message)); diff --git a/templates/default/account.html b/templates/default/account.html index b67d6424c..f3815e5c0 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -114,7 +114,7 @@
{/loop} + + + + + {/ifloop}
@@ -110,34 +142,6 @@ {module_include location='customer_bottom'} -
-
- -
    - {if $customer_page != 1} -
  • «
  • - {else} -
  • «
  • - {/if} - - {pageloop rel="customer_list"} - {if $PAGE != $CURRENT} -
  • {$PAGE}
  • - - {else} -
  • {$PAGE}
  • - {/if} - - {if $PAGE == $LAST && $LAST != $CURRENT} -
  • »
  • - {else} -
  • »
  • - {/if} - {/pageloop} -
- -
-
{* Adding a new Category *} From 8367863b489de325ec04794bd5aecf59b71e417e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 12:33:13 +0200 Subject: [PATCH 09/13] allow address removal from front --- core/lib/Thelia/Action/Address.php | 11 +++++- .../Thelia/Config/Resources/routing/front.xml | 5 +++ .../Controller/Front/AddressController.php | 17 ++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 +++ templates/default/account.html | 39 +++++++++++++++++-- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 0aee9a6f5..a912888c8 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -26,6 +26,7 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Address as AddressModel; use Thelia\Model\Map\AddressTableMap; @@ -52,6 +53,13 @@ class Address extends BaseAction implements EventSubscriberInterface $this->createOrUpdate($addressModel, $event); } + public function delete(AddressEvent $event) + { + $address = $event->getAddress(); + + $address->delete(); + } + protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { $addressModel->setDispatcher($this->getDispatcher()); @@ -116,7 +124,8 @@ class Address extends BaseAction implements EventSubscriberInterface { return array( TheliaEvents::ADDRESS_CREATE => array("create", 128), - TheliaEvents::ADDRESS_UPDATE => array("update", 128) + TheliaEvents::ADDRESS_UPDATE => array("update", 128), + TheliaEvents::ADDRESS_DELETE => array("delete", 128) ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index da3c1bdb7..38afb7d7f 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -79,6 +79,11 @@ address-update + + Thelia\Controller\Front\AddressController::deleteAction + account + + Thelia\Controller\Front\AddressController::generateModalAction modal-address diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 33fa67069..272fa6424 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Front; use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; use Thelia\Form\AddressUpdateForm; @@ -154,6 +155,22 @@ class AddressController extends BaseFrontController } } + public function deleteAction($address_id) + { + $this->checkAuth(); + + $customer = $this->getSecurityContext()->getCustomerUser(); + $address = AddressQuery::create()->findPk($address_id); + + if(!$address || $customer->getId() != $address->getCustomerId()) { + $this->redirectToRoute("home"); + } + + $this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address)); + + $this->redirectToRoute("customer.account.view"); + } + protected function createAddressEvent($form) { return new AddressCreateOrUpdateEvent( diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 97e140eb6..54f05c0c0 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -129,6 +129,11 @@ final class TheliaEvents */ const ADDRESS_UPDATE = "action.updateAddress"; + /** + * sent on address removal + */ + const ADDRESS_DELETE = "action.deleteAddress"; + const BEFORE_CREATEADDRESS = "action.before_createAddress"; const AFTER_CREATEADDRESS = "action.after_createAddress"; diff --git a/templates/default/account.html b/templates/default/account.html index f3815e5c0..94bd58501 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -78,8 +78,8 @@ {intl l="Add a new address"} - {loop type="address" name="customer.addresses"} - + {loop type="address" name="customer.addresses" customer="current"} + @@ -173,4 +173,37 @@ + + +{/block} + +{block name="after-javascript-include"} + + + {/block} \ No newline at end of file From ecc419fbdf53896c6ae8f40ce4710dbc0ac1ccaf Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 13 Sep 2013 13:59:16 +0200 Subject: [PATCH 10/13] tax engine retriever --- core/lib/Thelia/TaxEngine/Calculator.php | 75 ++++++++++++++++++- .../Thelia/TaxEngine/TaxType/BaseTaxType.php | 4 + .../TaxType/FeatureSlicePercentTaxType.php | 10 +++ .../TaxEngine/TaxType/FixAmountTaxType.php | 10 +++ .../TaxEngine/TaxType/PricePercentTaxType.php | 12 +++ .../Thelia/Tests/TaxEngine/CalculatorTest.php | 67 +++++++++++------ 6 files changed, 155 insertions(+), 23 deletions(-) diff --git a/core/lib/Thelia/TaxEngine/Calculator.php b/core/lib/Thelia/TaxEngine/Calculator.php index f8c527cd1..b5a2f995e 100755 --- a/core/lib/Thelia/TaxEngine/Calculator.php +++ b/core/lib/Thelia/TaxEngine/Calculator.php @@ -73,11 +73,16 @@ class Calculator return $this; } - public function getTaxAmount($untaxedPrice) + public function getTaxAmountFromUntaxedPrice($untaxedPrice) { return $this->getTaxedPrice($untaxedPrice) - $untaxedPrice; } + public function getTaxAmountFromTaxedPrice($taxedPrice) + { + return $taxedPrice - $this->getUntaxedPrice($taxedPrice); + } + public function getTaxedPrice($untaxedPrice) { if(null === $this->taxRulesCollection) { @@ -111,4 +116,72 @@ class Calculator return $taxedPrice; } + + public function getUntaxedPrice($taxedPrice) + { + if(null === $this->taxRulesCollection) { + throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION); + } + + if(false === filter_var($taxedPrice, FILTER_VALIDATE_FLOAT)) { + throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT); + } + + $taxRule = $this->taxRulesCollection->getLast(); + + $untaxedPrice = $taxedPrice; + $currentPosition = (int)$taxRule->getTaxRuleCountryPosition(); + $currentFixTax = 0; + $currentTaxFactor = 0; + + do { + $position = (int)$taxRule->getTaxRuleCountryPosition(); + + $taxType = $taxRule->getTypeInstance(); + $taxType->loadRequirements( $taxRule->getRequirements() ); + + if($currentPosition !== $position) { + $untaxedPrice -= $currentFixTax; + $untaxedPrice = $untaxedPrice / (1+$currentTaxFactor); + $currentFixTax = 0; + $currentTaxFactor = 0; + $currentPosition = $position; + } + + $currentFixTax += $taxType->fixAmountRetriever(); + $currentTaxFactor += $taxType->pricePercentRetriever(); + + + } while($taxRule = $this->taxRulesCollection->getPrevious()); + + $untaxedPrice -= $currentFixTax; + $untaxedPrice = $untaxedPrice / (1+$currentTaxFactor); + + /*do { + + $taxType = $taxRule->getTypeInstance(); + $taxType->loadRequirements( $taxRule->getRequirements() ); + + $untaxedPrice -= $taxType->fixAmountRetriever(); + + } while($taxRule = $this->taxRulesCollection->getPrevious()); + + $taxRule = $this->taxRulesCollection->getLast(); + + $currentTaxFactor = 0; + do { + + $taxType = $taxRule->getTypeInstance(); + $taxType->loadRequirements( $taxRule->getRequirements() ); + + $currentTaxFactor += $taxType->pricePercentRetriever($untaxedPrice); + + $toto = true; + + } while($taxRule = $this->taxRulesCollection->getPrevious()); + + $untaxedPrice = $untaxedPrice / (1+$currentTaxFactor);*/ + + return $untaxedPrice; + } } diff --git a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php index 7f487bf64..149e3f1df 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php @@ -36,6 +36,10 @@ abstract class BaseTaxType public abstract function calculate($untaxedPrice); + public abstract function pricePercentRetriever(); + + public abstract function fixAmountRetriever(); + public abstract function getRequirementsList(); public function loadRequirements($requirementsValues) diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php index 4485f1e21..911439574 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php @@ -37,6 +37,16 @@ class featureSlicePercentTaxType extends BaseTaxType } + public function pricePercentRetriever() + { + + } + + public function fixAmountRetriever() + { + + } + public function getRequirementsList() { return array( diff --git a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php index c533d0ec3..acd52bf8a 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php @@ -36,6 +36,16 @@ class FixAmountTaxType extends BaseTaxType return $this->getRequirement("amount"); } + public function pricePercentRetriever() + { + return 0; + } + + public function fixAmountRetriever() + { + return $this->getRequirement("amount"); + } + public function getRequirementsList() { return array( diff --git a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php index 1d7152fcf..a8cd8c759 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php @@ -36,6 +36,16 @@ class PricePercentTaxType extends BaseTaxType return $untaxedPrice * $this->getRequirement("percent") * 0.01; } + public function pricePercentRetriever() + { + return ($this->getRequirement("percent") * 0.01); + } + + public function fixAmountRetriever() + { + return 0; + } + public function getRequirementsList() { return array( @@ -43,3 +53,5 @@ class PricePercentTaxType extends BaseTaxType ); } } + +//600 / (1 + 0,10 + 0,10) =/= 600 / (1 + 0,10 ) + 600 / (1 + 0,10 ) \ No newline at end of file diff --git a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php index 165d5d517..e0443c5ba 100755 --- a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php +++ b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php @@ -112,17 +112,17 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase * @expectedException \Thelia\Exception\TaxEngineException * @expectedExceptionCode 503 */ - public function testGetTaxAmountBadTaxRulesCollection() + public function testGetTaxedPriceBadTaxRulesCollection() { $calculator = new Calculator(); - $calculator->getTaxAmount(500); + $calculator->getTaxedPrice(500); } /** * @expectedException \Thelia\Exception\TaxEngineException * @expectedExceptionCode 601 */ - public function testGetTaxAmountBadAmount() + public function testGetTaxedPriceBadAmount() { $taxRulesCollection = new ObjectCollection(); @@ -131,12 +131,11 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $rewritingUrlQuery = $this->getProperty('taxRulesCollection'); $rewritingUrlQuery->setValue($calculator, $taxRulesCollection); - $calculator->getTaxAmount('foo'); + $calculator->getTaxedPrice('foo'); } - public function testGetTaxAmountAndGetTaxedPrice() + public function testGetTaxedPriceAndGetTaxAmountFromUntaxedPrice() { - /* consecutives taxes */ $taxRulesCollection = new ObjectCollection(); $taxRulesCollection->setModel('\Thelia\Model\Tax'); @@ -144,14 +143,24 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $tax->setType('PricePercentTaxType') ->setRequirements(array('percent' => 10)) ->setVirtualColumn('taxRuleCountryPosition', 1); - $taxRulesCollection->append($tax); $tax = new Tax(); $tax->setType('PricePercentTaxType') ->setRequirements(array('percent' => 8)) + ->setVirtualColumn('taxRuleCountryPosition', 1); + $taxRulesCollection->append($tax); + + $tax = new Tax(); + $tax->setType('FixAmountTaxType') + ->setRequirements(array('amount' => 5)) ->setVirtualColumn('taxRuleCountryPosition', 2); + $taxRulesCollection->append($tax); + $tax = new Tax(); + $tax->setType('PricePercentTaxType') + ->setRequirements(array('percent' => 1)) + ->setVirtualColumn('taxRuleCountryPosition', 3); $taxRulesCollection->append($tax); $calculator = new Calculator(); @@ -159,19 +168,22 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $rewritingUrlQuery = $this->getProperty('taxRulesCollection'); $rewritingUrlQuery->setValue($calculator, $taxRulesCollection); - $taxAmount = $calculator->getTaxAmount(500); + $taxAmount = $calculator->getTaxAmountFromUntaxedPrice(500); $taxedPrice = $calculator->getTaxedPrice(500); /* * expect : - * tax 1 = 500*0.10 = 50 // amout with tax 1 : 550 - * tax 2 = 550*0.08 = 44 // amout with tax 2 : 594 - * total tax amount = 94 + * tax 1 = 500*0.10 = 50 + 500*0.08 = 40 // amount with tax 1 : 590 + * tax 2 = 5 // amount with tax 2 : 595 + * tax 3 = 595 * 0.01 = 5.95 // amount with tax 3 : 600.95 + * total tax amount = 100.95 */ - $this->assertEquals(94, $taxAmount); - $this->assertEquals(594, $taxedPrice); + $this->assertEquals(100.95, $taxAmount); + $this->assertEquals(600.95, $taxedPrice); + } - /* same position taxes */ + public function testGetUntaxedPriceAndGetTaxAmountFromTaxedPrice() + { $taxRulesCollection = new ObjectCollection(); $taxRulesCollection->setModel('\Thelia\Model\Tax'); @@ -179,14 +191,24 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $tax->setType('PricePercentTaxType') ->setRequirements(array('percent' => 10)) ->setVirtualColumn('taxRuleCountryPosition', 1); - $taxRulesCollection->append($tax); $tax = new Tax(); $tax->setType('PricePercentTaxType') ->setRequirements(array('percent' => 8)) ->setVirtualColumn('taxRuleCountryPosition', 1); + $taxRulesCollection->append($tax); + $tax = new Tax(); + $tax->setType('FixAmountTaxType') + ->setRequirements(array('amount' => 5)) + ->setVirtualColumn('taxRuleCountryPosition', 2); + $taxRulesCollection->append($tax); + + $tax = new Tax(); + $tax->setType('PricePercentTaxType') + ->setRequirements(array('percent' => 1)) + ->setVirtualColumn('taxRuleCountryPosition', 3); $taxRulesCollection->append($tax); $calculator = new Calculator(); @@ -194,16 +216,17 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $rewritingUrlQuery = $this->getProperty('taxRulesCollection'); $rewritingUrlQuery->setValue($calculator, $taxRulesCollection); - $taxAmount = $calculator->getTaxAmount(500); - $taxedPrice = $calculator->getTaxedPrice(500); + $taxAmount = $calculator->getTaxAmountFromTaxedPrice(600.95); + $untaxedPrice = $calculator->getUntaxedPrice(600.95); /* * expect : - * tax 1 = 500*0.10 = 50 // amout with tax 1 : 550 - * tax 2 = 500*0.08 = 40 // amout with tax 2 : 590 - * total tax amount = 90 + * tax 3 = 600.95 - 600.95 / (1 + 0.01) = 5,95 // amount without tax 3 : 595 + * tax 2 = 5 // amount without tax 2 : 590 + * tax 1 = 590 - 590 / (1 + 0.08 + 0.10) = 90 // amount without tax 1 : 500 + * total tax amount = 100.95 */ - $this->assertEquals(90, $taxAmount); - $this->assertEquals(590, $taxedPrice); + $this->assertEquals(100.95, $taxAmount); + $this->assertEquals(500, $untaxedPrice); } } From 8b0c8bd760262c92120b8bc45cf79f7ad2cb6f9b Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 13 Sep 2013 18:03:45 +0200 Subject: [PATCH 11/13] First version of installation wizard --- .../Config/Resources/routing/install.xml | 20 ++- .../Install/BaseInstallController.php | 2 +- .../Controller/Install/InstallController.php | 51 ++++++- core/lib/Thelia/Install/BaseInstall.php | 3 +- .../default/assets/less/thelia/thelia.less | 1 + .../default/assets/less/thelia/wizard.less | 129 ++++++++++++++++++ templates/install/index.html | 52 +++++-- templates/install/layout.html | 49 ------- templates/install/layout.tpl | 62 +++++++++ templates/install/step-2.html | 51 +++++++ templates/install/step-3.html | 56 ++++++++ templates/install/step-4.html | 77 +++++++++++ templates/install/step-5.html | 72 ++++++++++ templates/install/thanks.html | 42 ++++++ 14 files changed, 601 insertions(+), 66 deletions(-) create mode 100644 templates/admin/default/assets/less/thelia/wizard.less delete mode 100644 templates/install/layout.html create mode 100644 templates/install/layout.tpl create mode 100644 templates/install/step-2.html create mode 100644 templates/install/step-3.html create mode 100644 templates/install/step-4.html create mode 100644 templates/install/step-5.html create mode 100644 templates/install/thanks.html diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml index d53763948..37ddde487 100644 --- a/core/lib/Thelia/Config/Resources/routing/install.xml +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -4,12 +4,28 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + Thelia\Controller\Install\InstallController::index - + Thelia\Controller\Install\InstallController::checkPermission + + Thelia\Controller\Install\InstallController::databaseConnection + + + + Thelia\Controller\Install\InstallController::databaseSelection + + + + Thelia\Controller\Install\InstallController::generalInformation + + + + Thelia\Controller\Install\InstallController::thanks + + diff --git a/core/lib/Thelia/Controller/Install/BaseInstallController.php b/core/lib/Thelia/Controller/Install/BaseInstallController.php index 35293904e..bac7a4f19 100644 --- a/core/lib/Thelia/Controller/Install/BaseInstallController.php +++ b/core/lib/Thelia/Controller/Install/BaseInstallController.php @@ -39,7 +39,7 @@ class BaseInstallController extends BaseController { $parser = $this->container->get("thelia.parser"); - // Define the template thant shoud be used + // Define the template that shoud be used $parser->setTemplate("install"); return $parser; diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 0514ba0ff..40e6643db 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -33,18 +33,61 @@ class InstallController extends BaseInstallController { public function index() { - $this->verifyStep(1); + //$this->verifyStep(1); $this->getSession()->set("step", 1); - $this->render("index.html"); + return $this->render("index.html"); } public function checkPermission() { - $this->verifyStep(2); + //$this->verifyStep(2); - $permission = new CheckPermission(); + //$permission = new CheckPermission(); + + $this->getSession()->set("step", 2); + return $this->render("step-2.html"); + } + + public function databaseConnection() + { + //$this->verifyStep(2); + + //$permission = new CheckPermission(); + + $this->getSession()->set("step", 3); + return $this->render("step-3.html"); + } + + public function databaseSelection() + { + //$this->verifyStep(2); + + //$permission = new CheckPermission(); + + $this->getSession()->set("step", 4); + return $this->render("step-4.html"); + } + + public function generalInformation() + { + //$this->verifyStep(2); + + //$permission = new CheckPermission(); + + $this->getSession()->set("step", 5); + return $this->render("step-5.html"); + } + + public function thanks() + { + //$this->verifyStep(2); + + //$permission = new CheckPermission(); + + $this->getSession()->set("step", 6); + return $this->render("thanks.html"); } protected function verifyStep($step) diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php index 58c510267..11b8d0999 100644 --- a/core/lib/Thelia/Install/BaseInstall.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -34,9 +34,10 @@ abstract class BaseInstall */ public function __construct($verifyInstall = true) { + /* TODO : activate this part if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { throw new AlreadyInstallException("Thelia is already installed"); - } + }*/ $this->exec(); diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index ac525566f..50cd9bde6 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -8,6 +8,7 @@ @import "modals.less"; @import "tables.less"; @import "tablesorter.less"; +@import "wizard.less"; @import "bootstrap-editable.less"; @import "bootstrap-switch.less"; diff --git a/templates/admin/default/assets/less/thelia/wizard.less b/templates/admin/default/assets/less/thelia/wizard.less new file mode 100644 index 000000000..0d130a2d5 --- /dev/null +++ b/templates/admin/default/assets/less/thelia/wizard.less @@ -0,0 +1,129 @@ +.wizard { + background-color: #fff; + border: 1px solid #d4d4d4; + border-radius: 4px; + .box-shadow(0 1px 4px rgba(0, 0, 0, 0.065)); + *zoom: 1; + margin-bottom: 20px; + + &:before, + &:after { + display: table; + line-height: 0; + content: ""; + clear: both; + } + + ul { + padding: 0; + margin: 0; + list-style: none outside none; + } + + li { + position: relative; + float: left; + height: 46px; + padding: 0 10px 0 30px; + margin: 0; + font-size: 15px; + line-height: 46px; + color: #999999; + cursor: default; + background: #ededed; + + &.complete { + color: #468847; + background: #f3f4f5; + + &:hover{ + background: #e8e8e8; + + .chevron:before { + border-left: 14px solid #e8e8e8; + } + } + + a{ + color: inherit; + text-decoration: none; + font-weight: normal; + } + + .chevron:before { + border-left: 14px solid #f3f4f5; + } + + } + + &.active { + color: @link-color; + background: #fff; + + .chevron:before { + border-left: 14px solid #fff; + } + } + + .chevron { + position: absolute; + top: 0; + right: -14px; + display: block; + border: 24px solid transparent; + border-right: 0; + border-left: 14px solid #d4d4d4; + + &:before { + position: absolute; + top: -24px; + right: 1px; + display: block; + border: 24px solid transparent; + border-right: 0; + border-left: 14px solid #ededed; + content: ""; + } + + } + + .badge { + margin-right: 8px; + } + + &:nth-child(1) { + z-index: 10; + padding-left: 20px; + border-radius: 4px 0 0 4px; + } + &:nth-child(2) { + z-index: 9; + } + &:nth-child(3) { + z-index: 8; + } + &:nth-child(4) { + z-index: 7; + } + &:nth-child(5) { + z-index: 6; + } + &:nth-child(6) { + z-index: 5; + } + &:nth-child(7) { + z-index: 4; + } + &:nth-child(8) { + z-index: 3; + } + &:nth-child(9) { + z-index: 2; + } + &:nth-child(10) { + z-index: 1; + } + + } + +} \ No newline at end of file diff --git a/templates/install/index.html b/templates/install/index.html index a996cc241..dd1d5f62b 100644 --- a/templates/install/index.html +++ b/templates/install/index.html @@ -1,12 +1,46 @@ -{extends file="layout.html"} -{block name="content"} -

{intl l="Thelia installation wizard"}

-
+{extends file="layout.tpl"} - {intl l="Bienvenue au sein du programme d'installation de Thelia."}
- {intl l="Nous allons vous guider tout au long de ce processus afin d'installer l'application sur votre système."}

+{block name="page-title"}{intl l='Installation'}{/block} -
- - +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ +
+
    +
  • 1{intl l="Welcome"}
  • +
  • 2{intl l="Checking permissions"}
  • +
  • 3{intl l="Database connection"}
  • +
  • 4{intl l="Database selection"}
  • +
  • 5{intl l="General information"}
  • +
  • 6{intl l="Thanks"}
  • +
+
+ +
+

+ {intl l="Welcome in the Thelia installation wizard."} +

+

+ {intl l="We will guide you throughout this process to install any application on your system."} +

+ +
+ + + +
+
+
+ +
+
{/block} \ No newline at end of file diff --git a/templates/install/layout.html b/templates/install/layout.html deleted file mode 100644 index 0a13586ad..000000000 --- a/templates/install/layout.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - {block name="title"}Thelia Install{/block} - - {images file='../admin/default/assets/img/favicon.ico'}{/images} - - - - {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap.css' filters='cssembed'} - - {/stylesheets} - - {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap-responsive.css' filters='cssembed'} - - {/stylesheets} - - - {stylesheets file='../admin/default/assets/css/*' filters='less,cssembed'} - - {/stylesheets} - - - -
-
-
{intl l='Version %ver' ver="{$THELIA_VERSION}"}
-
-
-
- {block name="content"}{/block} -
- -
- - - - \ No newline at end of file diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl new file mode 100644 index 000000000..4539ce32f --- /dev/null +++ b/templates/install/layout.tpl @@ -0,0 +1,62 @@ + + + + {block name="page-title"}Thelia Install{/block} + + {images file='../admin/default/assets/img/favicon.ico'}{/images} + + + + {stylesheets file='../admin/default/assets/less/*' filters='less,cssembed'} + + {/stylesheets} + + + +
+
+ +
+
+
{intl l='Version %ver' ver="{$THELIA_VERSION}"}
+
+
+ +
+
+ + {* -- Main page content section ----------------------------------------- *} + + {block name="main-content"}Put here the content of the template{/block} + + {* -- Footer section ---------------------------------------------------- *} + +
+ + + {* -- Javascript section ------------------------------------------------ *} + + + + {block name="after-javascript-include"}{/block} + + {javascripts file='../admin/default/assets/js/bootstrap/bootstrap.js'} + + {/javascripts} + + {block name="javascript-initialization"}{/block} + + + \ No newline at end of file diff --git a/templates/install/step-2.html b/templates/install/step-2.html new file mode 100644 index 000000000..fc24d25cb --- /dev/null +++ b/templates/install/step-2.html @@ -0,0 +1,51 @@ +{extends file="layout.tpl"} + +{block name="page-title"}{intl l='Installation step 2'}{/block} + +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ +
+
    +
  • 1{intl l="Welcome"}
  • +
  • 2{intl l="Checking permissions"}
  • +
  • 3{intl l="Database connection"}
  • +
  • 4{intl l="Database selection"}
  • +
  • 5{intl l="General information"}
  • +
  • 6{intl l="Thanks"}
  • +
+
+ +
+

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

+
    +
  • 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.
  • +
+ +
+ + + +
+
+
+ +
+
+{/block} \ No newline at end of file diff --git a/templates/install/step-3.html b/templates/install/step-3.html new file mode 100644 index 000000000..cb4157dd7 --- /dev/null +++ b/templates/install/step-3.html @@ -0,0 +1,56 @@ +{extends file="layout.tpl"} + +{block name="page-title"}{intl l='Installation step 3'}{/block} + +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ +
+ +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ + + +
+
+
+ +
+
+{/block} \ No newline at end of file diff --git a/templates/install/step-4.html b/templates/install/step-4.html new file mode 100644 index 000000000..981be34bb --- /dev/null +++ b/templates/install/step-4.html @@ -0,0 +1,77 @@ +{extends file="layout.tpl"} + +{block name="page-title"}{intl l='Installation step 4'}{/block} + +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ +
+ +
+ +
+
+
+ {intl l="Choose your database"} +

+ The SQL server contains multiple databases.
+ Select below the one you want to use. +

+ +
+ +
+
+ +
+ +

+ {intl l="or"} +

+ +
+ +
+ +
+ +
+
+ +
+ + + +
+
+
+ +
+
+{/block} \ No newline at end of file diff --git a/templates/install/step-5.html b/templates/install/step-5.html new file mode 100644 index 000000000..611a86a20 --- /dev/null +++ b/templates/install/step-5.html @@ -0,0 +1,72 @@ +{extends file="layout.tpl"} + +{block name="page-title"}{intl l='Installation step 4'}{/block} + +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ + + +
+
+ +

+ The system will now you create a custom site access. +

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + + +
+
+
+ +
+
+{/block} \ No newline at end of file diff --git a/templates/install/thanks.html b/templates/install/thanks.html new file mode 100644 index 000000000..b6ed27065 --- /dev/null +++ b/templates/install/thanks.html @@ -0,0 +1,42 @@ +{extends file="layout.tpl"} + +{block name="page-title"}{intl l='Thanks'}{/block} + +{block name="main-content"} +
+
+ +
+
+
+ +

{intl l="Thelia installation wizard"}

+ + + +
+

+ {intl l="Thank you have installed Thelia"}. +

+

+ {intl l="You will be redirected to your personal space in order to manage your store now."} +

+ +
+ +
+
+
+ +
+
+{/block} \ No newline at end of file From a0f09057c490933d41366021c7d0b83c269fa765 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 20:21:47 +0200 Subject: [PATCH 12/13] Added Templates events --- core/lib/Thelia/Core/Event/TheliaEvents.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 97e140eb6..ac0064c41 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -362,6 +362,21 @@ final class TheliaEvents const BEFORE_DELETECURRENCY = "action.before_deleteCurrency"; const AFTER_DELETECURRENCY = "action.after_deleteCurrency"; + // -- Product templates management ----------------------------------------- + + const TEMPLATE_CREATE = "action.createTemplate"; + const TEMPLATE_UPDATE = "action.updateTemplate"; + const TEMPLATE_DELETE = "action.deleteTemplate"; + + const BEFORE_CREATETEMPLATE = "action.before_createTemplate"; + const AFTER_CREATETEMPLATE = "action.after_createTemplate"; + + const BEFORE_UPDATETEMPLATE = "action.before_updateTemplate"; + const AFTER_UPDATETEMPLATE = "action.after_updateTemplate"; + + const BEFORE_DELETETEMPLATE = "action.before_deleteTemplate"; + const AFTER_DELETETEMPLATE = "action.after_deleteTemplate"; + // -- Attributes management --------------------------------------------- const ATTRIBUTE_CREATE = "action.createAttribute"; From 71c1cee66d8f2e515e82478f792879fa63843644 Mon Sep 17 00:00:00 2001 From: franck Date: Mon, 16 Sep 2013 09:23:44 +0200 Subject: [PATCH 13/13] Implemented "Remember Me" feature on admin. Started template management --- core/lib/Thelia/Action/Attribute.php | 8 +- core/lib/Thelia/Action/Template.php | 127 + core/lib/Thelia/Config/Resources/action.xml | 5 + core/lib/Thelia/Config/Resources/config.xml | 5 + .../Thelia/Config/Resources/routing/admin.xml | 23 + .../Admin/AbstractCrudController.php | 33 +- .../Controller/Admin/AdminController.php | 4 + .../Controller/Admin/AttributeController.php | 4 +- .../Controller/Admin/BaseAdminController.php | 42 + .../Controller/Admin/SessionController.php | 49 +- .../Controller/Admin/TemplateController.php | 196 ++ core/lib/Thelia/Controller/BaseController.php | 4 +- .../Thelia/Core/Event/TemplateCreateEvent.php | 54 + .../Thelia/Core/Event/TemplateDeleteEvent.php | 59 + core/lib/Thelia/Core/Event/TemplateEvent.php | 52 + .../Thelia/Core/Event/TemplateUpdateEvent.php | 71 + .../AdminTokenAuthenticator.php | 37 + .../CustomerTokenAuthenticator.php | 37 + .../Authentication/TokenAuthenticator.php | 57 + .../TokenAuthenticationException.php | 28 + .../Security/Token/CookieTokenProvider.php | 55 + .../Core/Security/Token/TokenProvider.php | 27 + .../Core/Security/User/UserInterface.php | 22 +- .../UserProvider/AdminTokenUserProvider.php | 39 + .../UserProvider/AdminUserProvider.php | 22 + .../CustomerTokenUserProvider.php | 39 + .../UserProvider/CustomerUserProvider.php | 24 +- .../UserProvider/TokenUserProvider.php | 32 + .../UserProvider/UserProviderInterface.php | 21 + .../Thelia/Core/Template/Loop/Attribute.php | 33 +- .../Thelia/Core/Template/Loop/Template.php | 114 + .../Core/Template/Smarty/Plugins/Form.php | 30 +- core/lib/Thelia/Core/TheliaHttpKernel.php | 2 +- core/lib/Thelia/Form/TemplateCreationForm.php | 57 + .../Thelia/Form/TemplateModificationForm.php | 67 + core/lib/Thelia/Model/Admin.php | 39 + core/lib/Thelia/Model/AttributeTemplate.php | 10 + .../Thelia/Model/AttributeTemplateQuery.php | 21 + core/lib/Thelia/Model/Base/Admin.php | 134 +- core/lib/Thelia/Model/Base/AdminQuery.php | 68 +- core/lib/Thelia/Model/Base/Attribute.php | 398 +-- core/lib/Thelia/Model/Base/AttributeQuery.php | 54 +- .../Thelia/Model/Base/AttributeTemplate.php | 1495 ++++++++ .../Model/Base/AttributeTemplateQuery.php | 759 +++++ core/lib/Thelia/Model/Base/Category.php | 1060 ------ core/lib/Thelia/Model/Base/CategoryQuery.php | 188 - core/lib/Thelia/Model/Base/Customer.php | 134 +- core/lib/Thelia/Model/Base/CustomerQuery.php | 68 +- core/lib/Thelia/Model/Base/Feature.php | 398 +-- core/lib/Thelia/Model/Base/FeatureQuery.php | 54 +- .../lib/Thelia/Model/Base/FeatureTemplate.php | 1495 ++++++++ .../Model/Base/FeatureTemplateQuery.php | 759 +++++ core/lib/Thelia/Model/Base/Product.php | 185 +- core/lib/Thelia/Model/Base/ProductQuery.php | 128 +- core/lib/Thelia/Model/Base/ProductVersion.php | 106 +- .../Thelia/Model/Base/ProductVersionQuery.php | 47 +- core/lib/Thelia/Model/Base/TaxRule.php | 25 + core/lib/Thelia/Model/Base/Template.php | 3019 +++++++++++++++++ core/lib/Thelia/Model/Base/TemplateI18n.php | 1265 +++++++ .../Thelia/Model/Base/TemplateI18nQuery.php | 508 +++ core/lib/Thelia/Model/Base/TemplateQuery.php | 907 +++++ core/lib/Thelia/Model/Customer.php | 31 + core/lib/Thelia/Model/FeatureTemplate.php | 10 + .../lib/Thelia/Model/FeatureTemplateQuery.php | 21 + core/lib/Thelia/Model/Map/AdminTableMap.php | 44 +- .../Thelia/Model/Map/AttributeTableMap.php | 6 +- .../Model/Map/AttributeTemplateTableMap.php | 449 +++ .../lib/Thelia/Model/Map/CategoryTableMap.php | 6 - .../lib/Thelia/Model/Map/CustomerTableMap.php | 44 +- core/lib/Thelia/Model/Map/FeatureTableMap.php | 6 +- .../Model/Map/FeatureTemplateTableMap.php | 449 +++ core/lib/Thelia/Model/Map/ProductTableMap.php | 37 +- .../Model/Map/ProductVersionTableMap.php | 40 +- .../Thelia/Model/Map/TemplateI18nTableMap.php | 473 +++ .../lib/Thelia/Model/Map/TemplateTableMap.php | 455 +++ core/lib/Thelia/Model/Template.php | 68 + core/lib/Thelia/Model/TemplateI18n.php | 10 + core/lib/Thelia/Model/TemplateI18nQuery.php | 21 + core/lib/Thelia/Model/TemplateQuery.php | 21 + core/lib/Thelia/Tools/Redirect.php | 2 +- install/faker.php | 44 +- ...er_100categories_1000products_4locales.php | 14 +- install/insert.sql | 10 +- install/thelia.sql | 92 +- local/config/schema.xml | 2305 ++++++------- .../default/ajax/template-attribute-list.html | 15 + .../{includes => ajax}/thelia_news_feed.html | 0 templates/admin/default/attributes.html | 2 +- templates/admin/default/login.html | 2 +- templates/admin/default/template-edit.html | 115 + templates/admin/default/templates.html | 215 ++ 91 files changed, 16722 insertions(+), 3088 deletions(-) create mode 100644 core/lib/Thelia/Action/Template.php create mode 100644 core/lib/Thelia/Controller/Admin/TemplateController.php create mode 100644 core/lib/Thelia/Core/Event/TemplateCreateEvent.php create mode 100644 core/lib/Thelia/Core/Event/TemplateDeleteEvent.php create mode 100644 core/lib/Thelia/Core/Event/TemplateEvent.php create mode 100644 core/lib/Thelia/Core/Event/TemplateUpdateEvent.php create mode 100644 core/lib/Thelia/Core/Security/Authentication/AdminTokenAuthenticator.php create mode 100644 core/lib/Thelia/Core/Security/Authentication/CustomerTokenAuthenticator.php create mode 100644 core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php create mode 100644 core/lib/Thelia/Core/Security/Exception/TokenAuthenticationException.php create mode 100644 core/lib/Thelia/Core/Security/Token/CookieTokenProvider.php create mode 100644 core/lib/Thelia/Core/Security/Token/TokenProvider.php create mode 100644 core/lib/Thelia/Core/Security/UserProvider/AdminTokenUserProvider.php create mode 100644 core/lib/Thelia/Core/Security/UserProvider/CustomerTokenUserProvider.php create mode 100644 core/lib/Thelia/Core/Security/UserProvider/TokenUserProvider.php create mode 100644 core/lib/Thelia/Core/Template/Loop/Template.php create mode 100644 core/lib/Thelia/Form/TemplateCreationForm.php create mode 100644 core/lib/Thelia/Form/TemplateModificationForm.php create mode 100644 core/lib/Thelia/Model/AttributeTemplate.php create mode 100644 core/lib/Thelia/Model/AttributeTemplateQuery.php create mode 100644 core/lib/Thelia/Model/Base/AttributeTemplate.php create mode 100644 core/lib/Thelia/Model/Base/AttributeTemplateQuery.php create mode 100644 core/lib/Thelia/Model/Base/FeatureTemplate.php create mode 100644 core/lib/Thelia/Model/Base/FeatureTemplateQuery.php create mode 100644 core/lib/Thelia/Model/Base/Template.php create mode 100644 core/lib/Thelia/Model/Base/TemplateI18n.php create mode 100644 core/lib/Thelia/Model/Base/TemplateI18nQuery.php create mode 100644 core/lib/Thelia/Model/Base/TemplateQuery.php create mode 100644 core/lib/Thelia/Model/FeatureTemplate.php create mode 100644 core/lib/Thelia/Model/FeatureTemplateQuery.php create mode 100644 core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php create mode 100644 core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php create mode 100644 core/lib/Thelia/Model/Map/TemplateI18nTableMap.php create mode 100644 core/lib/Thelia/Model/Map/TemplateTableMap.php create mode 100644 core/lib/Thelia/Model/Template.php create mode 100644 core/lib/Thelia/Model/TemplateI18n.php create mode 100644 core/lib/Thelia/Model/TemplateI18nQuery.php create mode 100644 core/lib/Thelia/Model/TemplateQuery.php create mode 100644 templates/admin/default/ajax/template-attribute-list.html rename templates/admin/default/{includes => ajax}/thelia_news_feed.html (100%) create mode 100644 templates/admin/default/template-edit.html create mode 100644 templates/admin/default/templates.html diff --git a/core/lib/Thelia/Action/Attribute.php b/core/lib/Thelia/Action/Attribute.php index 2877ca388..a2e956d8e 100644 --- a/core/lib/Thelia/Action/Attribute.php +++ b/core/lib/Thelia/Action/Attribute.php @@ -39,6 +39,8 @@ use Thelia\Model\AttributeAvQuery; use Thelia\Core\Event\UpdatePositionEvent; use Thelia\Core\Event\CategoryEvent; use Thelia\Core\Event\AttributeEvent; +use Thelia\Model\AttributeTemplate; +use Thelia\Model\AttributeTemplateQuery; class Attribute extends BaseAction implements EventSubscriberInterface { @@ -137,10 +139,10 @@ class Attribute extends BaseAction implements EventSubscriberInterface public function addToAllTemplates(AttributeEvent $event) { - $templates = ProductTemplateAttributeQuery::create()->find(); + $templates = AttributeTemplateQuery::create()->find(); foreach($templates as $template) { - $pat = new ProductTemplateAttribute(); + $pat = new AttributeTemplate(); $pat->setTemplate($template->getId()) ->setAttributeId($event->getAttribute()->getId()) @@ -151,7 +153,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface public function removeFromAllTemplates(AttributeEvent $event) { // Delete this attribute from all product templates - ProductTemplateAttributeQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete(); + AttributeTemplateQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete(); } /** diff --git a/core/lib/Thelia/Action/Template.php b/core/lib/Thelia/Action/Template.php new file mode 100644 index 000000000..a06e10430 --- /dev/null +++ b/core/lib/Thelia/Action/Template.php @@ -0,0 +1,127 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +use Thelia\Model\TemplateQuery; +use Thelia\Model\Template as TemplateModel; + +use Thelia\Core\Event\TheliaEvents; + +use Thelia\Core\Event\TemplateUpdateEvent; +use Thelia\Core\Event\TemplateCreateEvent; +use Thelia\Core\Event\TemplateDeleteEvent; +use Thelia\Model\ConfigQuery; +use Thelia\Model\TemplateAv; +use Thelia\Model\TemplateAvQuery; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\CategoryEvent; +use Thelia\Core\Event\TemplateEvent; +use Thelia\Model\TemplateTemplate; +use Thelia\Model\TemplateTemplateQuery; +use Thelia\Model\ProductQuery; + +class Template extends BaseAction implements EventSubscriberInterface +{ + /** + * Create a new template entry + * + * @param TemplateCreateEvent $event + */ + public function create(TemplateCreateEvent $event) + { + $template = new TemplateModel(); + + $template + ->setDispatcher($this->getDispatcher()) + + ->setLocale($event->getLocale()) + ->setName($event->getTemplateName()) + + ->save() + ; + + $event->setTemplate($template); + } + + /** + * Change a product template + * + * @param TemplateUpdateEvent $event + */ + public function update(TemplateUpdateEvent $event) + { + $search = TemplateQuery::create(); + + if (null !== $template = TemplateQuery::create()->findPk($event->getTemplateId())) { + + $template + ->setDispatcher($this->getDispatcher()) + + ->setLocale($event->getLocale()) + ->setName($event->getTemplateName()) + ->save(); + + $event->setTemplate($template); + } + } + + /** + * Delete a product template entry + * + * @param TemplateDeleteEvent $event + */ + public function delete(TemplateDeleteEvent $event) + { + if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) { + + // Check if template is used by a product + $product_count = ProductQuery::create()->findByTemplateId($template->getId())->count(); + + if ($product_count <= 0) { + $template + ->setDispatcher($this->getDispatcher()) + ->delete() + ; + } + + $event->setTemplate($template); + + $event->setProductCount($product_count); + } + } + + /** + * {@inheritDoc} + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::TEMPLATE_CREATE => array("create", 128), + TheliaEvents::TEMPLATE_UPDATE => array("update", 128), + TheliaEvents::TEMPLATE_DELETE => array("delete", 128), + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 2b86ed33e..f2fa776c3 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -57,6 +57,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index ddb32cf65..8098eb9d4 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -36,6 +36,7 @@ + @@ -72,6 +73,10 @@
+ + + +
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c16ee05bd..5c9399e27 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -210,6 +210,29 @@
+ + + + Thelia\Controller\Admin\TemplateController::defaultAction + + + + Thelia\Controller\Admin\TemplateController::createAction + + + + Thelia\Controller\Admin\TemplateController::updateAction + + + + Thelia\Controller\Admin\TemplateController::processUpdateAction + + + + Thelia\Controller\Admin\TemplateController::deleteAction + + + diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index 31f9ba72a..fad774023 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -210,31 +210,34 @@ abstract class AbstractCrudController extends BaseAdminController /** * Put in this method post object creation processing if required. * - * @param unknown $createdObject the created object + * @param unknown $createEvent the create event + * @return Response a response, or null to continue normal processing */ - protected function performAdditionalCreateAction($createdObject) + protected function performAdditionalCreateAction($createEvent) { - // Nothing to do + return null; } /** * Put in this method post object update processing if required. * - * @param unknown $updatedObject the updated object + * @param unknown $updateEvent the update event + * @return Response a response, or null to continue normal processing */ - protected function performAdditionalUpdateAction($updatedObject) + protected function performAdditionalUpdateAction($updateeEvent) { - // Nothing to do + return null; } /** * Put in this method post object delete processing if required. * - * @param unknown $deletedObject the deleted object + * @param unknown $deleteEvent the delete event + * @return Response a response, or null to continue normal processing */ - protected function performAdditionalDeleteAction($deletedObject) + protected function performAdditionalDeleteAction($deleteEvent) { - // Nothing to do + return null; } /** @@ -306,7 +309,7 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); } - $this->performAdditionalCreateAction($createdObject); + $this->performAdditionalCreateAction($createEvent); // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl()); @@ -393,7 +396,7 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } - $this->performAdditionalUpdateAction($changedObject); + $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. @@ -494,8 +497,12 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend( sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject))); } - $this->performAdditionalDeleteAction($deletedObject); - $this->redirectToListTemplate(); + $response = $this->performAdditionalDeleteAction($deleteEvent); + + if ($response == null) + $this->redirectToListTemplate(); + else + return $response; } } diff --git a/core/lib/Thelia/Controller/Admin/AdminController.php b/core/lib/Thelia/Controller/Admin/AdminController.php index fdb6b13ac..2c252258d 100755 --- a/core/lib/Thelia/Controller/Admin/AdminController.php +++ b/core/lib/Thelia/Controller/Admin/AdminController.php @@ -23,6 +23,10 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Security\Authentication\AdminTokenAuthenticator; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Security\Exception\TokenAuthenticationException; + class AdminController extends BaseAdminController { public function indexAction() diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index 0ae181900..247b89632 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -107,7 +107,7 @@ class AttributeController extends AbstractCrudController * * @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction() */ - protected function performAdditionalUpdateAction($updatedObject) + protected function performAdditionalUpdateAction($updateEvent) { $attr_values = $this->getRequest()->get('attribute_values', null); @@ -123,6 +123,8 @@ class AttributeController extends AbstractCrudController $this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event); } } + + return null; } protected function createUpdatePositionEvent($positionChangeMode, $positionValue) diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 6471dda81..1e0f65055 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -40,6 +40,8 @@ use Thelia\Form\BaseForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Log\Tlog; use Symfony\Component\Routing\Router; +use Thelia\Model\Admin; +use Thelia\Core\Security\Token\CookieTokenProvider; class BaseAdminController extends BaseController { @@ -302,6 +304,46 @@ class BaseAdminController extends BaseController return $order; } + /** + * Create the remember me cookie for the given user. + */ + protected function createAdminRememberMeCookie(Admin $user) + { + $ctp = new CookieTokenProvider(); + + $cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn'); + $cookieExpiration = ConfigQuery::read('admin_remember_me_cookie_expiration', 2592000 /* 1 month */); + + $ctp->createCookie($user, $cookieName, $cookieExpiration); + } + + /** + * Get the rememberme key from the cookie. + * + * @return string hte key found, or null if no key was found. + */ + protected function getRememberMeKeyFromCookie() + { + // Check if we can authenticate the user with a cookie-based token + $cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn'); + + $ctp = new CookieTokenProvider(); + + return $ctp->getKeyFromCookie($this->getRequest(), $cookieName); + } + + /** Clear the remember me cookie. + * + */ + protected function clearRememberMeCookie() { + + $ctp = new CookieTokenProvider(); + + $cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn'); + + $ctp->clearCookie($cookieName); + } + /** * Render the given template, and returns the result as an Http Response. * diff --git a/core/lib/Thelia/Controller/Admin/SessionController.php b/core/lib/Thelia/Controller/Admin/SessionController.php index 81f366ddf..120a28b26 100755 --- a/core/lib/Thelia/Controller/Admin/SessionController.php +++ b/core/lib/Thelia/Controller/Admin/SessionController.php @@ -30,11 +30,44 @@ use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Security\Authentication\AdminTokenAuthenticator; +use Thelia\Core\Security\UserProvider\TokenProvider; +use Symfony\Component\HttpFoundation\Cookie; +use Thelia\Core\Security\UserProvider\CookieTokenProvider; +use Thelia\Core\Security\Exception\TokenAuthenticationException; class SessionController extends BaseAdminController { public function showLoginAction() { + // Check if we can authenticate the user with a cookie-based token + if (null !== $key = $this->getRememberMeKeyFromCookie()) { + + // Create the authenticator + $authenticator = new AdminTokenAuthenticator($key); + + try { + // If have found a user, store it in the security context + $user = $authenticator->getAuthentifiedUser(); + + $this->getSecurityContext()->setAdminUser($user); + + $this->adminLogAppend("Successful token authentication"); + + // Update the cookie + $cookie = $this->createAdminRememberMeCookie($user); + + // Render the home page + return $this->render("home"); + } + catch (TokenAuthenticationException $ex) { + $this->adminLogAppend("Token based authentication failed."); + + // Clear the cookie + $this->clearRememberMeCookie(); + } + } + return $this->render("login"); } @@ -44,6 +77,9 @@ class SessionController extends BaseAdminController $this->getSecurityContext()->clearAdminUser(); + // Clear the remember me cookie, if any + $this->clearRememberMeCookie(); + // Go back to login page. $this->redirectToRoute('admin.login'); } @@ -68,10 +104,19 @@ class SessionController extends BaseAdminController // Log authentication success AdminLog::append("Authentication successful", $request, $user); + /** + * FIXME: we have tou find a way to send cookie + */ + if (intval($adminLoginForm->getForm()->get('remember_me')->getData()) > 0) { + // If a remember me field if present and set in the form, create + // the cookie thant store "remember me" information + $this->createAdminRememberMeCookie($user); + } + $this->dispatch(TheliaEvents::ADMIN_LOGIN); - // Redirect to the success URL - return Redirect::exec($adminLoginForm->getSuccessUrl()); + // Redirect to the success URL, passing the cookie if one exists. + $this->redirect($adminLoginForm->getSuccessUrl()); } catch (FormValidationException $ex) { diff --git a/core/lib/Thelia/Controller/Admin/TemplateController.php b/core/lib/Thelia/Controller/Admin/TemplateController.php new file mode 100644 index 000000000..aafc56e4b --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/TemplateController.php @@ -0,0 +1,196 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +use Thelia\Core\Event\TemplateDeleteEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\TemplateUpdateEvent; +use Thelia\Core\Event\TemplateCreateEvent; +use Thelia\Model\TemplateQuery; +use Thelia\Form\TemplateModificationForm; +use Thelia\Form\TemplateCreationForm; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Model\TemplateAv; +use Thelia\Model\TemplateAvQuery; +use Thelia\Core\Event\TemplateAvUpdateEvent; +use Thelia\Core\Event\TemplateEvent; + +/** + * Manages templates sent by mail + * + * @author Franck Allimant + */ +class TemplateController extends AbstractCrudController +{ + public function __construct() + { + parent::__construct( + 'template', + null, + null, + + 'admin.configuration.templates.view', + 'admin.configuration.templates.create', + 'admin.configuration.templates.update', + 'admin.configuration.templates.delete', + + TheliaEvents::TEMPLATE_CREATE, + TheliaEvents::TEMPLATE_UPDATE, + TheliaEvents::TEMPLATE_DELETE, + null, // No visibility toggle + null // No position update + ); + } + + protected function getCreationForm() + { + return new TemplateCreationForm($this->getRequest()); + } + + protected function getUpdateForm() + { + return new TemplateModificationForm($this->getRequest()); + } + + protected function getCreationEvent($formData) + { + $createEvent = new TemplateCreateEvent(); + + $createEvent + ->setTemplateName($formData['name']) + ->setLocale($formData["locale"]) + ; + + return $createEvent; + } + + protected function getUpdateEvent($formData) + { + $changeEvent = new TemplateUpdateEvent($formData['id']); + + // Create and dispatch the change event + $changeEvent + ->setLocale($formData["locale"]) + ->setTemplateName($formData['name']) + ; + + // Add feature and attributes list + + return $changeEvent; + } + + protected function getDeleteEvent() + { + return new TemplateDeleteEvent($this->getRequest()->get('template_id')); + } + + protected function eventContainsObject($event) + { + return $event->hasTemplate(); + } + + protected function hydrateObjectForm($object) + { + + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'name' => $object->getName() + ); + + // Setup the object form + return new TemplateModificationForm($this->getRequest(), "form", $data); + } + + protected function getObjectFromEvent($event) + { + return $event->hasTemplate() ? $event->getTemplate() : null; + } + + protected function getExistingObject() + { + return TemplateQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('template_id')); + } + + protected function getObjectLabel($object) + { + return $object->getName(); + } + + protected function getObjectId($object) + { + return $object->getId(); + } + + protected function renderListTemplate($currentOrder) + { + return $this->render('templates', array('order' => $currentOrder)); + } + + protected function renderEditionTemplate() + { + return $this->render( + 'template-edit', + array( + 'template_id' => $this->getRequest()->get('template_id'), + ) + ); + } + + protected function redirectToEditionTemplate() + { + $this->redirectToRoute( + "admin.configuration.templates.update", + array( + 'template_id' => $this->getRequest()->get('template_id'), + ) + ); + } + + protected function redirectToListTemplate() + { + $this->redirectToRoute('admin.configuration.templates.default'); + } + + // Process delete failure, which may occurs if template is in use. + protected function performAdditionalDeleteAction($deleteEvent) + { + if ($deleteEvent->getProductCount() > 0) { + + $this->getParserContext()->setGeneralError( + $this->getTranslator()->trans( + "This template is in use in some of your products, and cannot be deleted. Delete it from all your products and try again." + ) + ); + + return $this->renderList(); + } + + // Normal delete processing + return null; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 56118635b..bd1e68422 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -198,9 +198,9 @@ class BaseController extends ContainerAware * * @param string $url */ - public function redirect($url, $status = 302) + public function redirect($url, $status = 302, $cookies = array()) { - Redirect::exec($url, $status); + Redirect::exec($url, $status, $cookies); } /** diff --git a/core/lib/Thelia/Core/Event/TemplateCreateEvent.php b/core/lib/Thelia/Core/Event/TemplateCreateEvent.php new file mode 100644 index 000000000..b966ce09b --- /dev/null +++ b/core/lib/Thelia/Core/Event/TemplateCreateEvent.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class TemplateCreateEvent extends TemplateEvent +{ + protected $template_name; + protected $locale; + + public function getLocale() + { + return $this->locale; + } + + public function setLocale($locale) + { + $this->locale = $locale; + + return $this; + } + + public function getTemplateName() + { + return $this->template_name; + } + + public function setTemplateName($template_name) + { + $this->template_name = $template_name; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/TemplateDeleteEvent.php b/core/lib/Thelia/Core/Event/TemplateDeleteEvent.php new file mode 100644 index 000000000..de504cc98 --- /dev/null +++ b/core/lib/Thelia/Core/Event/TemplateDeleteEvent.php @@ -0,0 +1,59 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class TemplateDeleteEvent extends TemplateEvent +{ + protected $template_id; + protected $product_count; + + public function __construct($template_id) + { + $this->setTemplateId($template_id); + } + + public function getTemplateId() + { + return $this->template_id; + } + + public function setTemplateId($template_id) + { + $this->template_id = $template_id; + + return $this; + } + + public function getProductCount() + { + return $this->product_count; + } + + public function setProductCount($product_count) + { + $this->product_count = $product_count; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/TemplateEvent.php b/core/lib/Thelia/Core/Event/TemplateEvent.php new file mode 100644 index 000000000..96945189e --- /dev/null +++ b/core/lib/Thelia/Core/Event/TemplateEvent.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; +use Thelia\Model\Template; + +class TemplateEvent extends ActionEvent +{ + protected $template = null; + + public function __construct(Template $template = null) + { + $this->template = $template; + } + + public function hasTemplate() + { + return ! is_null($this->template); + } + + public function getTemplate() + { + return $this->template; + } + + public function setTemplate($template) + { + $this->template = $template; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/TemplateUpdateEvent.php b/core/lib/Thelia/Core/Event/TemplateUpdateEvent.php new file mode 100644 index 000000000..bae8ec7da --- /dev/null +++ b/core/lib/Thelia/Core/Event/TemplateUpdateEvent.php @@ -0,0 +1,71 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +class TemplateUpdateEvent extends TemplateCreateEvent +{ + protected $template_id; + + protected $feature_list; + protected $attribute_list; + + public function __construct($template_id) + { + $this->setTemplateId($template_id); + } + + public function getTemplateId() + { + return $this->template_id; + } + + public function setTemplateId($template_id) + { + $this->template_id = $template_id; + + return $this; + } + + public function getFeatureList() + { + return $this->feature_list; + } + + public function setFeatureList($feature_list) + { + $this->feature_list = $feature_list; + return $this; + } + + public function getAttributeList() + { + return $this->attribute_list; + } + + public function setAttributeList($attribute_list) + { + $this->attribute_list = $attribute_list; + return $this; + } +} diff --git a/core/lib/Thelia/Core/Security/Authentication/AdminTokenAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/AdminTokenAuthenticator.php new file mode 100644 index 000000000..4c6dcec5c --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/AdminTokenAuthenticator.php @@ -0,0 +1,37 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Thelia\Core\Security\UserProvider\AdminTokenUserProvider; + +class AdminTokenAuthenticator extends TokenAuthenticator +{ + public function __construct($key) + { + parent::__construct( + $key, + new AdminTokenUserProvider() + ); + } +} diff --git a/core/lib/Thelia/Core/Security/Authentication/CustomerTokenAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/CustomerTokenAuthenticator.php new file mode 100644 index 000000000..d06400875 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/CustomerTokenAuthenticator.php @@ -0,0 +1,37 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Thelia\Core\Security\UserProvider\CustomerTokenUserProvider; + +class CustomerTokenAuthenticator extends TokenAuthenticator +{ + public function __construct($key) + { + parent::__construct( + $key, + new CustomerTokenUserProvider() + ); + } +} diff --git a/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php new file mode 100644 index 000000000..1c8c11c73 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php @@ -0,0 +1,57 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Thelia\Core\Security\Authentication\AuthenticatorInterface; +use Thelia\Core\Security\UserProvider\UserProviderInterface; +use Thelia\Core\Security\UserProvider\TokenUserProvider; +use Thelia\Core\Security\Exception\TokenAuthenticationException; + +class TokenAuthenticator implements AuthenticatorInterface +{ + protected $key; + + protected $userProvider; + + public function __construct($key, TokenUserProvider $userProvider) + { + $this->key = $key; + + $this->userProvider = $userProvider; + } + + /** + * @see \Thelia\Core\Security\Authentication\AuthenticatorInterface::getAuthentifiedUser() + */ + public function getAuthentifiedUser() + { + $keyData = $this->userProvider->decodeKey($this->key); + + $user = $this->userProvider->getUser($keyData); + + if ($user === null) throw new TokenAuthenticationException("No user matches the provided token"); + + return $user; + } +} diff --git a/core/lib/Thelia/Core/Security/Exception/TokenAuthenticationException.php b/core/lib/Thelia/Core/Security/Exception/TokenAuthenticationException.php new file mode 100644 index 000000000..6af57162d --- /dev/null +++ b/core/lib/Thelia/Core/Security/Exception/TokenAuthenticationException.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Exception; + +class TokenAuthenticationException extends \Exception +{ +} diff --git a/core/lib/Thelia/Core/Security/Token/CookieTokenProvider.php b/core/lib/Thelia/Core/Security/Token/CookieTokenProvider.php new file mode 100644 index 000000000..ee2d9291a --- /dev/null +++ b/core/lib/Thelia/Core/Security/Token/CookieTokenProvider.php @@ -0,0 +1,55 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Token; + +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Security\User\UserInterface; + +class CookieTokenProvider +{ + public function getKeyFromCookie(Request $request, $cookieName) + { + if ($request->cookies->has($cookieName)) { + + // Create the authenticator + return $request->cookies->get($cookieName); + } + + return null; + } + + public function createCookie(UserInterface $user, $cookieName, $cookieExpires) + { + $tokenProvider = new TokenProvider(); + + $key = $tokenProvider->encodeKey($user); + + setcookie($cookieName, $key, time() + $cookieExpires, '/'); + } + + public function clearCookie($cookieName) + { + setcookie($cookieName, '', time() - 3600, '/'); + } +} diff --git a/core/lib/Thelia/Core/Security/Token/TokenProvider.php b/core/lib/Thelia/Core/Security/Token/TokenProvider.php new file mode 100644 index 000000000..e50b60602 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Token/TokenProvider.php @@ -0,0 +1,27 @@ +setToken(uniqid()); + + return base64_encode(serialize( + array($user->getUsername(), $user->getToken(), $user->getSerial()))); + } + + public function decodeKey($key) { + $data = unserialize(base64_decode($key)); + + return array( + 'username' => $data[0], + 'token' => $data[1], + 'serial' => $data[2] + ); + } +} diff --git a/core/lib/Thelia/Core/Security/User/UserInterface.php b/core/lib/Thelia/Core/Security/User/UserInterface.php index 12e07f431..cdff4d44e 100755 --- a/core/lib/Thelia/Core/Security/User/UserInterface.php +++ b/core/lib/Thelia/Core/Security/User/UserInterface.php @@ -48,4 +48,24 @@ interface UserInterface * @return void */ public function eraseCredentials(); -} + + /** + * return the user token (used by remember me authnetication system) + */ + public function getToken(); + + /** + * Set a token in the user data (used by remember me authnetication system) + */ + public function setToken($token); + + /** + * return the user serial (used by remember me authnetication system) + */ + public function getSerial(); + + /** + * Set a serial number int the user data (used by remember me authnetication system) + */ + public function setSerial($serial); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/UserProvider/AdminTokenUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/AdminTokenUserProvider.php new file mode 100644 index 000000000..4567176e5 --- /dev/null +++ b/core/lib/Thelia/Core/Security/UserProvider/AdminTokenUserProvider.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\UserProvider; + +use Thelia\Model\Admin; +use Thelia\Model\AdminQuery; + +class AdminTokenUserProvider extends TokenUserProvider +{ + public function getUser($dataArray) { + + return AdminQuery::create() + ->filterByLogin($dataArray['username']) + ->filterByRememberMeSerial($dataArray['serial']) + ->filterByRememberMeToken($dataArray['token']) + ->findOne(); + } +} diff --git a/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php index a889053c4..a6147fca4 100755 --- a/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php +++ b/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php @@ -1,4 +1,26 @@ . */ +/* */ +/*************************************************************************************/ + namespace Thelia\Core\Security\UserProvider; use Thelia\Model\Admin; diff --git a/core/lib/Thelia/Core/Security/UserProvider/CustomerTokenUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/CustomerTokenUserProvider.php new file mode 100644 index 000000000..421d48dd4 --- /dev/null +++ b/core/lib/Thelia/Core/Security/UserProvider/CustomerTokenUserProvider.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\UserProvider; + +use Thelia\Action\Customer; +use Thelia\Model\CustomerQuery; + +class CustomerTokenUserProvider extends TokenUserProvider +{ + public function getUser($dataArray) { + + return CustomerQuery::create() + ->filterByEmail($dataArray['username']) + ->filterByRememberMeSerial($dataArray['serial']) + ->filterByRememberMeToken($dataArray['token']) + ->findOne(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php index 371af73fc..21db28cab 100755 --- a/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php +++ b/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php @@ -1,4 +1,26 @@ . */ +/* */ +/*************************************************************************************/ + namespace Thelia\Core\Security\UserProvider; use Thelia\Action\Customer; @@ -13,4 +35,4 @@ class CustomerUserProvider implements UserProviderInterface return $customer; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/UserProvider/TokenUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/TokenUserProvider.php new file mode 100644 index 000000000..6c46bcbbb --- /dev/null +++ b/core/lib/Thelia/Core/Security/UserProvider/TokenUserProvider.php @@ -0,0 +1,32 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\UserProvider; + +use Thelia\Core\Security\User\UserInterface; +use Thelia\Core\Security\Token\TokenProvider; + +abstract class TokenUserProvider extends TokenProvider implements UserProviderInterface +{ + public abstract function getUser($key); +} diff --git a/core/lib/Thelia/Core/Security/UserProvider/UserProviderInterface.php b/core/lib/Thelia/Core/Security/UserProvider/UserProviderInterface.php index dd4232ade..6fe5e5197 100755 --- a/core/lib/Thelia/Core/Security/UserProvider/UserProviderInterface.php +++ b/core/lib/Thelia/Core/Security/UserProvider/UserProviderInterface.php @@ -1,4 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Security\UserProvider; diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php index cb3a25e17..db9eb9b8f 100755 --- a/core/lib/Thelia/Core/Template/Loop/Attribute.php +++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php @@ -38,6 +38,9 @@ use Thelia\Model\Map\ProductCategoryTableMap; use Thelia\Type\TypeCollection; use Thelia\Type; use Thelia\Type\BooleanOrBothType; +use Thelia\Model\ProductQuery; +use Thelia\Model\TemplateQuery; +use Thelia\Model\AttributeTemplateQuery; /** * @@ -60,8 +63,7 @@ class Attribute extends BaseI18nLoop return new ArgumentCollection( Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('product'), - Argument::createIntListTypeArgument('category'), - Argument::createBooleanOrBothTypeArgument('visible', 1), + Argument::createIntListTypeArgument('template'), Argument::createIntListTypeArgument('exclude'), new Argument( 'order', @@ -101,26 +103,23 @@ class Attribute extends BaseI18nLoop $search->filterById($exclude, Criteria::NOT_IN); } - $visible = $this->getVisible(); - - if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); - $product = $this->getProduct(); - $category = $this->getCategory(); + $template = $this->getTemplate(); if (null !== $product) { - $productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData(); + // Find the template assigned to the product. + $productObj = ProductQuery::create()->findPk($product); - if (null === $category) { - $category = $productCategories; - } else { - $category = array_merge($category, $productCategories); - } - } + // Ignore if the product cannot be found. + if ($productObj !== null) + $template = $productObj->getTemplate(); + } - if (null !== $category) { - $search->filterByCategory( - CategoryQuery::create()->filterById($category)->find(), + + // If we have to filter by template, find all attributes assigned to this template, and filter by found IDs + if (null !== $template) { + $search->filterById( + AttributeTemplateQuery::create()->filterByTemplateId($template)->select('id')->find(), Criteria::IN ); } diff --git a/core/lib/Thelia/Core/Template/Loop/Template.php b/core/lib/Thelia/Core/Template/Loop/Template.php new file mode 100644 index 000000000..db8bca7ee --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Template.php @@ -0,0 +1,114 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; + +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Core\Template\Element\BaseI18nLoop; +use Thelia\Core\Template\Element\LoopResult; +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\TemplateQuery; +use Thelia\Model\Map\ProductCategoryTableMap; +use Thelia\Type\TypeCollection; +use Thelia\Type; +use Thelia\Type\BooleanOrBothType; + +/** + * + * Template loop + * + * + * Class Template + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class Template extends BaseI18nLoop +{ + public $timestampable = true; + + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createIntListTypeArgument('exclude') + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = TemplateQuery::create(); + + $backendContext = $this->getBackend_context(); + + $lang = $this->getLang(); + + /* manage translations */ + $locale = $this->configureI18nProcessing($search, $columns = array('NAME')); + + $id = $this->getId(); + + if (null !== $id) { + $search->filterById($id, Criteria::IN); + } + + $exclude = $this->getExclude(); + + if (null !== $exclude) { + $search->filterById($exclude, Criteria::NOT_IN); + } + + /* perform search */ + $templates = $this->search($search, $pagination); + + $loopResult = new LoopResult($templates); + + foreach ($templates as $template) { + $loopResultRow = new LoopResultRow($loopResult, $template, $this->versionable, $this->timestampable, $this->countable); + + $loopResultRow + ->set("ID", $template->getId()) + ->set("IS_TRANSLATED" , $template->getVirtualColumn('IS_TRANSLATED')) + ->set("LOCALE" , $locale) + ->set("NAME" , $template->getVirtualColumn('i18n_NAME')) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 2d5324644..4c953be3c 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -145,7 +145,7 @@ class Form extends AbstractSmartyPlugin public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat) { - if ($repeat) { + if ($repeat) { $formFieldView = $this->getFormFieldView($params); @@ -153,25 +153,25 @@ class Form extends AbstractSmartyPlugin $value = $formFieldView->vars["value"]; /* FIXME: doesnt work. We got "This form should not contain extra fields." error. - // We have a collection - if (is_array($value)) { +// We have a collection +if (is_array($value)) { - $key = $this->getParam($params, 'value_key'); +$key = $this->getParam($params, 'value_key'); - if ($key != null) { +if ($key != null) { - if (isset($value[$key])) { +if (isset($value[$key])) { - $name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); - $val = $value[$key]; +$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); +$val = $value[$key]; - $this->assignFieldValues($template, $name, $val, $formFieldView->vars); - } - } - } - else { - $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars); - } +$this->assignFieldValues($template, $name, $val, $formFieldView->vars); +} +} +} +else { +$this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars); +} */ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars); diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index cf1d35195..446983363 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -212,7 +212,7 @@ class TheliaHttpKernel extends HttpKernel if (Model\ConfigQuery::read("session_config.default")) { $storage->setSaveHandler(new Session\Storage\Handler\NativeFileSessionHandler(Model\ConfigQuery::read("session_config.save_path", THELIA_ROOT . '/local/session/'))); } else { - $handlerString = Model\ConfigQuery::read("session_config.handlers"); + $handlerString = Model\ConfigQuery::read("session_config.handlers", 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler'); $handler = new $handlerString; diff --git a/core/lib/Thelia/Form/TemplateCreationForm.php b/core/lib/Thelia/Form/TemplateCreationForm.php new file mode 100644 index 000000000..42e6db5a4 --- /dev/null +++ b/core/lib/Thelia/Form/TemplateCreationForm.php @@ -0,0 +1,57 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Thelia\Model\CurrencyQuery; +use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; + +class TemplateCreationForm extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("name" , "text" , array( + "constraints" => array( + new NotBlank() + ), + "label" => Translator::getInstance()->trans("Template Name *"), + "label_attr" => array( + "for" => "name" + )) + ) + ->add("locale" , "text" , array( + "constraints" => array( + new NotBlank() + )) + ) + ; + } + + public function getName() + { + return "thelia_template_creation"; + } +} diff --git a/core/lib/Thelia/Form/TemplateModificationForm.php b/core/lib/Thelia/Form/TemplateModificationForm.php new file mode 100644 index 000000000..b2b50a3ca --- /dev/null +++ b/core/lib/Thelia/Form/TemplateModificationForm.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Thelia\Model\CurrencyQuery; +use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; +use Symfony\Component\Validator\Constraints\GreaterThan; + +class TemplateModificationForm extends TemplateCreationForm +{ + use StandardDescriptionFieldsTrait; + + protected function buildForm() + { + parent::buildForm(); + + $this->formBuilder + ->add("id", "hidden", array( + "constraints" => array( + new GreaterThan( + array('value' => 0) + ) + ) + )) +/* + ->add('attributes', 'collection', array( + 'type' => 'text', + 'options' => array('required' => false) + )) +*/ +/* FIXME: doesn't work + ->add('features', 'collection', array( + 'type' => 'text', + 'options' => array('required' => false) + )) +*/ + ; + } + + public function getName() + { + return "thelia_template_modification"; + } +} diff --git a/core/lib/Thelia/Model/Admin.php b/core/lib/Thelia/Model/Admin.php index a6deb7e60..67f6a5928 100755 --- a/core/lib/Thelia/Model/Admin.php +++ b/core/lib/Thelia/Model/Admin.php @@ -6,6 +6,7 @@ use Thelia\Core\Security\User\UserInterface; use Thelia\Core\Security\Role\Role; use Thelia\Model\Base\Admin as BaseAdmin; +use Propel\Runtime\Connection\ConnectionInterface; /** * Skeleton subclass for representing a row from the 'admin' table. @@ -20,6 +21,16 @@ use Thelia\Model\Base\Admin as BaseAdmin; */ class Admin extends BaseAdmin implements UserInterface { + /** + * {@inheritDoc} + */ + public function preInsert(ConnectionInterface $con = null) + { + // Set the serial number (for auto-login) + $this->setRememberMeSerial(uniqid()); + + return true; + } public function setPassword($password) { @@ -65,4 +76,32 @@ class Admin extends BaseAdmin implements UserInterface public function getRoles() { return array(new Role('ADMIN')); } + + /** + * {@inheritDoc} + */ + public function getToken() { + return $this->getRememberMeToken(); + } + + /** + * {@inheritDoc} + */ + public function setToken($token) { + $this->setRememberMeToken($token)->save(); + } + + /** + * {@inheritDoc} + */ + public function getSerial() { + return $this->getRememberMeSerial(); + } + + /** + * {@inheritDoc} + */ + public function setSerial($serial) { + $this->setRememberMeSerial($serial)->save(); + } } diff --git a/core/lib/Thelia/Model/AttributeTemplate.php b/core/lib/Thelia/Model/AttributeTemplate.php new file mode 100644 index 000000000..57b4c3745 --- /dev/null +++ b/core/lib/Thelia/Model/AttributeTemplate.php @@ -0,0 +1,10 @@ +salt; } + /** + * Get the [remember_me_token] column value. + * + * @return string + */ + public function getRememberMeToken() + { + + return $this->remember_me_token; + } + + /** + * Get the [remember_me_serial] column value. + * + * @return string + */ + public function getRememberMeSerial() + { + + return $this->remember_me_serial; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -662,6 +696,48 @@ abstract class Admin implements ActiveRecordInterface return $this; } // setSalt() + /** + * Set the value of [remember_me_token] column. + * + * @param string $v new value + * @return \Thelia\Model\Admin The current object (for fluent API support) + */ + public function setRememberMeToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->remember_me_token !== $v) { + $this->remember_me_token = $v; + $this->modifiedColumns[] = AdminTableMap::REMEMBER_ME_TOKEN; + } + + + return $this; + } // setRememberMeToken() + + /** + * Set the value of [remember_me_serial] column. + * + * @param string $v new value + * @return \Thelia\Model\Admin The current object (for fluent API support) + */ + public function setRememberMeSerial($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->remember_me_serial !== $v) { + $this->remember_me_serial = $v; + $this->modifiedColumns[] = AdminTableMap::REMEMBER_ME_SERIAL; + } + + + return $this; + } // setRememberMeSerial() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -762,13 +838,19 @@ abstract class Admin implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AdminTableMap::translateFieldName('Salt', TableMap::TYPE_PHPNAME, $indexType)]; $this->salt = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : AdminTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : AdminTableMap::translateFieldName('RememberMeToken', TableMap::TYPE_PHPNAME, $indexType)]; + $this->remember_me_token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : AdminTableMap::translateFieldName('RememberMeSerial', TableMap::TYPE_PHPNAME, $indexType)]; + $this->remember_me_serial = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : AdminTableMap::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 ? 8 + $startcol : AdminTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : AdminTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -781,7 +863,7 @@ abstract class Admin implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 9; // 9 = AdminTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 11; // 11 = AdminTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Admin object", 0, $e); @@ -1069,6 +1151,12 @@ abstract class Admin implements ActiveRecordInterface if ($this->isColumnModified(AdminTableMap::SALT)) { $modifiedColumns[':p' . $index++] = 'SALT'; } + if ($this->isColumnModified(AdminTableMap::REMEMBER_ME_TOKEN)) { + $modifiedColumns[':p' . $index++] = 'REMEMBER_ME_TOKEN'; + } + if ($this->isColumnModified(AdminTableMap::REMEMBER_ME_SERIAL)) { + $modifiedColumns[':p' . $index++] = 'REMEMBER_ME_SERIAL'; + } if ($this->isColumnModified(AdminTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1107,6 +1195,12 @@ abstract class Admin implements ActiveRecordInterface case 'SALT': $stmt->bindValue($identifier, $this->salt, PDO::PARAM_STR); break; + case 'REMEMBER_ME_TOKEN': + $stmt->bindValue($identifier, $this->remember_me_token, PDO::PARAM_STR); + break; + case 'REMEMBER_ME_SERIAL': + $stmt->bindValue($identifier, $this->remember_me_serial, PDO::PARAM_STR); + 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; @@ -1197,9 +1291,15 @@ abstract class Admin implements ActiveRecordInterface return $this->getSalt(); break; case 7: - return $this->getCreatedAt(); + return $this->getRememberMeToken(); break; case 8: + return $this->getRememberMeSerial(); + break; + case 9: + return $this->getCreatedAt(); + break; + case 10: return $this->getUpdatedAt(); break; default: @@ -1238,8 +1338,10 @@ abstract class Admin implements ActiveRecordInterface $keys[4] => $this->getPassword(), $keys[5] => $this->getAlgo(), $keys[6] => $this->getSalt(), - $keys[7] => $this->getCreatedAt(), - $keys[8] => $this->getUpdatedAt(), + $keys[7] => $this->getRememberMeToken(), + $keys[8] => $this->getRememberMeSerial(), + $keys[9] => $this->getCreatedAt(), + $keys[10] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1307,9 +1409,15 @@ abstract class Admin implements ActiveRecordInterface $this->setSalt($value); break; case 7: - $this->setCreatedAt($value); + $this->setRememberMeToken($value); break; case 8: + $this->setRememberMeSerial($value); + break; + case 9: + $this->setCreatedAt($value); + break; + case 10: $this->setUpdatedAt($value); break; } // switch() @@ -1343,8 +1451,10 @@ abstract class Admin implements ActiveRecordInterface if (array_key_exists($keys[4], $arr)) $this->setPassword($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setAlgo($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setSalt($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]); + if (array_key_exists($keys[7], $arr)) $this->setRememberMeToken($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setRememberMeSerial($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setCreatedAt($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setUpdatedAt($arr[$keys[10]]); } /** @@ -1363,6 +1473,8 @@ abstract class Admin implements ActiveRecordInterface if ($this->isColumnModified(AdminTableMap::PASSWORD)) $criteria->add(AdminTableMap::PASSWORD, $this->password); if ($this->isColumnModified(AdminTableMap::ALGO)) $criteria->add(AdminTableMap::ALGO, $this->algo); if ($this->isColumnModified(AdminTableMap::SALT)) $criteria->add(AdminTableMap::SALT, $this->salt); + if ($this->isColumnModified(AdminTableMap::REMEMBER_ME_TOKEN)) $criteria->add(AdminTableMap::REMEMBER_ME_TOKEN, $this->remember_me_token); + if ($this->isColumnModified(AdminTableMap::REMEMBER_ME_SERIAL)) $criteria->add(AdminTableMap::REMEMBER_ME_SERIAL, $this->remember_me_serial); if ($this->isColumnModified(AdminTableMap::CREATED_AT)) $criteria->add(AdminTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AdminTableMap::UPDATED_AT)) $criteria->add(AdminTableMap::UPDATED_AT, $this->updated_at); @@ -1434,6 +1546,8 @@ abstract class Admin implements ActiveRecordInterface $copyObj->setPassword($this->getPassword()); $copyObj->setAlgo($this->getAlgo()); $copyObj->setSalt($this->getSalt()); + $copyObj->setRememberMeToken($this->getRememberMeToken()); + $copyObj->setRememberMeSerial($this->getRememberMeSerial()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1935,6 +2049,8 @@ abstract class Admin implements ActiveRecordInterface $this->password = null; $this->algo = null; $this->salt = null; + $this->remember_me_token = null; + $this->remember_me_serial = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/AdminQuery.php b/core/lib/Thelia/Model/Base/AdminQuery.php index 1ac79b4fe..071832d9b 100644 --- a/core/lib/Thelia/Model/Base/AdminQuery.php +++ b/core/lib/Thelia/Model/Base/AdminQuery.php @@ -28,6 +28,8 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdminQuery orderByPassword($order = Criteria::ASC) Order by the password column * @method ChildAdminQuery orderByAlgo($order = Criteria::ASC) Order by the algo column * @method ChildAdminQuery orderBySalt($order = Criteria::ASC) Order by the salt column + * @method ChildAdminQuery orderByRememberMeToken($order = Criteria::ASC) Order by the remember_me_token column + * @method ChildAdminQuery orderByRememberMeSerial($order = Criteria::ASC) Order by the remember_me_serial column * @method ChildAdminQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAdminQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -38,6 +40,8 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdminQuery groupByPassword() Group by the password column * @method ChildAdminQuery groupByAlgo() Group by the algo column * @method ChildAdminQuery groupBySalt() Group by the salt column + * @method ChildAdminQuery groupByRememberMeToken() Group by the remember_me_token column + * @method ChildAdminQuery groupByRememberMeSerial() Group by the remember_me_serial column * @method ChildAdminQuery groupByCreatedAt() Group by the created_at column * @method ChildAdminQuery groupByUpdatedAt() Group by the updated_at column * @@ -59,6 +63,8 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdmin findOneByPassword(string $password) Return the first ChildAdmin filtered by the password column * @method ChildAdmin findOneByAlgo(string $algo) Return the first ChildAdmin filtered by the algo column * @method ChildAdmin findOneBySalt(string $salt) Return the first ChildAdmin filtered by the salt column + * @method ChildAdmin findOneByRememberMeToken(string $remember_me_token) Return the first ChildAdmin filtered by the remember_me_token column + * @method ChildAdmin findOneByRememberMeSerial(string $remember_me_serial) Return the first ChildAdmin filtered by the remember_me_serial column * @method ChildAdmin findOneByCreatedAt(string $created_at) Return the first ChildAdmin filtered by the created_at column * @method ChildAdmin findOneByUpdatedAt(string $updated_at) Return the first ChildAdmin filtered by the updated_at column * @@ -69,6 +75,8 @@ use Thelia\Model\Map\AdminTableMap; * @method array findByPassword(string $password) Return ChildAdmin objects filtered by the password column * @method array findByAlgo(string $algo) Return ChildAdmin objects filtered by the algo column * @method array findBySalt(string $salt) Return ChildAdmin objects filtered by the salt column + * @method array findByRememberMeToken(string $remember_me_token) Return ChildAdmin objects filtered by the remember_me_token column + * @method array findByRememberMeSerial(string $remember_me_serial) Return ChildAdmin objects filtered by the remember_me_serial column * @method array findByCreatedAt(string $created_at) Return ChildAdmin objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAdmin objects filtered by the updated_at column * @@ -159,7 +167,7 @@ abstract class AdminQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, FIRSTNAME, LASTNAME, LOGIN, PASSWORD, ALGO, SALT, CREATED_AT, UPDATED_AT FROM admin WHERE ID = :p0'; + $sql = 'SELECT ID, FIRSTNAME, LASTNAME, LOGIN, PASSWORD, ALGO, SALT, REMEMBER_ME_TOKEN, REMEMBER_ME_SERIAL, CREATED_AT, UPDATED_AT FROM admin WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -463,6 +471,64 @@ abstract class AdminQuery extends ModelCriteria return $this->addUsingAlias(AdminTableMap::SALT, $salt, $comparison); } + /** + * Filter the query on the remember_me_token column + * + * Example usage: + * + * $query->filterByRememberMeToken('fooValue'); // WHERE remember_me_token = 'fooValue' + * $query->filterByRememberMeToken('%fooValue%'); // WHERE remember_me_token LIKE '%fooValue%' + * + * + * @param string $rememberMeToken The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAdminQuery The current query, for fluid interface + */ + public function filterByRememberMeToken($rememberMeToken = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($rememberMeToken)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $rememberMeToken)) { + $rememberMeToken = str_replace('*', '%', $rememberMeToken); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AdminTableMap::REMEMBER_ME_TOKEN, $rememberMeToken, $comparison); + } + + /** + * Filter the query on the remember_me_serial column + * + * Example usage: + * + * $query->filterByRememberMeSerial('fooValue'); // WHERE remember_me_serial = 'fooValue' + * $query->filterByRememberMeSerial('%fooValue%'); // WHERE remember_me_serial LIKE '%fooValue%' + * + * + * @param string $rememberMeSerial The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAdminQuery The current query, for fluid interface + */ + public function filterByRememberMeSerial($rememberMeSerial = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($rememberMeSerial)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $rememberMeSerial)) { + $rememberMeSerial = str_replace('*', '%', $rememberMeSerial); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AdminTableMap::REMEMBER_ME_SERIAL, $rememberMeSerial, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/Attribute.php b/core/lib/Thelia/Model/Base/Attribute.php index 3c754c3b5..64e765fdd 100644 --- a/core/lib/Thelia/Model/Base/Attribute.php +++ b/core/lib/Thelia/Model/Base/Attribute.php @@ -20,15 +20,15 @@ use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\Attribute as ChildAttribute; use Thelia\Model\AttributeAv as ChildAttributeAv; use Thelia\Model\AttributeAvQuery as ChildAttributeAvQuery; -use Thelia\Model\AttributeCategory as ChildAttributeCategory; -use Thelia\Model\AttributeCategoryQuery as ChildAttributeCategoryQuery; use Thelia\Model\AttributeCombination as ChildAttributeCombination; use Thelia\Model\AttributeCombinationQuery as ChildAttributeCombinationQuery; use Thelia\Model\AttributeI18n as ChildAttributeI18n; use Thelia\Model\AttributeI18nQuery as ChildAttributeI18nQuery; use Thelia\Model\AttributeQuery as ChildAttributeQuery; -use Thelia\Model\Category as ChildCategory; -use Thelia\Model\CategoryQuery as ChildCategoryQuery; +use Thelia\Model\AttributeTemplate as ChildAttributeTemplate; +use Thelia\Model\AttributeTemplateQuery as ChildAttributeTemplateQuery; +use Thelia\Model\Template as ChildTemplate; +use Thelia\Model\TemplateQuery as ChildTemplateQuery; use Thelia\Model\Map\AttributeTableMap; abstract class Attribute implements ActiveRecordInterface @@ -102,10 +102,10 @@ abstract class Attribute implements ActiveRecordInterface protected $collAttributeCombinationsPartial; /** - * @var ObjectCollection|ChildAttributeCategory[] Collection to store aggregation of ChildAttributeCategory objects. + * @var ObjectCollection|ChildAttributeTemplate[] Collection to store aggregation of ChildAttributeTemplate objects. */ - protected $collAttributeCategories; - protected $collAttributeCategoriesPartial; + protected $collAttributeTemplates; + protected $collAttributeTemplatesPartial; /** * @var ObjectCollection|ChildAttributeI18n[] Collection to store aggregation of ChildAttributeI18n objects. @@ -114,9 +114,9 @@ abstract class Attribute implements ActiveRecordInterface protected $collAttributeI18nsPartial; /** - * @var ChildCategory[] Collection to store aggregation of ChildCategory objects. + * @var ChildTemplate[] Collection to store aggregation of ChildTemplate objects. */ - protected $collCategories; + protected $collTemplates; /** * Flag to prevent endless save loop, if this object is referenced @@ -144,7 +144,7 @@ abstract class Attribute implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $categoriesScheduledForDeletion = null; + protected $templatesScheduledForDeletion = null; /** * An array of objects scheduled for deletion. @@ -162,7 +162,7 @@ abstract class Attribute implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $attributeCategoriesScheduledForDeletion = null; + protected $attributeTemplatesScheduledForDeletion = null; /** * An array of objects scheduled for deletion. @@ -697,11 +697,11 @@ abstract class Attribute implements ActiveRecordInterface $this->collAttributeCombinations = null; - $this->collAttributeCategories = null; + $this->collAttributeTemplates = null; $this->collAttributeI18ns = null; - $this->collCategories = null; + $this->collTemplates = null; } // if (deep) } @@ -835,29 +835,29 @@ abstract class Attribute implements ActiveRecordInterface $this->resetModified(); } - if ($this->categoriesScheduledForDeletion !== null) { - if (!$this->categoriesScheduledForDeletion->isEmpty()) { + if ($this->templatesScheduledForDeletion !== null) { + if (!$this->templatesScheduledForDeletion->isEmpty()) { $pks = array(); $pk = $this->getPrimaryKey(); - foreach ($this->categoriesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($remotePk, $pk); + foreach ($this->templatesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); } - AttributeCategoryQuery::create() + AttributeTemplateQuery::create() ->filterByPrimaryKeys($pks) ->delete($con); - $this->categoriesScheduledForDeletion = null; + $this->templatesScheduledForDeletion = null; } - foreach ($this->getCategories() as $category) { - if ($category->isModified()) { - $category->save($con); + foreach ($this->getTemplates() as $template) { + if ($template->isModified()) { + $template->save($con); } } - } elseif ($this->collCategories) { - foreach ($this->collCategories as $category) { - if ($category->isModified()) { - $category->save($con); + } elseif ($this->collTemplates) { + foreach ($this->collTemplates as $template) { + if ($template->isModified()) { + $template->save($con); } } } @@ -896,17 +896,17 @@ abstract class Attribute implements ActiveRecordInterface } } - if ($this->attributeCategoriesScheduledForDeletion !== null) { - if (!$this->attributeCategoriesScheduledForDeletion->isEmpty()) { - \Thelia\Model\AttributeCategoryQuery::create() - ->filterByPrimaryKeys($this->attributeCategoriesScheduledForDeletion->getPrimaryKeys(false)) + if ($this->attributeTemplatesScheduledForDeletion !== null) { + if (!$this->attributeTemplatesScheduledForDeletion->isEmpty()) { + \Thelia\Model\AttributeTemplateQuery::create() + ->filterByPrimaryKeys($this->attributeTemplatesScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); - $this->attributeCategoriesScheduledForDeletion = null; + $this->attributeTemplatesScheduledForDeletion = null; } } - if ($this->collAttributeCategories !== null) { - foreach ($this->collAttributeCategories as $referrerFK) { + if ($this->collAttributeTemplates !== null) { + foreach ($this->collAttributeTemplates as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } @@ -1112,8 +1112,8 @@ abstract class Attribute implements ActiveRecordInterface if (null !== $this->collAttributeCombinations) { $result['AttributeCombinations'] = $this->collAttributeCombinations->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } - if (null !== $this->collAttributeCategories) { - $result['AttributeCategories'] = $this->collAttributeCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collAttributeTemplates) { + $result['AttributeTemplates'] = $this->collAttributeTemplates->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collAttributeI18ns) { $result['AttributeI18ns'] = $this->collAttributeI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); @@ -1291,9 +1291,9 @@ abstract class Attribute implements ActiveRecordInterface } } - foreach ($this->getAttributeCategories() as $relObj) { + foreach ($this->getAttributeTemplates() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addAttributeCategory($relObj->copy($deepCopy)); + $copyObj->addAttributeTemplate($relObj->copy($deepCopy)); } } @@ -1350,8 +1350,8 @@ abstract class Attribute implements ActiveRecordInterface if ('AttributeCombination' == $relationName) { return $this->initAttributeCombinations(); } - if ('AttributeCategory' == $relationName) { - return $this->initAttributeCategories(); + if ('AttributeTemplate' == $relationName) { + return $this->initAttributeTemplates(); } if ('AttributeI18n' == $relationName) { return $this->initAttributeI18ns(); @@ -1848,31 +1848,31 @@ abstract class Attribute implements ActiveRecordInterface } /** - * Clears out the collAttributeCategories collection + * Clears out the collAttributeTemplates collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addAttributeCategories() + * @see addAttributeTemplates() */ - public function clearAttributeCategories() + public function clearAttributeTemplates() { - $this->collAttributeCategories = null; // important to set this to NULL since that means it is uninitialized + $this->collAttributeTemplates = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collAttributeCategories collection loaded partially. + * Reset is the collAttributeTemplates collection loaded partially. */ - public function resetPartialAttributeCategories($v = true) + public function resetPartialAttributeTemplates($v = true) { - $this->collAttributeCategoriesPartial = $v; + $this->collAttributeTemplatesPartial = $v; } /** - * Initializes the collAttributeCategories collection. + * Initializes the collAttributeTemplates collection. * - * By default this just sets the collAttributeCategories collection to an empty array (like clearcollAttributeCategories()); + * By default this just sets the collAttributeTemplates collection to an empty array (like clearcollAttributeTemplates()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * @@ -1881,17 +1881,17 @@ abstract class Attribute implements ActiveRecordInterface * * @return void */ - public function initAttributeCategories($overrideExisting = true) + public function initAttributeTemplates($overrideExisting = true) { - if (null !== $this->collAttributeCategories && !$overrideExisting) { + if (null !== $this->collAttributeTemplates && !$overrideExisting) { return; } - $this->collAttributeCategories = new ObjectCollection(); - $this->collAttributeCategories->setModel('\Thelia\Model\AttributeCategory'); + $this->collAttributeTemplates = new ObjectCollection(); + $this->collAttributeTemplates->setModel('\Thelia\Model\AttributeTemplate'); } /** - * Gets an array of ChildAttributeCategory objects which contain a foreign key that references this object. + * Gets an array of ChildAttributeTemplate objects which contain a foreign key that references this object. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. @@ -1901,109 +1901,109 @@ abstract class Attribute implements ActiveRecordInterface * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildAttributeCategory[] List of ChildAttributeCategory objects + * @return Collection|ChildAttributeTemplate[] List of ChildAttributeTemplate objects * @throws PropelException */ - public function getAttributeCategories($criteria = null, ConnectionInterface $con = null) + public function getAttributeTemplates($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collAttributeCategoriesPartial && !$this->isNew(); - if (null === $this->collAttributeCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAttributeCategories) { + $partial = $this->collAttributeTemplatesPartial && !$this->isNew(); + if (null === $this->collAttributeTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAttributeTemplates) { // return empty collection - $this->initAttributeCategories(); + $this->initAttributeTemplates(); } else { - $collAttributeCategories = ChildAttributeCategoryQuery::create(null, $criteria) + $collAttributeTemplates = ChildAttributeTemplateQuery::create(null, $criteria) ->filterByAttribute($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collAttributeCategoriesPartial && count($collAttributeCategories)) { - $this->initAttributeCategories(false); + if (false !== $this->collAttributeTemplatesPartial && count($collAttributeTemplates)) { + $this->initAttributeTemplates(false); - foreach ($collAttributeCategories as $obj) { - if (false == $this->collAttributeCategories->contains($obj)) { - $this->collAttributeCategories->append($obj); + foreach ($collAttributeTemplates as $obj) { + if (false == $this->collAttributeTemplates->contains($obj)) { + $this->collAttributeTemplates->append($obj); } } - $this->collAttributeCategoriesPartial = true; + $this->collAttributeTemplatesPartial = true; } - $collAttributeCategories->getInternalIterator()->rewind(); + $collAttributeTemplates->getInternalIterator()->rewind(); - return $collAttributeCategories; + return $collAttributeTemplates; } - if ($partial && $this->collAttributeCategories) { - foreach ($this->collAttributeCategories as $obj) { + if ($partial && $this->collAttributeTemplates) { + foreach ($this->collAttributeTemplates as $obj) { if ($obj->isNew()) { - $collAttributeCategories[] = $obj; + $collAttributeTemplates[] = $obj; } } } - $this->collAttributeCategories = $collAttributeCategories; - $this->collAttributeCategoriesPartial = false; + $this->collAttributeTemplates = $collAttributeTemplates; + $this->collAttributeTemplatesPartial = false; } } - return $this->collAttributeCategories; + return $this->collAttributeTemplates; } /** - * Sets a collection of AttributeCategory objects related by a one-to-many relationship + * Sets a collection of AttributeTemplate objects related by a one-to-many relationship * to the current object. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $attributeCategories A Propel collection. + * @param Collection $attributeTemplates A Propel collection. * @param ConnectionInterface $con Optional connection object * @return ChildAttribute The current object (for fluent API support) */ - public function setAttributeCategories(Collection $attributeCategories, ConnectionInterface $con = null) + public function setAttributeTemplates(Collection $attributeTemplates, ConnectionInterface $con = null) { - $attributeCategoriesToDelete = $this->getAttributeCategories(new Criteria(), $con)->diff($attributeCategories); + $attributeTemplatesToDelete = $this->getAttributeTemplates(new Criteria(), $con)->diff($attributeTemplates); - $this->attributeCategoriesScheduledForDeletion = $attributeCategoriesToDelete; + $this->attributeTemplatesScheduledForDeletion = $attributeTemplatesToDelete; - foreach ($attributeCategoriesToDelete as $attributeCategoryRemoved) { - $attributeCategoryRemoved->setAttribute(null); + foreach ($attributeTemplatesToDelete as $attributeTemplateRemoved) { + $attributeTemplateRemoved->setAttribute(null); } - $this->collAttributeCategories = null; - foreach ($attributeCategories as $attributeCategory) { - $this->addAttributeCategory($attributeCategory); + $this->collAttributeTemplates = null; + foreach ($attributeTemplates as $attributeTemplate) { + $this->addAttributeTemplate($attributeTemplate); } - $this->collAttributeCategories = $attributeCategories; - $this->collAttributeCategoriesPartial = false; + $this->collAttributeTemplates = $attributeTemplates; + $this->collAttributeTemplatesPartial = false; return $this; } /** - * Returns the number of related AttributeCategory objects. + * Returns the number of related AttributeTemplate objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related AttributeCategory objects. + * @return int Count of related AttributeTemplate objects. * @throws PropelException */ - public function countAttributeCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countAttributeTemplates(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collAttributeCategoriesPartial && !$this->isNew(); - if (null === $this->collAttributeCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAttributeCategories) { + $partial = $this->collAttributeTemplatesPartial && !$this->isNew(); + if (null === $this->collAttributeTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAttributeTemplates) { return 0; } if ($partial && !$criteria) { - return count($this->getAttributeCategories()); + return count($this->getAttributeTemplates()); } - $query = ChildAttributeCategoryQuery::create(null, $criteria); + $query = ChildAttributeTemplateQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } @@ -2013,53 +2013,53 @@ abstract class Attribute implements ActiveRecordInterface ->count($con); } - return count($this->collAttributeCategories); + return count($this->collAttributeTemplates); } /** - * Method called to associate a ChildAttributeCategory object to this object - * through the ChildAttributeCategory foreign key attribute. + * Method called to associate a ChildAttributeTemplate object to this object + * through the ChildAttributeTemplate foreign key attribute. * - * @param ChildAttributeCategory $l ChildAttributeCategory + * @param ChildAttributeTemplate $l ChildAttributeTemplate * @return \Thelia\Model\Attribute The current object (for fluent API support) */ - public function addAttributeCategory(ChildAttributeCategory $l) + public function addAttributeTemplate(ChildAttributeTemplate $l) { - if ($this->collAttributeCategories === null) { - $this->initAttributeCategories(); - $this->collAttributeCategoriesPartial = true; + if ($this->collAttributeTemplates === null) { + $this->initAttributeTemplates(); + $this->collAttributeTemplatesPartial = true; } - if (!in_array($l, $this->collAttributeCategories->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddAttributeCategory($l); + if (!in_array($l, $this->collAttributeTemplates->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddAttributeTemplate($l); } return $this; } /** - * @param AttributeCategory $attributeCategory The attributeCategory object to add. + * @param AttributeTemplate $attributeTemplate The attributeTemplate object to add. */ - protected function doAddAttributeCategory($attributeCategory) + protected function doAddAttributeTemplate($attributeTemplate) { - $this->collAttributeCategories[]= $attributeCategory; - $attributeCategory->setAttribute($this); + $this->collAttributeTemplates[]= $attributeTemplate; + $attributeTemplate->setAttribute($this); } /** - * @param AttributeCategory $attributeCategory The attributeCategory object to remove. + * @param AttributeTemplate $attributeTemplate The attributeTemplate object to remove. * @return ChildAttribute The current object (for fluent API support) */ - public function removeAttributeCategory($attributeCategory) + public function removeAttributeTemplate($attributeTemplate) { - if ($this->getAttributeCategories()->contains($attributeCategory)) { - $this->collAttributeCategories->remove($this->collAttributeCategories->search($attributeCategory)); - if (null === $this->attributeCategoriesScheduledForDeletion) { - $this->attributeCategoriesScheduledForDeletion = clone $this->collAttributeCategories; - $this->attributeCategoriesScheduledForDeletion->clear(); + if ($this->getAttributeTemplates()->contains($attributeTemplate)) { + $this->collAttributeTemplates->remove($this->collAttributeTemplates->search($attributeTemplate)); + if (null === $this->attributeTemplatesScheduledForDeletion) { + $this->attributeTemplatesScheduledForDeletion = clone $this->collAttributeTemplates; + $this->attributeTemplatesScheduledForDeletion->clear(); } - $this->attributeCategoriesScheduledForDeletion[]= clone $attributeCategory; - $attributeCategory->setAttribute(null); + $this->attributeTemplatesScheduledForDeletion[]= clone $attributeTemplate; + $attributeTemplate->setAttribute(null); } return $this; @@ -2071,7 +2071,7 @@ abstract class Attribute implements ActiveRecordInterface * an identical criteria, it returns the collection. * Otherwise if this Attribute is new, it will return * an empty collection; or if this Attribute has previously - * been saved, it will retrieve related AttributeCategories from storage. + * been saved, it will retrieve related AttributeTemplates from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you @@ -2080,14 +2080,14 @@ abstract class Attribute implements ActiveRecordInterface * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) - * @return Collection|ChildAttributeCategory[] List of ChildAttributeCategory objects + * @return Collection|ChildAttributeTemplate[] List of ChildAttributeTemplate objects */ - public function getAttributeCategoriesJoinCategory($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + public function getAttributeTemplatesJoinTemplate($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { - $query = ChildAttributeCategoryQuery::create(null, $criteria); - $query->joinWith('Category', $joinBehavior); + $query = ChildAttributeTemplateQuery::create(null, $criteria); + $query->joinWith('Template', $joinBehavior); - return $this->getAttributeCategories($query, $con); + return $this->getAttributeTemplates($query, $con); } /** @@ -2316,38 +2316,38 @@ abstract class Attribute implements ActiveRecordInterface } /** - * Clears out the collCategories collection + * Clears out the collTemplates collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addCategories() + * @see addTemplates() */ - public function clearCategories() + public function clearTemplates() { - $this->collCategories = null; // important to set this to NULL since that means it is uninitialized - $this->collCategoriesPartial = null; + $this->collTemplates = null; // important to set this to NULL since that means it is uninitialized + $this->collTemplatesPartial = null; } /** - * Initializes the collCategories collection. + * Initializes the collTemplates collection. * - * By default this just sets the collCategories collection to an empty collection (like clearCategories()); + * By default this just sets the collTemplates collection to an empty collection (like clearTemplates()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ - public function initCategories() + public function initTemplates() { - $this->collCategories = new ObjectCollection(); - $this->collCategories->setModel('\Thelia\Model\Category'); + $this->collTemplates = new ObjectCollection(); + $this->collTemplates->setModel('\Thelia\Model\Template'); } /** - * Gets a collection of ChildCategory objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. + * Gets a collection of ChildTemplate objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. @@ -2358,73 +2358,73 @@ abstract class Attribute implements ActiveRecordInterface * @param Criteria $criteria Optional query object to filter the query * @param ConnectionInterface $con Optional connection object * - * @return ObjectCollection|ChildCategory[] List of ChildCategory objects + * @return ObjectCollection|ChildTemplate[] List of ChildTemplate objects */ - public function getCategories($criteria = null, ConnectionInterface $con = null) + public function getTemplates($criteria = null, ConnectionInterface $con = null) { - if (null === $this->collCategories || null !== $criteria) { - if ($this->isNew() && null === $this->collCategories) { + if (null === $this->collTemplates || null !== $criteria) { + if ($this->isNew() && null === $this->collTemplates) { // return empty collection - $this->initCategories(); + $this->initTemplates(); } else { - $collCategories = ChildCategoryQuery::create(null, $criteria) + $collTemplates = ChildTemplateQuery::create(null, $criteria) ->filterByAttribute($this) ->find($con); if (null !== $criteria) { - return $collCategories; + return $collTemplates; } - $this->collCategories = $collCategories; + $this->collTemplates = $collTemplates; } } - return $this->collCategories; + return $this->collTemplates; } /** - * Sets a collection of Category objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. + * Sets a collection of Template objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $categories A Propel collection. + * @param Collection $templates A Propel collection. * @param ConnectionInterface $con Optional connection object * @return ChildAttribute The current object (for fluent API support) */ - public function setCategories(Collection $categories, ConnectionInterface $con = null) + public function setTemplates(Collection $templates, ConnectionInterface $con = null) { - $this->clearCategories(); - $currentCategories = $this->getCategories(); + $this->clearTemplates(); + $currentTemplates = $this->getTemplates(); - $this->categoriesScheduledForDeletion = $currentCategories->diff($categories); + $this->templatesScheduledForDeletion = $currentTemplates->diff($templates); - foreach ($categories as $category) { - if (!$currentCategories->contains($category)) { - $this->doAddCategory($category); + foreach ($templates as $template) { + if (!$currentTemplates->contains($template)) { + $this->doAddTemplate($template); } } - $this->collCategories = $categories; + $this->collTemplates = $templates; return $this; } /** - * Gets the number of ChildCategory objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. + * Gets the number of ChildTemplate objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param ConnectionInterface $con Optional connection object * - * @return int the number of related ChildCategory objects + * @return int the number of related ChildTemplate objects */ - public function countCategories($criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countTemplates($criteria = null, $distinct = false, ConnectionInterface $con = null) { - if (null === $this->collCategories || null !== $criteria) { - if ($this->isNew() && null === $this->collCategories) { + if (null === $this->collTemplates || null !== $criteria) { + if ($this->isNew() && null === $this->collTemplates) { return 0; } else { - $query = ChildCategoryQuery::create(null, $criteria); + $query = ChildTemplateQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } @@ -2434,65 +2434,65 @@ abstract class Attribute implements ActiveRecordInterface ->count($con); } } else { - return count($this->collCategories); + return count($this->collTemplates); } } /** - * Associate a ChildCategory object to this object - * through the attribute_category cross reference table. + * Associate a ChildTemplate object to this object + * through the attribute_template cross reference table. * - * @param ChildCategory $category The ChildAttributeCategory object to relate + * @param ChildTemplate $template The ChildAttributeTemplate object to relate * @return ChildAttribute The current object (for fluent API support) */ - public function addCategory(ChildCategory $category) + public function addTemplate(ChildTemplate $template) { - if ($this->collCategories === null) { - $this->initCategories(); + if ($this->collTemplates === null) { + $this->initTemplates(); } - if (!$this->collCategories->contains($category)) { // only add it if the **same** object is not already associated - $this->doAddCategory($category); - $this->collCategories[] = $category; + if (!$this->collTemplates->contains($template)) { // only add it if the **same** object is not already associated + $this->doAddTemplate($template); + $this->collTemplates[] = $template; } return $this; } /** - * @param Category $category The category object to add. + * @param Template $template The template object to add. */ - protected function doAddCategory($category) + protected function doAddTemplate($template) { - $attributeCategory = new ChildAttributeCategory(); - $attributeCategory->setCategory($category); - $this->addAttributeCategory($attributeCategory); + $attributeTemplate = new ChildAttributeTemplate(); + $attributeTemplate->setTemplate($template); + $this->addAttributeTemplate($attributeTemplate); // set the back reference to this object directly as using provided method either results // in endless loop or in multiple relations - if (!$category->getAttributes()->contains($this)) { - $foreignCollection = $category->getAttributes(); + if (!$template->getAttributes()->contains($this)) { + $foreignCollection = $template->getAttributes(); $foreignCollection[] = $this; } } /** - * Remove a ChildCategory object to this object - * through the attribute_category cross reference table. + * Remove a ChildTemplate object to this object + * through the attribute_template cross reference table. * - * @param ChildCategory $category The ChildAttributeCategory object to relate + * @param ChildTemplate $template The ChildAttributeTemplate object to relate * @return ChildAttribute The current object (for fluent API support) */ - public function removeCategory(ChildCategory $category) + public function removeTemplate(ChildTemplate $template) { - if ($this->getCategories()->contains($category)) { - $this->collCategories->remove($this->collCategories->search($category)); + if ($this->getTemplates()->contains($template)) { + $this->collTemplates->remove($this->collTemplates->search($template)); - if (null === $this->categoriesScheduledForDeletion) { - $this->categoriesScheduledForDeletion = clone $this->collCategories; - $this->categoriesScheduledForDeletion->clear(); + if (null === $this->templatesScheduledForDeletion) { + $this->templatesScheduledForDeletion = clone $this->collTemplates; + $this->templatesScheduledForDeletion->clear(); } - $this->categoriesScheduledForDeletion[] = $category; + $this->templatesScheduledForDeletion[] = $template; } return $this; @@ -2536,8 +2536,8 @@ abstract class Attribute implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collAttributeCategories) { - foreach ($this->collAttributeCategories as $o) { + if ($this->collAttributeTemplates) { + foreach ($this->collAttributeTemplates as $o) { $o->clearAllReferences($deep); } } @@ -2546,8 +2546,8 @@ abstract class Attribute implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collCategories) { - foreach ($this->collCategories as $o) { + if ($this->collTemplates) { + foreach ($this->collTemplates as $o) { $o->clearAllReferences($deep); } } @@ -2565,18 +2565,18 @@ abstract class Attribute implements ActiveRecordInterface $this->collAttributeCombinations->clearIterator(); } $this->collAttributeCombinations = null; - if ($this->collAttributeCategories instanceof Collection) { - $this->collAttributeCategories->clearIterator(); + if ($this->collAttributeTemplates instanceof Collection) { + $this->collAttributeTemplates->clearIterator(); } - $this->collAttributeCategories = null; + $this->collAttributeTemplates = null; if ($this->collAttributeI18ns instanceof Collection) { $this->collAttributeI18ns->clearIterator(); } $this->collAttributeI18ns = null; - if ($this->collCategories instanceof Collection) { - $this->collCategories->clearIterator(); + if ($this->collTemplates instanceof Collection) { + $this->collTemplates->clearIterator(); } - $this->collCategories = null; + $this->collTemplates = null; } /** diff --git a/core/lib/Thelia/Model/Base/AttributeQuery.php b/core/lib/Thelia/Model/Base/AttributeQuery.php index cabbaf7ac..b496289f8 100644 --- a/core/lib/Thelia/Model/Base/AttributeQuery.php +++ b/core/lib/Thelia/Model/Base/AttributeQuery.php @@ -44,9 +44,9 @@ use Thelia\Model\Map\AttributeTableMap; * @method ChildAttributeQuery rightJoinAttributeCombination($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AttributeCombination relation * @method ChildAttributeQuery innerJoinAttributeCombination($relationAlias = null) Adds a INNER JOIN clause to the query using the AttributeCombination relation * - * @method ChildAttributeQuery leftJoinAttributeCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the AttributeCategory relation - * @method ChildAttributeQuery rightJoinAttributeCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AttributeCategory relation - * @method ChildAttributeQuery innerJoinAttributeCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the AttributeCategory relation + * @method ChildAttributeQuery leftJoinAttributeTemplate($relationAlias = null) Adds a LEFT JOIN clause to the query using the AttributeTemplate relation + * @method ChildAttributeQuery rightJoinAttributeTemplate($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AttributeTemplate relation + * @method ChildAttributeQuery innerJoinAttributeTemplate($relationAlias = null) Adds a INNER JOIN clause to the query using the AttributeTemplate relation * * @method ChildAttributeQuery leftJoinAttributeI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the AttributeI18n relation * @method ChildAttributeQuery rightJoinAttributeI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AttributeI18n relation @@ -556,40 +556,40 @@ abstract class AttributeQuery extends ModelCriteria } /** - * Filter the query by a related \Thelia\Model\AttributeCategory object + * Filter the query by a related \Thelia\Model\AttributeTemplate object * - * @param \Thelia\Model\AttributeCategory|ObjectCollection $attributeCategory the related object to use as filter + * @param \Thelia\Model\AttributeTemplate|ObjectCollection $attributeTemplate the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildAttributeQuery The current query, for fluid interface */ - public function filterByAttributeCategory($attributeCategory, $comparison = null) + public function filterByAttributeTemplate($attributeTemplate, $comparison = null) { - if ($attributeCategory instanceof \Thelia\Model\AttributeCategory) { + if ($attributeTemplate instanceof \Thelia\Model\AttributeTemplate) { return $this - ->addUsingAlias(AttributeTableMap::ID, $attributeCategory->getAttributeId(), $comparison); - } elseif ($attributeCategory instanceof ObjectCollection) { + ->addUsingAlias(AttributeTableMap::ID, $attributeTemplate->getAttributeId(), $comparison); + } elseif ($attributeTemplate instanceof ObjectCollection) { return $this - ->useAttributeCategoryQuery() - ->filterByPrimaryKeys($attributeCategory->getPrimaryKeys()) + ->useAttributeTemplateQuery() + ->filterByPrimaryKeys($attributeTemplate->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByAttributeCategory() only accepts arguments of type \Thelia\Model\AttributeCategory or Collection'); + throw new PropelException('filterByAttributeTemplate() only accepts arguments of type \Thelia\Model\AttributeTemplate or Collection'); } } /** - * Adds a JOIN clause to the query using the AttributeCategory relation + * Adds a JOIN clause to the query using the AttributeTemplate relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildAttributeQuery The current query, for fluid interface */ - public function joinAttributeCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinAttributeTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('AttributeCategory'); + $relationMap = $tableMap->getRelation('AttributeTemplate'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -604,14 +604,14 @@ abstract class AttributeQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'AttributeCategory'); + $this->addJoinObject($join, 'AttributeTemplate'); } return $this; } /** - * Use the AttributeCategory relation AttributeCategory object + * Use the AttributeTemplate relation AttributeTemplate object * * @see useQuery() * @@ -619,13 +619,13 @@ abstract class AttributeQuery extends ModelCriteria * 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\AttributeCategoryQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\AttributeTemplateQuery A secondary query class using the current class as primary query */ - public function useAttributeCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useAttributeTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this - ->joinAttributeCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'AttributeCategory', '\Thelia\Model\AttributeCategoryQuery'); + ->joinAttributeTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'AttributeTemplate', '\Thelia\Model\AttributeTemplateQuery'); } /** @@ -702,19 +702,19 @@ abstract class AttributeQuery extends ModelCriteria } /** - * Filter the query by a related Category object - * using the attribute_category table as cross reference + * Filter the query by a related Template object + * using the attribute_template table as cross reference * - * @param Category $category the related object to use as filter + * @param Template $template the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildAttributeQuery The current query, for fluid interface */ - public function filterByCategory($category, $comparison = Criteria::EQUAL) + public function filterByTemplate($template, $comparison = Criteria::EQUAL) { return $this - ->useAttributeCategoryQuery() - ->filterByCategory($category, $comparison) + ->useAttributeTemplateQuery() + ->filterByTemplate($template, $comparison) ->endUse(); } diff --git a/core/lib/Thelia/Model/Base/AttributeTemplate.php b/core/lib/Thelia/Model/Base/AttributeTemplate.php new file mode 100644 index 000000000..cedc85431 --- /dev/null +++ b/core/lib/Thelia/Model/Base/AttributeTemplate.php @@ -0,0 +1,1495 @@ +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 AttributeTemplate instance. If + * obj is an instance of AttributeTemplate, delegates to + * equals(AttributeTemplate). 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 AttributeTemplate 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 AttributeTemplate 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 [attribute_id] column value. + * + * @return int + */ + public function getAttributeId() + { + + return $this->attribute_id; + } + + /** + * Get the [template_id] column value. + * + * @return int + */ + public function getTemplateId() + { + + return $this->template_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\AttributeTemplate 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[] = AttributeTemplateTableMap::ID; + } + + + return $this; + } // setId() + + /** + * Set the value of [attribute_id] column. + * + * @param int $v new value + * @return \Thelia\Model\AttributeTemplate 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[] = AttributeTemplateTableMap::ATTRIBUTE_ID; + } + + if ($this->aAttribute !== null && $this->aAttribute->getId() !== $v) { + $this->aAttribute = null; + } + + + return $this; + } // setAttributeId() + + /** + * Set the value of [template_id] column. + * + * @param int $v new value + * @return \Thelia\Model\AttributeTemplate The current object (for fluent API support) + */ + public function setTemplateId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->template_id !== $v) { + $this->template_id = $v; + $this->modifiedColumns[] = AttributeTemplateTableMap::TEMPLATE_ID; + } + + if ($this->aTemplate !== null && $this->aTemplate->getId() !== $v) { + $this->aTemplate = null; + } + + + return $this; + } // setTemplateId() + + /** + * 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\AttributeTemplate 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[] = AttributeTemplateTableMap::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\AttributeTemplate 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[] = AttributeTemplateTableMap::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 : AttributeTemplateTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AttributeTemplateTableMap::translateFieldName('AttributeId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->attribute_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AttributeTemplateTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->template_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeTemplateTableMap::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 : AttributeTemplateTableMap::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 = AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\AttributeTemplate 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->aAttribute !== null && $this->attribute_id !== $this->aAttribute->getId()) { + $this->aAttribute = null; + } + if ($this->aTemplate !== null && $this->template_id !== $this->aTemplate->getId()) { + $this->aTemplate = 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(AttributeTemplateTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildAttributeTemplateQuery::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->aAttribute = null; + $this->aTemplate = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see AttributeTemplate::setDeleted() + * @see AttributeTemplate::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(AttributeTemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildAttributeTemplateQuery::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(AttributeTemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + AttributeTemplateTableMap::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->aAttribute !== null) { + if ($this->aAttribute->isModified() || $this->aAttribute->isNew()) { + $affectedRows += $this->aAttribute->save($con); + } + $this->setAttribute($this->aAttribute); + } + + if ($this->aTemplate !== null) { + if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) { + $affectedRows += $this->aTemplate->save($con); + } + $this->setTemplate($this->aTemplate); + } + + 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[] = AttributeTemplateTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeTemplateTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(AttributeTemplateTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_ID)) { + $modifiedColumns[':p' . $index++] = 'ATTRIBUTE_ID'; + } + if ($this->isColumnModified(AttributeTemplateTableMap::TEMPLATE_ID)) { + $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; + } + if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO attribute_template (%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 'ATTRIBUTE_ID': + $stmt->bindValue($identifier, $this->attribute_id, PDO::PARAM_INT); + break; + case 'TEMPLATE_ID': + $stmt->bindValue($identifier, $this->template_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 = AttributeTemplateTableMap::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->getAttributeId(); + break; + case 2: + return $this->getTemplateId(); + 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['AttributeTemplate'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['AttributeTemplate'][$this->getPrimaryKey()] = true; + $keys = AttributeTemplateTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getAttributeId(), + $keys[2] => $this->getTemplateId(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aAttribute) { + $result['Attribute'] = $this->aAttribute->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aTemplate) { + $result['Template'] = $this->aTemplate->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 = AttributeTemplateTableMap::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->setAttributeId($value); + break; + case 2: + $this->setTemplateId($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 = AttributeTemplateTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setAttributeId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTemplateId($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(AttributeTemplateTableMap::DATABASE_NAME); + + if ($this->isColumnModified(AttributeTemplateTableMap::ID)) $criteria->add(AttributeTemplateTableMap::ID, $this->id); + if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_ID)) $criteria->add(AttributeTemplateTableMap::ATTRIBUTE_ID, $this->attribute_id); + if ($this->isColumnModified(AttributeTemplateTableMap::TEMPLATE_ID)) $criteria->add(AttributeTemplateTableMap::TEMPLATE_ID, $this->template_id); + if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) $criteria->add(AttributeTemplateTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) $criteria->add(AttributeTemplateTableMap::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(AttributeTemplateTableMap::DATABASE_NAME); + $criteria->add(AttributeTemplateTableMap::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\AttributeTemplate (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->setAttributeId($this->getAttributeId()); + $copyObj->setTemplateId($this->getTemplateId()); + $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\AttributeTemplate 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 ChildAttribute object. + * + * @param ChildAttribute $v + * @return \Thelia\Model\AttributeTemplate 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->addAttributeTemplate($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->addAttributeTemplates($this); + */ + } + + return $this->aAttribute; + } + + /** + * Declares an association between this object and a ChildTemplate object. + * + * @param ChildTemplate $v + * @return \Thelia\Model\AttributeTemplate The current object (for fluent API support) + * @throws PropelException + */ + public function setTemplate(ChildTemplate $v = null) + { + if ($v === null) { + $this->setTemplateId(NULL); + } else { + $this->setTemplateId($v->getId()); + } + + $this->aTemplate = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildTemplate object, it will not be re-added. + if ($v !== null) { + $v->addAttributeTemplate($this); + } + + + return $this; + } + + + /** + * Get the associated ChildTemplate object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildTemplate The associated ChildTemplate object. + * @throws PropelException + */ + public function getTemplate(ConnectionInterface $con = null) + { + if ($this->aTemplate === null && ($this->template_id !== null)) { + $this->aTemplate = ChildTemplateQuery::create()->findPk($this->template_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->aTemplate->addAttributeTemplates($this); + */ + } + + return $this->aTemplate; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->attribute_id = null; + $this->template_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->aAttribute = null; + $this->aTemplate = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(AttributeTemplateTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildAttributeTemplate The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[] = AttributeTemplateTableMap::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/AttributeTemplateQuery.php b/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php new file mode 100644 index 000000000..bd895360b --- /dev/null +++ b/core/lib/Thelia/Model/Base/AttributeTemplateQuery.php @@ -0,0 +1,759 @@ +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 ChildAttributeTemplate|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = AttributeTemplateTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(AttributeTemplateTableMap::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 ChildAttributeTemplate A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, ATTRIBUTE_ID, TEMPLATE_ID, CREATED_AT, UPDATED_AT FROM attribute_template 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 ChildAttributeTemplate(); + $obj->hydrate($row); + AttributeTemplateTableMap::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 ChildAttributeTemplate|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 ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(AttributeTemplateTableMap::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 ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(AttributeTemplateTableMap::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 ChildAttributeTemplateQuery 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(AttributeTemplateTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::ID, $id, $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 ChildAttributeTemplateQuery 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(AttributeTemplateTableMap::ATTRIBUTE_ID, $attributeId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($attributeId['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::ATTRIBUTE_ID, $attributeId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::ATTRIBUTE_ID, $attributeId, $comparison); + } + + /** + * Filter the query on the template_id column + * + * Example usage: + * + * $query->filterByTemplateId(1234); // WHERE template_id = 1234 + * $query->filterByTemplateId(array(12, 34)); // WHERE template_id IN (12, 34) + * $query->filterByTemplateId(array('min' => 12)); // WHERE template_id > 12 + * + * + * @see filterByTemplate() + * + * @param mixed $templateId 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 ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByTemplateId($templateId = null, $comparison = null) + { + if (is_array($templateId)) { + $useMinMax = false; + if (isset($templateId['min'])) { + $this->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $templateId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($templateId['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $templateId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $templateId, $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 ChildAttributeTemplateQuery 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(AttributeTemplateTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::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 ChildAttributeTemplateQuery 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(AttributeTemplateTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(AttributeTemplateTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTemplateTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * 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 ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByAttribute($attribute, $comparison = null) + { + if ($attribute instanceof \Thelia\Model\Attribute) { + return $this + ->addUsingAlias(AttributeTemplateTableMap::ATTRIBUTE_ID, $attribute->getId(), $comparison); + } elseif ($attribute instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(AttributeTemplateTableMap::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 ChildAttributeTemplateQuery 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'); + } + + /** + * Filter the query by a related \Thelia\Model\Template object + * + * @param \Thelia\Model\Template|ObjectCollection $template The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function filterByTemplate($template, $comparison = null) + { + if ($template instanceof \Thelia\Model\Template) { + return $this + ->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $template->getId(), $comparison); + } elseif ($template instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(AttributeTemplateTableMap::TEMPLATE_ID, $template->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByTemplate() only accepts arguments of type \Thelia\Model\Template or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Template relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function joinTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Template'); + + // 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, 'Template'); + } + + return $this; + } + + /** + * Use the Template relation Template 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\TemplateQuery A secondary query class using the current class as primary query + */ + public function useTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Template', '\Thelia\Model\TemplateQuery'); + } + + /** + * Exclude object from result + * + * @param ChildAttributeTemplate $attributeTemplate Object to remove from the list of results + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function prune($attributeTemplate = null) + { + if ($attributeTemplate) { + $this->addUsingAlias(AttributeTemplateTableMap::ID, $attributeTemplate->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the attribute_template 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(AttributeTemplateTableMap::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). + AttributeTemplateTableMap::clearInstancePool(); + AttributeTemplateTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildAttributeTemplate or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildAttributeTemplate 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(AttributeTemplateTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(AttributeTemplateTableMap::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(); + + + AttributeTemplateTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + AttributeTemplateTableMap::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 ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(AttributeTemplateTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(AttributeTemplateTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(AttributeTemplateTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(AttributeTemplateTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(AttributeTemplateTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildAttributeTemplateQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(AttributeTemplateTableMap::CREATED_AT); + } + +} // AttributeTemplateQuery diff --git a/core/lib/Thelia/Model/Base/Category.php b/core/lib/Thelia/Model/Base/Category.php index ee56670a1..6dc9b727a 100644 --- a/core/lib/Thelia/Model/Base/Category.php +++ b/core/lib/Thelia/Model/Base/Category.php @@ -17,10 +17,6 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; -use Thelia\Model\Attribute as ChildAttribute; -use Thelia\Model\AttributeCategory as ChildAttributeCategory; -use Thelia\Model\AttributeCategoryQuery as ChildAttributeCategoryQuery; -use Thelia\Model\AttributeQuery as ChildAttributeQuery; use Thelia\Model\Category as ChildCategory; use Thelia\Model\CategoryAssociatedContent as ChildCategoryAssociatedContent; use Thelia\Model\CategoryAssociatedContentQuery as ChildCategoryAssociatedContentQuery; @@ -33,10 +29,6 @@ use Thelia\Model\CategoryImageQuery as ChildCategoryImageQuery; use Thelia\Model\CategoryQuery as ChildCategoryQuery; use Thelia\Model\CategoryVersion as ChildCategoryVersion; use Thelia\Model\CategoryVersionQuery as ChildCategoryVersionQuery; -use Thelia\Model\Feature as ChildFeature; -use Thelia\Model\FeatureCategory as ChildFeatureCategory; -use Thelia\Model\FeatureCategoryQuery as ChildFeatureCategoryQuery; -use Thelia\Model\FeatureQuery as ChildFeatureQuery; use Thelia\Model\Product as ChildProduct; use Thelia\Model\ProductCategory as ChildProductCategory; use Thelia\Model\ProductCategoryQuery as ChildProductCategoryQuery; @@ -139,18 +131,6 @@ abstract class Category implements ActiveRecordInterface protected $collProductCategories; protected $collProductCategoriesPartial; - /** - * @var ObjectCollection|ChildFeatureCategory[] Collection to store aggregation of ChildFeatureCategory objects. - */ - protected $collFeatureCategories; - protected $collFeatureCategoriesPartial; - - /** - * @var ObjectCollection|ChildAttributeCategory[] Collection to store aggregation of ChildAttributeCategory objects. - */ - protected $collAttributeCategories; - protected $collAttributeCategoriesPartial; - /** * @var ObjectCollection|ChildCategoryImage[] Collection to store aggregation of ChildCategoryImage objects. */ @@ -186,16 +166,6 @@ abstract class Category implements ActiveRecordInterface */ protected $collProducts; - /** - * @var ChildFeature[] Collection to store aggregation of ChildFeature objects. - */ - protected $collFeatures; - - /** - * @var ChildAttribute[] Collection to store aggregation of ChildAttribute objects. - */ - protected $collAttributes; - /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -232,36 +202,12 @@ abstract class Category implements ActiveRecordInterface */ protected $productsScheduledForDeletion = null; - /** - * An array of objects scheduled for deletion. - * @var ObjectCollection - */ - protected $featuresScheduledForDeletion = null; - - /** - * An array of objects scheduled for deletion. - * @var ObjectCollection - */ - protected $attributesScheduledForDeletion = null; - /** * An array of objects scheduled for deletion. * @var ObjectCollection */ protected $productCategoriesScheduledForDeletion = null; - /** - * An array of objects scheduled for deletion. - * @var ObjectCollection - */ - protected $featureCategoriesScheduledForDeletion = null; - - /** - * An array of objects scheduled for deletion. - * @var ObjectCollection - */ - protected $attributeCategoriesScheduledForDeletion = null; - /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -1021,10 +967,6 @@ abstract class Category implements ActiveRecordInterface $this->collProductCategories = null; - $this->collFeatureCategories = null; - - $this->collAttributeCategories = null; - $this->collCategoryImages = null; $this->collCategoryDocuments = null; @@ -1036,8 +978,6 @@ abstract class Category implements ActiveRecordInterface $this->collCategoryVersions = null; $this->collProducts = null; - $this->collFeatures = null; - $this->collAttributes = null; } // if (deep) } @@ -1210,60 +1150,6 @@ abstract class Category implements ActiveRecordInterface } } - if ($this->featuresScheduledForDeletion !== null) { - if (!$this->featuresScheduledForDeletion->isEmpty()) { - $pks = array(); - $pk = $this->getPrimaryKey(); - foreach ($this->featuresScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($pk, $remotePk); - } - - FeatureCategoryQuery::create() - ->filterByPrimaryKeys($pks) - ->delete($con); - $this->featuresScheduledForDeletion = null; - } - - foreach ($this->getFeatures() as $feature) { - if ($feature->isModified()) { - $feature->save($con); - } - } - } elseif ($this->collFeatures) { - foreach ($this->collFeatures as $feature) { - if ($feature->isModified()) { - $feature->save($con); - } - } - } - - if ($this->attributesScheduledForDeletion !== null) { - if (!$this->attributesScheduledForDeletion->isEmpty()) { - $pks = array(); - $pk = $this->getPrimaryKey(); - foreach ($this->attributesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($pk, $remotePk); - } - - AttributeCategoryQuery::create() - ->filterByPrimaryKeys($pks) - ->delete($con); - $this->attributesScheduledForDeletion = null; - } - - foreach ($this->getAttributes() as $attribute) { - if ($attribute->isModified()) { - $attribute->save($con); - } - } - } elseif ($this->collAttributes) { - foreach ($this->collAttributes as $attribute) { - if ($attribute->isModified()) { - $attribute->save($con); - } - } - } - if ($this->productCategoriesScheduledForDeletion !== null) { if (!$this->productCategoriesScheduledForDeletion->isEmpty()) { \Thelia\Model\ProductCategoryQuery::create() @@ -1281,40 +1167,6 @@ abstract class Category implements ActiveRecordInterface } } - if ($this->featureCategoriesScheduledForDeletion !== null) { - if (!$this->featureCategoriesScheduledForDeletion->isEmpty()) { - \Thelia\Model\FeatureCategoryQuery::create() - ->filterByPrimaryKeys($this->featureCategoriesScheduledForDeletion->getPrimaryKeys(false)) - ->delete($con); - $this->featureCategoriesScheduledForDeletion = null; - } - } - - if ($this->collFeatureCategories !== null) { - foreach ($this->collFeatureCategories as $referrerFK) { - if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { - $affectedRows += $referrerFK->save($con); - } - } - } - - if ($this->attributeCategoriesScheduledForDeletion !== null) { - if (!$this->attributeCategoriesScheduledForDeletion->isEmpty()) { - \Thelia\Model\AttributeCategoryQuery::create() - ->filterByPrimaryKeys($this->attributeCategoriesScheduledForDeletion->getPrimaryKeys(false)) - ->delete($con); - $this->attributeCategoriesScheduledForDeletion = null; - } - } - - if ($this->collAttributeCategories !== null) { - foreach ($this->collAttributeCategories as $referrerFK) { - if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { - $affectedRows += $referrerFK->save($con); - } - } - } - if ($this->categoryImagesScheduledForDeletion !== null) { if (!$this->categoryImagesScheduledForDeletion->isEmpty()) { \Thelia\Model\CategoryImageQuery::create() @@ -1629,12 +1481,6 @@ abstract class Category implements ActiveRecordInterface if (null !== $this->collProductCategories) { $result['ProductCategories'] = $this->collProductCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } - if (null !== $this->collFeatureCategories) { - $result['FeatureCategories'] = $this->collFeatureCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); - } - if (null !== $this->collAttributeCategories) { - $result['AttributeCategories'] = $this->collAttributeCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); - } if (null !== $this->collCategoryImages) { $result['CategoryImages'] = $this->collCategoryImages->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -1847,18 +1693,6 @@ abstract class Category implements ActiveRecordInterface } } - foreach ($this->getFeatureCategories() as $relObj) { - if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addFeatureCategory($relObj->copy($deepCopy)); - } - } - - foreach ($this->getAttributeCategories() as $relObj) { - if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addAttributeCategory($relObj->copy($deepCopy)); - } - } - foreach ($this->getCategoryImages() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addCategoryImage($relObj->copy($deepCopy)); @@ -1933,12 +1767,6 @@ abstract class Category implements ActiveRecordInterface if ('ProductCategory' == $relationName) { return $this->initProductCategories(); } - if ('FeatureCategory' == $relationName) { - return $this->initFeatureCategories(); - } - if ('AttributeCategory' == $relationName) { - return $this->initAttributeCategories(); - } if ('CategoryImage' == $relationName) { return $this->initCategoryImages(); } @@ -2202,492 +2030,6 @@ abstract class Category implements ActiveRecordInterface return $this->getProductCategories($query, $con); } - /** - * Clears out the collFeatureCategories collection - * - * This does not modify the database; however, it will remove any associated objects, causing - * them to be refetched by subsequent calls to accessor method. - * - * @return void - * @see addFeatureCategories() - */ - public function clearFeatureCategories() - { - $this->collFeatureCategories = null; // important to set this to NULL since that means it is uninitialized - } - - /** - * Reset is the collFeatureCategories collection loaded partially. - */ - public function resetPartialFeatureCategories($v = true) - { - $this->collFeatureCategoriesPartial = $v; - } - - /** - * Initializes the collFeatureCategories collection. - * - * By default this just sets the collFeatureCategories collection to an empty array (like clearcollFeatureCategories()); - * however, you may wish to override this method in your stub class to provide setting appropriate - * to your application -- for example, setting the initial array to the values stored in database. - * - * @param boolean $overrideExisting If set to true, the method call initializes - * the collection even if it is not empty - * - * @return void - */ - public function initFeatureCategories($overrideExisting = true) - { - if (null !== $this->collFeatureCategories && !$overrideExisting) { - return; - } - $this->collFeatureCategories = new ObjectCollection(); - $this->collFeatureCategories->setModel('\Thelia\Model\FeatureCategory'); - } - - /** - * Gets an array of ChildFeatureCategory objects which contain a foreign key that references this object. - * - * If the $criteria is not null, it is used to always fetch the results from the database. - * Otherwise the results are fetched from the database the first time, then cached. - * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildCategory is new, it will return - * an empty collection or the current collection; the criteria is ignored on a new object. - * - * @param Criteria $criteria optional Criteria object to narrow the query - * @param ConnectionInterface $con optional connection object - * @return Collection|ChildFeatureCategory[] List of ChildFeatureCategory objects - * @throws PropelException - */ - public function getFeatureCategories($criteria = null, ConnectionInterface $con = null) - { - $partial = $this->collFeatureCategoriesPartial && !$this->isNew(); - if (null === $this->collFeatureCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collFeatureCategories) { - // return empty collection - $this->initFeatureCategories(); - } else { - $collFeatureCategories = ChildFeatureCategoryQuery::create(null, $criteria) - ->filterByCategory($this) - ->find($con); - - if (null !== $criteria) { - if (false !== $this->collFeatureCategoriesPartial && count($collFeatureCategories)) { - $this->initFeatureCategories(false); - - foreach ($collFeatureCategories as $obj) { - if (false == $this->collFeatureCategories->contains($obj)) { - $this->collFeatureCategories->append($obj); - } - } - - $this->collFeatureCategoriesPartial = true; - } - - $collFeatureCategories->getInternalIterator()->rewind(); - - return $collFeatureCategories; - } - - if ($partial && $this->collFeatureCategories) { - foreach ($this->collFeatureCategories as $obj) { - if ($obj->isNew()) { - $collFeatureCategories[] = $obj; - } - } - } - - $this->collFeatureCategories = $collFeatureCategories; - $this->collFeatureCategoriesPartial = false; - } - } - - return $this->collFeatureCategories; - } - - /** - * Sets a collection of FeatureCategory objects related by a one-to-many relationship - * to the current object. - * It will also schedule objects for deletion based on a diff between old objects (aka persisted) - * and new objects from the given Propel collection. - * - * @param Collection $featureCategories A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildCategory The current object (for fluent API support) - */ - public function setFeatureCategories(Collection $featureCategories, ConnectionInterface $con = null) - { - $featureCategoriesToDelete = $this->getFeatureCategories(new Criteria(), $con)->diff($featureCategories); - - - $this->featureCategoriesScheduledForDeletion = $featureCategoriesToDelete; - - foreach ($featureCategoriesToDelete as $featureCategoryRemoved) { - $featureCategoryRemoved->setCategory(null); - } - - $this->collFeatureCategories = null; - foreach ($featureCategories as $featureCategory) { - $this->addFeatureCategory($featureCategory); - } - - $this->collFeatureCategories = $featureCategories; - $this->collFeatureCategoriesPartial = false; - - return $this; - } - - /** - * Returns the number of related FeatureCategory objects. - * - * @param Criteria $criteria - * @param boolean $distinct - * @param ConnectionInterface $con - * @return int Count of related FeatureCategory objects. - * @throws PropelException - */ - public function countFeatureCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) - { - $partial = $this->collFeatureCategoriesPartial && !$this->isNew(); - if (null === $this->collFeatureCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collFeatureCategories) { - return 0; - } - - if ($partial && !$criteria) { - return count($this->getFeatureCategories()); - } - - $query = ChildFeatureCategoryQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByCategory($this) - ->count($con); - } - - return count($this->collFeatureCategories); - } - - /** - * Method called to associate a ChildFeatureCategory object to this object - * through the ChildFeatureCategory foreign key attribute. - * - * @param ChildFeatureCategory $l ChildFeatureCategory - * @return \Thelia\Model\Category The current object (for fluent API support) - */ - public function addFeatureCategory(ChildFeatureCategory $l) - { - if ($this->collFeatureCategories === null) { - $this->initFeatureCategories(); - $this->collFeatureCategoriesPartial = true; - } - - if (!in_array($l, $this->collFeatureCategories->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddFeatureCategory($l); - } - - return $this; - } - - /** - * @param FeatureCategory $featureCategory The featureCategory object to add. - */ - protected function doAddFeatureCategory($featureCategory) - { - $this->collFeatureCategories[]= $featureCategory; - $featureCategory->setCategory($this); - } - - /** - * @param FeatureCategory $featureCategory The featureCategory object to remove. - * @return ChildCategory The current object (for fluent API support) - */ - public function removeFeatureCategory($featureCategory) - { - if ($this->getFeatureCategories()->contains($featureCategory)) { - $this->collFeatureCategories->remove($this->collFeatureCategories->search($featureCategory)); - if (null === $this->featureCategoriesScheduledForDeletion) { - $this->featureCategoriesScheduledForDeletion = clone $this->collFeatureCategories; - $this->featureCategoriesScheduledForDeletion->clear(); - } - $this->featureCategoriesScheduledForDeletion[]= clone $featureCategory; - $featureCategory->setCategory(null); - } - - return $this; - } - - - /** - * If this collection has already been initialized with - * an identical criteria, it returns the collection. - * Otherwise if this Category is new, it will return - * an empty collection; or if this Category has previously - * been saved, it will retrieve related FeatureCategories from storage. - * - * This method is protected by default in order to keep the public - * api reasonable. You can provide public methods for those you - * actually need in Category. - * - * @param Criteria $criteria optional Criteria object to narrow the query - * @param ConnectionInterface $con optional connection object - * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) - * @return Collection|ChildFeatureCategory[] List of ChildFeatureCategory objects - */ - public function getFeatureCategoriesJoinFeature($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) - { - $query = ChildFeatureCategoryQuery::create(null, $criteria); - $query->joinWith('Feature', $joinBehavior); - - return $this->getFeatureCategories($query, $con); - } - - /** - * Clears out the collAttributeCategories collection - * - * This does not modify the database; however, it will remove any associated objects, causing - * them to be refetched by subsequent calls to accessor method. - * - * @return void - * @see addAttributeCategories() - */ - public function clearAttributeCategories() - { - $this->collAttributeCategories = null; // important to set this to NULL since that means it is uninitialized - } - - /** - * Reset is the collAttributeCategories collection loaded partially. - */ - public function resetPartialAttributeCategories($v = true) - { - $this->collAttributeCategoriesPartial = $v; - } - - /** - * Initializes the collAttributeCategories collection. - * - * By default this just sets the collAttributeCategories collection to an empty array (like clearcollAttributeCategories()); - * however, you may wish to override this method in your stub class to provide setting appropriate - * to your application -- for example, setting the initial array to the values stored in database. - * - * @param boolean $overrideExisting If set to true, the method call initializes - * the collection even if it is not empty - * - * @return void - */ - public function initAttributeCategories($overrideExisting = true) - { - if (null !== $this->collAttributeCategories && !$overrideExisting) { - return; - } - $this->collAttributeCategories = new ObjectCollection(); - $this->collAttributeCategories->setModel('\Thelia\Model\AttributeCategory'); - } - - /** - * Gets an array of ChildAttributeCategory objects which contain a foreign key that references this object. - * - * If the $criteria is not null, it is used to always fetch the results from the database. - * Otherwise the results are fetched from the database the first time, then cached. - * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildCategory is new, it will return - * an empty collection or the current collection; the criteria is ignored on a new object. - * - * @param Criteria $criteria optional Criteria object to narrow the query - * @param ConnectionInterface $con optional connection object - * @return Collection|ChildAttributeCategory[] List of ChildAttributeCategory objects - * @throws PropelException - */ - public function getAttributeCategories($criteria = null, ConnectionInterface $con = null) - { - $partial = $this->collAttributeCategoriesPartial && !$this->isNew(); - if (null === $this->collAttributeCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAttributeCategories) { - // return empty collection - $this->initAttributeCategories(); - } else { - $collAttributeCategories = ChildAttributeCategoryQuery::create(null, $criteria) - ->filterByCategory($this) - ->find($con); - - if (null !== $criteria) { - if (false !== $this->collAttributeCategoriesPartial && count($collAttributeCategories)) { - $this->initAttributeCategories(false); - - foreach ($collAttributeCategories as $obj) { - if (false == $this->collAttributeCategories->contains($obj)) { - $this->collAttributeCategories->append($obj); - } - } - - $this->collAttributeCategoriesPartial = true; - } - - $collAttributeCategories->getInternalIterator()->rewind(); - - return $collAttributeCategories; - } - - if ($partial && $this->collAttributeCategories) { - foreach ($this->collAttributeCategories as $obj) { - if ($obj->isNew()) { - $collAttributeCategories[] = $obj; - } - } - } - - $this->collAttributeCategories = $collAttributeCategories; - $this->collAttributeCategoriesPartial = false; - } - } - - return $this->collAttributeCategories; - } - - /** - * Sets a collection of AttributeCategory objects related by a one-to-many relationship - * to the current object. - * It will also schedule objects for deletion based on a diff between old objects (aka persisted) - * and new objects from the given Propel collection. - * - * @param Collection $attributeCategories A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildCategory The current object (for fluent API support) - */ - public function setAttributeCategories(Collection $attributeCategories, ConnectionInterface $con = null) - { - $attributeCategoriesToDelete = $this->getAttributeCategories(new Criteria(), $con)->diff($attributeCategories); - - - $this->attributeCategoriesScheduledForDeletion = $attributeCategoriesToDelete; - - foreach ($attributeCategoriesToDelete as $attributeCategoryRemoved) { - $attributeCategoryRemoved->setCategory(null); - } - - $this->collAttributeCategories = null; - foreach ($attributeCategories as $attributeCategory) { - $this->addAttributeCategory($attributeCategory); - } - - $this->collAttributeCategories = $attributeCategories; - $this->collAttributeCategoriesPartial = false; - - return $this; - } - - /** - * Returns the number of related AttributeCategory objects. - * - * @param Criteria $criteria - * @param boolean $distinct - * @param ConnectionInterface $con - * @return int Count of related AttributeCategory objects. - * @throws PropelException - */ - public function countAttributeCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) - { - $partial = $this->collAttributeCategoriesPartial && !$this->isNew(); - if (null === $this->collAttributeCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAttributeCategories) { - return 0; - } - - if ($partial && !$criteria) { - return count($this->getAttributeCategories()); - } - - $query = ChildAttributeCategoryQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByCategory($this) - ->count($con); - } - - return count($this->collAttributeCategories); - } - - /** - * Method called to associate a ChildAttributeCategory object to this object - * through the ChildAttributeCategory foreign key attribute. - * - * @param ChildAttributeCategory $l ChildAttributeCategory - * @return \Thelia\Model\Category The current object (for fluent API support) - */ - public function addAttributeCategory(ChildAttributeCategory $l) - { - if ($this->collAttributeCategories === null) { - $this->initAttributeCategories(); - $this->collAttributeCategoriesPartial = true; - } - - if (!in_array($l, $this->collAttributeCategories->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddAttributeCategory($l); - } - - return $this; - } - - /** - * @param AttributeCategory $attributeCategory The attributeCategory object to add. - */ - protected function doAddAttributeCategory($attributeCategory) - { - $this->collAttributeCategories[]= $attributeCategory; - $attributeCategory->setCategory($this); - } - - /** - * @param AttributeCategory $attributeCategory The attributeCategory object to remove. - * @return ChildCategory The current object (for fluent API support) - */ - public function removeAttributeCategory($attributeCategory) - { - if ($this->getAttributeCategories()->contains($attributeCategory)) { - $this->collAttributeCategories->remove($this->collAttributeCategories->search($attributeCategory)); - if (null === $this->attributeCategoriesScheduledForDeletion) { - $this->attributeCategoriesScheduledForDeletion = clone $this->collAttributeCategories; - $this->attributeCategoriesScheduledForDeletion->clear(); - } - $this->attributeCategoriesScheduledForDeletion[]= clone $attributeCategory; - $attributeCategory->setCategory(null); - } - - return $this; - } - - - /** - * If this collection has already been initialized with - * an identical criteria, it returns the collection. - * Otherwise if this Category is new, it will return - * an empty collection; or if this Category has previously - * been saved, it will retrieve related AttributeCategories from storage. - * - * This method is protected by default in order to keep the public - * api reasonable. You can provide public methods for those you - * actually need in Category. - * - * @param Criteria $criteria optional Criteria object to narrow the query - * @param ConnectionInterface $con optional connection object - * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) - * @return Collection|ChildAttributeCategory[] List of ChildAttributeCategory objects - */ - public function getAttributeCategoriesJoinAttribute($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) - { - $query = ChildAttributeCategoryQuery::create(null, $criteria); - $query->joinWith('Attribute', $joinBehavior); - - return $this->getAttributeCategories($query, $con); - } - /** * Clears out the collCategoryImages collection * @@ -3996,372 +3338,6 @@ abstract class Category implements ActiveRecordInterface return $this; } - /** - * Clears out the collFeatures collection - * - * This does not modify the database; however, it will remove any associated objects, causing - * them to be refetched by subsequent calls to accessor method. - * - * @return void - * @see addFeatures() - */ - public function clearFeatures() - { - $this->collFeatures = null; // important to set this to NULL since that means it is uninitialized - $this->collFeaturesPartial = null; - } - - /** - * Initializes the collFeatures collection. - * - * By default this just sets the collFeatures collection to an empty collection (like clearFeatures()); - * however, you may wish to override this method in your stub class to provide setting appropriate - * to your application -- for example, setting the initial array to the values stored in database. - * - * @return void - */ - public function initFeatures() - { - $this->collFeatures = new ObjectCollection(); - $this->collFeatures->setModel('\Thelia\Model\Feature'); - } - - /** - * Gets a collection of ChildFeature objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. - * - * If the $criteria is not null, it is used to always fetch the results from the database. - * Otherwise the results are fetched from the database the first time, then cached. - * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildCategory is new, it will return - * an empty collection or the current collection; the criteria is ignored on a new object. - * - * @param Criteria $criteria Optional query object to filter the query - * @param ConnectionInterface $con Optional connection object - * - * @return ObjectCollection|ChildFeature[] List of ChildFeature objects - */ - public function getFeatures($criteria = null, ConnectionInterface $con = null) - { - if (null === $this->collFeatures || null !== $criteria) { - if ($this->isNew() && null === $this->collFeatures) { - // return empty collection - $this->initFeatures(); - } else { - $collFeatures = ChildFeatureQuery::create(null, $criteria) - ->filterByCategory($this) - ->find($con); - if (null !== $criteria) { - return $collFeatures; - } - $this->collFeatures = $collFeatures; - } - } - - return $this->collFeatures; - } - - /** - * Sets a collection of Feature objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. - * It will also schedule objects for deletion based on a diff between old objects (aka persisted) - * and new objects from the given Propel collection. - * - * @param Collection $features A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildCategory The current object (for fluent API support) - */ - public function setFeatures(Collection $features, ConnectionInterface $con = null) - { - $this->clearFeatures(); - $currentFeatures = $this->getFeatures(); - - $this->featuresScheduledForDeletion = $currentFeatures->diff($features); - - foreach ($features as $feature) { - if (!$currentFeatures->contains($feature)) { - $this->doAddFeature($feature); - } - } - - $this->collFeatures = $features; - - return $this; - } - - /** - * Gets the number of ChildFeature objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. - * - * @param Criteria $criteria Optional query object to filter the query - * @param boolean $distinct Set to true to force count distinct - * @param ConnectionInterface $con Optional connection object - * - * @return int the number of related ChildFeature objects - */ - public function countFeatures($criteria = null, $distinct = false, ConnectionInterface $con = null) - { - if (null === $this->collFeatures || null !== $criteria) { - if ($this->isNew() && null === $this->collFeatures) { - return 0; - } else { - $query = ChildFeatureQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByCategory($this) - ->count($con); - } - } else { - return count($this->collFeatures); - } - } - - /** - * Associate a ChildFeature object to this object - * through the feature_category cross reference table. - * - * @param ChildFeature $feature The ChildFeatureCategory object to relate - * @return ChildCategory The current object (for fluent API support) - */ - public function addFeature(ChildFeature $feature) - { - if ($this->collFeatures === null) { - $this->initFeatures(); - } - - if (!$this->collFeatures->contains($feature)) { // only add it if the **same** object is not already associated - $this->doAddFeature($feature); - $this->collFeatures[] = $feature; - } - - return $this; - } - - /** - * @param Feature $feature The feature object to add. - */ - protected function doAddFeature($feature) - { - $featureCategory = new ChildFeatureCategory(); - $featureCategory->setFeature($feature); - $this->addFeatureCategory($featureCategory); - // set the back reference to this object directly as using provided method either results - // in endless loop or in multiple relations - if (!$feature->getCategories()->contains($this)) { - $foreignCollection = $feature->getCategories(); - $foreignCollection[] = $this; - } - } - - /** - * Remove a ChildFeature object to this object - * through the feature_category cross reference table. - * - * @param ChildFeature $feature The ChildFeatureCategory object to relate - * @return ChildCategory The current object (for fluent API support) - */ - public function removeFeature(ChildFeature $feature) - { - if ($this->getFeatures()->contains($feature)) { - $this->collFeatures->remove($this->collFeatures->search($feature)); - - if (null === $this->featuresScheduledForDeletion) { - $this->featuresScheduledForDeletion = clone $this->collFeatures; - $this->featuresScheduledForDeletion->clear(); - } - - $this->featuresScheduledForDeletion[] = $feature; - } - - return $this; - } - - /** - * Clears out the collAttributes collection - * - * This does not modify the database; however, it will remove any associated objects, causing - * them to be refetched by subsequent calls to accessor method. - * - * @return void - * @see addAttributes() - */ - public function clearAttributes() - { - $this->collAttributes = null; // important to set this to NULL since that means it is uninitialized - $this->collAttributesPartial = null; - } - - /** - * Initializes the collAttributes collection. - * - * By default this just sets the collAttributes collection to an empty collection (like clearAttributes()); - * however, you may wish to override this method in your stub class to provide setting appropriate - * to your application -- for example, setting the initial array to the values stored in database. - * - * @return void - */ - public function initAttributes() - { - $this->collAttributes = new ObjectCollection(); - $this->collAttributes->setModel('\Thelia\Model\Attribute'); - } - - /** - * Gets a collection of ChildAttribute objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. - * - * If the $criteria is not null, it is used to always fetch the results from the database. - * Otherwise the results are fetched from the database the first time, then cached. - * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildCategory is new, it will return - * an empty collection or the current collection; the criteria is ignored on a new object. - * - * @param Criteria $criteria Optional query object to filter the query - * @param ConnectionInterface $con Optional connection object - * - * @return ObjectCollection|ChildAttribute[] List of ChildAttribute objects - */ - public function getAttributes($criteria = null, ConnectionInterface $con = null) - { - if (null === $this->collAttributes || null !== $criteria) { - if ($this->isNew() && null === $this->collAttributes) { - // return empty collection - $this->initAttributes(); - } else { - $collAttributes = ChildAttributeQuery::create(null, $criteria) - ->filterByCategory($this) - ->find($con); - if (null !== $criteria) { - return $collAttributes; - } - $this->collAttributes = $collAttributes; - } - } - - return $this->collAttributes; - } - - /** - * Sets a collection of Attribute objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. - * It will also schedule objects for deletion based on a diff between old objects (aka persisted) - * and new objects from the given Propel collection. - * - * @param Collection $attributes A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildCategory The current object (for fluent API support) - */ - public function setAttributes(Collection $attributes, ConnectionInterface $con = null) - { - $this->clearAttributes(); - $currentAttributes = $this->getAttributes(); - - $this->attributesScheduledForDeletion = $currentAttributes->diff($attributes); - - foreach ($attributes as $attribute) { - if (!$currentAttributes->contains($attribute)) { - $this->doAddAttribute($attribute); - } - } - - $this->collAttributes = $attributes; - - return $this; - } - - /** - * Gets the number of ChildAttribute objects related by a many-to-many relationship - * to the current object by way of the attribute_category cross-reference table. - * - * @param Criteria $criteria Optional query object to filter the query - * @param boolean $distinct Set to true to force count distinct - * @param ConnectionInterface $con Optional connection object - * - * @return int the number of related ChildAttribute objects - */ - public function countAttributes($criteria = null, $distinct = false, ConnectionInterface $con = null) - { - if (null === $this->collAttributes || null !== $criteria) { - if ($this->isNew() && null === $this->collAttributes) { - return 0; - } else { - $query = ChildAttributeQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByCategory($this) - ->count($con); - } - } else { - return count($this->collAttributes); - } - } - - /** - * Associate a ChildAttribute object to this object - * through the attribute_category cross reference table. - * - * @param ChildAttribute $attribute The ChildAttributeCategory object to relate - * @return ChildCategory The current object (for fluent API support) - */ - public function addAttribute(ChildAttribute $attribute) - { - if ($this->collAttributes === null) { - $this->initAttributes(); - } - - if (!$this->collAttributes->contains($attribute)) { // only add it if the **same** object is not already associated - $this->doAddAttribute($attribute); - $this->collAttributes[] = $attribute; - } - - return $this; - } - - /** - * @param Attribute $attribute The attribute object to add. - */ - protected function doAddAttribute($attribute) - { - $attributeCategory = new ChildAttributeCategory(); - $attributeCategory->setAttribute($attribute); - $this->addAttributeCategory($attributeCategory); - // set the back reference to this object directly as using provided method either results - // in endless loop or in multiple relations - if (!$attribute->getCategories()->contains($this)) { - $foreignCollection = $attribute->getCategories(); - $foreignCollection[] = $this; - } - } - - /** - * Remove a ChildAttribute object to this object - * through the attribute_category cross reference table. - * - * @param ChildAttribute $attribute The ChildAttributeCategory object to relate - * @return ChildCategory The current object (for fluent API support) - */ - public function removeAttribute(ChildAttribute $attribute) - { - if ($this->getAttributes()->contains($attribute)) { - $this->collAttributes->remove($this->collAttributes->search($attribute)); - - if (null === $this->attributesScheduledForDeletion) { - $this->attributesScheduledForDeletion = clone $this->collAttributes; - $this->attributesScheduledForDeletion->clear(); - } - - $this->attributesScheduledForDeletion[] = $attribute; - } - - return $this; - } - /** * Clears the current object and sets all attributes to their default values */ @@ -4401,16 +3377,6 @@ abstract class Category implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collFeatureCategories) { - foreach ($this->collFeatureCategories as $o) { - $o->clearAllReferences($deep); - } - } - if ($this->collAttributeCategories) { - foreach ($this->collAttributeCategories as $o) { - $o->clearAllReferences($deep); - } - } if ($this->collCategoryImages) { foreach ($this->collCategoryImages as $o) { $o->clearAllReferences($deep); @@ -4441,16 +3407,6 @@ abstract class Category implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collFeatures) { - foreach ($this->collFeatures as $o) { - $o->clearAllReferences($deep); - } - } - if ($this->collAttributes) { - foreach ($this->collAttributes as $o) { - $o->clearAllReferences($deep); - } - } } // if ($deep) // i18n behavior @@ -4461,14 +3417,6 @@ abstract class Category implements ActiveRecordInterface $this->collProductCategories->clearIterator(); } $this->collProductCategories = null; - if ($this->collFeatureCategories instanceof Collection) { - $this->collFeatureCategories->clearIterator(); - } - $this->collFeatureCategories = null; - if ($this->collAttributeCategories instanceof Collection) { - $this->collAttributeCategories->clearIterator(); - } - $this->collAttributeCategories = null; if ($this->collCategoryImages instanceof Collection) { $this->collCategoryImages->clearIterator(); } @@ -4493,14 +3441,6 @@ abstract class Category implements ActiveRecordInterface $this->collProducts->clearIterator(); } $this->collProducts = null; - if ($this->collFeatures instanceof Collection) { - $this->collFeatures->clearIterator(); - } - $this->collFeatures = null; - if ($this->collAttributes instanceof Collection) { - $this->collAttributes->clearIterator(); - } - $this->collAttributes = null; } /** diff --git a/core/lib/Thelia/Model/Base/CategoryQuery.php b/core/lib/Thelia/Model/Base/CategoryQuery.php index 7f0fb8f1c..4ef552094 100644 --- a/core/lib/Thelia/Model/Base/CategoryQuery.php +++ b/core/lib/Thelia/Model/Base/CategoryQuery.php @@ -50,14 +50,6 @@ use Thelia\Model\Map\CategoryTableMap; * @method ChildCategoryQuery rightJoinProductCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProductCategory relation * @method ChildCategoryQuery innerJoinProductCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ProductCategory relation * - * @method ChildCategoryQuery leftJoinFeatureCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the FeatureCategory relation - * @method ChildCategoryQuery rightJoinFeatureCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the FeatureCategory relation - * @method ChildCategoryQuery innerJoinFeatureCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the FeatureCategory relation - * - * @method ChildCategoryQuery leftJoinAttributeCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the AttributeCategory relation - * @method ChildCategoryQuery rightJoinAttributeCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AttributeCategory relation - * @method ChildCategoryQuery innerJoinAttributeCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the AttributeCategory relation - * * @method ChildCategoryQuery leftJoinCategoryImage($relationAlias = null) Adds a LEFT JOIN clause to the query using the CategoryImage relation * @method ChildCategoryQuery rightJoinCategoryImage($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CategoryImage relation * @method ChildCategoryQuery innerJoinCategoryImage($relationAlias = null) Adds a INNER JOIN clause to the query using the CategoryImage relation @@ -720,152 +712,6 @@ abstract class CategoryQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ProductCategory', '\Thelia\Model\ProductCategoryQuery'); } - /** - * Filter the query by a related \Thelia\Model\FeatureCategory object - * - * @param \Thelia\Model\FeatureCategory|ObjectCollection $featureCategory the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function filterByFeatureCategory($featureCategory, $comparison = null) - { - if ($featureCategory instanceof \Thelia\Model\FeatureCategory) { - return $this - ->addUsingAlias(CategoryTableMap::ID, $featureCategory->getCategoryId(), $comparison); - } elseif ($featureCategory instanceof ObjectCollection) { - return $this - ->useFeatureCategoryQuery() - ->filterByPrimaryKeys($featureCategory->getPrimaryKeys()) - ->endUse(); - } else { - throw new PropelException('filterByFeatureCategory() only accepts arguments of type \Thelia\Model\FeatureCategory or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the FeatureCategory relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function joinFeatureCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('FeatureCategory'); - - // 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, 'FeatureCategory'); - } - - return $this; - } - - /** - * Use the FeatureCategory relation FeatureCategory 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\FeatureCategoryQuery A secondary query class using the current class as primary query - */ - public function useFeatureCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinFeatureCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'FeatureCategory', '\Thelia\Model\FeatureCategoryQuery'); - } - - /** - * Filter the query by a related \Thelia\Model\AttributeCategory object - * - * @param \Thelia\Model\AttributeCategory|ObjectCollection $attributeCategory the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function filterByAttributeCategory($attributeCategory, $comparison = null) - { - if ($attributeCategory instanceof \Thelia\Model\AttributeCategory) { - return $this - ->addUsingAlias(CategoryTableMap::ID, $attributeCategory->getCategoryId(), $comparison); - } elseif ($attributeCategory instanceof ObjectCollection) { - return $this - ->useAttributeCategoryQuery() - ->filterByPrimaryKeys($attributeCategory->getPrimaryKeys()) - ->endUse(); - } else { - throw new PropelException('filterByAttributeCategory() only accepts arguments of type \Thelia\Model\AttributeCategory or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the AttributeCategory relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function joinAttributeCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('AttributeCategory'); - - // 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, 'AttributeCategory'); - } - - return $this; - } - - /** - * Use the AttributeCategory relation AttributeCategory 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\AttributeCategoryQuery A secondary query class using the current class as primary query - */ - public function useAttributeCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinAttributeCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'AttributeCategory', '\Thelia\Model\AttributeCategoryQuery'); - } - /** * Filter the query by a related \Thelia\Model\CategoryImage object * @@ -1248,40 +1094,6 @@ abstract class CategoryQuery extends ModelCriteria ->endUse(); } - /** - * Filter the query by a related Feature object - * using the feature_category table as cross reference - * - * @param Feature $feature the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function filterByFeature($feature, $comparison = Criteria::EQUAL) - { - return $this - ->useFeatureCategoryQuery() - ->filterByFeature($feature, $comparison) - ->endUse(); - } - - /** - * Filter the query by a related Attribute object - * using the attribute_category table as cross reference - * - * @param Attribute $attribute the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCategoryQuery The current query, for fluid interface - */ - public function filterByAttribute($attribute, $comparison = Criteria::EQUAL) - { - return $this - ->useAttributeCategoryQuery() - ->filterByAttribute($attribute, $comparison) - ->endUse(); - } - /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Customer.php b/core/lib/Thelia/Model/Base/Customer.php index 3d87f3e28..06553ecfe 100644 --- a/core/lib/Thelia/Model/Base/Customer.php +++ b/core/lib/Thelia/Model/Base/Customer.php @@ -135,6 +135,18 @@ abstract class Customer implements ActiveRecordInterface */ protected $discount; + /** + * The value for the remember_me_token field. + * @var string + */ + protected $remember_me_token; + + /** + * The value for the remember_me_serial field. + * @var string + */ + protected $remember_me_serial; + /** * The value for the created_at field. * @var string @@ -582,6 +594,28 @@ abstract class Customer implements ActiveRecordInterface return $this->discount; } + /** + * Get the [remember_me_token] column value. + * + * @return string + */ + public function getRememberMeToken() + { + + return $this->remember_me_token; + } + + /** + * Get the [remember_me_serial] column value. + * + * @return string + */ + public function getRememberMeSerial() + { + + return $this->remember_me_serial; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -878,6 +912,48 @@ abstract class Customer implements ActiveRecordInterface return $this; } // setDiscount() + /** + * Set the value of [remember_me_token] column. + * + * @param string $v new value + * @return \Thelia\Model\Customer The current object (for fluent API support) + */ + public function setRememberMeToken($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->remember_me_token !== $v) { + $this->remember_me_token = $v; + $this->modifiedColumns[] = CustomerTableMap::REMEMBER_ME_TOKEN; + } + + + return $this; + } // setRememberMeToken() + + /** + * Set the value of [remember_me_serial] column. + * + * @param string $v new value + * @return \Thelia\Model\Customer The current object (for fluent API support) + */ + public function setRememberMeSerial($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->remember_me_serial !== $v) { + $this->remember_me_serial = $v; + $this->modifiedColumns[] = CustomerTableMap::REMEMBER_ME_SERIAL; + } + + + return $this; + } // setRememberMeSerial() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -993,13 +1069,19 @@ abstract class Customer implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CustomerTableMap::translateFieldName('Discount', TableMap::TYPE_PHPNAME, $indexType)]; $this->discount = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CustomerTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CustomerTableMap::translateFieldName('RememberMeToken', TableMap::TYPE_PHPNAME, $indexType)]; + $this->remember_me_token = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CustomerTableMap::translateFieldName('RememberMeSerial', TableMap::TYPE_PHPNAME, $indexType)]; + $this->remember_me_serial = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CustomerTableMap::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 ? 13 + $startcol : CustomerTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : CustomerTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -1012,7 +1094,7 @@ abstract class Customer implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 14; // 14 = CustomerTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 16; // 16 = CustomerTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Customer object", 0, $e); @@ -1342,6 +1424,12 @@ abstract class Customer implements ActiveRecordInterface if ($this->isColumnModified(CustomerTableMap::DISCOUNT)) { $modifiedColumns[':p' . $index++] = 'DISCOUNT'; } + if ($this->isColumnModified(CustomerTableMap::REMEMBER_ME_TOKEN)) { + $modifiedColumns[':p' . $index++] = 'REMEMBER_ME_TOKEN'; + } + if ($this->isColumnModified(CustomerTableMap::REMEMBER_ME_SERIAL)) { + $modifiedColumns[':p' . $index++] = 'REMEMBER_ME_SERIAL'; + } if ($this->isColumnModified(CustomerTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1395,6 +1483,12 @@ abstract class Customer implements ActiveRecordInterface case 'DISCOUNT': $stmt->bindValue($identifier, $this->discount, PDO::PARAM_STR); break; + case 'REMEMBER_ME_TOKEN': + $stmt->bindValue($identifier, $this->remember_me_token, PDO::PARAM_STR); + break; + case 'REMEMBER_ME_SERIAL': + $stmt->bindValue($identifier, $this->remember_me_serial, PDO::PARAM_STR); + 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; @@ -1500,9 +1594,15 @@ abstract class Customer implements ActiveRecordInterface return $this->getDiscount(); break; case 12: - return $this->getCreatedAt(); + return $this->getRememberMeToken(); break; case 13: + return $this->getRememberMeSerial(); + break; + case 14: + return $this->getCreatedAt(); + break; + case 15: return $this->getUpdatedAt(); break; default: @@ -1546,8 +1646,10 @@ abstract class Customer implements ActiveRecordInterface $keys[9] => $this->getLang(), $keys[10] => $this->getSponsor(), $keys[11] => $this->getDiscount(), - $keys[12] => $this->getCreatedAt(), - $keys[13] => $this->getUpdatedAt(), + $keys[12] => $this->getRememberMeToken(), + $keys[13] => $this->getRememberMeSerial(), + $keys[14] => $this->getCreatedAt(), + $keys[15] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1639,9 +1741,15 @@ abstract class Customer implements ActiveRecordInterface $this->setDiscount($value); break; case 12: - $this->setCreatedAt($value); + $this->setRememberMeToken($value); break; case 13: + $this->setRememberMeSerial($value); + break; + case 14: + $this->setCreatedAt($value); + break; + case 15: $this->setUpdatedAt($value); break; } // switch() @@ -1680,8 +1788,10 @@ abstract class Customer implements ActiveRecordInterface if (array_key_exists($keys[9], $arr)) $this->setLang($arr[$keys[9]]); if (array_key_exists($keys[10], $arr)) $this->setSponsor($arr[$keys[10]]); if (array_key_exists($keys[11], $arr)) $this->setDiscount($arr[$keys[11]]); - if (array_key_exists($keys[12], $arr)) $this->setCreatedAt($arr[$keys[12]]); - if (array_key_exists($keys[13], $arr)) $this->setUpdatedAt($arr[$keys[13]]); + if (array_key_exists($keys[12], $arr)) $this->setRememberMeToken($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setRememberMeSerial($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setCreatedAt($arr[$keys[14]]); + if (array_key_exists($keys[15], $arr)) $this->setUpdatedAt($arr[$keys[15]]); } /** @@ -1705,6 +1815,8 @@ abstract class Customer implements ActiveRecordInterface if ($this->isColumnModified(CustomerTableMap::LANG)) $criteria->add(CustomerTableMap::LANG, $this->lang); if ($this->isColumnModified(CustomerTableMap::SPONSOR)) $criteria->add(CustomerTableMap::SPONSOR, $this->sponsor); if ($this->isColumnModified(CustomerTableMap::DISCOUNT)) $criteria->add(CustomerTableMap::DISCOUNT, $this->discount); + if ($this->isColumnModified(CustomerTableMap::REMEMBER_ME_TOKEN)) $criteria->add(CustomerTableMap::REMEMBER_ME_TOKEN, $this->remember_me_token); + if ($this->isColumnModified(CustomerTableMap::REMEMBER_ME_SERIAL)) $criteria->add(CustomerTableMap::REMEMBER_ME_SERIAL, $this->remember_me_serial); if ($this->isColumnModified(CustomerTableMap::CREATED_AT)) $criteria->add(CustomerTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(CustomerTableMap::UPDATED_AT)) $criteria->add(CustomerTableMap::UPDATED_AT, $this->updated_at); @@ -1781,6 +1893,8 @@ abstract class Customer implements ActiveRecordInterface $copyObj->setLang($this->getLang()); $copyObj->setSponsor($this->getSponsor()); $copyObj->setDiscount($this->getDiscount()); + $copyObj->setRememberMeToken($this->getRememberMeToken()); + $copyObj->setRememberMeSerial($this->getRememberMeSerial()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -2806,6 +2920,8 @@ abstract class Customer implements ActiveRecordInterface $this->lang = null; $this->sponsor = null; $this->discount = null; + $this->remember_me_token = null; + $this->remember_me_serial = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/CustomerQuery.php b/core/lib/Thelia/Model/Base/CustomerQuery.php index f02e76c24..897bb5ee9 100644 --- a/core/lib/Thelia/Model/Base/CustomerQuery.php +++ b/core/lib/Thelia/Model/Base/CustomerQuery.php @@ -33,6 +33,8 @@ use Thelia\Model\Map\CustomerTableMap; * @method ChildCustomerQuery orderByLang($order = Criteria::ASC) Order by the lang column * @method ChildCustomerQuery orderBySponsor($order = Criteria::ASC) Order by the sponsor column * @method ChildCustomerQuery orderByDiscount($order = Criteria::ASC) Order by the discount column + * @method ChildCustomerQuery orderByRememberMeToken($order = Criteria::ASC) Order by the remember_me_token column + * @method ChildCustomerQuery orderByRememberMeSerial($order = Criteria::ASC) Order by the remember_me_serial column * @method ChildCustomerQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildCustomerQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -48,6 +50,8 @@ use Thelia\Model\Map\CustomerTableMap; * @method ChildCustomerQuery groupByLang() Group by the lang column * @method ChildCustomerQuery groupBySponsor() Group by the sponsor column * @method ChildCustomerQuery groupByDiscount() Group by the discount column + * @method ChildCustomerQuery groupByRememberMeToken() Group by the remember_me_token column + * @method ChildCustomerQuery groupByRememberMeSerial() Group by the remember_me_serial column * @method ChildCustomerQuery groupByCreatedAt() Group by the created_at column * @method ChildCustomerQuery groupByUpdatedAt() Group by the updated_at column * @@ -86,6 +90,8 @@ use Thelia\Model\Map\CustomerTableMap; * @method ChildCustomer findOneByLang(string $lang) Return the first ChildCustomer filtered by the lang column * @method ChildCustomer findOneBySponsor(string $sponsor) Return the first ChildCustomer filtered by the sponsor column * @method ChildCustomer findOneByDiscount(double $discount) Return the first ChildCustomer filtered by the discount column + * @method ChildCustomer findOneByRememberMeToken(string $remember_me_token) Return the first ChildCustomer filtered by the remember_me_token column + * @method ChildCustomer findOneByRememberMeSerial(string $remember_me_serial) Return the first ChildCustomer filtered by the remember_me_serial column * @method ChildCustomer findOneByCreatedAt(string $created_at) Return the first ChildCustomer filtered by the created_at column * @method ChildCustomer findOneByUpdatedAt(string $updated_at) Return the first ChildCustomer filtered by the updated_at column * @@ -101,6 +107,8 @@ use Thelia\Model\Map\CustomerTableMap; * @method array findByLang(string $lang) Return ChildCustomer objects filtered by the lang column * @method array findBySponsor(string $sponsor) Return ChildCustomer objects filtered by the sponsor column * @method array findByDiscount(double $discount) Return ChildCustomer objects filtered by the discount column + * @method array findByRememberMeToken(string $remember_me_token) Return ChildCustomer objects filtered by the remember_me_token column + * @method array findByRememberMeSerial(string $remember_me_serial) Return ChildCustomer objects filtered by the remember_me_serial column * @method array findByCreatedAt(string $created_at) Return ChildCustomer objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildCustomer objects filtered by the updated_at column * @@ -191,7 +199,7 @@ abstract class CustomerQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, REF, TITLE_ID, FIRSTNAME, LASTNAME, EMAIL, PASSWORD, ALGO, RESELLER, LANG, SPONSOR, DISCOUNT, CREATED_AT, UPDATED_AT FROM customer WHERE ID = :p0'; + $sql = 'SELECT ID, REF, TITLE_ID, FIRSTNAME, LASTNAME, EMAIL, PASSWORD, ALGO, RESELLER, LANG, SPONSOR, DISCOUNT, REMEMBER_ME_TOKEN, REMEMBER_ME_SERIAL, CREATED_AT, UPDATED_AT FROM customer WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -678,6 +686,64 @@ abstract class CustomerQuery extends ModelCriteria return $this->addUsingAlias(CustomerTableMap::DISCOUNT, $discount, $comparison); } + /** + * Filter the query on the remember_me_token column + * + * Example usage: + * + * $query->filterByRememberMeToken('fooValue'); // WHERE remember_me_token = 'fooValue' + * $query->filterByRememberMeToken('%fooValue%'); // WHERE remember_me_token LIKE '%fooValue%' + * + * + * @param string $rememberMeToken The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCustomerQuery The current query, for fluid interface + */ + public function filterByRememberMeToken($rememberMeToken = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($rememberMeToken)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $rememberMeToken)) { + $rememberMeToken = str_replace('*', '%', $rememberMeToken); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(CustomerTableMap::REMEMBER_ME_TOKEN, $rememberMeToken, $comparison); + } + + /** + * Filter the query on the remember_me_serial column + * + * Example usage: + * + * $query->filterByRememberMeSerial('fooValue'); // WHERE remember_me_serial = 'fooValue' + * $query->filterByRememberMeSerial('%fooValue%'); // WHERE remember_me_serial LIKE '%fooValue%' + * + * + * @param string $rememberMeSerial The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCustomerQuery The current query, for fluid interface + */ + public function filterByRememberMeSerial($rememberMeSerial = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($rememberMeSerial)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $rememberMeSerial)) { + $rememberMeSerial = str_replace('*', '%', $rememberMeSerial); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(CustomerTableMap::REMEMBER_ME_SERIAL, $rememberMeSerial, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/Feature.php b/core/lib/Thelia/Model/Base/Feature.php index 2860a4155..c9b6c5ed4 100644 --- a/core/lib/Thelia/Model/Base/Feature.php +++ b/core/lib/Thelia/Model/Base/Feature.php @@ -17,18 +17,18 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; -use Thelia\Model\Category as ChildCategory; -use Thelia\Model\CategoryQuery as ChildCategoryQuery; use Thelia\Model\Feature as ChildFeature; use Thelia\Model\FeatureAv as ChildFeatureAv; use Thelia\Model\FeatureAvQuery as ChildFeatureAvQuery; -use Thelia\Model\FeatureCategory as ChildFeatureCategory; -use Thelia\Model\FeatureCategoryQuery as ChildFeatureCategoryQuery; use Thelia\Model\FeatureI18n as ChildFeatureI18n; use Thelia\Model\FeatureI18nQuery as ChildFeatureI18nQuery; use Thelia\Model\FeatureProduct as ChildFeatureProduct; use Thelia\Model\FeatureProductQuery as ChildFeatureProductQuery; use Thelia\Model\FeatureQuery as ChildFeatureQuery; +use Thelia\Model\FeatureTemplate as ChildFeatureTemplate; +use Thelia\Model\FeatureTemplateQuery as ChildFeatureTemplateQuery; +use Thelia\Model\Template as ChildTemplate; +use Thelia\Model\TemplateQuery as ChildTemplateQuery; use Thelia\Model\Map\FeatureTableMap; abstract class Feature implements ActiveRecordInterface @@ -109,10 +109,10 @@ abstract class Feature implements ActiveRecordInterface protected $collFeatureProductsPartial; /** - * @var ObjectCollection|ChildFeatureCategory[] Collection to store aggregation of ChildFeatureCategory objects. + * @var ObjectCollection|ChildFeatureTemplate[] Collection to store aggregation of ChildFeatureTemplate objects. */ - protected $collFeatureCategories; - protected $collFeatureCategoriesPartial; + protected $collFeatureTemplates; + protected $collFeatureTemplatesPartial; /** * @var ObjectCollection|ChildFeatureI18n[] Collection to store aggregation of ChildFeatureI18n objects. @@ -121,9 +121,9 @@ abstract class Feature implements ActiveRecordInterface protected $collFeatureI18nsPartial; /** - * @var ChildCategory[] Collection to store aggregation of ChildCategory objects. + * @var ChildTemplate[] Collection to store aggregation of ChildTemplate objects. */ - protected $collCategories; + protected $collTemplates; /** * Flag to prevent endless save loop, if this object is referenced @@ -151,7 +151,7 @@ abstract class Feature implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $categoriesScheduledForDeletion = null; + protected $templatesScheduledForDeletion = null; /** * An array of objects scheduled for deletion. @@ -169,7 +169,7 @@ abstract class Feature implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $featureCategoriesScheduledForDeletion = null; + protected $featureTemplatesScheduledForDeletion = null; /** * An array of objects scheduled for deletion. @@ -756,11 +756,11 @@ abstract class Feature implements ActiveRecordInterface $this->collFeatureProducts = null; - $this->collFeatureCategories = null; + $this->collFeatureTemplates = null; $this->collFeatureI18ns = null; - $this->collCategories = null; + $this->collTemplates = null; } // if (deep) } @@ -894,29 +894,29 @@ abstract class Feature implements ActiveRecordInterface $this->resetModified(); } - if ($this->categoriesScheduledForDeletion !== null) { - if (!$this->categoriesScheduledForDeletion->isEmpty()) { + if ($this->templatesScheduledForDeletion !== null) { + if (!$this->templatesScheduledForDeletion->isEmpty()) { $pks = array(); $pk = $this->getPrimaryKey(); - foreach ($this->categoriesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($remotePk, $pk); + foreach ($this->templatesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); } - FeatureCategoryQuery::create() + FeatureTemplateQuery::create() ->filterByPrimaryKeys($pks) ->delete($con); - $this->categoriesScheduledForDeletion = null; + $this->templatesScheduledForDeletion = null; } - foreach ($this->getCategories() as $category) { - if ($category->isModified()) { - $category->save($con); + foreach ($this->getTemplates() as $template) { + if ($template->isModified()) { + $template->save($con); } } - } elseif ($this->collCategories) { - foreach ($this->collCategories as $category) { - if ($category->isModified()) { - $category->save($con); + } elseif ($this->collTemplates) { + foreach ($this->collTemplates as $template) { + if ($template->isModified()) { + $template->save($con); } } } @@ -955,17 +955,17 @@ abstract class Feature implements ActiveRecordInterface } } - if ($this->featureCategoriesScheduledForDeletion !== null) { - if (!$this->featureCategoriesScheduledForDeletion->isEmpty()) { - \Thelia\Model\FeatureCategoryQuery::create() - ->filterByPrimaryKeys($this->featureCategoriesScheduledForDeletion->getPrimaryKeys(false)) + if ($this->featureTemplatesScheduledForDeletion !== null) { + if (!$this->featureTemplatesScheduledForDeletion->isEmpty()) { + \Thelia\Model\FeatureTemplateQuery::create() + ->filterByPrimaryKeys($this->featureTemplatesScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); - $this->featureCategoriesScheduledForDeletion = null; + $this->featureTemplatesScheduledForDeletion = null; } } - if ($this->collFeatureCategories !== null) { - foreach ($this->collFeatureCategories as $referrerFK) { + if ($this->collFeatureTemplates !== null) { + foreach ($this->collFeatureTemplates as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } @@ -1181,8 +1181,8 @@ abstract class Feature implements ActiveRecordInterface if (null !== $this->collFeatureProducts) { $result['FeatureProducts'] = $this->collFeatureProducts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } - if (null !== $this->collFeatureCategories) { - $result['FeatureCategories'] = $this->collFeatureCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collFeatureTemplates) { + $result['FeatureTemplates'] = $this->collFeatureTemplates->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collFeatureI18ns) { $result['FeatureI18ns'] = $this->collFeatureI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); @@ -1366,9 +1366,9 @@ abstract class Feature implements ActiveRecordInterface } } - foreach ($this->getFeatureCategories() as $relObj) { + foreach ($this->getFeatureTemplates() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addFeatureCategory($relObj->copy($deepCopy)); + $copyObj->addFeatureTemplate($relObj->copy($deepCopy)); } } @@ -1425,8 +1425,8 @@ abstract class Feature implements ActiveRecordInterface if ('FeatureProduct' == $relationName) { return $this->initFeatureProducts(); } - if ('FeatureCategory' == $relationName) { - return $this->initFeatureCategories(); + if ('FeatureTemplate' == $relationName) { + return $this->initFeatureTemplates(); } if ('FeatureI18n' == $relationName) { return $this->initFeatureI18ns(); @@ -1920,31 +1920,31 @@ abstract class Feature implements ActiveRecordInterface } /** - * Clears out the collFeatureCategories collection + * Clears out the collFeatureTemplates collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addFeatureCategories() + * @see addFeatureTemplates() */ - public function clearFeatureCategories() + public function clearFeatureTemplates() { - $this->collFeatureCategories = null; // important to set this to NULL since that means it is uninitialized + $this->collFeatureTemplates = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collFeatureCategories collection loaded partially. + * Reset is the collFeatureTemplates collection loaded partially. */ - public function resetPartialFeatureCategories($v = true) + public function resetPartialFeatureTemplates($v = true) { - $this->collFeatureCategoriesPartial = $v; + $this->collFeatureTemplatesPartial = $v; } /** - * Initializes the collFeatureCategories collection. + * Initializes the collFeatureTemplates collection. * - * By default this just sets the collFeatureCategories collection to an empty array (like clearcollFeatureCategories()); + * By default this just sets the collFeatureTemplates collection to an empty array (like clearcollFeatureTemplates()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * @@ -1953,17 +1953,17 @@ abstract class Feature implements ActiveRecordInterface * * @return void */ - public function initFeatureCategories($overrideExisting = true) + public function initFeatureTemplates($overrideExisting = true) { - if (null !== $this->collFeatureCategories && !$overrideExisting) { + if (null !== $this->collFeatureTemplates && !$overrideExisting) { return; } - $this->collFeatureCategories = new ObjectCollection(); - $this->collFeatureCategories->setModel('\Thelia\Model\FeatureCategory'); + $this->collFeatureTemplates = new ObjectCollection(); + $this->collFeatureTemplates->setModel('\Thelia\Model\FeatureTemplate'); } /** - * Gets an array of ChildFeatureCategory objects which contain a foreign key that references this object. + * Gets an array of ChildFeatureTemplate objects which contain a foreign key that references this object. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. @@ -1973,109 +1973,109 @@ abstract class Feature implements ActiveRecordInterface * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildFeatureCategory[] List of ChildFeatureCategory objects + * @return Collection|ChildFeatureTemplate[] List of ChildFeatureTemplate objects * @throws PropelException */ - public function getFeatureCategories($criteria = null, ConnectionInterface $con = null) + public function getFeatureTemplates($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collFeatureCategoriesPartial && !$this->isNew(); - if (null === $this->collFeatureCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collFeatureCategories) { + $partial = $this->collFeatureTemplatesPartial && !$this->isNew(); + if (null === $this->collFeatureTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFeatureTemplates) { // return empty collection - $this->initFeatureCategories(); + $this->initFeatureTemplates(); } else { - $collFeatureCategories = ChildFeatureCategoryQuery::create(null, $criteria) + $collFeatureTemplates = ChildFeatureTemplateQuery::create(null, $criteria) ->filterByFeature($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collFeatureCategoriesPartial && count($collFeatureCategories)) { - $this->initFeatureCategories(false); + if (false !== $this->collFeatureTemplatesPartial && count($collFeatureTemplates)) { + $this->initFeatureTemplates(false); - foreach ($collFeatureCategories as $obj) { - if (false == $this->collFeatureCategories->contains($obj)) { - $this->collFeatureCategories->append($obj); + foreach ($collFeatureTemplates as $obj) { + if (false == $this->collFeatureTemplates->contains($obj)) { + $this->collFeatureTemplates->append($obj); } } - $this->collFeatureCategoriesPartial = true; + $this->collFeatureTemplatesPartial = true; } - $collFeatureCategories->getInternalIterator()->rewind(); + $collFeatureTemplates->getInternalIterator()->rewind(); - return $collFeatureCategories; + return $collFeatureTemplates; } - if ($partial && $this->collFeatureCategories) { - foreach ($this->collFeatureCategories as $obj) { + if ($partial && $this->collFeatureTemplates) { + foreach ($this->collFeatureTemplates as $obj) { if ($obj->isNew()) { - $collFeatureCategories[] = $obj; + $collFeatureTemplates[] = $obj; } } } - $this->collFeatureCategories = $collFeatureCategories; - $this->collFeatureCategoriesPartial = false; + $this->collFeatureTemplates = $collFeatureTemplates; + $this->collFeatureTemplatesPartial = false; } } - return $this->collFeatureCategories; + return $this->collFeatureTemplates; } /** - * Sets a collection of FeatureCategory objects related by a one-to-many relationship + * Sets a collection of FeatureTemplate objects related by a one-to-many relationship * to the current object. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $featureCategories A Propel collection. + * @param Collection $featureTemplates A Propel collection. * @param ConnectionInterface $con Optional connection object * @return ChildFeature The current object (for fluent API support) */ - public function setFeatureCategories(Collection $featureCategories, ConnectionInterface $con = null) + public function setFeatureTemplates(Collection $featureTemplates, ConnectionInterface $con = null) { - $featureCategoriesToDelete = $this->getFeatureCategories(new Criteria(), $con)->diff($featureCategories); + $featureTemplatesToDelete = $this->getFeatureTemplates(new Criteria(), $con)->diff($featureTemplates); - $this->featureCategoriesScheduledForDeletion = $featureCategoriesToDelete; + $this->featureTemplatesScheduledForDeletion = $featureTemplatesToDelete; - foreach ($featureCategoriesToDelete as $featureCategoryRemoved) { - $featureCategoryRemoved->setFeature(null); + foreach ($featureTemplatesToDelete as $featureTemplateRemoved) { + $featureTemplateRemoved->setFeature(null); } - $this->collFeatureCategories = null; - foreach ($featureCategories as $featureCategory) { - $this->addFeatureCategory($featureCategory); + $this->collFeatureTemplates = null; + foreach ($featureTemplates as $featureTemplate) { + $this->addFeatureTemplate($featureTemplate); } - $this->collFeatureCategories = $featureCategories; - $this->collFeatureCategoriesPartial = false; + $this->collFeatureTemplates = $featureTemplates; + $this->collFeatureTemplatesPartial = false; return $this; } /** - * Returns the number of related FeatureCategory objects. + * Returns the number of related FeatureTemplate objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related FeatureCategory objects. + * @return int Count of related FeatureTemplate objects. * @throws PropelException */ - public function countFeatureCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countFeatureTemplates(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collFeatureCategoriesPartial && !$this->isNew(); - if (null === $this->collFeatureCategories || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collFeatureCategories) { + $partial = $this->collFeatureTemplatesPartial && !$this->isNew(); + if (null === $this->collFeatureTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFeatureTemplates) { return 0; } if ($partial && !$criteria) { - return count($this->getFeatureCategories()); + return count($this->getFeatureTemplates()); } - $query = ChildFeatureCategoryQuery::create(null, $criteria); + $query = ChildFeatureTemplateQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } @@ -2085,53 +2085,53 @@ abstract class Feature implements ActiveRecordInterface ->count($con); } - return count($this->collFeatureCategories); + return count($this->collFeatureTemplates); } /** - * Method called to associate a ChildFeatureCategory object to this object - * through the ChildFeatureCategory foreign key attribute. + * Method called to associate a ChildFeatureTemplate object to this object + * through the ChildFeatureTemplate foreign key attribute. * - * @param ChildFeatureCategory $l ChildFeatureCategory + * @param ChildFeatureTemplate $l ChildFeatureTemplate * @return \Thelia\Model\Feature The current object (for fluent API support) */ - public function addFeatureCategory(ChildFeatureCategory $l) + public function addFeatureTemplate(ChildFeatureTemplate $l) { - if ($this->collFeatureCategories === null) { - $this->initFeatureCategories(); - $this->collFeatureCategoriesPartial = true; + if ($this->collFeatureTemplates === null) { + $this->initFeatureTemplates(); + $this->collFeatureTemplatesPartial = true; } - if (!in_array($l, $this->collFeatureCategories->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddFeatureCategory($l); + if (!in_array($l, $this->collFeatureTemplates->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddFeatureTemplate($l); } return $this; } /** - * @param FeatureCategory $featureCategory The featureCategory object to add. + * @param FeatureTemplate $featureTemplate The featureTemplate object to add. */ - protected function doAddFeatureCategory($featureCategory) + protected function doAddFeatureTemplate($featureTemplate) { - $this->collFeatureCategories[]= $featureCategory; - $featureCategory->setFeature($this); + $this->collFeatureTemplates[]= $featureTemplate; + $featureTemplate->setFeature($this); } /** - * @param FeatureCategory $featureCategory The featureCategory object to remove. + * @param FeatureTemplate $featureTemplate The featureTemplate object to remove. * @return ChildFeature The current object (for fluent API support) */ - public function removeFeatureCategory($featureCategory) + public function removeFeatureTemplate($featureTemplate) { - if ($this->getFeatureCategories()->contains($featureCategory)) { - $this->collFeatureCategories->remove($this->collFeatureCategories->search($featureCategory)); - if (null === $this->featureCategoriesScheduledForDeletion) { - $this->featureCategoriesScheduledForDeletion = clone $this->collFeatureCategories; - $this->featureCategoriesScheduledForDeletion->clear(); + if ($this->getFeatureTemplates()->contains($featureTemplate)) { + $this->collFeatureTemplates->remove($this->collFeatureTemplates->search($featureTemplate)); + if (null === $this->featureTemplatesScheduledForDeletion) { + $this->featureTemplatesScheduledForDeletion = clone $this->collFeatureTemplates; + $this->featureTemplatesScheduledForDeletion->clear(); } - $this->featureCategoriesScheduledForDeletion[]= clone $featureCategory; - $featureCategory->setFeature(null); + $this->featureTemplatesScheduledForDeletion[]= clone $featureTemplate; + $featureTemplate->setFeature(null); } return $this; @@ -2143,7 +2143,7 @@ abstract class Feature implements ActiveRecordInterface * an identical criteria, it returns the collection. * Otherwise if this Feature is new, it will return * an empty collection; or if this Feature has previously - * been saved, it will retrieve related FeatureCategories from storage. + * been saved, it will retrieve related FeatureTemplates from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you @@ -2152,14 +2152,14 @@ abstract class Feature implements ActiveRecordInterface * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) - * @return Collection|ChildFeatureCategory[] List of ChildFeatureCategory objects + * @return Collection|ChildFeatureTemplate[] List of ChildFeatureTemplate objects */ - public function getFeatureCategoriesJoinCategory($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + public function getFeatureTemplatesJoinTemplate($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { - $query = ChildFeatureCategoryQuery::create(null, $criteria); - $query->joinWith('Category', $joinBehavior); + $query = ChildFeatureTemplateQuery::create(null, $criteria); + $query->joinWith('Template', $joinBehavior); - return $this->getFeatureCategories($query, $con); + return $this->getFeatureTemplates($query, $con); } /** @@ -2388,38 +2388,38 @@ abstract class Feature implements ActiveRecordInterface } /** - * Clears out the collCategories collection + * Clears out the collTemplates collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addCategories() + * @see addTemplates() */ - public function clearCategories() + public function clearTemplates() { - $this->collCategories = null; // important to set this to NULL since that means it is uninitialized - $this->collCategoriesPartial = null; + $this->collTemplates = null; // important to set this to NULL since that means it is uninitialized + $this->collTemplatesPartial = null; } /** - * Initializes the collCategories collection. + * Initializes the collTemplates collection. * - * By default this just sets the collCategories collection to an empty collection (like clearCategories()); + * By default this just sets the collTemplates collection to an empty collection (like clearTemplates()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ - public function initCategories() + public function initTemplates() { - $this->collCategories = new ObjectCollection(); - $this->collCategories->setModel('\Thelia\Model\Category'); + $this->collTemplates = new ObjectCollection(); + $this->collTemplates->setModel('\Thelia\Model\Template'); } /** - * Gets a collection of ChildCategory objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. + * Gets a collection of ChildTemplate objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. @@ -2430,73 +2430,73 @@ abstract class Feature implements ActiveRecordInterface * @param Criteria $criteria Optional query object to filter the query * @param ConnectionInterface $con Optional connection object * - * @return ObjectCollection|ChildCategory[] List of ChildCategory objects + * @return ObjectCollection|ChildTemplate[] List of ChildTemplate objects */ - public function getCategories($criteria = null, ConnectionInterface $con = null) + public function getTemplates($criteria = null, ConnectionInterface $con = null) { - if (null === $this->collCategories || null !== $criteria) { - if ($this->isNew() && null === $this->collCategories) { + if (null === $this->collTemplates || null !== $criteria) { + if ($this->isNew() && null === $this->collTemplates) { // return empty collection - $this->initCategories(); + $this->initTemplates(); } else { - $collCategories = ChildCategoryQuery::create(null, $criteria) + $collTemplates = ChildTemplateQuery::create(null, $criteria) ->filterByFeature($this) ->find($con); if (null !== $criteria) { - return $collCategories; + return $collTemplates; } - $this->collCategories = $collCategories; + $this->collTemplates = $collTemplates; } } - return $this->collCategories; + return $this->collTemplates; } /** - * Sets a collection of Category objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. + * Sets a collection of Template objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $categories A Propel collection. + * @param Collection $templates A Propel collection. * @param ConnectionInterface $con Optional connection object * @return ChildFeature The current object (for fluent API support) */ - public function setCategories(Collection $categories, ConnectionInterface $con = null) + public function setTemplates(Collection $templates, ConnectionInterface $con = null) { - $this->clearCategories(); - $currentCategories = $this->getCategories(); + $this->clearTemplates(); + $currentTemplates = $this->getTemplates(); - $this->categoriesScheduledForDeletion = $currentCategories->diff($categories); + $this->templatesScheduledForDeletion = $currentTemplates->diff($templates); - foreach ($categories as $category) { - if (!$currentCategories->contains($category)) { - $this->doAddCategory($category); + foreach ($templates as $template) { + if (!$currentTemplates->contains($template)) { + $this->doAddTemplate($template); } } - $this->collCategories = $categories; + $this->collTemplates = $templates; return $this; } /** - * Gets the number of ChildCategory objects related by a many-to-many relationship - * to the current object by way of the feature_category cross-reference table. + * Gets the number of ChildTemplate objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param ConnectionInterface $con Optional connection object * - * @return int the number of related ChildCategory objects + * @return int the number of related ChildTemplate objects */ - public function countCategories($criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countTemplates($criteria = null, $distinct = false, ConnectionInterface $con = null) { - if (null === $this->collCategories || null !== $criteria) { - if ($this->isNew() && null === $this->collCategories) { + if (null === $this->collTemplates || null !== $criteria) { + if ($this->isNew() && null === $this->collTemplates) { return 0; } else { - $query = ChildCategoryQuery::create(null, $criteria); + $query = ChildTemplateQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } @@ -2506,65 +2506,65 @@ abstract class Feature implements ActiveRecordInterface ->count($con); } } else { - return count($this->collCategories); + return count($this->collTemplates); } } /** - * Associate a ChildCategory object to this object - * through the feature_category cross reference table. + * Associate a ChildTemplate object to this object + * through the feature_template cross reference table. * - * @param ChildCategory $category The ChildFeatureCategory object to relate + * @param ChildTemplate $template The ChildFeatureTemplate object to relate * @return ChildFeature The current object (for fluent API support) */ - public function addCategory(ChildCategory $category) + public function addTemplate(ChildTemplate $template) { - if ($this->collCategories === null) { - $this->initCategories(); + if ($this->collTemplates === null) { + $this->initTemplates(); } - if (!$this->collCategories->contains($category)) { // only add it if the **same** object is not already associated - $this->doAddCategory($category); - $this->collCategories[] = $category; + if (!$this->collTemplates->contains($template)) { // only add it if the **same** object is not already associated + $this->doAddTemplate($template); + $this->collTemplates[] = $template; } return $this; } /** - * @param Category $category The category object to add. + * @param Template $template The template object to add. */ - protected function doAddCategory($category) + protected function doAddTemplate($template) { - $featureCategory = new ChildFeatureCategory(); - $featureCategory->setCategory($category); - $this->addFeatureCategory($featureCategory); + $featureTemplate = new ChildFeatureTemplate(); + $featureTemplate->setTemplate($template); + $this->addFeatureTemplate($featureTemplate); // set the back reference to this object directly as using provided method either results // in endless loop or in multiple relations - if (!$category->getFeatures()->contains($this)) { - $foreignCollection = $category->getFeatures(); + if (!$template->getFeatures()->contains($this)) { + $foreignCollection = $template->getFeatures(); $foreignCollection[] = $this; } } /** - * Remove a ChildCategory object to this object - * through the feature_category cross reference table. + * Remove a ChildTemplate object to this object + * through the feature_template cross reference table. * - * @param ChildCategory $category The ChildFeatureCategory object to relate + * @param ChildTemplate $template The ChildFeatureTemplate object to relate * @return ChildFeature The current object (for fluent API support) */ - public function removeCategory(ChildCategory $category) + public function removeTemplate(ChildTemplate $template) { - if ($this->getCategories()->contains($category)) { - $this->collCategories->remove($this->collCategories->search($category)); + if ($this->getTemplates()->contains($template)) { + $this->collTemplates->remove($this->collTemplates->search($template)); - if (null === $this->categoriesScheduledForDeletion) { - $this->categoriesScheduledForDeletion = clone $this->collCategories; - $this->categoriesScheduledForDeletion->clear(); + if (null === $this->templatesScheduledForDeletion) { + $this->templatesScheduledForDeletion = clone $this->collTemplates; + $this->templatesScheduledForDeletion->clear(); } - $this->categoriesScheduledForDeletion[] = $category; + $this->templatesScheduledForDeletion[] = $template; } return $this; @@ -2610,8 +2610,8 @@ abstract class Feature implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collFeatureCategories) { - foreach ($this->collFeatureCategories as $o) { + if ($this->collFeatureTemplates) { + foreach ($this->collFeatureTemplates as $o) { $o->clearAllReferences($deep); } } @@ -2620,8 +2620,8 @@ abstract class Feature implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collCategories) { - foreach ($this->collCategories as $o) { + if ($this->collTemplates) { + foreach ($this->collTemplates as $o) { $o->clearAllReferences($deep); } } @@ -2639,18 +2639,18 @@ abstract class Feature implements ActiveRecordInterface $this->collFeatureProducts->clearIterator(); } $this->collFeatureProducts = null; - if ($this->collFeatureCategories instanceof Collection) { - $this->collFeatureCategories->clearIterator(); + if ($this->collFeatureTemplates instanceof Collection) { + $this->collFeatureTemplates->clearIterator(); } - $this->collFeatureCategories = null; + $this->collFeatureTemplates = null; if ($this->collFeatureI18ns instanceof Collection) { $this->collFeatureI18ns->clearIterator(); } $this->collFeatureI18ns = null; - if ($this->collCategories instanceof Collection) { - $this->collCategories->clearIterator(); + if ($this->collTemplates instanceof Collection) { + $this->collTemplates->clearIterator(); } - $this->collCategories = null; + $this->collTemplates = null; } /** diff --git a/core/lib/Thelia/Model/Base/FeatureQuery.php b/core/lib/Thelia/Model/Base/FeatureQuery.php index 9b00e812e..097646c87 100644 --- a/core/lib/Thelia/Model/Base/FeatureQuery.php +++ b/core/lib/Thelia/Model/Base/FeatureQuery.php @@ -46,9 +46,9 @@ use Thelia\Model\Map\FeatureTableMap; * @method ChildFeatureQuery rightJoinFeatureProduct($relationAlias = null) Adds a RIGHT JOIN clause to the query using the FeatureProduct relation * @method ChildFeatureQuery innerJoinFeatureProduct($relationAlias = null) Adds a INNER JOIN clause to the query using the FeatureProduct relation * - * @method ChildFeatureQuery leftJoinFeatureCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the FeatureCategory relation - * @method ChildFeatureQuery rightJoinFeatureCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the FeatureCategory relation - * @method ChildFeatureQuery innerJoinFeatureCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the FeatureCategory relation + * @method ChildFeatureQuery leftJoinFeatureTemplate($relationAlias = null) Adds a LEFT JOIN clause to the query using the FeatureTemplate relation + * @method ChildFeatureQuery rightJoinFeatureTemplate($relationAlias = null) Adds a RIGHT JOIN clause to the query using the FeatureTemplate relation + * @method ChildFeatureQuery innerJoinFeatureTemplate($relationAlias = null) Adds a INNER JOIN clause to the query using the FeatureTemplate relation * * @method ChildFeatureQuery leftJoinFeatureI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the FeatureI18n relation * @method ChildFeatureQuery rightJoinFeatureI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the FeatureI18n relation @@ -601,40 +601,40 @@ abstract class FeatureQuery extends ModelCriteria } /** - * Filter the query by a related \Thelia\Model\FeatureCategory object + * Filter the query by a related \Thelia\Model\FeatureTemplate object * - * @param \Thelia\Model\FeatureCategory|ObjectCollection $featureCategory the related object to use as filter + * @param \Thelia\Model\FeatureTemplate|ObjectCollection $featureTemplate the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildFeatureQuery The current query, for fluid interface */ - public function filterByFeatureCategory($featureCategory, $comparison = null) + public function filterByFeatureTemplate($featureTemplate, $comparison = null) { - if ($featureCategory instanceof \Thelia\Model\FeatureCategory) { + if ($featureTemplate instanceof \Thelia\Model\FeatureTemplate) { return $this - ->addUsingAlias(FeatureTableMap::ID, $featureCategory->getFeatureId(), $comparison); - } elseif ($featureCategory instanceof ObjectCollection) { + ->addUsingAlias(FeatureTableMap::ID, $featureTemplate->getFeatureId(), $comparison); + } elseif ($featureTemplate instanceof ObjectCollection) { return $this - ->useFeatureCategoryQuery() - ->filterByPrimaryKeys($featureCategory->getPrimaryKeys()) + ->useFeatureTemplateQuery() + ->filterByPrimaryKeys($featureTemplate->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByFeatureCategory() only accepts arguments of type \Thelia\Model\FeatureCategory or Collection'); + throw new PropelException('filterByFeatureTemplate() only accepts arguments of type \Thelia\Model\FeatureTemplate or Collection'); } } /** - * Adds a JOIN clause to the query using the FeatureCategory relation + * Adds a JOIN clause to the query using the FeatureTemplate relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildFeatureQuery The current query, for fluid interface */ - public function joinFeatureCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinFeatureTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('FeatureCategory'); + $relationMap = $tableMap->getRelation('FeatureTemplate'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -649,14 +649,14 @@ abstract class FeatureQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'FeatureCategory'); + $this->addJoinObject($join, 'FeatureTemplate'); } return $this; } /** - * Use the FeatureCategory relation FeatureCategory object + * Use the FeatureTemplate relation FeatureTemplate object * * @see useQuery() * @@ -664,13 +664,13 @@ abstract class FeatureQuery extends ModelCriteria * 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\FeatureCategoryQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\FeatureTemplateQuery A secondary query class using the current class as primary query */ - public function useFeatureCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useFeatureTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this - ->joinFeatureCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'FeatureCategory', '\Thelia\Model\FeatureCategoryQuery'); + ->joinFeatureTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'FeatureTemplate', '\Thelia\Model\FeatureTemplateQuery'); } /** @@ -747,19 +747,19 @@ abstract class FeatureQuery extends ModelCriteria } /** - * Filter the query by a related Category object - * using the feature_category table as cross reference + * Filter the query by a related Template object + * using the feature_template table as cross reference * - * @param Category $category the related object to use as filter + * @param Template $template the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildFeatureQuery The current query, for fluid interface */ - public function filterByCategory($category, $comparison = Criteria::EQUAL) + public function filterByTemplate($template, $comparison = Criteria::EQUAL) { return $this - ->useFeatureCategoryQuery() - ->filterByCategory($category, $comparison) + ->useFeatureTemplateQuery() + ->filterByTemplate($template, $comparison) ->endUse(); } diff --git a/core/lib/Thelia/Model/Base/FeatureTemplate.php b/core/lib/Thelia/Model/Base/FeatureTemplate.php new file mode 100644 index 000000000..bbccd9251 --- /dev/null +++ b/core/lib/Thelia/Model/Base/FeatureTemplate.php @@ -0,0 +1,1495 @@ +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 FeatureTemplate instance. If + * obj is an instance of FeatureTemplate, delegates to + * equals(FeatureTemplate). 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 FeatureTemplate 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 FeatureTemplate 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 [template_id] column value. + * + * @return int + */ + public function getTemplateId() + { + + return $this->template_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\FeatureTemplate 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[] = FeatureTemplateTableMap::ID; + } + + + return $this; + } // setId() + + /** + * Set the value of [feature_id] column. + * + * @param int $v new value + * @return \Thelia\Model\FeatureTemplate 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[] = FeatureTemplateTableMap::FEATURE_ID; + } + + if ($this->aFeature !== null && $this->aFeature->getId() !== $v) { + $this->aFeature = null; + } + + + return $this; + } // setFeatureId() + + /** + * Set the value of [template_id] column. + * + * @param int $v new value + * @return \Thelia\Model\FeatureTemplate The current object (for fluent API support) + */ + public function setTemplateId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->template_id !== $v) { + $this->template_id = $v; + $this->modifiedColumns[] = FeatureTemplateTableMap::TEMPLATE_ID; + } + + if ($this->aTemplate !== null && $this->aTemplate->getId() !== $v) { + $this->aTemplate = null; + } + + + return $this; + } // setTemplateId() + + /** + * 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\FeatureTemplate 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[] = FeatureTemplateTableMap::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\FeatureTemplate 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[] = FeatureTemplateTableMap::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 : FeatureTemplateTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : FeatureTemplateTableMap::translateFieldName('FeatureId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->feature_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : FeatureTemplateTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->template_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FeatureTemplateTableMap::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 : FeatureTemplateTableMap::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 = FeatureTemplateTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\FeatureTemplate 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->aTemplate !== null && $this->template_id !== $this->aTemplate->getId()) { + $this->aTemplate = 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(FeatureTemplateTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildFeatureTemplateQuery::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->aFeature = null; + $this->aTemplate = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see FeatureTemplate::setDeleted() + * @see FeatureTemplate::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(FeatureTemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildFeatureTemplateQuery::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(FeatureTemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(FeatureTemplateTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(FeatureTemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(FeatureTemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + FeatureTemplateTableMap::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->aFeature !== null) { + if ($this->aFeature->isModified() || $this->aFeature->isNew()) { + $affectedRows += $this->aFeature->save($con); + } + $this->setFeature($this->aFeature); + } + + if ($this->aTemplate !== null) { + if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) { + $affectedRows += $this->aTemplate->save($con); + } + $this->setTemplate($this->aTemplate); + } + + 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[] = FeatureTemplateTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureTemplateTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(FeatureTemplateTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(FeatureTemplateTableMap::FEATURE_ID)) { + $modifiedColumns[':p' . $index++] = 'FEATURE_ID'; + } + if ($this->isColumnModified(FeatureTemplateTableMap::TEMPLATE_ID)) { + $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; + } + if ($this->isColumnModified(FeatureTemplateTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(FeatureTemplateTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO feature_template (%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 'TEMPLATE_ID': + $stmt->bindValue($identifier, $this->template_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 = FeatureTemplateTableMap::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->getTemplateId(); + 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['FeatureTemplate'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['FeatureTemplate'][$this->getPrimaryKey()] = true; + $keys = FeatureTemplateTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getFeatureId(), + $keys[2] => $this->getTemplateId(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aFeature) { + $result['Feature'] = $this->aFeature->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aTemplate) { + $result['Template'] = $this->aTemplate->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 = FeatureTemplateTableMap::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->setTemplateId($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 = FeatureTemplateTableMap::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->setTemplateId($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(FeatureTemplateTableMap::DATABASE_NAME); + + if ($this->isColumnModified(FeatureTemplateTableMap::ID)) $criteria->add(FeatureTemplateTableMap::ID, $this->id); + if ($this->isColumnModified(FeatureTemplateTableMap::FEATURE_ID)) $criteria->add(FeatureTemplateTableMap::FEATURE_ID, $this->feature_id); + if ($this->isColumnModified(FeatureTemplateTableMap::TEMPLATE_ID)) $criteria->add(FeatureTemplateTableMap::TEMPLATE_ID, $this->template_id); + if ($this->isColumnModified(FeatureTemplateTableMap::CREATED_AT)) $criteria->add(FeatureTemplateTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(FeatureTemplateTableMap::UPDATED_AT)) $criteria->add(FeatureTemplateTableMap::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(FeatureTemplateTableMap::DATABASE_NAME); + $criteria->add(FeatureTemplateTableMap::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\FeatureTemplate (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->setTemplateId($this->getTemplateId()); + $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\FeatureTemplate 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 ChildFeature object. + * + * @param ChildFeature $v + * @return \Thelia\Model\FeatureTemplate 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->addFeatureTemplate($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->addFeatureTemplates($this); + */ + } + + return $this->aFeature; + } + + /** + * Declares an association between this object and a ChildTemplate object. + * + * @param ChildTemplate $v + * @return \Thelia\Model\FeatureTemplate The current object (for fluent API support) + * @throws PropelException + */ + public function setTemplate(ChildTemplate $v = null) + { + if ($v === null) { + $this->setTemplateId(NULL); + } else { + $this->setTemplateId($v->getId()); + } + + $this->aTemplate = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildTemplate object, it will not be re-added. + if ($v !== null) { + $v->addFeatureTemplate($this); + } + + + return $this; + } + + + /** + * Get the associated ChildTemplate object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildTemplate The associated ChildTemplate object. + * @throws PropelException + */ + public function getTemplate(ConnectionInterface $con = null) + { + if ($this->aTemplate === null && ($this->template_id !== null)) { + $this->aTemplate = ChildTemplateQuery::create()->findPk($this->template_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->aTemplate->addFeatureTemplates($this); + */ + } + + return $this->aTemplate; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->feature_id = null; + $this->template_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->aFeature = null; + $this->aTemplate = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(FeatureTemplateTableMap::DEFAULT_STRING_FORMAT); + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildFeatureTemplate The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[] = FeatureTemplateTableMap::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/FeatureTemplateQuery.php b/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php new file mode 100644 index 000000000..c99c1305f --- /dev/null +++ b/core/lib/Thelia/Model/Base/FeatureTemplateQuery.php @@ -0,0 +1,759 @@ +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 ChildFeatureTemplate|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = FeatureTemplateTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(FeatureTemplateTableMap::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 ChildFeatureTemplate A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, FEATURE_ID, TEMPLATE_ID, CREATED_AT, UPDATED_AT FROM feature_template 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 ChildFeatureTemplate(); + $obj->hydrate($row); + FeatureTemplateTableMap::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 ChildFeatureTemplate|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 ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(FeatureTemplateTableMap::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 ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(FeatureTemplateTableMap::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 ChildFeatureTemplateQuery 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(FeatureTemplateTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::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 ChildFeatureTemplateQuery 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(FeatureTemplateTableMap::FEATURE_ID, $featureId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($featureId['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::FEATURE_ID, $featureId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::FEATURE_ID, $featureId, $comparison); + } + + /** + * Filter the query on the template_id column + * + * Example usage: + * + * $query->filterByTemplateId(1234); // WHERE template_id = 1234 + * $query->filterByTemplateId(array(12, 34)); // WHERE template_id IN (12, 34) + * $query->filterByTemplateId(array('min' => 12)); // WHERE template_id > 12 + * + * + * @see filterByTemplate() + * + * @param mixed $templateId 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 ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByTemplateId($templateId = null, $comparison = null) + { + if (is_array($templateId)) { + $useMinMax = false; + if (isset($templateId['min'])) { + $this->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $templateId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($templateId['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $templateId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $templateId, $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 ChildFeatureTemplateQuery 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(FeatureTemplateTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::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 ChildFeatureTemplateQuery 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(FeatureTemplateTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(FeatureTemplateTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FeatureTemplateTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * 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 ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByFeature($feature, $comparison = null) + { + if ($feature instanceof \Thelia\Model\Feature) { + return $this + ->addUsingAlias(FeatureTemplateTableMap::FEATURE_ID, $feature->getId(), $comparison); + } elseif ($feature instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(FeatureTemplateTableMap::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 ChildFeatureTemplateQuery 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'); + } + + /** + * Filter the query by a related \Thelia\Model\Template object + * + * @param \Thelia\Model\Template|ObjectCollection $template The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function filterByTemplate($template, $comparison = null) + { + if ($template instanceof \Thelia\Model\Template) { + return $this + ->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $template->getId(), $comparison); + } elseif ($template instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(FeatureTemplateTableMap::TEMPLATE_ID, $template->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByTemplate() only accepts arguments of type \Thelia\Model\Template or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Template relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function joinTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Template'); + + // 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, 'Template'); + } + + return $this; + } + + /** + * Use the Template relation Template 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\TemplateQuery A secondary query class using the current class as primary query + */ + public function useTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Template', '\Thelia\Model\TemplateQuery'); + } + + /** + * Exclude object from result + * + * @param ChildFeatureTemplate $featureTemplate Object to remove from the list of results + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function prune($featureTemplate = null) + { + if ($featureTemplate) { + $this->addUsingAlias(FeatureTemplateTableMap::ID, $featureTemplate->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the feature_template 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(FeatureTemplateTableMap::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). + FeatureTemplateTableMap::clearInstancePool(); + FeatureTemplateTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildFeatureTemplate or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildFeatureTemplate 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(FeatureTemplateTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(FeatureTemplateTableMap::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(); + + + FeatureTemplateTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + FeatureTemplateTableMap::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 ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(FeatureTemplateTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(FeatureTemplateTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(FeatureTemplateTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(FeatureTemplateTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(FeatureTemplateTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildFeatureTemplateQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(FeatureTemplateTableMap::CREATED_AT); + } + +} // FeatureTemplateQuery diff --git a/core/lib/Thelia/Model/Base/Product.php b/core/lib/Thelia/Model/Base/Product.php index f7457d47b..9ec203fec 100644 --- a/core/lib/Thelia/Model/Base/Product.php +++ b/core/lib/Thelia/Model/Base/Product.php @@ -43,6 +43,8 @@ use Thelia\Model\ProductVersion as ChildProductVersion; use Thelia\Model\ProductVersionQuery as ChildProductVersionQuery; use Thelia\Model\TaxRule as ChildTaxRule; use Thelia\Model\TaxRuleQuery as ChildTaxRuleQuery; +use Thelia\Model\Template as ChildTemplate; +use Thelia\Model\TemplateQuery as ChildTemplateQuery; use Thelia\Model\Map\ProductTableMap; use Thelia\Model\Map\ProductVersionTableMap; @@ -111,6 +113,12 @@ abstract class Product implements ActiveRecordInterface */ protected $position; + /** + * The value for the template_id field. + * @var int + */ + protected $template_id; + /** * The value for the created_at field. * @var string @@ -147,6 +155,11 @@ abstract class Product implements ActiveRecordInterface */ protected $aTaxRule; + /** + * @var Template + */ + protected $aTemplate; + /** * @var ObjectCollection|ChildProductCategory[] Collection to store aggregation of ChildProductCategory objects. */ @@ -665,6 +678,17 @@ abstract class Product implements ActiveRecordInterface return $this->position; } + /** + * Get the [template_id] column value. + * + * @return int + */ + public function getTemplateId() + { + + return $this->template_id; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -856,6 +880,31 @@ abstract class Product implements ActiveRecordInterface return $this; } // setPosition() + /** + * Set the value of [template_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Product The current object (for fluent API support) + */ + public function setTemplateId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->template_id !== $v) { + $this->template_id = $v; + $this->modifiedColumns[] = ProductTableMap::TEMPLATE_ID; + } + + if ($this->aTemplate !== null && $this->aTemplate->getId() !== $v) { + $this->aTemplate = null; + } + + + return $this; + } // setTemplateId() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -1021,28 +1070,31 @@ abstract class Product implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->template_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductTableMap::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 ? 6 + $startcol : ProductTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductTableMap::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; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; $this->version = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : ProductTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; $this->version_created_by = (null !== $col) ? (string) $col : null; $this->resetModified(); @@ -1052,7 +1104,7 @@ abstract class Product implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 10; // 10 = ProductTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 11; // 11 = ProductTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Product object", 0, $e); @@ -1077,6 +1129,9 @@ abstract class Product implements ActiveRecordInterface if ($this->aTaxRule !== null && $this->tax_rule_id !== $this->aTaxRule->getId()) { $this->aTaxRule = null; } + if ($this->aTemplate !== null && $this->template_id !== $this->aTemplate->getId()) { + $this->aTemplate = null; + } } // ensureConsistency /** @@ -1117,6 +1172,7 @@ abstract class Product implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? $this->aTaxRule = null; + $this->aTemplate = null; $this->collProductCategories = null; $this->collFeatureProducts = null; @@ -1288,6 +1344,13 @@ abstract class Product implements ActiveRecordInterface $this->setTaxRule($this->aTaxRule); } + if ($this->aTemplate !== null) { + if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) { + $affectedRows += $this->aTemplate->save($con); + } + $this->setTemplate($this->aTemplate); + } + if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { @@ -1608,6 +1671,9 @@ abstract class Product implements ActiveRecordInterface if ($this->isColumnModified(ProductTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = 'POSITION'; } + if ($this->isColumnModified(ProductTableMap::TEMPLATE_ID)) { + $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; + } if ($this->isColumnModified(ProductTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1649,6 +1715,9 @@ abstract class Product implements ActiveRecordInterface case 'POSITION': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); break; + case 'TEMPLATE_ID': + $stmt->bindValue($identifier, $this->template_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; @@ -1742,18 +1811,21 @@ abstract class Product implements ActiveRecordInterface return $this->getPosition(); break; case 5: - return $this->getCreatedAt(); + return $this->getTemplateId(); break; case 6: - return $this->getUpdatedAt(); + return $this->getCreatedAt(); break; case 7: - return $this->getVersion(); + return $this->getUpdatedAt(); break; case 8: - return $this->getVersionCreatedAt(); + return $this->getVersion(); break; case 9: + return $this->getVersionCreatedAt(); + break; + case 10: return $this->getVersionCreatedBy(); break; default: @@ -1790,11 +1862,12 @@ abstract class Product implements ActiveRecordInterface $keys[2] => $this->getRef(), $keys[3] => $this->getVisible(), $keys[4] => $this->getPosition(), - $keys[5] => $this->getCreatedAt(), - $keys[6] => $this->getUpdatedAt(), - $keys[7] => $this->getVersion(), - $keys[8] => $this->getVersionCreatedAt(), - $keys[9] => $this->getVersionCreatedBy(), + $keys[5] => $this->getTemplateId(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), + $keys[8] => $this->getVersion(), + $keys[9] => $this->getVersionCreatedAt(), + $keys[10] => $this->getVersionCreatedBy(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1806,6 +1879,9 @@ abstract class Product implements ActiveRecordInterface if (null !== $this->aTaxRule) { $result['TaxRule'] = $this->aTaxRule->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } + if (null !== $this->aTemplate) { + $result['Template'] = $this->aTemplate->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } if (null !== $this->collProductCategories) { $result['ProductCategories'] = $this->collProductCategories->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -1889,18 +1965,21 @@ abstract class Product implements ActiveRecordInterface $this->setPosition($value); break; case 5: - $this->setCreatedAt($value); + $this->setTemplateId($value); break; case 6: - $this->setUpdatedAt($value); + $this->setCreatedAt($value); break; case 7: - $this->setVersion($value); + $this->setUpdatedAt($value); break; case 8: - $this->setVersionCreatedAt($value); + $this->setVersion($value); break; case 9: + $this->setVersionCreatedAt($value); + break; + case 10: $this->setVersionCreatedBy($value); break; } // switch() @@ -1932,11 +2011,12 @@ abstract class Product implements ActiveRecordInterface if (array_key_exists($keys[2], $arr)) $this->setRef($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setVisible($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setPosition($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setVersion($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setVersionCreatedAt($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setVersionCreatedBy($arr[$keys[9]]); + if (array_key_exists($keys[5], $arr)) $this->setTemplateId($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setVersion($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setVersionCreatedAt($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setVersionCreatedBy($arr[$keys[10]]); } /** @@ -1953,6 +2033,7 @@ abstract class Product implements ActiveRecordInterface if ($this->isColumnModified(ProductTableMap::REF)) $criteria->add(ProductTableMap::REF, $this->ref); if ($this->isColumnModified(ProductTableMap::VISIBLE)) $criteria->add(ProductTableMap::VISIBLE, $this->visible); if ($this->isColumnModified(ProductTableMap::POSITION)) $criteria->add(ProductTableMap::POSITION, $this->position); + if ($this->isColumnModified(ProductTableMap::TEMPLATE_ID)) $criteria->add(ProductTableMap::TEMPLATE_ID, $this->template_id); if ($this->isColumnModified(ProductTableMap::CREATED_AT)) $criteria->add(ProductTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ProductTableMap::UPDATED_AT)) $criteria->add(ProductTableMap::UPDATED_AT, $this->updated_at); if ($this->isColumnModified(ProductTableMap::VERSION)) $criteria->add(ProductTableMap::VERSION, $this->version); @@ -2025,6 +2106,7 @@ abstract class Product implements ActiveRecordInterface $copyObj->setRef($this->getRef()); $copyObj->setVisible($this->getVisible()); $copyObj->setPosition($this->getPosition()); + $copyObj->setTemplateId($this->getTemplateId()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); $copyObj->setVersion($this->getVersion()); @@ -2183,6 +2265,57 @@ abstract class Product implements ActiveRecordInterface return $this->aTaxRule; } + /** + * Declares an association between this object and a ChildTemplate object. + * + * @param ChildTemplate $v + * @return \Thelia\Model\Product The current object (for fluent API support) + * @throws PropelException + */ + public function setTemplate(ChildTemplate $v = null) + { + if ($v === null) { + $this->setTemplateId(NULL); + } else { + $this->setTemplateId($v->getId()); + } + + $this->aTemplate = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildTemplate object, it will not be re-added. + if ($v !== null) { + $v->addProduct($this); + } + + + return $this; + } + + + /** + * Get the associated ChildTemplate object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildTemplate The associated ChildTemplate object. + * @throws PropelException + */ + public function getTemplate(ConnectionInterface $con = null) + { + if ($this->aTemplate === null && ($this->template_id !== null)) { + $this->aTemplate = ChildTemplateQuery::create()->findPk($this->template_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->aTemplate->addProducts($this); + */ + } + + return $this->aTemplate; + } + /** * Initializes a collection based on the name of a relation. @@ -5349,6 +5482,7 @@ abstract class Product implements ActiveRecordInterface $this->ref = null; $this->visible = null; $this->position = null; + $this->template_id = null; $this->created_at = null; $this->updated_at = null; $this->version = null; @@ -5507,6 +5641,7 @@ abstract class Product implements ActiveRecordInterface } $this->collProductsRelatedByProductId = null; $this->aTaxRule = null; + $this->aTemplate = null; } /** @@ -5781,6 +5916,7 @@ abstract class Product implements ActiveRecordInterface $version->setRef($this->getRef()); $version->setVisible($this->getVisible()); $version->setPosition($this->getPosition()); + $version->setTemplateId($this->getTemplateId()); $version->setCreatedAt($this->getCreatedAt()); $version->setUpdatedAt($this->getUpdatedAt()); $version->setVersion($this->getVersion()); @@ -5828,6 +5964,7 @@ abstract class Product implements ActiveRecordInterface $this->setRef($version->getRef()); $this->setVisible($version->getVisible()); $this->setPosition($version->getPosition()); + $this->setTemplateId($version->getTemplateId()); $this->setCreatedAt($version->getCreatedAt()); $this->setUpdatedAt($version->getUpdatedAt()); $this->setVersion($version->getVersion()); diff --git a/core/lib/Thelia/Model/Base/ProductQuery.php b/core/lib/Thelia/Model/Base/ProductQuery.php index 75f05dfcf..9b1710f03 100644 --- a/core/lib/Thelia/Model/Base/ProductQuery.php +++ b/core/lib/Thelia/Model/Base/ProductQuery.php @@ -27,6 +27,7 @@ use Thelia\Model\Map\ProductTableMap; * @method ChildProductQuery orderByRef($order = Criteria::ASC) Order by the ref column * @method ChildProductQuery orderByVisible($order = Criteria::ASC) Order by the visible column * @method ChildProductQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildProductQuery orderByTemplateId($order = Criteria::ASC) Order by the template_id column * @method ChildProductQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildProductQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @method ChildProductQuery orderByVersion($order = Criteria::ASC) Order by the version column @@ -38,6 +39,7 @@ use Thelia\Model\Map\ProductTableMap; * @method ChildProductQuery groupByRef() Group by the ref column * @method ChildProductQuery groupByVisible() Group by the visible column * @method ChildProductQuery groupByPosition() Group by the position column + * @method ChildProductQuery groupByTemplateId() Group by the template_id column * @method ChildProductQuery groupByCreatedAt() Group by the created_at column * @method ChildProductQuery groupByUpdatedAt() Group by the updated_at column * @method ChildProductQuery groupByVersion() Group by the version column @@ -52,6 +54,10 @@ use Thelia\Model\Map\ProductTableMap; * @method ChildProductQuery rightJoinTaxRule($relationAlias = null) Adds a RIGHT JOIN clause to the query using the TaxRule relation * @method ChildProductQuery innerJoinTaxRule($relationAlias = null) Adds a INNER JOIN clause to the query using the TaxRule relation * + * @method ChildProductQuery leftJoinTemplate($relationAlias = null) Adds a LEFT JOIN clause to the query using the Template relation + * @method ChildProductQuery rightJoinTemplate($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Template relation + * @method ChildProductQuery innerJoinTemplate($relationAlias = null) Adds a INNER JOIN clause to the query using the Template relation + * * @method ChildProductQuery leftJoinProductCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ProductCategory relation * @method ChildProductQuery rightJoinProductCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProductCategory relation * @method ChildProductQuery innerJoinProductCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ProductCategory relation @@ -104,6 +110,7 @@ use Thelia\Model\Map\ProductTableMap; * @method ChildProduct findOneByRef(string $ref) Return the first ChildProduct filtered by the ref column * @method ChildProduct findOneByVisible(int $visible) Return the first ChildProduct filtered by the visible column * @method ChildProduct findOneByPosition(int $position) Return the first ChildProduct filtered by the position column + * @method ChildProduct findOneByTemplateId(int $template_id) Return the first ChildProduct filtered by the template_id column * @method ChildProduct findOneByCreatedAt(string $created_at) Return the first ChildProduct filtered by the created_at column * @method ChildProduct findOneByUpdatedAt(string $updated_at) Return the first ChildProduct filtered by the updated_at column * @method ChildProduct findOneByVersion(int $version) Return the first ChildProduct filtered by the version column @@ -115,6 +122,7 @@ use Thelia\Model\Map\ProductTableMap; * @method array findByRef(string $ref) Return ChildProduct objects filtered by the ref column * @method array findByVisible(int $visible) Return ChildProduct objects filtered by the visible column * @method array findByPosition(int $position) Return ChildProduct objects filtered by the position column + * @method array findByTemplateId(int $template_id) Return ChildProduct objects filtered by the template_id column * @method array findByCreatedAt(string $created_at) Return ChildProduct objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildProduct objects filtered by the updated_at column * @method array findByVersion(int $version) Return ChildProduct objects filtered by the version column @@ -215,7 +223,7 @@ abstract class ProductQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, TAX_RULE_ID, REF, VISIBLE, POSITION, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY FROM product WHERE ID = :p0'; + $sql = 'SELECT ID, TAX_RULE_ID, REF, VISIBLE, POSITION, TEMPLATE_ID, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY FROM product WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -499,6 +507,49 @@ abstract class ProductQuery extends ModelCriteria return $this->addUsingAlias(ProductTableMap::POSITION, $position, $comparison); } + /** + * Filter the query on the template_id column + * + * Example usage: + * + * $query->filterByTemplateId(1234); // WHERE template_id = 1234 + * $query->filterByTemplateId(array(12, 34)); // WHERE template_id IN (12, 34) + * $query->filterByTemplateId(array('min' => 12)); // WHERE template_id > 12 + * + * + * @see filterByTemplate() + * + * @param mixed $templateId 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 ChildProductQuery The current query, for fluid interface + */ + public function filterByTemplateId($templateId = null, $comparison = null) + { + if (is_array($templateId)) { + $useMinMax = false; + if (isset($templateId['min'])) { + $this->addUsingAlias(ProductTableMap::TEMPLATE_ID, $templateId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($templateId['max'])) { + $this->addUsingAlias(ProductTableMap::TEMPLATE_ID, $templateId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ProductTableMap::TEMPLATE_ID, $templateId, $comparison); + } + /** * Filter the query on the created_at column * @@ -773,6 +824,81 @@ abstract class ProductQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'TaxRule', '\Thelia\Model\TaxRuleQuery'); } + /** + * Filter the query by a related \Thelia\Model\Template object + * + * @param \Thelia\Model\Template|ObjectCollection $template The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildProductQuery The current query, for fluid interface + */ + public function filterByTemplate($template, $comparison = null) + { + if ($template instanceof \Thelia\Model\Template) { + return $this + ->addUsingAlias(ProductTableMap::TEMPLATE_ID, $template->getId(), $comparison); + } elseif ($template instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ProductTableMap::TEMPLATE_ID, $template->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByTemplate() only accepts arguments of type \Thelia\Model\Template or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Template relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildProductQuery The current query, for fluid interface + */ + public function joinTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Template'); + + // 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, 'Template'); + } + + return $this; + } + + /** + * Use the Template relation Template 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\TemplateQuery A secondary query class using the current class as primary query + */ + public function useTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Template', '\Thelia\Model\TemplateQuery'); + } + /** * Filter the query by a related \Thelia\Model\ProductCategory object * diff --git a/core/lib/Thelia/Model/Base/ProductVersion.php b/core/lib/Thelia/Model/Base/ProductVersion.php index 071dfc742..a5d22e498 100644 --- a/core/lib/Thelia/Model/Base/ProductVersion.php +++ b/core/lib/Thelia/Model/Base/ProductVersion.php @@ -86,6 +86,12 @@ abstract class ProductVersion implements ActiveRecordInterface */ protected $position; + /** + * The value for the template_id field. + * @var int + */ + protected $template_id; + /** * The value for the created_at field. * @var string @@ -453,6 +459,17 @@ abstract class ProductVersion implements ActiveRecordInterface return $this->position; } + /** + * Get the [template_id] column value. + * + * @return int + */ + public function getTemplateId() + { + + return $this->template_id; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -644,6 +661,27 @@ abstract class ProductVersion implements ActiveRecordInterface return $this; } // setPosition() + /** + * Set the value of [template_id] column. + * + * @param int $v new value + * @return \Thelia\Model\ProductVersion The current object (for fluent API support) + */ + public function setTemplateId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->template_id !== $v) { + $this->template_id = $v; + $this->modifiedColumns[] = ProductVersionTableMap::TEMPLATE_ID; + } + + + return $this; + } // setTemplateId() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -809,28 +847,31 @@ abstract class ProductVersion implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductVersionTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductVersionTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductVersionTableMap::translateFieldName('TemplateId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->template_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductVersionTableMap::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 ? 6 + $startcol : ProductVersionTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductVersionTableMap::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; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; $this->version = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductVersionTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductVersionTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductVersionTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : ProductVersionTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; $this->version_created_by = (null !== $col) ? (string) $col : null; $this->resetModified(); @@ -840,7 +881,7 @@ abstract class ProductVersion implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 10; // 10 = ProductVersionTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 11; // 11 = ProductVersionTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\ProductVersion object", 0, $e); @@ -1076,6 +1117,9 @@ abstract class ProductVersion implements ActiveRecordInterface if ($this->isColumnModified(ProductVersionTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = 'POSITION'; } + if ($this->isColumnModified(ProductVersionTableMap::TEMPLATE_ID)) { + $modifiedColumns[':p' . $index++] = 'TEMPLATE_ID'; + } if ($this->isColumnModified(ProductVersionTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1117,6 +1161,9 @@ abstract class ProductVersion implements ActiveRecordInterface case 'POSITION': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); break; + case 'TEMPLATE_ID': + $stmt->bindValue($identifier, $this->template_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; @@ -1203,18 +1250,21 @@ abstract class ProductVersion implements ActiveRecordInterface return $this->getPosition(); break; case 5: - return $this->getCreatedAt(); + return $this->getTemplateId(); break; case 6: - return $this->getUpdatedAt(); + return $this->getCreatedAt(); break; case 7: - return $this->getVersion(); + return $this->getUpdatedAt(); break; case 8: - return $this->getVersionCreatedAt(); + return $this->getVersion(); break; case 9: + return $this->getVersionCreatedAt(); + break; + case 10: return $this->getVersionCreatedBy(); break; default: @@ -1251,11 +1301,12 @@ abstract class ProductVersion implements ActiveRecordInterface $keys[2] => $this->getRef(), $keys[3] => $this->getVisible(), $keys[4] => $this->getPosition(), - $keys[5] => $this->getCreatedAt(), - $keys[6] => $this->getUpdatedAt(), - $keys[7] => $this->getVersion(), - $keys[8] => $this->getVersionCreatedAt(), - $keys[9] => $this->getVersionCreatedBy(), + $keys[5] => $this->getTemplateId(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), + $keys[8] => $this->getVersion(), + $keys[9] => $this->getVersionCreatedAt(), + $keys[10] => $this->getVersionCreatedBy(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1317,18 +1368,21 @@ abstract class ProductVersion implements ActiveRecordInterface $this->setPosition($value); break; case 5: - $this->setCreatedAt($value); + $this->setTemplateId($value); break; case 6: - $this->setUpdatedAt($value); + $this->setCreatedAt($value); break; case 7: - $this->setVersion($value); + $this->setUpdatedAt($value); break; case 8: - $this->setVersionCreatedAt($value); + $this->setVersion($value); break; case 9: + $this->setVersionCreatedAt($value); + break; + case 10: $this->setVersionCreatedBy($value); break; } // switch() @@ -1360,11 +1414,12 @@ abstract class ProductVersion implements ActiveRecordInterface if (array_key_exists($keys[2], $arr)) $this->setRef($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setVisible($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setPosition($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setVersion($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setVersionCreatedAt($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setVersionCreatedBy($arr[$keys[9]]); + if (array_key_exists($keys[5], $arr)) $this->setTemplateId($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setVersion($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setVersionCreatedAt($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setVersionCreatedBy($arr[$keys[10]]); } /** @@ -1381,6 +1436,7 @@ abstract class ProductVersion implements ActiveRecordInterface if ($this->isColumnModified(ProductVersionTableMap::REF)) $criteria->add(ProductVersionTableMap::REF, $this->ref); if ($this->isColumnModified(ProductVersionTableMap::VISIBLE)) $criteria->add(ProductVersionTableMap::VISIBLE, $this->visible); if ($this->isColumnModified(ProductVersionTableMap::POSITION)) $criteria->add(ProductVersionTableMap::POSITION, $this->position); + if ($this->isColumnModified(ProductVersionTableMap::TEMPLATE_ID)) $criteria->add(ProductVersionTableMap::TEMPLATE_ID, $this->template_id); if ($this->isColumnModified(ProductVersionTableMap::CREATED_AT)) $criteria->add(ProductVersionTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ProductVersionTableMap::UPDATED_AT)) $criteria->add(ProductVersionTableMap::UPDATED_AT, $this->updated_at); if ($this->isColumnModified(ProductVersionTableMap::VERSION)) $criteria->add(ProductVersionTableMap::VERSION, $this->version); @@ -1461,6 +1517,7 @@ abstract class ProductVersion implements ActiveRecordInterface $copyObj->setRef($this->getRef()); $copyObj->setVisible($this->getVisible()); $copyObj->setPosition($this->getPosition()); + $copyObj->setTemplateId($this->getTemplateId()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); $copyObj->setVersion($this->getVersion()); @@ -1554,6 +1611,7 @@ abstract class ProductVersion implements ActiveRecordInterface $this->ref = null; $this->visible = null; $this->position = null; + $this->template_id = null; $this->created_at = null; $this->updated_at = null; $this->version = null; diff --git a/core/lib/Thelia/Model/Base/ProductVersionQuery.php b/core/lib/Thelia/Model/Base/ProductVersionQuery.php index 1b43f7e66..b659becb9 100644 --- a/core/lib/Thelia/Model/Base/ProductVersionQuery.php +++ b/core/lib/Thelia/Model/Base/ProductVersionQuery.php @@ -26,6 +26,7 @@ use Thelia\Model\Map\ProductVersionTableMap; * @method ChildProductVersionQuery orderByRef($order = Criteria::ASC) Order by the ref column * @method ChildProductVersionQuery orderByVisible($order = Criteria::ASC) Order by the visible column * @method ChildProductVersionQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildProductVersionQuery orderByTemplateId($order = Criteria::ASC) Order by the template_id column * @method ChildProductVersionQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildProductVersionQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @method ChildProductVersionQuery orderByVersion($order = Criteria::ASC) Order by the version column @@ -37,6 +38,7 @@ use Thelia\Model\Map\ProductVersionTableMap; * @method ChildProductVersionQuery groupByRef() Group by the ref column * @method ChildProductVersionQuery groupByVisible() Group by the visible column * @method ChildProductVersionQuery groupByPosition() Group by the position column + * @method ChildProductVersionQuery groupByTemplateId() Group by the template_id column * @method ChildProductVersionQuery groupByCreatedAt() Group by the created_at column * @method ChildProductVersionQuery groupByUpdatedAt() Group by the updated_at column * @method ChildProductVersionQuery groupByVersion() Group by the version column @@ -59,6 +61,7 @@ use Thelia\Model\Map\ProductVersionTableMap; * @method ChildProductVersion findOneByRef(string $ref) Return the first ChildProductVersion filtered by the ref column * @method ChildProductVersion findOneByVisible(int $visible) Return the first ChildProductVersion filtered by the visible column * @method ChildProductVersion findOneByPosition(int $position) Return the first ChildProductVersion filtered by the position column + * @method ChildProductVersion findOneByTemplateId(int $template_id) Return the first ChildProductVersion filtered by the template_id column * @method ChildProductVersion findOneByCreatedAt(string $created_at) Return the first ChildProductVersion filtered by the created_at column * @method ChildProductVersion findOneByUpdatedAt(string $updated_at) Return the first ChildProductVersion filtered by the updated_at column * @method ChildProductVersion findOneByVersion(int $version) Return the first ChildProductVersion filtered by the version column @@ -70,6 +73,7 @@ use Thelia\Model\Map\ProductVersionTableMap; * @method array findByRef(string $ref) Return ChildProductVersion objects filtered by the ref column * @method array findByVisible(int $visible) Return ChildProductVersion objects filtered by the visible column * @method array findByPosition(int $position) Return ChildProductVersion objects filtered by the position column + * @method array findByTemplateId(int $template_id) Return ChildProductVersion objects filtered by the template_id column * @method array findByCreatedAt(string $created_at) Return ChildProductVersion objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildProductVersion objects filtered by the updated_at column * @method array findByVersion(int $version) Return ChildProductVersion objects filtered by the version column @@ -163,7 +167,7 @@ abstract class ProductVersionQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, TAX_RULE_ID, REF, VISIBLE, POSITION, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY FROM product_version WHERE ID = :p0 AND VERSION = :p1'; + $sql = 'SELECT ID, TAX_RULE_ID, REF, VISIBLE, POSITION, TEMPLATE_ID, CREATED_AT, UPDATED_AT, VERSION, VERSION_CREATED_AT, VERSION_CREATED_BY FROM product_version WHERE ID = :p0 AND VERSION = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -459,6 +463,47 @@ abstract class ProductVersionQuery extends ModelCriteria return $this->addUsingAlias(ProductVersionTableMap::POSITION, $position, $comparison); } + /** + * Filter the query on the template_id column + * + * Example usage: + * + * $query->filterByTemplateId(1234); // WHERE template_id = 1234 + * $query->filterByTemplateId(array(12, 34)); // WHERE template_id IN (12, 34) + * $query->filterByTemplateId(array('min' => 12)); // WHERE template_id > 12 + * + * + * @param mixed $templateId 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 ChildProductVersionQuery The current query, for fluid interface + */ + public function filterByTemplateId($templateId = null, $comparison = null) + { + if (is_array($templateId)) { + $useMinMax = false; + if (isset($templateId['min'])) { + $this->addUsingAlias(ProductVersionTableMap::TEMPLATE_ID, $templateId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($templateId['max'])) { + $this->addUsingAlias(ProductVersionTableMap::TEMPLATE_ID, $templateId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ProductVersionTableMap::TEMPLATE_ID, $templateId, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/TaxRule.php b/core/lib/Thelia/Model/Base/TaxRule.php index 61f21d4e1..9edb7b2fc 100644 --- a/core/lib/Thelia/Model/Base/TaxRule.php +++ b/core/lib/Thelia/Model/Base/TaxRule.php @@ -1434,6 +1434,31 @@ abstract class TaxRule implements ActiveRecordInterface return $this; } + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this TaxRule is new, it will return + * an empty collection; or if this TaxRule has previously + * been saved, it will retrieve related Products from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in TaxRule. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildProduct[] List of ChildProduct objects + */ + public function getProductsJoinTemplate($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildProductQuery::create(null, $criteria); + $query->joinWith('Template', $joinBehavior); + + return $this->getProducts($query, $con); + } + /** * Clears out the collTaxRuleCountries collection * diff --git a/core/lib/Thelia/Model/Base/Template.php b/core/lib/Thelia/Model/Base/Template.php new file mode 100644 index 000000000..77efa7ba0 --- /dev/null +++ b/core/lib/Thelia/Model/Base/Template.php @@ -0,0 +1,3019 @@ +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 Template instance. If + * obj is an instance of Template, delegates to + * equals(Template). 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 Template 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 Template 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 [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\Template 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[] = TemplateTableMap::ID; + } + + + return $this; + } // setId() + + /** + * 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\Template 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[] = TemplateTableMap::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\Template 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[] = TemplateTableMap::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 : TemplateTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : TemplateTableMap::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 ? 2 + $startcol : TemplateTableMap::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 + 3; // 3 = TemplateTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\Template 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() + { + } // 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(TemplateTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildTemplateQuery::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->collProducts = null; + + $this->collFeatureTemplates = null; + + $this->collAttributeTemplates = null; + + $this->collTemplateI18ns = null; + + $this->collFeatures = null; + $this->collAttributes = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Template::setDeleted() + * @see Template::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(TemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildTemplateQuery::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(TemplateTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(TemplateTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(TemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(TemplateTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + TemplateTableMap::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; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->featuresScheduledForDeletion !== null) { + if (!$this->featuresScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->featuresScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + + FeatureTemplateQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->featuresScheduledForDeletion = null; + } + + foreach ($this->getFeatures() as $feature) { + if ($feature->isModified()) { + $feature->save($con); + } + } + } elseif ($this->collFeatures) { + foreach ($this->collFeatures as $feature) { + if ($feature->isModified()) { + $feature->save($con); + } + } + } + + if ($this->attributesScheduledForDeletion !== null) { + if (!$this->attributesScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->attributesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + + AttributeTemplateQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->attributesScheduledForDeletion = null; + } + + foreach ($this->getAttributes() as $attribute) { + if ($attribute->isModified()) { + $attribute->save($con); + } + } + } elseif ($this->collAttributes) { + foreach ($this->collAttributes as $attribute) { + if ($attribute->isModified()) { + $attribute->save($con); + } + } + } + + if ($this->productsScheduledForDeletion !== null) { + if (!$this->productsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ProductQuery::create() + ->filterByPrimaryKeys($this->productsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->productsScheduledForDeletion = null; + } + } + + if ($this->collProducts !== null) { + foreach ($this->collProducts as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->featureTemplatesScheduledForDeletion !== null) { + if (!$this->featureTemplatesScheduledForDeletion->isEmpty()) { + \Thelia\Model\FeatureTemplateQuery::create() + ->filterByPrimaryKeys($this->featureTemplatesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->featureTemplatesScheduledForDeletion = null; + } + } + + if ($this->collFeatureTemplates !== null) { + foreach ($this->collFeatureTemplates as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->attributeTemplatesScheduledForDeletion !== null) { + if (!$this->attributeTemplatesScheduledForDeletion->isEmpty()) { + \Thelia\Model\AttributeTemplateQuery::create() + ->filterByPrimaryKeys($this->attributeTemplatesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->attributeTemplatesScheduledForDeletion = null; + } + } + + if ($this->collAttributeTemplates !== null) { + foreach ($this->collAttributeTemplates as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->templateI18nsScheduledForDeletion !== null) { + if (!$this->templateI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\TemplateI18nQuery::create() + ->filterByPrimaryKeys($this->templateI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->templateI18nsScheduledForDeletion = null; + } + } + + if ($this->collTemplateI18ns !== null) { + foreach ($this->collTemplateI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $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[] = TemplateTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . TemplateTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(TemplateTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(TemplateTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = 'CREATED_AT'; + } + if ($this->isColumnModified(TemplateTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; + } + + $sql = sprintf( + 'INSERT INTO template (%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 '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 = TemplateTableMap::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->getCreatedAt(); + break; + case 2: + 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['Template'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Template'][$this->getPrimaryKey()] = true; + $keys = TemplateTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getCreatedAt(), + $keys[2] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collProducts) { + $result['Products'] = $this->collProducts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collFeatureTemplates) { + $result['FeatureTemplates'] = $this->collFeatureTemplates->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collAttributeTemplates) { + $result['AttributeTemplates'] = $this->collAttributeTemplates->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collTemplateI18ns) { + $result['TemplateI18ns'] = $this->collTemplateI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + 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 = TemplateTableMap::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->setCreatedAt($value); + break; + case 2: + $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 = TemplateTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCreatedAt($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setUpdatedAt($arr[$keys[2]]); + } + + /** + * 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(TemplateTableMap::DATABASE_NAME); + + if ($this->isColumnModified(TemplateTableMap::ID)) $criteria->add(TemplateTableMap::ID, $this->id); + if ($this->isColumnModified(TemplateTableMap::CREATED_AT)) $criteria->add(TemplateTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(TemplateTableMap::UPDATED_AT)) $criteria->add(TemplateTableMap::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(TemplateTableMap::DATABASE_NAME); + $criteria->add(TemplateTableMap::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\Template (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->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getProducts() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addProduct($relObj->copy($deepCopy)); + } + } + + foreach ($this->getFeatureTemplates() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addFeatureTemplate($relObj->copy($deepCopy)); + } + } + + foreach ($this->getAttributeTemplates() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addAttributeTemplate($relObj->copy($deepCopy)); + } + } + + foreach ($this->getTemplateI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addTemplateI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + 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\Template 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; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('Product' == $relationName) { + return $this->initProducts(); + } + if ('FeatureTemplate' == $relationName) { + return $this->initFeatureTemplates(); + } + if ('AttributeTemplate' == $relationName) { + return $this->initAttributeTemplates(); + } + if ('TemplateI18n' == $relationName) { + return $this->initTemplateI18ns(); + } + } + + /** + * Clears out the collProducts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addProducts() + */ + public function clearProducts() + { + $this->collProducts = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collProducts collection loaded partially. + */ + public function resetPartialProducts($v = true) + { + $this->collProductsPartial = $v; + } + + /** + * Initializes the collProducts collection. + * + * By default this just sets the collProducts collection to an empty array (like clearcollProducts()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initProducts($overrideExisting = true) + { + if (null !== $this->collProducts && !$overrideExisting) { + return; + } + $this->collProducts = new ObjectCollection(); + $this->collProducts->setModel('\Thelia\Model\Product'); + } + + /** + * Gets an array of ChildProduct objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildProduct[] List of ChildProduct objects + * @throws PropelException + */ + public function getProducts($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collProductsPartial && !$this->isNew(); + if (null === $this->collProducts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collProducts) { + // return empty collection + $this->initProducts(); + } else { + $collProducts = ChildProductQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collProductsPartial && count($collProducts)) { + $this->initProducts(false); + + foreach ($collProducts as $obj) { + if (false == $this->collProducts->contains($obj)) { + $this->collProducts->append($obj); + } + } + + $this->collProductsPartial = true; + } + + $collProducts->getInternalIterator()->rewind(); + + return $collProducts; + } + + if ($partial && $this->collProducts) { + foreach ($this->collProducts as $obj) { + if ($obj->isNew()) { + $collProducts[] = $obj; + } + } + } + + $this->collProducts = $collProducts; + $this->collProductsPartial = false; + } + } + + return $this->collProducts; + } + + /** + * Sets a collection of Product objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $products A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setProducts(Collection $products, ConnectionInterface $con = null) + { + $productsToDelete = $this->getProducts(new Criteria(), $con)->diff($products); + + + $this->productsScheduledForDeletion = $productsToDelete; + + foreach ($productsToDelete as $productRemoved) { + $productRemoved->setTemplate(null); + } + + $this->collProducts = null; + foreach ($products as $product) { + $this->addProduct($product); + } + + $this->collProducts = $products; + $this->collProductsPartial = false; + + return $this; + } + + /** + * Returns the number of related Product objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Product objects. + * @throws PropelException + */ + public function countProducts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collProductsPartial && !$this->isNew(); + if (null === $this->collProducts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collProducts) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getProducts()); + } + + $query = ChildProductQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + + return count($this->collProducts); + } + + /** + * Method called to associate a ChildProduct object to this object + * through the ChildProduct foreign key attribute. + * + * @param ChildProduct $l ChildProduct + * @return \Thelia\Model\Template The current object (for fluent API support) + */ + public function addProduct(ChildProduct $l) + { + if ($this->collProducts === null) { + $this->initProducts(); + $this->collProductsPartial = true; + } + + if (!in_array($l, $this->collProducts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddProduct($l); + } + + return $this; + } + + /** + * @param Product $product The product object to add. + */ + protected function doAddProduct($product) + { + $this->collProducts[]= $product; + $product->setTemplate($this); + } + + /** + * @param Product $product The product object to remove. + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeProduct($product) + { + if ($this->getProducts()->contains($product)) { + $this->collProducts->remove($this->collProducts->search($product)); + if (null === $this->productsScheduledForDeletion) { + $this->productsScheduledForDeletion = clone $this->collProducts; + $this->productsScheduledForDeletion->clear(); + } + $this->productsScheduledForDeletion[]= clone $product; + $product->setTemplate(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Template is new, it will return + * an empty collection; or if this Template has previously + * been saved, it will retrieve related Products from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Template. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildProduct[] List of ChildProduct objects + */ + public function getProductsJoinTaxRule($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildProductQuery::create(null, $criteria); + $query->joinWith('TaxRule', $joinBehavior); + + return $this->getProducts($query, $con); + } + + /** + * Clears out the collFeatureTemplates collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addFeatureTemplates() + */ + public function clearFeatureTemplates() + { + $this->collFeatureTemplates = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collFeatureTemplates collection loaded partially. + */ + public function resetPartialFeatureTemplates($v = true) + { + $this->collFeatureTemplatesPartial = $v; + } + + /** + * Initializes the collFeatureTemplates collection. + * + * By default this just sets the collFeatureTemplates collection to an empty array (like clearcollFeatureTemplates()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initFeatureTemplates($overrideExisting = true) + { + if (null !== $this->collFeatureTemplates && !$overrideExisting) { + return; + } + $this->collFeatureTemplates = new ObjectCollection(); + $this->collFeatureTemplates->setModel('\Thelia\Model\FeatureTemplate'); + } + + /** + * Gets an array of ChildFeatureTemplate objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildFeatureTemplate[] List of ChildFeatureTemplate objects + * @throws PropelException + */ + public function getFeatureTemplates($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collFeatureTemplatesPartial && !$this->isNew(); + if (null === $this->collFeatureTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFeatureTemplates) { + // return empty collection + $this->initFeatureTemplates(); + } else { + $collFeatureTemplates = ChildFeatureTemplateQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collFeatureTemplatesPartial && count($collFeatureTemplates)) { + $this->initFeatureTemplates(false); + + foreach ($collFeatureTemplates as $obj) { + if (false == $this->collFeatureTemplates->contains($obj)) { + $this->collFeatureTemplates->append($obj); + } + } + + $this->collFeatureTemplatesPartial = true; + } + + $collFeatureTemplates->getInternalIterator()->rewind(); + + return $collFeatureTemplates; + } + + if ($partial && $this->collFeatureTemplates) { + foreach ($this->collFeatureTemplates as $obj) { + if ($obj->isNew()) { + $collFeatureTemplates[] = $obj; + } + } + } + + $this->collFeatureTemplates = $collFeatureTemplates; + $this->collFeatureTemplatesPartial = false; + } + } + + return $this->collFeatureTemplates; + } + + /** + * Sets a collection of FeatureTemplate objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $featureTemplates A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setFeatureTemplates(Collection $featureTemplates, ConnectionInterface $con = null) + { + $featureTemplatesToDelete = $this->getFeatureTemplates(new Criteria(), $con)->diff($featureTemplates); + + + $this->featureTemplatesScheduledForDeletion = $featureTemplatesToDelete; + + foreach ($featureTemplatesToDelete as $featureTemplateRemoved) { + $featureTemplateRemoved->setTemplate(null); + } + + $this->collFeatureTemplates = null; + foreach ($featureTemplates as $featureTemplate) { + $this->addFeatureTemplate($featureTemplate); + } + + $this->collFeatureTemplates = $featureTemplates; + $this->collFeatureTemplatesPartial = false; + + return $this; + } + + /** + * Returns the number of related FeatureTemplate objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related FeatureTemplate objects. + * @throws PropelException + */ + public function countFeatureTemplates(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collFeatureTemplatesPartial && !$this->isNew(); + if (null === $this->collFeatureTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFeatureTemplates) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getFeatureTemplates()); + } + + $query = ChildFeatureTemplateQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + + return count($this->collFeatureTemplates); + } + + /** + * Method called to associate a ChildFeatureTemplate object to this object + * through the ChildFeatureTemplate foreign key attribute. + * + * @param ChildFeatureTemplate $l ChildFeatureTemplate + * @return \Thelia\Model\Template The current object (for fluent API support) + */ + public function addFeatureTemplate(ChildFeatureTemplate $l) + { + if ($this->collFeatureTemplates === null) { + $this->initFeatureTemplates(); + $this->collFeatureTemplatesPartial = true; + } + + if (!in_array($l, $this->collFeatureTemplates->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddFeatureTemplate($l); + } + + return $this; + } + + /** + * @param FeatureTemplate $featureTemplate The featureTemplate object to add. + */ + protected function doAddFeatureTemplate($featureTemplate) + { + $this->collFeatureTemplates[]= $featureTemplate; + $featureTemplate->setTemplate($this); + } + + /** + * @param FeatureTemplate $featureTemplate The featureTemplate object to remove. + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeFeatureTemplate($featureTemplate) + { + if ($this->getFeatureTemplates()->contains($featureTemplate)) { + $this->collFeatureTemplates->remove($this->collFeatureTemplates->search($featureTemplate)); + if (null === $this->featureTemplatesScheduledForDeletion) { + $this->featureTemplatesScheduledForDeletion = clone $this->collFeatureTemplates; + $this->featureTemplatesScheduledForDeletion->clear(); + } + $this->featureTemplatesScheduledForDeletion[]= clone $featureTemplate; + $featureTemplate->setTemplate(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Template is new, it will return + * an empty collection; or if this Template has previously + * been saved, it will retrieve related FeatureTemplates from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Template. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildFeatureTemplate[] List of ChildFeatureTemplate objects + */ + public function getFeatureTemplatesJoinFeature($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildFeatureTemplateQuery::create(null, $criteria); + $query->joinWith('Feature', $joinBehavior); + + return $this->getFeatureTemplates($query, $con); + } + + /** + * Clears out the collAttributeTemplates collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addAttributeTemplates() + */ + public function clearAttributeTemplates() + { + $this->collAttributeTemplates = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collAttributeTemplates collection loaded partially. + */ + public function resetPartialAttributeTemplates($v = true) + { + $this->collAttributeTemplatesPartial = $v; + } + + /** + * Initializes the collAttributeTemplates collection. + * + * By default this just sets the collAttributeTemplates collection to an empty array (like clearcollAttributeTemplates()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initAttributeTemplates($overrideExisting = true) + { + if (null !== $this->collAttributeTemplates && !$overrideExisting) { + return; + } + $this->collAttributeTemplates = new ObjectCollection(); + $this->collAttributeTemplates->setModel('\Thelia\Model\AttributeTemplate'); + } + + /** + * Gets an array of ChildAttributeTemplate objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildAttributeTemplate[] List of ChildAttributeTemplate objects + * @throws PropelException + */ + public function getAttributeTemplates($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collAttributeTemplatesPartial && !$this->isNew(); + if (null === $this->collAttributeTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAttributeTemplates) { + // return empty collection + $this->initAttributeTemplates(); + } else { + $collAttributeTemplates = ChildAttributeTemplateQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collAttributeTemplatesPartial && count($collAttributeTemplates)) { + $this->initAttributeTemplates(false); + + foreach ($collAttributeTemplates as $obj) { + if (false == $this->collAttributeTemplates->contains($obj)) { + $this->collAttributeTemplates->append($obj); + } + } + + $this->collAttributeTemplatesPartial = true; + } + + $collAttributeTemplates->getInternalIterator()->rewind(); + + return $collAttributeTemplates; + } + + if ($partial && $this->collAttributeTemplates) { + foreach ($this->collAttributeTemplates as $obj) { + if ($obj->isNew()) { + $collAttributeTemplates[] = $obj; + } + } + } + + $this->collAttributeTemplates = $collAttributeTemplates; + $this->collAttributeTemplatesPartial = false; + } + } + + return $this->collAttributeTemplates; + } + + /** + * Sets a collection of AttributeTemplate objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $attributeTemplates A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setAttributeTemplates(Collection $attributeTemplates, ConnectionInterface $con = null) + { + $attributeTemplatesToDelete = $this->getAttributeTemplates(new Criteria(), $con)->diff($attributeTemplates); + + + $this->attributeTemplatesScheduledForDeletion = $attributeTemplatesToDelete; + + foreach ($attributeTemplatesToDelete as $attributeTemplateRemoved) { + $attributeTemplateRemoved->setTemplate(null); + } + + $this->collAttributeTemplates = null; + foreach ($attributeTemplates as $attributeTemplate) { + $this->addAttributeTemplate($attributeTemplate); + } + + $this->collAttributeTemplates = $attributeTemplates; + $this->collAttributeTemplatesPartial = false; + + return $this; + } + + /** + * Returns the number of related AttributeTemplate objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related AttributeTemplate objects. + * @throws PropelException + */ + public function countAttributeTemplates(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collAttributeTemplatesPartial && !$this->isNew(); + if (null === $this->collAttributeTemplates || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAttributeTemplates) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getAttributeTemplates()); + } + + $query = ChildAttributeTemplateQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + + return count($this->collAttributeTemplates); + } + + /** + * Method called to associate a ChildAttributeTemplate object to this object + * through the ChildAttributeTemplate foreign key attribute. + * + * @param ChildAttributeTemplate $l ChildAttributeTemplate + * @return \Thelia\Model\Template The current object (for fluent API support) + */ + public function addAttributeTemplate(ChildAttributeTemplate $l) + { + if ($this->collAttributeTemplates === null) { + $this->initAttributeTemplates(); + $this->collAttributeTemplatesPartial = true; + } + + if (!in_array($l, $this->collAttributeTemplates->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddAttributeTemplate($l); + } + + return $this; + } + + /** + * @param AttributeTemplate $attributeTemplate The attributeTemplate object to add. + */ + protected function doAddAttributeTemplate($attributeTemplate) + { + $this->collAttributeTemplates[]= $attributeTemplate; + $attributeTemplate->setTemplate($this); + } + + /** + * @param AttributeTemplate $attributeTemplate The attributeTemplate object to remove. + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeAttributeTemplate($attributeTemplate) + { + if ($this->getAttributeTemplates()->contains($attributeTemplate)) { + $this->collAttributeTemplates->remove($this->collAttributeTemplates->search($attributeTemplate)); + if (null === $this->attributeTemplatesScheduledForDeletion) { + $this->attributeTemplatesScheduledForDeletion = clone $this->collAttributeTemplates; + $this->attributeTemplatesScheduledForDeletion->clear(); + } + $this->attributeTemplatesScheduledForDeletion[]= clone $attributeTemplate; + $attributeTemplate->setTemplate(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Template is new, it will return + * an empty collection; or if this Template has previously + * been saved, it will retrieve related AttributeTemplates from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Template. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildAttributeTemplate[] List of ChildAttributeTemplate objects + */ + public function getAttributeTemplatesJoinAttribute($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildAttributeTemplateQuery::create(null, $criteria); + $query->joinWith('Attribute', $joinBehavior); + + return $this->getAttributeTemplates($query, $con); + } + + /** + * Clears out the collTemplateI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addTemplateI18ns() + */ + public function clearTemplateI18ns() + { + $this->collTemplateI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collTemplateI18ns collection loaded partially. + */ + public function resetPartialTemplateI18ns($v = true) + { + $this->collTemplateI18nsPartial = $v; + } + + /** + * Initializes the collTemplateI18ns collection. + * + * By default this just sets the collTemplateI18ns collection to an empty array (like clearcollTemplateI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initTemplateI18ns($overrideExisting = true) + { + if (null !== $this->collTemplateI18ns && !$overrideExisting) { + return; + } + $this->collTemplateI18ns = new ObjectCollection(); + $this->collTemplateI18ns->setModel('\Thelia\Model\TemplateI18n'); + } + + /** + * Gets an array of ChildTemplateI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildTemplateI18n[] List of ChildTemplateI18n objects + * @throws PropelException + */ + public function getTemplateI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collTemplateI18nsPartial && !$this->isNew(); + if (null === $this->collTemplateI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collTemplateI18ns) { + // return empty collection + $this->initTemplateI18ns(); + } else { + $collTemplateI18ns = ChildTemplateI18nQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collTemplateI18nsPartial && count($collTemplateI18ns)) { + $this->initTemplateI18ns(false); + + foreach ($collTemplateI18ns as $obj) { + if (false == $this->collTemplateI18ns->contains($obj)) { + $this->collTemplateI18ns->append($obj); + } + } + + $this->collTemplateI18nsPartial = true; + } + + $collTemplateI18ns->getInternalIterator()->rewind(); + + return $collTemplateI18ns; + } + + if ($partial && $this->collTemplateI18ns) { + foreach ($this->collTemplateI18ns as $obj) { + if ($obj->isNew()) { + $collTemplateI18ns[] = $obj; + } + } + } + + $this->collTemplateI18ns = $collTemplateI18ns; + $this->collTemplateI18nsPartial = false; + } + } + + return $this->collTemplateI18ns; + } + + /** + * Sets a collection of TemplateI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $templateI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setTemplateI18ns(Collection $templateI18ns, ConnectionInterface $con = null) + { + $templateI18nsToDelete = $this->getTemplateI18ns(new Criteria(), $con)->diff($templateI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->templateI18nsScheduledForDeletion = clone $templateI18nsToDelete; + + foreach ($templateI18nsToDelete as $templateI18nRemoved) { + $templateI18nRemoved->setTemplate(null); + } + + $this->collTemplateI18ns = null; + foreach ($templateI18ns as $templateI18n) { + $this->addTemplateI18n($templateI18n); + } + + $this->collTemplateI18ns = $templateI18ns; + $this->collTemplateI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related TemplateI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related TemplateI18n objects. + * @throws PropelException + */ + public function countTemplateI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collTemplateI18nsPartial && !$this->isNew(); + if (null === $this->collTemplateI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collTemplateI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getTemplateI18ns()); + } + + $query = ChildTemplateI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + + return count($this->collTemplateI18ns); + } + + /** + * Method called to associate a ChildTemplateI18n object to this object + * through the ChildTemplateI18n foreign key attribute. + * + * @param ChildTemplateI18n $l ChildTemplateI18n + * @return \Thelia\Model\Template The current object (for fluent API support) + */ + public function addTemplateI18n(ChildTemplateI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collTemplateI18ns === null) { + $this->initTemplateI18ns(); + $this->collTemplateI18nsPartial = true; + } + + if (!in_array($l, $this->collTemplateI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddTemplateI18n($l); + } + + return $this; + } + + /** + * @param TemplateI18n $templateI18n The templateI18n object to add. + */ + protected function doAddTemplateI18n($templateI18n) + { + $this->collTemplateI18ns[]= $templateI18n; + $templateI18n->setTemplate($this); + } + + /** + * @param TemplateI18n $templateI18n The templateI18n object to remove. + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeTemplateI18n($templateI18n) + { + if ($this->getTemplateI18ns()->contains($templateI18n)) { + $this->collTemplateI18ns->remove($this->collTemplateI18ns->search($templateI18n)); + if (null === $this->templateI18nsScheduledForDeletion) { + $this->templateI18nsScheduledForDeletion = clone $this->collTemplateI18ns; + $this->templateI18nsScheduledForDeletion->clear(); + } + $this->templateI18nsScheduledForDeletion[]= clone $templateI18n; + $templateI18n->setTemplate(null); + } + + return $this; + } + + /** + * Clears out the collFeatures collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addFeatures() + */ + public function clearFeatures() + { + $this->collFeatures = null; // important to set this to NULL since that means it is uninitialized + $this->collFeaturesPartial = null; + } + + /** + * Initializes the collFeatures collection. + * + * By default this just sets the collFeatures collection to an empty collection (like clearFeatures()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @return void + */ + public function initFeatures() + { + $this->collFeatures = new ObjectCollection(); + $this->collFeatures->setModel('\Thelia\Model\Feature'); + } + + /** + * Gets a collection of ChildFeature objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildFeature[] List of ChildFeature objects + */ + public function getFeatures($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collFeatures || null !== $criteria) { + if ($this->isNew() && null === $this->collFeatures) { + // return empty collection + $this->initFeatures(); + } else { + $collFeatures = ChildFeatureQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + if (null !== $criteria) { + return $collFeatures; + } + $this->collFeatures = $collFeatures; + } + } + + return $this->collFeatures; + } + + /** + * Sets a collection of Feature objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $features A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setFeatures(Collection $features, ConnectionInterface $con = null) + { + $this->clearFeatures(); + $currentFeatures = $this->getFeatures(); + + $this->featuresScheduledForDeletion = $currentFeatures->diff($features); + + foreach ($features as $feature) { + if (!$currentFeatures->contains($feature)) { + $this->doAddFeature($feature); + } + } + + $this->collFeatures = $features; + + return $this; + } + + /** + * Gets the number of ChildFeature objects related by a many-to-many relationship + * to the current object by way of the feature_template cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildFeature objects + */ + public function countFeatures($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collFeatures || null !== $criteria) { + if ($this->isNew() && null === $this->collFeatures) { + return 0; + } else { + $query = ChildFeatureQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + } else { + return count($this->collFeatures); + } + } + + /** + * Associate a ChildFeature object to this object + * through the feature_template cross reference table. + * + * @param ChildFeature $feature The ChildFeatureTemplate object to relate + * @return ChildTemplate The current object (for fluent API support) + */ + public function addFeature(ChildFeature $feature) + { + if ($this->collFeatures === null) { + $this->initFeatures(); + } + + if (!$this->collFeatures->contains($feature)) { // only add it if the **same** object is not already associated + $this->doAddFeature($feature); + $this->collFeatures[] = $feature; + } + + return $this; + } + + /** + * @param Feature $feature The feature object to add. + */ + protected function doAddFeature($feature) + { + $featureTemplate = new ChildFeatureTemplate(); + $featureTemplate->setFeature($feature); + $this->addFeatureTemplate($featureTemplate); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$feature->getTemplates()->contains($this)) { + $foreignCollection = $feature->getTemplates(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildFeature object to this object + * through the feature_template cross reference table. + * + * @param ChildFeature $feature The ChildFeatureTemplate object to relate + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeFeature(ChildFeature $feature) + { + if ($this->getFeatures()->contains($feature)) { + $this->collFeatures->remove($this->collFeatures->search($feature)); + + if (null === $this->featuresScheduledForDeletion) { + $this->featuresScheduledForDeletion = clone $this->collFeatures; + $this->featuresScheduledForDeletion->clear(); + } + + $this->featuresScheduledForDeletion[] = $feature; + } + + return $this; + } + + /** + * Clears out the collAttributes collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addAttributes() + */ + public function clearAttributes() + { + $this->collAttributes = null; // important to set this to NULL since that means it is uninitialized + $this->collAttributesPartial = null; + } + + /** + * Initializes the collAttributes collection. + * + * By default this just sets the collAttributes collection to an empty collection (like clearAttributes()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @return void + */ + public function initAttributes() + { + $this->collAttributes = new ObjectCollection(); + $this->collAttributes->setModel('\Thelia\Model\Attribute'); + } + + /** + * Gets a collection of ChildAttribute objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildTemplate is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildAttribute[] List of ChildAttribute objects + */ + public function getAttributes($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collAttributes || null !== $criteria) { + if ($this->isNew() && null === $this->collAttributes) { + // return empty collection + $this->initAttributes(); + } else { + $collAttributes = ChildAttributeQuery::create(null, $criteria) + ->filterByTemplate($this) + ->find($con); + if (null !== $criteria) { + return $collAttributes; + } + $this->collAttributes = $collAttributes; + } + } + + return $this->collAttributes; + } + + /** + * Sets a collection of Attribute objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $attributes A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildTemplate The current object (for fluent API support) + */ + public function setAttributes(Collection $attributes, ConnectionInterface $con = null) + { + $this->clearAttributes(); + $currentAttributes = $this->getAttributes(); + + $this->attributesScheduledForDeletion = $currentAttributes->diff($attributes); + + foreach ($attributes as $attribute) { + if (!$currentAttributes->contains($attribute)) { + $this->doAddAttribute($attribute); + } + } + + $this->collAttributes = $attributes; + + return $this; + } + + /** + * Gets the number of ChildAttribute objects related by a many-to-many relationship + * to the current object by way of the attribute_template cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildAttribute objects + */ + public function countAttributes($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collAttributes || null !== $criteria) { + if ($this->isNew() && null === $this->collAttributes) { + return 0; + } else { + $query = ChildAttributeQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByTemplate($this) + ->count($con); + } + } else { + return count($this->collAttributes); + } + } + + /** + * Associate a ChildAttribute object to this object + * through the attribute_template cross reference table. + * + * @param ChildAttribute $attribute The ChildAttributeTemplate object to relate + * @return ChildTemplate The current object (for fluent API support) + */ + public function addAttribute(ChildAttribute $attribute) + { + if ($this->collAttributes === null) { + $this->initAttributes(); + } + + if (!$this->collAttributes->contains($attribute)) { // only add it if the **same** object is not already associated + $this->doAddAttribute($attribute); + $this->collAttributes[] = $attribute; + } + + return $this; + } + + /** + * @param Attribute $attribute The attribute object to add. + */ + protected function doAddAttribute($attribute) + { + $attributeTemplate = new ChildAttributeTemplate(); + $attributeTemplate->setAttribute($attribute); + $this->addAttributeTemplate($attributeTemplate); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$attribute->getTemplates()->contains($this)) { + $foreignCollection = $attribute->getTemplates(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildAttribute object to this object + * through the attribute_template cross reference table. + * + * @param ChildAttribute $attribute The ChildAttributeTemplate object to relate + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeAttribute(ChildAttribute $attribute) + { + if ($this->getAttributes()->contains($attribute)) { + $this->collAttributes->remove($this->collAttributes->search($attribute)); + + if (null === $this->attributesScheduledForDeletion) { + $this->attributesScheduledForDeletion = clone $this->collAttributes; + $this->attributesScheduledForDeletion->clear(); + } + + $this->attributesScheduledForDeletion[] = $attribute; + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->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 ($this->collProducts) { + foreach ($this->collProducts as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collFeatureTemplates) { + foreach ($this->collFeatureTemplates as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collAttributeTemplates) { + foreach ($this->collAttributeTemplates as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collTemplateI18ns) { + foreach ($this->collTemplateI18ns as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collFeatures) { + foreach ($this->collFeatures as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collAttributes) { + foreach ($this->collAttributes as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + if ($this->collProducts instanceof Collection) { + $this->collProducts->clearIterator(); + } + $this->collProducts = null; + if ($this->collFeatureTemplates instanceof Collection) { + $this->collFeatureTemplates->clearIterator(); + } + $this->collFeatureTemplates = null; + if ($this->collAttributeTemplates instanceof Collection) { + $this->collAttributeTemplates->clearIterator(); + } + $this->collAttributeTemplates = null; + if ($this->collTemplateI18ns instanceof Collection) { + $this->collTemplateI18ns->clearIterator(); + } + $this->collTemplateI18ns = null; + if ($this->collFeatures instanceof Collection) { + $this->collFeatures->clearIterator(); + } + $this->collFeatures = null; + if ($this->collAttributes instanceof Collection) { + $this->collAttributes->clearIterator(); + } + $this->collAttributes = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(TemplateTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildTemplate The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildTemplateI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collTemplateI18ns) { + foreach ($this->collTemplateI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildTemplateI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildTemplateI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addTemplateI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildTemplate The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildTemplateI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collTemplateI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collTemplateI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildTemplateI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->getCurrentTranslation()->getName(); + } + + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return \Thelia\Model\TemplateI18n The current object (for fluent API support) + */ + public function setName($v) + { $this->getCurrentTranslation()->setName($v); + + return $this; + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildTemplate The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[] = TemplateTableMap::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/TemplateI18n.php b/core/lib/Thelia/Model/Base/TemplateI18n.php new file mode 100644 index 000000000..7c61c6983 --- /dev/null +++ b/core/lib/Thelia/Model/Base/TemplateI18n.php @@ -0,0 +1,1265 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of Thelia\Model\Base\TemplateI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !empty($this->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 TemplateI18n instance. If + * obj is an instance of TemplateI18n, delegates to + * equals(TemplateI18n). 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 TemplateI18n 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 TemplateI18n 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 [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + + return $this->name; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\TemplateI18n 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[] = TemplateI18nTableMap::ID; + } + + if ($this->aTemplate !== null && $this->aTemplate->getId() !== $v) { + $this->aTemplate = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \Thelia\Model\TemplateI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[] = TemplateI18nTableMap::LOCALE; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return \Thelia\Model\TemplateI18n The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[] = TemplateI18nTableMap::NAME; + } + + + return $this; + } // setName() + + /** + * 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() + { + if ($this->locale !== 'en_US') { + return false; + } + + // 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 : TemplateI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : TemplateI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : TemplateI18nTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = TemplateI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\TemplateI18n 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->aTemplate !== null && $this->id !== $this->aTemplate->getId()) { + $this->aTemplate = 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(TemplateI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildTemplateI18nQuery::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->aTemplate = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see TemplateI18n::setDeleted() + * @see TemplateI18n::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(TemplateI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildTemplateI18nQuery::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(TemplateI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + TemplateI18nTableMap::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->aTemplate !== null) { + if ($this->aTemplate->isModified() || $this->aTemplate->isNew()) { + $affectedRows += $this->aTemplate->save($con); + } + $this->setTemplate($this->aTemplate); + } + + 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; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(TemplateI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(TemplateI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = 'LOCALE'; + } + if ($this->isColumnModified(TemplateI18nTableMap::NAME)) { + $modifiedColumns[':p' . $index++] = 'NAME'; + } + + $sql = sprintf( + 'INSERT INTO template_i18n (%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 'LOCALE': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case 'NAME': + $stmt->bindValue($identifier, $this->name, 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); + } + + $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 = TemplateI18nTableMap::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->getLocale(); + break; + case 2: + return $this->getName(); + 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['TemplateI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['TemplateI18n'][serialize($this->getPrimaryKey())] = true; + $keys = TemplateI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getName(), + ); + $virtualColumns = $this->virtualColumns; + foreach($virtualColumns as $key => $virtualColumn) + { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aTemplate) { + $result['Template'] = $this->aTemplate->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 = TemplateI18nTableMap::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->setLocale($value); + break; + case 2: + $this->setName($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 = TemplateI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]); + } + + /** + * 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(TemplateI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(TemplateI18nTableMap::ID)) $criteria->add(TemplateI18nTableMap::ID, $this->id); + if ($this->isColumnModified(TemplateI18nTableMap::LOCALE)) $criteria->add(TemplateI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(TemplateI18nTableMap::NAME)) $criteria->add(TemplateI18nTableMap::NAME, $this->name); + + 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(TemplateI18nTableMap::DATABASE_NAME); + $criteria->add(TemplateI18nTableMap::ID, $this->id); + $criteria->add(TemplateI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * 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\TemplateI18n (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->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setName($this->getName()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * 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\TemplateI18n 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 ChildTemplate object. + * + * @param ChildTemplate $v + * @return \Thelia\Model\TemplateI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setTemplate(ChildTemplate $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aTemplate = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildTemplate object, it will not be re-added. + if ($v !== null) { + $v->addTemplateI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildTemplate object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildTemplate The associated ChildTemplate object. + * @throws PropelException + */ + public function getTemplate(ConnectionInterface $con = null) + { + if ($this->aTemplate === null && ($this->id !== null)) { + $this->aTemplate = ChildTemplateQuery::create()->findPk($this->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->aTemplate->addTemplateI18ns($this); + */ + } + + return $this->aTemplate; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->name = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $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->aTemplate = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(TemplateI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * 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/TemplateI18nQuery.php b/core/lib/Thelia/Model/Base/TemplateI18nQuery.php new file mode 100644 index 000000000..12e7b7d1f --- /dev/null +++ b/core/lib/Thelia/Model/Base/TemplateI18nQuery.php @@ -0,0 +1,508 @@ +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(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildTemplateI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = TemplateI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(TemplateI18nTableMap::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 ChildTemplateI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, LOCALE, NAME FROM template_i18n WHERE ID = :p0 AND LOCALE = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $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 ChildTemplateI18n(); + $obj->hydrate($row); + TemplateI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $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 ChildTemplateI18n|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(array(12, 56), array(832, 123), array(123, 456)), $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 ChildTemplateI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(TemplateI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(TemplateI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(TemplateI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(TemplateI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * 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 + * + * + * @see filterByTemplate() + * + * @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 ChildTemplateI18nQuery 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(TemplateI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(TemplateI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(TemplateI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(TemplateI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $name)) { + $name = str_replace('*', '%', $name); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(TemplateI18nTableMap::NAME, $name, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Template object + * + * @param \Thelia\Model\Template|ObjectCollection $template The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function filterByTemplate($template, $comparison = null) + { + if ($template instanceof \Thelia\Model\Template) { + return $this + ->addUsingAlias(TemplateI18nTableMap::ID, $template->getId(), $comparison); + } elseif ($template instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(TemplateI18nTableMap::ID, $template->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByTemplate() only accepts arguments of type \Thelia\Model\Template or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Template relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function joinTemplate($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Template'); + + // 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, 'Template'); + } + + return $this; + } + + /** + * Use the Template relation Template 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\TemplateQuery A secondary query class using the current class as primary query + */ + public function useTemplateQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Template', '\Thelia\Model\TemplateQuery'); + } + + /** + * Exclude object from result + * + * @param ChildTemplateI18n $templateI18n Object to remove from the list of results + * + * @return ChildTemplateI18nQuery The current query, for fluid interface + */ + public function prune($templateI18n = null) + { + if ($templateI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(TemplateI18nTableMap::ID), $templateI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(TemplateI18nTableMap::LOCALE), $templateI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the template_i18n 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(TemplateI18nTableMap::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). + TemplateI18nTableMap::clearInstancePool(); + TemplateI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildTemplateI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildTemplateI18n 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(TemplateI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(TemplateI18nTableMap::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(); + + + TemplateI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + TemplateI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // TemplateI18nQuery diff --git a/core/lib/Thelia/Model/Base/TemplateQuery.php b/core/lib/Thelia/Model/Base/TemplateQuery.php new file mode 100644 index 000000000..506d7d943 --- /dev/null +++ b/core/lib/Thelia/Model/Base/TemplateQuery.php @@ -0,0 +1,907 @@ +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 ChildTemplate|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = TemplateTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(TemplateTableMap::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 ChildTemplate A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, CREATED_AT, UPDATED_AT FROM template 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 ChildTemplate(); + $obj->hydrate($row); + TemplateTableMap::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 ChildTemplate|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 ChildTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(TemplateTableMap::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 ChildTemplateQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(TemplateTableMap::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 ChildTemplateQuery 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(TemplateTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(TemplateTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(TemplateTableMap::ID, $id, $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 ChildTemplateQuery 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(TemplateTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(TemplateTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(TemplateTableMap::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 ChildTemplateQuery 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(TemplateTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(TemplateTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(TemplateTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Product object + * + * @param \Thelia\Model\Product|ObjectCollection $product the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByProduct($product, $comparison = null) + { + if ($product instanceof \Thelia\Model\Product) { + return $this + ->addUsingAlias(TemplateTableMap::ID, $product->getTemplateId(), $comparison); + } elseif ($product instanceof ObjectCollection) { + return $this + ->useProductQuery() + ->filterByPrimaryKeys($product->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByProduct() only accepts arguments of type \Thelia\Model\Product or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Product relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Product'); + + // 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, 'Product'); + } + + return $this; + } + + /** + * Use the Product relation Product 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\ProductQuery A secondary query class using the current class as primary query + */ + public function useProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinProduct($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Product', '\Thelia\Model\ProductQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\FeatureTemplate object + * + * @param \Thelia\Model\FeatureTemplate|ObjectCollection $featureTemplate the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByFeatureTemplate($featureTemplate, $comparison = null) + { + if ($featureTemplate instanceof \Thelia\Model\FeatureTemplate) { + return $this + ->addUsingAlias(TemplateTableMap::ID, $featureTemplate->getTemplateId(), $comparison); + } elseif ($featureTemplate instanceof ObjectCollection) { + return $this + ->useFeatureTemplateQuery() + ->filterByPrimaryKeys($featureTemplate->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByFeatureTemplate() only accepts arguments of type \Thelia\Model\FeatureTemplate or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the FeatureTemplate relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinFeatureTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('FeatureTemplate'); + + // 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, 'FeatureTemplate'); + } + + return $this; + } + + /** + * Use the FeatureTemplate relation FeatureTemplate 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\FeatureTemplateQuery A secondary query class using the current class as primary query + */ + public function useFeatureTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinFeatureTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'FeatureTemplate', '\Thelia\Model\FeatureTemplateQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\AttributeTemplate object + * + * @param \Thelia\Model\AttributeTemplate|ObjectCollection $attributeTemplate the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByAttributeTemplate($attributeTemplate, $comparison = null) + { + if ($attributeTemplate instanceof \Thelia\Model\AttributeTemplate) { + return $this + ->addUsingAlias(TemplateTableMap::ID, $attributeTemplate->getTemplateId(), $comparison); + } elseif ($attributeTemplate instanceof ObjectCollection) { + return $this + ->useAttributeTemplateQuery() + ->filterByPrimaryKeys($attributeTemplate->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByAttributeTemplate() only accepts arguments of type \Thelia\Model\AttributeTemplate or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the AttributeTemplate relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinAttributeTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('AttributeTemplate'); + + // 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, 'AttributeTemplate'); + } + + return $this; + } + + /** + * Use the AttributeTemplate relation AttributeTemplate 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\AttributeTemplateQuery A secondary query class using the current class as primary query + */ + public function useAttributeTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinAttributeTemplate($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'AttributeTemplate', '\Thelia\Model\AttributeTemplateQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\TemplateI18n object + * + * @param \Thelia\Model\TemplateI18n|ObjectCollection $templateI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByTemplateI18n($templateI18n, $comparison = null) + { + if ($templateI18n instanceof \Thelia\Model\TemplateI18n) { + return $this + ->addUsingAlias(TemplateTableMap::ID, $templateI18n->getId(), $comparison); + } elseif ($templateI18n instanceof ObjectCollection) { + return $this + ->useTemplateI18nQuery() + ->filterByPrimaryKeys($templateI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByTemplateI18n() only accepts arguments of type \Thelia\Model\TemplateI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the TemplateI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinTemplateI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('TemplateI18n'); + + // 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, 'TemplateI18n'); + } + + return $this; + } + + /** + * Use the TemplateI18n relation TemplateI18n 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\TemplateI18nQuery A secondary query class using the current class as primary query + */ + public function useTemplateI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinTemplateI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'TemplateI18n', '\Thelia\Model\TemplateI18nQuery'); + } + + /** + * Filter the query by a related Feature object + * using the feature_template table as cross reference + * + * @param Feature $feature the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByFeature($feature, $comparison = Criteria::EQUAL) + { + return $this + ->useFeatureTemplateQuery() + ->filterByFeature($feature, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Attribute object + * using the attribute_template table as cross reference + * + * @param Attribute $attribute the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function filterByAttribute($attribute, $comparison = Criteria::EQUAL) + { + return $this + ->useAttributeTemplateQuery() + ->filterByAttribute($attribute, $comparison) + ->endUse(); + } + + /** + * Exclude object from result + * + * @param ChildTemplate $template Object to remove from the list of results + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function prune($template = null) + { + if ($template) { + $this->addUsingAlias(TemplateTableMap::ID, $template->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the template 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(TemplateTableMap::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). + TemplateTableMap::clearInstancePool(); + TemplateTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildTemplate or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildTemplate 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(TemplateTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(TemplateTableMap::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(); + + + TemplateTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + TemplateTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'TemplateI18n'; + + return $this + ->joinTemplateI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('TemplateI18n'); + $this->with['TemplateI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildTemplateI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'TemplateI18n', '\Thelia\Model\TemplateI18nQuery'); + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(TemplateTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(TemplateTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(TemplateTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(TemplateTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(TemplateTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildTemplateQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(TemplateTableMap::CREATED_AT); + } + +} // TemplateQuery diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index f839d5f5b..820928224 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -205,11 +205,42 @@ class Customer extends BaseCustomer implements UserInterface return array(new Role('CUSTOMER')); } + /** + * {@inheritDoc} + */ + public function getToken() { + return $this->getRememberMeToken(); + } + + /** + * {@inheritDoc} + */ + public function setToken($token) { + $this->setRememberMeToken($token)->save(); + } + + /** + * {@inheritDoc} + */ + public function getSerial() { + return $this->getRememberMeSerial(); + } + + /** + * {@inheritDoc} + */ + public function setSerial($serial) { + $this->setRememberMeSerial($serial)->save(); + } + /** * {@inheritDoc} */ public function preInsert(ConnectionInterface $con = null) { + // Set the serial number (for auto-login) + $this->setRememberMeSerial(uniqid()); + $this->setRef($this->generateRef()); $this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, new CustomerEvent($this)); diff --git a/core/lib/Thelia/Model/FeatureTemplate.php b/core/lib/Thelia/Model/FeatureTemplate.php new file mode 100644 index 000000000..47a33027a --- /dev/null +++ b/core/lib/Thelia/Model/FeatureTemplate.php @@ -0,0 +1,10 @@ + array('Id', 'Firstname', 'Lastname', 'Login', 'Password', 'Algo', 'Salt', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'firstname', 'lastname', 'login', 'password', 'algo', 'salt', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AdminTableMap::ID, AdminTableMap::FIRSTNAME, AdminTableMap::LASTNAME, AdminTableMap::LOGIN, AdminTableMap::PASSWORD, AdminTableMap::ALGO, AdminTableMap::SALT, AdminTableMap::CREATED_AT, AdminTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'FIRSTNAME', 'LASTNAME', 'LOGIN', 'PASSWORD', 'ALGO', 'SALT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'firstname', 'lastname', 'login', 'password', 'algo', 'salt', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id', 'Firstname', 'Lastname', 'Login', 'Password', 'Algo', 'Salt', 'RememberMeToken', 'RememberMeSerial', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'firstname', 'lastname', 'login', 'password', 'algo', 'salt', 'rememberMeToken', 'rememberMeSerial', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AdminTableMap::ID, AdminTableMap::FIRSTNAME, AdminTableMap::LASTNAME, AdminTableMap::LOGIN, AdminTableMap::PASSWORD, AdminTableMap::ALGO, AdminTableMap::SALT, AdminTableMap::REMEMBER_ME_TOKEN, AdminTableMap::REMEMBER_ME_SERIAL, AdminTableMap::CREATED_AT, AdminTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'FIRSTNAME', 'LASTNAME', 'LOGIN', 'PASSWORD', 'ALGO', 'SALT', 'REMEMBER_ME_TOKEN', 'REMEMBER_ME_SERIAL', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'firstname', 'lastname', 'login', 'password', 'algo', 'salt', 'remember_me_token', 'remember_me_serial', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -141,12 +151,12 @@ class AdminTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Firstname' => 1, 'Lastname' => 2, 'Login' => 3, 'Password' => 4, 'Algo' => 5, 'Salt' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'firstname' => 1, 'lastname' => 2, 'login' => 3, 'password' => 4, 'algo' => 5, 'salt' => 6, 'createdAt' => 7, 'updatedAt' => 8, ), - self::TYPE_COLNAME => array(AdminTableMap::ID => 0, AdminTableMap::FIRSTNAME => 1, AdminTableMap::LASTNAME => 2, AdminTableMap::LOGIN => 3, AdminTableMap::PASSWORD => 4, AdminTableMap::ALGO => 5, AdminTableMap::SALT => 6, AdminTableMap::CREATED_AT => 7, AdminTableMap::UPDATED_AT => 8, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'FIRSTNAME' => 1, 'LASTNAME' => 2, 'LOGIN' => 3, 'PASSWORD' => 4, 'ALGO' => 5, 'SALT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ), - self::TYPE_FIELDNAME => array('id' => 0, 'firstname' => 1, 'lastname' => 2, 'login' => 3, 'password' => 4, 'algo' => 5, 'salt' => 6, 'created_at' => 7, 'updated_at' => 8, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id' => 0, 'Firstname' => 1, 'Lastname' => 2, 'Login' => 3, 'Password' => 4, 'Algo' => 5, 'Salt' => 6, 'RememberMeToken' => 7, 'RememberMeSerial' => 8, 'CreatedAt' => 9, 'UpdatedAt' => 10, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'firstname' => 1, 'lastname' => 2, 'login' => 3, 'password' => 4, 'algo' => 5, 'salt' => 6, 'rememberMeToken' => 7, 'rememberMeSerial' => 8, 'createdAt' => 9, 'updatedAt' => 10, ), + self::TYPE_COLNAME => array(AdminTableMap::ID => 0, AdminTableMap::FIRSTNAME => 1, AdminTableMap::LASTNAME => 2, AdminTableMap::LOGIN => 3, AdminTableMap::PASSWORD => 4, AdminTableMap::ALGO => 5, AdminTableMap::SALT => 6, AdminTableMap::REMEMBER_ME_TOKEN => 7, AdminTableMap::REMEMBER_ME_SERIAL => 8, AdminTableMap::CREATED_AT => 9, AdminTableMap::UPDATED_AT => 10, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'FIRSTNAME' => 1, 'LASTNAME' => 2, 'LOGIN' => 3, 'PASSWORD' => 4, 'ALGO' => 5, 'SALT' => 6, 'REMEMBER_ME_TOKEN' => 7, 'REMEMBER_ME_SERIAL' => 8, 'CREATED_AT' => 9, 'UPDATED_AT' => 10, ), + self::TYPE_FIELDNAME => array('id' => 0, 'firstname' => 1, 'lastname' => 2, 'login' => 3, 'password' => 4, 'algo' => 5, 'salt' => 6, 'remember_me_token' => 7, 'remember_me_serial' => 8, 'created_at' => 9, 'updated_at' => 10, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -172,6 +182,8 @@ class AdminTableMap extends TableMap $this->addColumn('PASSWORD', 'Password', 'VARCHAR', true, 128, null); $this->addColumn('ALGO', 'Algo', 'VARCHAR', false, 128, null); $this->addColumn('SALT', 'Salt', 'VARCHAR', false, 128, null); + $this->addColumn('REMEMBER_ME_TOKEN', 'RememberMeToken', 'VARCHAR', false, 255, null); + $this->addColumn('REMEMBER_ME_SERIAL', 'RememberMeSerial', 'VARCHAR', false, 255, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -352,6 +364,8 @@ class AdminTableMap extends TableMap $criteria->addSelectColumn(AdminTableMap::PASSWORD); $criteria->addSelectColumn(AdminTableMap::ALGO); $criteria->addSelectColumn(AdminTableMap::SALT); + $criteria->addSelectColumn(AdminTableMap::REMEMBER_ME_TOKEN); + $criteria->addSelectColumn(AdminTableMap::REMEMBER_ME_SERIAL); $criteria->addSelectColumn(AdminTableMap::CREATED_AT); $criteria->addSelectColumn(AdminTableMap::UPDATED_AT); } else { @@ -362,6 +376,8 @@ class AdminTableMap extends TableMap $criteria->addSelectColumn($alias . '.PASSWORD'); $criteria->addSelectColumn($alias . '.ALGO'); $criteria->addSelectColumn($alias . '.SALT'); + $criteria->addSelectColumn($alias . '.REMEMBER_ME_TOKEN'); + $criteria->addSelectColumn($alias . '.REMEMBER_ME_SERIAL'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/AttributeTableMap.php b/core/lib/Thelia/Model/Map/AttributeTableMap.php index 773e13cab..245dc08d3 100644 --- a/core/lib/Thelia/Model/Map/AttributeTableMap.php +++ b/core/lib/Thelia/Model/Map/AttributeTableMap.php @@ -162,9 +162,9 @@ class AttributeTableMap extends TableMap { $this->addRelation('AttributeAv', '\\Thelia\\Model\\AttributeAv', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeAvs'); $this->addRelation('AttributeCombination', '\\Thelia\\Model\\AttributeCombination', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeCombinations'); - $this->addRelation('AttributeCategory', '\\Thelia\\Model\\AttributeCategory', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeCategories'); + $this->addRelation('AttributeTemplate', '\\Thelia\\Model\\AttributeTemplate', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeTemplates'); $this->addRelation('AttributeI18n', '\\Thelia\\Model\\AttributeI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'AttributeI18ns'); - $this->addRelation('Category', '\\Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categories'); + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_MANY, array(), null, null, 'Templates'); } // buildRelations() /** @@ -189,7 +189,7 @@ class AttributeTableMap extends TableMap // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. AttributeAvTableMap::clearInstancePool(); AttributeCombinationTableMap::clearInstancePool(); - AttributeCategoryTableMap::clearInstancePool(); + AttributeTemplateTableMap::clearInstancePool(); AttributeI18nTableMap::clearInstancePool(); } diff --git a/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php new file mode 100644 index 000000000..04d3a9a4a --- /dev/null +++ b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php @@ -0,0 +1,449 @@ + array('Id', 'AttributeId', 'TemplateId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_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, 'AttributeId' => 1, 'TemplateId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::CREATED_AT => 3, AttributeTemplateTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_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_template'); + $this->setPhpName('AttributeTemplate'); + $this->setClassName('\\Thelia\\Model\\AttributeTemplate'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + $this->setIsCrossRef(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER', 'attribute', 'ID', true, null, null); + $this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', '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('Attribute', '\\Thelia\\Model\\Attribute', RelationMap::MANY_TO_ONE, array('attribute_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_ONE, array('template_id' => 'id', ), null, null); + } // 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 ? AttributeTemplateTableMap::CLASS_DEFAULT : AttributeTemplateTableMap::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 (AttributeTemplate object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = AttributeTemplateTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = AttributeTemplateTableMap::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 + AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = AttributeTemplateTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + AttributeTemplateTableMap::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 = AttributeTemplateTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = AttributeTemplateTableMap::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; + AttributeTemplateTableMap::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(AttributeTemplateTableMap::ID); + $criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_ID); + $criteria->addSelectColumn(AttributeTemplateTableMap::TEMPLATE_ID); + $criteria->addSelectColumn(AttributeTemplateTableMap::CREATED_AT); + $criteria->addSelectColumn(AttributeTemplateTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.ATTRIBUTE_ID'); + $criteria->addSelectColumn($alias . '.TEMPLATE_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(AttributeTemplateTableMap::DATABASE_NAME)->getTable(AttributeTemplateTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(AttributeTemplateTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(AttributeTemplateTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new AttributeTemplateTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a AttributeTemplate or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or AttributeTemplate 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(AttributeTemplateTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\AttributeTemplate) { // 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(AttributeTemplateTableMap::DATABASE_NAME); + $criteria->add(AttributeTemplateTableMap::ID, (array) $values, Criteria::IN); + } + + $query = AttributeTemplateQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { AttributeTemplateTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { AttributeTemplateTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the attribute_template 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 AttributeTemplateQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a AttributeTemplate or Criteria object. + * + * @param mixed $criteria Criteria or AttributeTemplate 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(AttributeTemplateTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from AttributeTemplate object + } + + if ($criteria->containsKey(AttributeTemplateTableMap::ID) && $criteria->keyContainsValue(AttributeTemplateTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.AttributeTemplateTableMap::ID.')'); + } + + + // Set the correct dbName + $query = AttributeTemplateQuery::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; + } + +} // AttributeTemplateTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +AttributeTemplateTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/CategoryTableMap.php b/core/lib/Thelia/Model/Map/CategoryTableMap.php index 6a2d052a1..cd0ca3799 100644 --- a/core/lib/Thelia/Model/Map/CategoryTableMap.php +++ b/core/lib/Thelia/Model/Map/CategoryTableMap.php @@ -191,16 +191,12 @@ class CategoryTableMap extends TableMap public function buildRelations() { $this->addRelation('ProductCategory', '\\Thelia\\Model\\ProductCategory', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'ProductCategories'); - $this->addRelation('FeatureCategory', '\\Thelia\\Model\\FeatureCategory', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'FeatureCategories'); - $this->addRelation('AttributeCategory', '\\Thelia\\Model\\AttributeCategory', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'AttributeCategories'); $this->addRelation('CategoryImage', '\\Thelia\\Model\\CategoryImage', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'CategoryImages'); $this->addRelation('CategoryDocument', '\\Thelia\\Model\\CategoryDocument', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'CategoryDocuments'); $this->addRelation('CategoryAssociatedContent', '\\Thelia\\Model\\CategoryAssociatedContent', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'CategoryAssociatedContents'); $this->addRelation('CategoryI18n', '\\Thelia\\Model\\CategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CategoryI18ns'); $this->addRelation('CategoryVersion', '\\Thelia\\Model\\CategoryVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CategoryVersions'); $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Products'); - $this->addRelation('Feature', '\\Thelia\\Model\\Feature', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Features'); - $this->addRelation('Attribute', '\\Thelia\\Model\\Attribute', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Attributes'); } // buildRelations() /** @@ -225,8 +221,6 @@ class CategoryTableMap extends TableMap // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. ProductCategoryTableMap::clearInstancePool(); - FeatureCategoryTableMap::clearInstancePool(); - AttributeCategoryTableMap::clearInstancePool(); CategoryImageTableMap::clearInstancePool(); CategoryDocumentTableMap::clearInstancePool(); CategoryAssociatedContentTableMap::clearInstancePool(); diff --git a/core/lib/Thelia/Model/Map/CustomerTableMap.php b/core/lib/Thelia/Model/Map/CustomerTableMap.php index b23f4d6b0..32ccf07ee 100644 --- a/core/lib/Thelia/Model/Map/CustomerTableMap.php +++ b/core/lib/Thelia/Model/Map/CustomerTableMap.php @@ -57,7 +57,7 @@ class CustomerTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 14; + const NUM_COLUMNS = 16; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class CustomerTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 14; + const NUM_HYDRATE_COLUMNS = 16; /** * the column name for the ID field @@ -129,6 +129,16 @@ class CustomerTableMap extends TableMap */ const DISCOUNT = 'customer.DISCOUNT'; + /** + * the column name for the REMEMBER_ME_TOKEN field + */ + const REMEMBER_ME_TOKEN = 'customer.REMEMBER_ME_TOKEN'; + + /** + * the column name for the REMEMBER_ME_SERIAL field + */ + const REMEMBER_ME_SERIAL = 'customer.REMEMBER_ME_SERIAL'; + /** * the column name for the CREATED_AT field */ @@ -151,12 +161,12 @@ class CustomerTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Ref', 'TitleId', 'Firstname', 'Lastname', 'Email', 'Password', 'Algo', 'Reseller', 'Lang', 'Sponsor', 'Discount', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'ref', 'titleId', 'firstname', 'lastname', 'email', 'password', 'algo', 'reseller', 'lang', 'sponsor', 'discount', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(CustomerTableMap::ID, CustomerTableMap::REF, CustomerTableMap::TITLE_ID, CustomerTableMap::FIRSTNAME, CustomerTableMap::LASTNAME, CustomerTableMap::EMAIL, CustomerTableMap::PASSWORD, CustomerTableMap::ALGO, CustomerTableMap::RESELLER, CustomerTableMap::LANG, CustomerTableMap::SPONSOR, CustomerTableMap::DISCOUNT, CustomerTableMap::CREATED_AT, CustomerTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'REF', 'TITLE_ID', 'FIRSTNAME', 'LASTNAME', 'EMAIL', 'PASSWORD', 'ALGO', 'RESELLER', 'LANG', 'SPONSOR', 'DISCOUNT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'ref', 'title_id', 'firstname', 'lastname', 'email', 'password', 'algo', 'reseller', 'lang', 'sponsor', 'discount', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ) + self::TYPE_PHPNAME => array('Id', 'Ref', 'TitleId', 'Firstname', 'Lastname', 'Email', 'Password', 'Algo', 'Reseller', 'Lang', 'Sponsor', 'Discount', 'RememberMeToken', 'RememberMeSerial', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'ref', 'titleId', 'firstname', 'lastname', 'email', 'password', 'algo', 'reseller', 'lang', 'sponsor', 'discount', 'rememberMeToken', 'rememberMeSerial', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(CustomerTableMap::ID, CustomerTableMap::REF, CustomerTableMap::TITLE_ID, CustomerTableMap::FIRSTNAME, CustomerTableMap::LASTNAME, CustomerTableMap::EMAIL, CustomerTableMap::PASSWORD, CustomerTableMap::ALGO, CustomerTableMap::RESELLER, CustomerTableMap::LANG, CustomerTableMap::SPONSOR, CustomerTableMap::DISCOUNT, CustomerTableMap::REMEMBER_ME_TOKEN, CustomerTableMap::REMEMBER_ME_SERIAL, CustomerTableMap::CREATED_AT, CustomerTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'REF', 'TITLE_ID', 'FIRSTNAME', 'LASTNAME', 'EMAIL', 'PASSWORD', 'ALGO', 'RESELLER', 'LANG', 'SPONSOR', 'DISCOUNT', 'REMEMBER_ME_TOKEN', 'REMEMBER_ME_SERIAL', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'ref', 'title_id', 'firstname', 'lastname', 'email', 'password', 'algo', 'reseller', 'lang', 'sponsor', 'discount', 'remember_me_token', 'remember_me_serial', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ) ); /** @@ -166,12 +176,12 @@ class CustomerTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Ref' => 1, 'TitleId' => 2, 'Firstname' => 3, 'Lastname' => 4, 'Email' => 5, 'Password' => 6, 'Algo' => 7, 'Reseller' => 8, 'Lang' => 9, 'Sponsor' => 10, 'Discount' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'ref' => 1, 'titleId' => 2, 'firstname' => 3, 'lastname' => 4, 'email' => 5, 'password' => 6, 'algo' => 7, 'reseller' => 8, 'lang' => 9, 'sponsor' => 10, 'discount' => 11, 'createdAt' => 12, 'updatedAt' => 13, ), - self::TYPE_COLNAME => array(CustomerTableMap::ID => 0, CustomerTableMap::REF => 1, CustomerTableMap::TITLE_ID => 2, CustomerTableMap::FIRSTNAME => 3, CustomerTableMap::LASTNAME => 4, CustomerTableMap::EMAIL => 5, CustomerTableMap::PASSWORD => 6, CustomerTableMap::ALGO => 7, CustomerTableMap::RESELLER => 8, CustomerTableMap::LANG => 9, CustomerTableMap::SPONSOR => 10, CustomerTableMap::DISCOUNT => 11, CustomerTableMap::CREATED_AT => 12, CustomerTableMap::UPDATED_AT => 13, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'REF' => 1, 'TITLE_ID' => 2, 'FIRSTNAME' => 3, 'LASTNAME' => 4, 'EMAIL' => 5, 'PASSWORD' => 6, 'ALGO' => 7, 'RESELLER' => 8, 'LANG' => 9, 'SPONSOR' => 10, 'DISCOUNT' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, ), - self::TYPE_FIELDNAME => array('id' => 0, 'ref' => 1, 'title_id' => 2, 'firstname' => 3, 'lastname' => 4, 'email' => 5, 'password' => 6, 'algo' => 7, 'reseller' => 8, 'lang' => 9, 'sponsor' => 10, 'discount' => 11, 'created_at' => 12, 'updated_at' => 13, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ) + self::TYPE_PHPNAME => array('Id' => 0, 'Ref' => 1, 'TitleId' => 2, 'Firstname' => 3, 'Lastname' => 4, 'Email' => 5, 'Password' => 6, 'Algo' => 7, 'Reseller' => 8, 'Lang' => 9, 'Sponsor' => 10, 'Discount' => 11, 'RememberMeToken' => 12, 'RememberMeSerial' => 13, 'CreatedAt' => 14, 'UpdatedAt' => 15, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'ref' => 1, 'titleId' => 2, 'firstname' => 3, 'lastname' => 4, 'email' => 5, 'password' => 6, 'algo' => 7, 'reseller' => 8, 'lang' => 9, 'sponsor' => 10, 'discount' => 11, 'rememberMeToken' => 12, 'rememberMeSerial' => 13, 'createdAt' => 14, 'updatedAt' => 15, ), + self::TYPE_COLNAME => array(CustomerTableMap::ID => 0, CustomerTableMap::REF => 1, CustomerTableMap::TITLE_ID => 2, CustomerTableMap::FIRSTNAME => 3, CustomerTableMap::LASTNAME => 4, CustomerTableMap::EMAIL => 5, CustomerTableMap::PASSWORD => 6, CustomerTableMap::ALGO => 7, CustomerTableMap::RESELLER => 8, CustomerTableMap::LANG => 9, CustomerTableMap::SPONSOR => 10, CustomerTableMap::DISCOUNT => 11, CustomerTableMap::REMEMBER_ME_TOKEN => 12, CustomerTableMap::REMEMBER_ME_SERIAL => 13, CustomerTableMap::CREATED_AT => 14, CustomerTableMap::UPDATED_AT => 15, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'REF' => 1, 'TITLE_ID' => 2, 'FIRSTNAME' => 3, 'LASTNAME' => 4, 'EMAIL' => 5, 'PASSWORD' => 6, 'ALGO' => 7, 'RESELLER' => 8, 'LANG' => 9, 'SPONSOR' => 10, 'DISCOUNT' => 11, 'REMEMBER_ME_TOKEN' => 12, 'REMEMBER_ME_SERIAL' => 13, 'CREATED_AT' => 14, 'UPDATED_AT' => 15, ), + self::TYPE_FIELDNAME => array('id' => 0, 'ref' => 1, 'title_id' => 2, 'firstname' => 3, 'lastname' => 4, 'email' => 5, 'password' => 6, 'algo' => 7, 'reseller' => 8, 'lang' => 9, 'sponsor' => 10, 'discount' => 11, 'remember_me_token' => 12, 'remember_me_serial' => 13, 'created_at' => 14, 'updated_at' => 15, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ) ); /** @@ -202,6 +212,8 @@ class CustomerTableMap extends TableMap $this->addColumn('LANG', 'Lang', 'VARCHAR', false, 10, null); $this->addColumn('SPONSOR', 'Sponsor', 'VARCHAR', false, 50, null); $this->addColumn('DISCOUNT', 'Discount', 'FLOAT', false, null, null); + $this->addColumn('REMEMBER_ME_TOKEN', 'RememberMeToken', 'VARCHAR', false, 255, null); + $this->addColumn('REMEMBER_ME_SERIAL', 'RememberMeSerial', 'VARCHAR', false, 255, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -390,6 +402,8 @@ class CustomerTableMap extends TableMap $criteria->addSelectColumn(CustomerTableMap::LANG); $criteria->addSelectColumn(CustomerTableMap::SPONSOR); $criteria->addSelectColumn(CustomerTableMap::DISCOUNT); + $criteria->addSelectColumn(CustomerTableMap::REMEMBER_ME_TOKEN); + $criteria->addSelectColumn(CustomerTableMap::REMEMBER_ME_SERIAL); $criteria->addSelectColumn(CustomerTableMap::CREATED_AT); $criteria->addSelectColumn(CustomerTableMap::UPDATED_AT); } else { @@ -405,6 +419,8 @@ class CustomerTableMap extends TableMap $criteria->addSelectColumn($alias . '.LANG'); $criteria->addSelectColumn($alias . '.SPONSOR'); $criteria->addSelectColumn($alias . '.DISCOUNT'); + $criteria->addSelectColumn($alias . '.REMEMBER_ME_TOKEN'); + $criteria->addSelectColumn($alias . '.REMEMBER_ME_SERIAL'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/FeatureTableMap.php b/core/lib/Thelia/Model/Map/FeatureTableMap.php index 76c2fe724..067a242a3 100644 --- a/core/lib/Thelia/Model/Map/FeatureTableMap.php +++ b/core/lib/Thelia/Model/Map/FeatureTableMap.php @@ -168,9 +168,9 @@ class FeatureTableMap extends TableMap { $this->addRelation('FeatureAv', '\\Thelia\\Model\\FeatureAv', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureAvs'); $this->addRelation('FeatureProduct', '\\Thelia\\Model\\FeatureProduct', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureProducts'); - $this->addRelation('FeatureCategory', '\\Thelia\\Model\\FeatureCategory', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureCategories'); + $this->addRelation('FeatureTemplate', '\\Thelia\\Model\\FeatureTemplate', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureTemplates'); $this->addRelation('FeatureI18n', '\\Thelia\\Model\\FeatureI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'FeatureI18ns'); - $this->addRelation('Category', '\\Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categories'); + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_MANY, array(), null, null, 'Templates'); } // buildRelations() /** @@ -195,7 +195,7 @@ class FeatureTableMap extends TableMap // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. FeatureAvTableMap::clearInstancePool(); FeatureProductTableMap::clearInstancePool(); - FeatureCategoryTableMap::clearInstancePool(); + FeatureTemplateTableMap::clearInstancePool(); FeatureI18nTableMap::clearInstancePool(); } diff --git a/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php b/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php new file mode 100644 index 000000000..abb1a98b7 --- /dev/null +++ b/core/lib/Thelia/Model/Map/FeatureTemplateTableMap.php @@ -0,0 +1,449 @@ + array('Id', 'FeatureId', 'TemplateId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'featureId', 'templateId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID, FeatureTemplateTableMap::FEATURE_ID, FeatureTemplateTableMap::TEMPLATE_ID, FeatureTemplateTableMap::CREATED_AT, FeatureTemplateTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'FEATURE_ID', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'feature_id', 'template_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, 'TemplateId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'featureId' => 1, 'templateId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(FeatureTemplateTableMap::ID => 0, FeatureTemplateTableMap::FEATURE_ID => 1, FeatureTemplateTableMap::TEMPLATE_ID => 2, FeatureTemplateTableMap::CREATED_AT => 3, FeatureTemplateTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'FEATURE_ID' => 1, 'TEMPLATE_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'feature_id' => 1, 'template_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_template'); + $this->setPhpName('FeatureTemplate'); + $this->setClassName('\\Thelia\\Model\\FeatureTemplate'); + $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('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', '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('Feature', '\\Thelia\\Model\\Feature', RelationMap::MANY_TO_ONE, array('feature_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_ONE, array('template_id' => 'id', ), null, null); + } // 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 ? FeatureTemplateTableMap::CLASS_DEFAULT : FeatureTemplateTableMap::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 (FeatureTemplate object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = FeatureTemplateTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = FeatureTemplateTableMap::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 + FeatureTemplateTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = FeatureTemplateTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + FeatureTemplateTableMap::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 = FeatureTemplateTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = FeatureTemplateTableMap::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; + FeatureTemplateTableMap::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(FeatureTemplateTableMap::ID); + $criteria->addSelectColumn(FeatureTemplateTableMap::FEATURE_ID); + $criteria->addSelectColumn(FeatureTemplateTableMap::TEMPLATE_ID); + $criteria->addSelectColumn(FeatureTemplateTableMap::CREATED_AT); + $criteria->addSelectColumn(FeatureTemplateTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.FEATURE_ID'); + $criteria->addSelectColumn($alias . '.TEMPLATE_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(FeatureTemplateTableMap::DATABASE_NAME)->getTable(FeatureTemplateTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(FeatureTemplateTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(FeatureTemplateTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new FeatureTemplateTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a FeatureTemplate or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or FeatureTemplate 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(FeatureTemplateTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\FeatureTemplate) { // 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(FeatureTemplateTableMap::DATABASE_NAME); + $criteria->add(FeatureTemplateTableMap::ID, (array) $values, Criteria::IN); + } + + $query = FeatureTemplateQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { FeatureTemplateTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { FeatureTemplateTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the feature_template 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 FeatureTemplateQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a FeatureTemplate or Criteria object. + * + * @param mixed $criteria Criteria or FeatureTemplate 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(FeatureTemplateTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from FeatureTemplate object + } + + if ($criteria->containsKey(FeatureTemplateTableMap::ID) && $criteria->keyContainsValue(FeatureTemplateTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.FeatureTemplateTableMap::ID.')'); + } + + + // Set the correct dbName + $query = FeatureTemplateQuery::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; + } + +} // FeatureTemplateTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +FeatureTemplateTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ProductTableMap.php b/core/lib/Thelia/Model/Map/ProductTableMap.php index f69f6f702..17c4585f0 100644 --- a/core/lib/Thelia/Model/Map/ProductTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductTableMap.php @@ -57,7 +57,7 @@ class ProductTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 10; + const NUM_COLUMNS = 11; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class ProductTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 10; + const NUM_HYDRATE_COLUMNS = 11; /** * the column name for the ID field @@ -94,6 +94,11 @@ class ProductTableMap extends TableMap */ const POSITION = 'product.POSITION'; + /** + * the column name for the TEMPLATE_ID field + */ + const TEMPLATE_ID = 'product.TEMPLATE_ID'; + /** * the column name for the CREATED_AT field */ @@ -140,12 +145,12 @@ class ProductTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'TaxRuleId', 'Ref', 'Visible', 'Position', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), - self::TYPE_STUDLYPHPNAME => array('id', 'taxRuleId', 'ref', 'visible', 'position', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), - self::TYPE_COLNAME => array(ProductTableMap::ID, ProductTableMap::TAX_RULE_ID, ProductTableMap::REF, ProductTableMap::VISIBLE, ProductTableMap::POSITION, ProductTableMap::CREATED_AT, ProductTableMap::UPDATED_AT, ProductTableMap::VERSION, ProductTableMap::VERSION_CREATED_AT, ProductTableMap::VERSION_CREATED_BY, ), - self::TYPE_RAW_COLNAME => array('ID', 'TAX_RULE_ID', 'REF', 'VISIBLE', 'POSITION', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), - self::TYPE_FIELDNAME => array('id', 'tax_rule_id', 'ref', 'visible', 'position', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + self::TYPE_PHPNAME => array('Id', 'TaxRuleId', 'Ref', 'Visible', 'Position', 'TemplateId', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), + self::TYPE_STUDLYPHPNAME => array('id', 'taxRuleId', 'ref', 'visible', 'position', 'templateId', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), + self::TYPE_COLNAME => array(ProductTableMap::ID, ProductTableMap::TAX_RULE_ID, ProductTableMap::REF, ProductTableMap::VISIBLE, ProductTableMap::POSITION, ProductTableMap::TEMPLATE_ID, ProductTableMap::CREATED_AT, ProductTableMap::UPDATED_AT, ProductTableMap::VERSION, ProductTableMap::VERSION_CREATED_AT, ProductTableMap::VERSION_CREATED_BY, ), + self::TYPE_RAW_COLNAME => array('ID', 'TAX_RULE_ID', 'REF', 'VISIBLE', 'POSITION', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), + self::TYPE_FIELDNAME => array('id', 'tax_rule_id', 'ref', 'visible', 'position', 'template_id', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -155,12 +160,12 @@ class ProductTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'TaxRuleId' => 1, 'Ref' => 2, 'Visible' => 3, 'Position' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, 'Version' => 7, 'VersionCreatedAt' => 8, 'VersionCreatedBy' => 9, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'taxRuleId' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'createdAt' => 5, 'updatedAt' => 6, 'version' => 7, 'versionCreatedAt' => 8, 'versionCreatedBy' => 9, ), - self::TYPE_COLNAME => array(ProductTableMap::ID => 0, ProductTableMap::TAX_RULE_ID => 1, ProductTableMap::REF => 2, ProductTableMap::VISIBLE => 3, ProductTableMap::POSITION => 4, ProductTableMap::CREATED_AT => 5, ProductTableMap::UPDATED_AT => 6, ProductTableMap::VERSION => 7, ProductTableMap::VERSION_CREATED_AT => 8, ProductTableMap::VERSION_CREATED_BY => 9, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'TAX_RULE_ID' => 1, 'REF' => 2, 'VISIBLE' => 3, 'POSITION' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, 'VERSION' => 7, 'VERSION_CREATED_AT' => 8, 'VERSION_CREATED_BY' => 9, ), - self::TYPE_FIELDNAME => array('id' => 0, 'tax_rule_id' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'created_at' => 5, 'updated_at' => 6, 'version' => 7, 'version_created_at' => 8, 'version_created_by' => 9, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + self::TYPE_PHPNAME => array('Id' => 0, 'TaxRuleId' => 1, 'Ref' => 2, 'Visible' => 3, 'Position' => 4, 'TemplateId' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, 'Version' => 8, 'VersionCreatedAt' => 9, 'VersionCreatedBy' => 10, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'taxRuleId' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'templateId' => 5, 'createdAt' => 6, 'updatedAt' => 7, 'version' => 8, 'versionCreatedAt' => 9, 'versionCreatedBy' => 10, ), + self::TYPE_COLNAME => array(ProductTableMap::ID => 0, ProductTableMap::TAX_RULE_ID => 1, ProductTableMap::REF => 2, ProductTableMap::VISIBLE => 3, ProductTableMap::POSITION => 4, ProductTableMap::TEMPLATE_ID => 5, ProductTableMap::CREATED_AT => 6, ProductTableMap::UPDATED_AT => 7, ProductTableMap::VERSION => 8, ProductTableMap::VERSION_CREATED_AT => 9, ProductTableMap::VERSION_CREATED_BY => 10, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'TAX_RULE_ID' => 1, 'REF' => 2, 'VISIBLE' => 3, 'POSITION' => 4, 'TEMPLATE_ID' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, 'VERSION' => 8, 'VERSION_CREATED_AT' => 9, 'VERSION_CREATED_BY' => 10, ), + self::TYPE_FIELDNAME => array('id' => 0, 'tax_rule_id' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'template_id' => 5, 'created_at' => 6, 'updated_at' => 7, 'version' => 8, 'version_created_at' => 9, 'version_created_by' => 10, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -184,6 +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->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); @@ -197,6 +203,7 @@ class ProductTableMap extends TableMap public function buildRelations() { $this->addRelation('TaxRule', '\\Thelia\\Model\\TaxRule', RelationMap::MANY_TO_ONE, array('tax_rule_id' => 'id', ), 'SET NULL', 'RESTRICT'); + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_ONE, array('template_id' => 'id', ), null, null); $this->addRelation('ProductCategory', '\\Thelia\\Model\\ProductCategory', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'ProductCategories'); $this->addRelation('FeatureProduct', '\\Thelia\\Model\\FeatureProduct', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'FeatureProducts'); $this->addRelation('ProductSaleElements', '\\Thelia\\Model\\ProductSaleElements', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'ProductSaleElementss'); @@ -388,6 +395,7 @@ class ProductTableMap extends TableMap $criteria->addSelectColumn(ProductTableMap::REF); $criteria->addSelectColumn(ProductTableMap::VISIBLE); $criteria->addSelectColumn(ProductTableMap::POSITION); + $criteria->addSelectColumn(ProductTableMap::TEMPLATE_ID); $criteria->addSelectColumn(ProductTableMap::CREATED_AT); $criteria->addSelectColumn(ProductTableMap::UPDATED_AT); $criteria->addSelectColumn(ProductTableMap::VERSION); @@ -399,6 +407,7 @@ class ProductTableMap extends TableMap $criteria->addSelectColumn($alias . '.REF'); $criteria->addSelectColumn($alias . '.VISIBLE'); $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.TEMPLATE_ID'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.VERSION'); diff --git a/core/lib/Thelia/Model/Map/ProductVersionTableMap.php b/core/lib/Thelia/Model/Map/ProductVersionTableMap.php index d3e69b16f..4e84b4db8 100644 --- a/core/lib/Thelia/Model/Map/ProductVersionTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductVersionTableMap.php @@ -57,7 +57,7 @@ class ProductVersionTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 10; + const NUM_COLUMNS = 11; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class ProductVersionTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 10; + const NUM_HYDRATE_COLUMNS = 11; /** * the column name for the ID field @@ -94,6 +94,11 @@ class ProductVersionTableMap extends TableMap */ const POSITION = 'product_version.POSITION'; + /** + * the column name for the TEMPLATE_ID field + */ + const TEMPLATE_ID = 'product_version.TEMPLATE_ID'; + /** * the column name for the CREATED_AT field */ @@ -131,12 +136,12 @@ class ProductVersionTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'TaxRuleId', 'Ref', 'Visible', 'Position', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), - self::TYPE_STUDLYPHPNAME => array('id', 'taxRuleId', 'ref', 'visible', 'position', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), - self::TYPE_COLNAME => array(ProductVersionTableMap::ID, ProductVersionTableMap::TAX_RULE_ID, ProductVersionTableMap::REF, ProductVersionTableMap::VISIBLE, ProductVersionTableMap::POSITION, ProductVersionTableMap::CREATED_AT, ProductVersionTableMap::UPDATED_AT, ProductVersionTableMap::VERSION, ProductVersionTableMap::VERSION_CREATED_AT, ProductVersionTableMap::VERSION_CREATED_BY, ), - self::TYPE_RAW_COLNAME => array('ID', 'TAX_RULE_ID', 'REF', 'VISIBLE', 'POSITION', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), - self::TYPE_FIELDNAME => array('id', 'tax_rule_id', 'ref', 'visible', 'position', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + self::TYPE_PHPNAME => array('Id', 'TaxRuleId', 'Ref', 'Visible', 'Position', 'TemplateId', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), + self::TYPE_STUDLYPHPNAME => array('id', 'taxRuleId', 'ref', 'visible', 'position', 'templateId', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), + self::TYPE_COLNAME => array(ProductVersionTableMap::ID, ProductVersionTableMap::TAX_RULE_ID, ProductVersionTableMap::REF, ProductVersionTableMap::VISIBLE, ProductVersionTableMap::POSITION, ProductVersionTableMap::TEMPLATE_ID, ProductVersionTableMap::CREATED_AT, ProductVersionTableMap::UPDATED_AT, ProductVersionTableMap::VERSION, ProductVersionTableMap::VERSION_CREATED_AT, ProductVersionTableMap::VERSION_CREATED_BY, ), + self::TYPE_RAW_COLNAME => array('ID', 'TAX_RULE_ID', 'REF', 'VISIBLE', 'POSITION', 'TEMPLATE_ID', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), + self::TYPE_FIELDNAME => array('id', 'tax_rule_id', 'ref', 'visible', 'position', 'template_id', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -146,12 +151,12 @@ class ProductVersionTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'TaxRuleId' => 1, 'Ref' => 2, 'Visible' => 3, 'Position' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, 'Version' => 7, 'VersionCreatedAt' => 8, 'VersionCreatedBy' => 9, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'taxRuleId' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'createdAt' => 5, 'updatedAt' => 6, 'version' => 7, 'versionCreatedAt' => 8, 'versionCreatedBy' => 9, ), - self::TYPE_COLNAME => array(ProductVersionTableMap::ID => 0, ProductVersionTableMap::TAX_RULE_ID => 1, ProductVersionTableMap::REF => 2, ProductVersionTableMap::VISIBLE => 3, ProductVersionTableMap::POSITION => 4, ProductVersionTableMap::CREATED_AT => 5, ProductVersionTableMap::UPDATED_AT => 6, ProductVersionTableMap::VERSION => 7, ProductVersionTableMap::VERSION_CREATED_AT => 8, ProductVersionTableMap::VERSION_CREATED_BY => 9, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'TAX_RULE_ID' => 1, 'REF' => 2, 'VISIBLE' => 3, 'POSITION' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, 'VERSION' => 7, 'VERSION_CREATED_AT' => 8, 'VERSION_CREATED_BY' => 9, ), - self::TYPE_FIELDNAME => array('id' => 0, 'tax_rule_id' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'created_at' => 5, 'updated_at' => 6, 'version' => 7, 'version_created_at' => 8, 'version_created_by' => 9, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + self::TYPE_PHPNAME => array('Id' => 0, 'TaxRuleId' => 1, 'Ref' => 2, 'Visible' => 3, 'Position' => 4, 'TemplateId' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, 'Version' => 8, 'VersionCreatedAt' => 9, 'VersionCreatedBy' => 10, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'taxRuleId' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'templateId' => 5, 'createdAt' => 6, 'updatedAt' => 7, 'version' => 8, 'versionCreatedAt' => 9, 'versionCreatedBy' => 10, ), + self::TYPE_COLNAME => array(ProductVersionTableMap::ID => 0, ProductVersionTableMap::TAX_RULE_ID => 1, ProductVersionTableMap::REF => 2, ProductVersionTableMap::VISIBLE => 3, ProductVersionTableMap::POSITION => 4, ProductVersionTableMap::TEMPLATE_ID => 5, ProductVersionTableMap::CREATED_AT => 6, ProductVersionTableMap::UPDATED_AT => 7, ProductVersionTableMap::VERSION => 8, ProductVersionTableMap::VERSION_CREATED_AT => 9, ProductVersionTableMap::VERSION_CREATED_BY => 10, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'TAX_RULE_ID' => 1, 'REF' => 2, 'VISIBLE' => 3, 'POSITION' => 4, 'TEMPLATE_ID' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, 'VERSION' => 8, 'VERSION_CREATED_AT' => 9, 'VERSION_CREATED_BY' => 10, ), + self::TYPE_FIELDNAME => array('id' => 0, 'tax_rule_id' => 1, 'ref' => 2, 'visible' => 3, 'position' => 4, 'template_id' => 5, 'created_at' => 6, 'updated_at' => 7, 'version' => 8, 'version_created_at' => 9, 'version_created_by' => 10, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -175,6 +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('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); $this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0); @@ -257,11 +263,11 @@ class ProductVersionTableMap extends TableMap 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 && $row[TableMap::TYPE_NUM == $indexType ? 7 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) { + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 8 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) { return null; } - return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 7 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)])); + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 8 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)])); } /** @@ -382,6 +388,7 @@ class ProductVersionTableMap extends TableMap $criteria->addSelectColumn(ProductVersionTableMap::REF); $criteria->addSelectColumn(ProductVersionTableMap::VISIBLE); $criteria->addSelectColumn(ProductVersionTableMap::POSITION); + $criteria->addSelectColumn(ProductVersionTableMap::TEMPLATE_ID); $criteria->addSelectColumn(ProductVersionTableMap::CREATED_AT); $criteria->addSelectColumn(ProductVersionTableMap::UPDATED_AT); $criteria->addSelectColumn(ProductVersionTableMap::VERSION); @@ -393,6 +400,7 @@ class ProductVersionTableMap extends TableMap $criteria->addSelectColumn($alias . '.REF'); $criteria->addSelectColumn($alias . '.VISIBLE'); $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.TEMPLATE_ID'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.VERSION'); diff --git a/core/lib/Thelia/Model/Map/TemplateI18nTableMap.php b/core/lib/Thelia/Model/Map/TemplateI18nTableMap.php new file mode 100644 index 000000000..8db2f4fcf --- /dev/null +++ b/core/lib/Thelia/Model/Map/TemplateI18nTableMap.php @@ -0,0 +1,473 @@ + array('Id', 'Locale', 'Name', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'name', ), + self::TYPE_COLNAME => array(TemplateI18nTableMap::ID, TemplateI18nTableMap::LOCALE, TemplateI18nTableMap::NAME, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'NAME', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'name', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * 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, 'Locale' => 1, 'Name' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'name' => 2, ), + self::TYPE_COLNAME => array(TemplateI18nTableMap::ID => 0, TemplateI18nTableMap::LOCALE => 1, TemplateI18nTableMap::NAME => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'NAME' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'name' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * 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('template_i18n'); + $this->setPhpName('TemplateI18n'); + $this->setClassName('\\Thelia\\Model\\TemplateI18n'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'template', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Template', '\\Thelia\\Model\\Template', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\TemplateI18n $obj A \Thelia\Model\TemplateI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\TemplateI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\TemplateI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\TemplateI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * 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 && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', 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 $pks; + } + + /** + * 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 ? TemplateI18nTableMap::CLASS_DEFAULT : TemplateI18nTableMap::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 (TemplateI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = TemplateI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = TemplateI18nTableMap::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 + TemplateI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = TemplateI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + TemplateI18nTableMap::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 = TemplateI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = TemplateI18nTableMap::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; + TemplateI18nTableMap::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(TemplateI18nTableMap::ID); + $criteria->addSelectColumn(TemplateI18nTableMap::LOCALE); + $criteria->addSelectColumn(TemplateI18nTableMap::NAME); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.NAME'); + } + } + + /** + * 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(TemplateI18nTableMap::DATABASE_NAME)->getTable(TemplateI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(TemplateI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(TemplateI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new TemplateI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a TemplateI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or TemplateI18n 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(TemplateI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\TemplateI18n) { // 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(TemplateI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(TemplateI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(TemplateI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = TemplateI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { TemplateI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { TemplateI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the template_i18n 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 TemplateI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a TemplateI18n or Criteria object. + * + * @param mixed $criteria Criteria or TemplateI18n 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(TemplateI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from TemplateI18n object + } + + + // Set the correct dbName + $query = TemplateI18nQuery::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; + } + +} // TemplateI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +TemplateI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/TemplateTableMap.php b/core/lib/Thelia/Model/Map/TemplateTableMap.php new file mode 100644 index 000000000..f1509cbc7 --- /dev/null +++ b/core/lib/Thelia/Model/Map/TemplateTableMap.php @@ -0,0 +1,455 @@ + array('Id', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(TemplateTableMap::ID, TemplateTableMap::CREATED_AT, TemplateTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * 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, 'CreatedAt' => 1, 'UpdatedAt' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'createdAt' => 1, 'updatedAt' => 2, ), + self::TYPE_COLNAME => array(TemplateTableMap::ID => 0, TemplateTableMap::CREATED_AT => 1, TemplateTableMap::UPDATED_AT => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CREATED_AT' => 1, 'UPDATED_AT' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'created_at' => 1, 'updated_at' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * 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('template'); + $this->setPhpName('Template'); + $this->setClassName('\\Thelia\\Model\\Template'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', 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('Product', '\\Thelia\\Model\\Product', RelationMap::ONE_TO_MANY, array('id' => 'template_id', ), null, null, 'Products'); + $this->addRelation('FeatureTemplate', '\\Thelia\\Model\\FeatureTemplate', RelationMap::ONE_TO_MANY, array('id' => 'template_id', ), null, null, 'FeatureTemplates'); + $this->addRelation('AttributeTemplate', '\\Thelia\\Model\\AttributeTemplate', RelationMap::ONE_TO_MANY, array('id' => 'template_id', ), null, null, 'AttributeTemplates'); + $this->addRelation('TemplateI18n', '\\Thelia\\Model\\TemplateI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'TemplateI18ns'); + $this->addRelation('Feature', '\\Thelia\\Model\\Feature', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Features'); + $this->addRelation('Attribute', '\\Thelia\\Model\\Attribute', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Attributes'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'name', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to template * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + TemplateI18nTableMap::clearInstancePool(); + } + + /** + * 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 ? TemplateTableMap::CLASS_DEFAULT : TemplateTableMap::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 (Template object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = TemplateTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = TemplateTableMap::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 + TemplateTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = TemplateTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + TemplateTableMap::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 = TemplateTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = TemplateTableMap::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; + TemplateTableMap::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(TemplateTableMap::ID); + $criteria->addSelectColumn(TemplateTableMap::CREATED_AT); + $criteria->addSelectColumn(TemplateTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.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(TemplateTableMap::DATABASE_NAME)->getTable(TemplateTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(TemplateTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(TemplateTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new TemplateTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Template or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Template 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(TemplateTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\Template) { // 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(TemplateTableMap::DATABASE_NAME); + $criteria->add(TemplateTableMap::ID, (array) $values, Criteria::IN); + } + + $query = TemplateQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { TemplateTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { TemplateTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the template 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 TemplateQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Template or Criteria object. + * + * @param mixed $criteria Criteria or Template 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(TemplateTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Template object + } + + if ($criteria->containsKey(TemplateTableMap::ID) && $criteria->keyContainsValue(TemplateTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.TemplateTableMap::ID.')'); + } + + + // Set the correct dbName + $query = TemplateQuery::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; + } + +} // TemplateTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +TemplateTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Template.php b/core/lib/Thelia/Model/Template.php new file mode 100644 index 000000000..881187573 --- /dev/null +++ b/core/lib/Thelia/Model/Template.php @@ -0,0 +1,68 @@ +dispatchEvent(TheliaEvents::BEFORE_CREATETEMPLATE, new TemplateEvent($this)); + + return true; + } + + /** + * {@inheritDoc} + */ + public function postInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_CREATETEMPLATE, new TemplateEvent($this)); + } + + /** + * {@inheritDoc} + */ + public function preUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATETEMPLATE, new TemplateEvent($this)); + + return true; + } + + /** + * {@inheritDoc} + */ + public function postUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_UPDATETEMPLATE, new TemplateEvent($this)); + } + + /** + * {@inheritDoc} + */ + public function preDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_DELETETEMPLATE, new TemplateEvent($this)); + + return true; + } + + /** + * {@inheritDoc} + */ + public function postDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_DELETETEMPLATE, new TemplateEvent($this)); + } + +} diff --git a/core/lib/Thelia/Model/TemplateI18n.php b/core/lib/Thelia/Model/TemplateI18n.php new file mode 100644 index 000000000..19e88f692 --- /dev/null +++ b/core/lib/Thelia/Model/TemplateI18n.php @@ -0,0 +1,10 @@ +send(); + exit; } } diff --git a/install/faker.php b/install/faker.php index fdcf6212c..f15570e8a 100755 --- a/install/faker.php +++ b/install/faker.php @@ -240,6 +240,28 @@ try { } } + $template = new Thelia\Model\Template(); + setI18n($faker, $template, array("Name" => 20)); + $template->save(); + + foreach($attributeList as $attributeId => $attributeAvId) { + $at = new Thelia\Model\AttributeTemplate(); + + $at + ->setTemplate($template) + ->setAttributeId($attributeId) + ->save(); + } + + foreach($featureList as $featureId => $featureAvId) { + $ft = new Thelia\Model\FeatureTemplate(); + + $ft + ->setTemplate($template) + ->setFeatureId($featureId) + ->save(); + } + //folders and contents $contentIdList = array(); for($i=0; $i<4; $i++) { @@ -296,12 +318,12 @@ try { $subcategory = createCategory($faker, $category->getId(), $j, $categoryIdList, $contentIdList); for($k=0; $krollBack(); } -function createProduct($faker, $category, $position, &$productIdList) +function createProduct($faker, $category, $position, $template, &$productIdList) { $product = new Thelia\Model\Product(); $product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8)); @@ -424,6 +446,8 @@ function createProduct($faker, $category, $position, &$productIdList) $product->setVisible(rand(1, 10)>7 ? 0 : 1); $product->setPosition($position); $product->setTaxRuleId(1); + $product->setTemplate($template); + setI18n($faker, $product); $product->save(); @@ -521,18 +545,18 @@ function generate_image($image, $position, $typeobj, $id) { $image->save($image_file); } -function setI18n($faker, &$object) +function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description' => 50) ) { - $localeList = array('fr_FR', 'en_EN'); - - $title = $faker->text(20); - $description = $faker->text(50); + $localeList = $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); foreach($localeList as $locale) { $object->setLocale($locale); - $object->setTitle($locale . ' : ' . $title); - $object->setDescription($locale . ' : ' . $description); + foreach($fields as $name => $length) { + $func = "set".ucfirst(strtolower($name)); + + $object->$func($locale . ' : ' . $faker->text($length)); + } } } /** diff --git a/install/faker_100categories_1000products_4locales.php b/install/faker_100categories_1000products_4locales.php index ce18aa5c7..eb98d3e10 100755 --- a/install/faker_100categories_1000products_4locales.php +++ b/install/faker_100categories_1000products_4locales.php @@ -156,18 +156,18 @@ try { $con->rollBack(); } -function setI18n($faker, &$object) +function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description' => 50) ) { - $localeList = array('fr_FR', 'en_EN', 'es_ES', 'it_IT'); - - $title = $faker->text(20); - $description = $faker->text(50); + $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); foreach($localeList as $locale) { $object->setLocale($locale); - $object->setTitle($locale . ' : ' . $title); - $object->setDescription($locale . ' : ' . $description); + foreach($fields as $name => $length) { + $func = "set$name"; + + $object->$func($locale . ' : ' . $faker->text($length)); + } } } diff --git a/install/insert.sql b/install/insert.sql index d91035382..1cc7c55e6 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -17,8 +17,14 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()), ('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()), ('page_not_found_view', '404.html', 0, 0, NOW(), NOW()), -('use_tax_free_amounts', 0, 1, 0, NOW(), NOW()), -('process_assets', '1', 0, 0, NOW(), NOW()); +('use_tax_free_amounts', 0, 0, 0, NOW(), NOW()), +('process_assets', '1', 0, 0, NOW(), NOW()), +('thelia_admin_remember_me_cookie_name', 'tarmcn', 0, 0, NOW(), NOW()), +('thelia_admin_remember_me_cookie_expiration', 2592000, 0, 0, NOW(), NOW()), +('thelia_customer_remember_me_cookie_name', 'tcrmcn', 0, 0, NOW(), NOW()), +('thelia_customer_remember_me_cookie_expiration', 31536000, 0, 0, NOW(), NOW()), +('session_config.handlers', 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler', 0, 0, NOW(), NOW()) +; INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES diff --git a/install/thelia.sql b/install/thelia.sql index dd0e9a79c..5aa478da5 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -36,6 +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, `created_at` DATETIME, `updated_at` DATETIME, `version` INTEGER DEFAULT 0, @@ -44,11 +45,15 @@ CREATE TABLE `product` PRIMARY KEY (`id`), UNIQUE INDEX `ref_UNIQUE` (`ref`), INDEX `idx_product_tax_rule_id` (`tax_rule_id`), + INDEX `fk_product_template1_idx` (`template_id`), CONSTRAINT `fk_product_tax_rule_id` FOREIGN KEY (`tax_rule_id`) REFERENCES `tax_rule` (`id`) ON UPDATE RESTRICT - ON DELETE SET NULL + ON DELETE SET NULL, + CONSTRAINT `fk_product_template1` + FOREIGN KEY (`template_id`) + REFERENCES `template` (`id`) ) ENGINE=InnoDB; -- --------------------------------------------------------------------- @@ -243,31 +248,29 @@ CREATE TABLE `feature_product` ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- feature_category +-- feature_template -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `feature_category`; +DROP TABLE IF EXISTS `feature_template`; -CREATE TABLE `feature_category` +CREATE TABLE `feature_template` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `feature_id` INTEGER NOT NULL, - `category_id` INTEGER NOT NULL, + `template_id` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_feature_category_category_id` (`category_id`), - INDEX `idx_feature_category_feature_id` (`feature_id`), - CONSTRAINT `fk_feature_category_category_id` - FOREIGN KEY (`category_id`) - REFERENCES `category` (`id`) - ON UPDATE RESTRICT - ON DELETE CASCADE, - CONSTRAINT `fk_feature_category_feature_id` + INDEX `idx_feature_template_id` (`feature_id`), + INDEX `fk_feature_template_idx` (`template_id`), + CONSTRAINT `fk_feature_template_id` FOREIGN KEY (`feature_id`) REFERENCES `feature` (`id`) ON UPDATE RESTRICT - ON DELETE CASCADE + ON DELETE CASCADE, + CONSTRAINT `fk_feature_template` + FOREIGN KEY (`template_id`) + REFERENCES `template` (`id`) ) ENGINE=InnoDB; -- --------------------------------------------------------------------- @@ -367,31 +370,29 @@ CREATE TABLE `product_sale_elements` ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- attribute_category +-- attribute_template -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `attribute_category`; +DROP TABLE IF EXISTS `attribute_template`; -CREATE TABLE `attribute_category` +CREATE TABLE `attribute_template` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `category_id` INTEGER NOT NULL, `attribute_id` INTEGER NOT NULL, + `template_id` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_attribute_category_category_id` (`category_id`), - INDEX `idx_attribute_category_attribute_id` (`attribute_id`), - CONSTRAINT `fk_attribute_category_category_id` - FOREIGN KEY (`category_id`) - REFERENCES `category` (`id`) - ON UPDATE RESTRICT - ON DELETE CASCADE, - CONSTRAINT `fk_attribute_category_attribute_id` + INDEX `idx_attribute_template_id` (`attribute_id`), + INDEX `fk_attribute_template_idx` (`template_id`), + CONSTRAINT `fk_attribute_template_id` FOREIGN KEY (`attribute_id`) REFERENCES `attribute` (`id`) ON UPDATE RESTRICT - ON DELETE CASCADE + ON DELETE CASCADE, + CONSTRAINT `fk_attribute_template` + FOREIGN KEY (`template_id`) + REFERENCES `template` (`id`) ) ENGINE=InnoDB; -- --------------------------------------------------------------------- @@ -433,6 +434,8 @@ CREATE TABLE `customer` `lang` VARCHAR(10), `sponsor` VARCHAR(50), `discount` FLOAT, + `remember_me_token` VARCHAR(255), + `remember_me_serial` VARCHAR(255), `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), @@ -923,6 +926,8 @@ CREATE TABLE `admin` `password` VARCHAR(128) NOT NULL, `algo` VARCHAR(128), `salt` VARCHAR(128), + `remember_me_token` VARCHAR(255), + `remember_me_serial` VARCHAR(255), `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) @@ -1482,6 +1487,20 @@ CREATE TABLE `rewriting_argument` ON DELETE CASCADE ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- template +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `template`; + +CREATE TABLE `template` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + -- --------------------------------------------------------------------- -- category_i18n -- --------------------------------------------------------------------- @@ -2060,6 +2079,24 @@ CREATE TABLE `folder_document_i18n` ON DELETE CASCADE ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- template_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `template_i18n`; + +CREATE TABLE `template_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `name` VARCHAR(255), + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `template_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `template` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + -- --------------------------------------------------------------------- -- category_version -- --------------------------------------------------------------------- @@ -2097,6 +2134,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, `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 1d928bc7b..1ffeb028a 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,1143 +1,1162 @@ - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + +
+
diff --git a/templates/admin/default/ajax/template-attribute-list.html b/templates/admin/default/ajax/template-attribute-list.html new file mode 100644 index 000000000..b6379672a --- /dev/null +++ b/templates/admin/default/ajax/template-attribute-list.html @@ -0,0 +1,15 @@ +
+ {ifloop rel="free_attributes"} + + {intl l='Select an attribute and click (+) to add it to this template'} + {/ifloop} + {elseloop rel="free_attributes"} +
There is currently no available attributes.
+ {/elseloop} +
+ diff --git a/templates/admin/default/includes/thelia_news_feed.html b/templates/admin/default/ajax/thelia_news_feed.html similarity index 100% rename from templates/admin/default/includes/thelia_news_feed.html rename to templates/admin/default/ajax/thelia_news_feed.html diff --git a/templates/admin/default/attributes.html b/templates/admin/default/attributes.html index 57fd9c256..348219f5c 100644 --- a/templates/admin/default/attributes.html +++ b/templates/admin/default/attributes.html @@ -224,7 +224,7 @@ dialog_title = {intl l="Delete attribute"} dialog_message = {intl l="Do you really want to delete this attribute ? It will be removed from all product templates."} - form_action = {url path='/admin/configuration/attributes/remove_from-all-templates' attribute_id=$ID} + form_action = {url path='/admin/configuration/attributes/delete'} form_content = {$smarty.capture.delete_dialog nofilter} } diff --git a/templates/admin/default/login.html b/templates/admin/default/login.html index 07e238c88..682d2b954 100755 --- a/templates/admin/default/login.html +++ b/templates/admin/default/login.html @@ -64,7 +64,7 @@ {block name="javascript-initialization"} {/block} \ No newline at end of file diff --git a/templates/admin/default/template-edit.html b/templates/admin/default/template-edit.html new file mode 100644 index 000000000..0a073b719 --- /dev/null +++ b/templates/admin/default/template-edit.html @@ -0,0 +1,115 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Edit a template'}{/block} + +{block name="check-permissions"}admin.configuration.templates.edit{/block} + +{block name="main-content"} +
+ +
+ + {loop name="template_edit" type="template" id="$template_id" backend_context="1" lang="$edit_language_id"} + + + +
+
+
+ +
+ {intl l="Edit template $NAME"} +
+ +
+
+ + {form name="thelia.admin.template.modification"} + + + {* Be sure to get the template ID, even if the form could not be validated *} + + + {include file="includes/inner-form-toolbar.html" close_url="{url path='/admin/configuration/templates'}"} + + {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} + + {form_field form=$form field='name'} +
+ + +
+ {/form_field} + + {/form} +
+
+ +
+
+
+

{intl l='Attributes'}

+

Manage attributes included in this product templates

+ +
+
+
+ +
+ +
+

{intl l='Features'}

+

Manage features included in this product templates

+ +
+
+
+
+
+
+ +
+
+ +
+ + {/loop} + + {elseloop rel="template_edit"} +
+
+
+ {intl l="Sorry, template ID=$template_id was not found."} +
+
+
+ {/elseloop} + +
+
+{/block} + +{block name="javascript-initialization"} + + +{/block} \ No newline at end of file diff --git a/templates/admin/default/templates.html b/templates/admin/default/templates.html new file mode 100644 index 000000000..6f88bed47 --- /dev/null +++ b/templates/admin/default/templates.html @@ -0,0 +1,215 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Thelia Product Templates'}{/block} + +{block name="check-permissions"}admin.configuration.templates.view{/block} + +{block name="main-content"} +
+ +
+ + + + {module_include location='templates_top'} + +
+
+
+
+ + {if ! empty($general_error) } +
{$general_error}
+ {/if} + + + + + + + + + + {module_include location='templates_table_header'} + + + + + + + {loop name="list" type="template" backend_context="1" lang=$lang_id order=$order} + + + + + + {module_include location='templates_table_row'} + + + + {/loop} + + {elseloop rel="list"} + + + + {/elseloop} + +
+ {intl l='Thelia product templates'} + + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.templates.create"} + + + + {/loop} +
+ {admin_sortable_header + current_order=$order + order='id' + reverse_order='id_reverse' + path='/admin/configuration/templates' + label="{intl l='ID'}" + } + + {admin_sortable_header + current_order=$order + order='alpha' + reverse_order='alpha_reverse' + path='/admin/configuration/templates' + label="{intl l='Title'}" + } + {intl l="Actions"}
{$ID} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.templates.change"} + {$NAME} + {/loop} + {elseloop rel="can_change"} + {$NAME} + {/elseloop} + +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.templates.change"} + + {/loop} + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.templates.delete"} + + {/loop} +
+
+
+ {intl l="No product template has been created yet. Click the + button to create one."} +
+
+
+
+
+
+ + {module_include location='templates_bottom'} + +
+
+ +{* Adding a new template *} + +{form name="thelia.admin.template.creation"} + + {* Capture the dialog body, to pass it to the generic dialog *} + {capture "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 template ID, see controller *} + + {/form_field} + + {form_field form=$form field='name'} +
+ + + {loop type="lang" name="default-lang" default_only="1"} +
+ + {intl l=$TITLE} +
+ +
{intl l="Enter here the template name in the default language ($TITLE)"}
+ + {* Switch edition to the current locale *} + + + {form_field form=$form field='locale'} + + {/form_field} + {/loop} +
+ {/form_field} + + {module_include location='template_create_form'} + + {/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "creation_dialog" + dialog_title = {intl l="Create a new product template"} + dialog_body = {$smarty.capture.creation_dialog nofilter} + + dialog_ok_label = {intl l="Create this product template"} + + form_action = {url path='/admin/configuration/templates/create'} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } +{/form} + +{* Delete confirmation dialog *} + +{capture "delete_dialog"} + + + {module_include location='template_delete_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "delete_dialog" + dialog_title = {intl l="Delete template"} + dialog_message = {intl l="Do you really want to delete this template ? It will be removed from all products."} + + form_action = {url path='/admin/configuration/templates/delete'} + form_content = {$smarty.capture.delete_dialog nofilter} +} +{/block} + +{block name="javascript-initialization"} + + {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'} + + {/javascripts} + + +{/block} \ No newline at end of file