diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 4fd8b886e..857790141 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -135,6 +135,8 @@ class CreateAdminUser extends ContainerAwareCommand $output->writeln("Passwords are different, please try again."); } while (true); + $admin->setProfile(null); + return $admin; } diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 7e77e30a0..192b6f368 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -7,6 +7,7 @@ + diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php index 38ec9cb6b..090aca572 100644 --- a/core/lib/Thelia/Controller/Admin/AddressController.php +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; use Thelia\Core\Event\Address\AddressEvent; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; @@ -46,10 +47,10 @@ class AddressController extends AbstractCrudController null, null, - 'admin.customer.update.view', - 'admin.address.create', - 'admin.address.update', - 'admin.address.delete', + AdminResources::ADDRESS_VIEW, + AdminResources::ADDRESS_CREATE, + AdminResources::ADDRESS_UPDATE, + AdminResources::ADDRESS_DELETE, TheliaEvents::ADDRESS_CREATE, TheliaEvents::ADDRESS_UPDATE, @@ -62,7 +63,7 @@ class AddressController extends AbstractCrudController public function useAddressAction() { - if (null !== $response = $this->checkAuth("admin.customer.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $address_id = $this->getRequest()->request->get('address_id'); diff --git a/core/lib/Thelia/Controller/Admin/AreaController.php b/core/lib/Thelia/Controller/Admin/AreaController.php index d6ac7918a..bceddad96 100644 --- a/core/lib/Thelia/Controller/Admin/AreaController.php +++ b/core/lib/Thelia/Controller/Admin/AreaController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Area\AreaAddCountryEvent; use Thelia\Core\Event\Area\AreaCreateEvent; use Thelia\Core\Event\Area\AreaDeleteEvent; @@ -52,10 +53,10 @@ class AreaController extends AbstractCrudController null, null, - 'admin.area.default', - 'admin.area.create', - 'admin.area.update', - 'admin.area.delete', + AdminResources::AREA_VIEW, + AdminResources::AREA_CREATE, + AdminResources::AREA_UPDATE, + AdminResources::AREA_DELETE, TheliaEvents::AREA_CREATE, TheliaEvents::AREA_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/AttributeAvController.php b/core/lib/Thelia/Controller/Admin/AttributeAvController.php index bc6984e9e..1e060de2c 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeAvController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeAvController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent; @@ -46,10 +47,10 @@ class AttributeAvController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.attributes-av.view', - 'admin.configuration.attributes-av.create', - 'admin.configuration.attributes-av.update', - 'admin.configuration.attributes-av.delete', + AdminResources::ATTRIBUTE_VIEW, + AdminResources::ATTRIBUTE_CREATE, + AdminResources::ATTRIBUTE_UPDATE, + AdminResources::ATTRIBUTE_DELETE, TheliaEvents::ATTRIBUTE_AV_CREATE, TheliaEvents::ATTRIBUTE_AV_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index 689b92a01..e2e3f1a7e 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Attribute\AttributeDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Attribute\AttributeUpdateEvent; @@ -50,10 +51,10 @@ class AttributeController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.attributes.view', - 'admin.configuration.attributes.create', - 'admin.configuration.attributes.update', - 'admin.configuration.attributes.delete', + AdminResources::ATTRIBUTE_VIEW, + AdminResources::ATTRIBUTE_CREATE, + AdminResources::ATTRIBUTE_UPDATE, + AdminResources::ATTRIBUTE_DELETE, TheliaEvents::ATTRIBUTE_CREATE, TheliaEvents::ATTRIBUTE_UPDATE, @@ -253,7 +254,7 @@ class AttributeController extends AbstractCrudController protected function addRemoveFromAllTemplates($eventType) { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; try { if (null !== $object = $this->getExistingObject()) { diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index ff2dae1e4..e08ffdff9 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Symfony\Component\HttpFoundation\Response; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Category\CategoryDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Category\CategoryUpdateEvent; @@ -54,10 +55,10 @@ class CategoryController extends AbstractCrudController 'manual', 'category_order', - 'admin.categories.default', - 'admin.categories.create', - 'admin.categories.update', - 'admin.categories.delete', + AdminResources::CATEGORY_VIEW, + AdminResources::CATEGORY_CREATE, + AdminResources::CATEGORY_UPDATE, + AdminResources::CATEGORY_DELETE, TheliaEvents::CATEGORY_CREATE, TheliaEvents::CATEGORY_UPDATE, @@ -216,7 +217,7 @@ class CategoryController extends AbstractCrudController public function setToggleVisibilityAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $event = new CategoryToggleVisibilityEvent($this->getExistingObject()); @@ -296,7 +297,7 @@ class CategoryController extends AbstractCrudController public function addRelatedContentAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $content_id = intval($this->getRequest()->get('content_id')); @@ -326,7 +327,7 @@ class CategoryController extends AbstractCrudController public function addRelatedPictureAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) { + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) { return $response; } @@ -354,7 +355,7 @@ class CategoryController extends AbstractCrudController public function deleteRelatedContentAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $content_id = intval($this->getRequest()->get('content_id')); diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index dc19107d8..1a99d8470 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Config\ConfigDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Config\ConfigUpdateEvent; @@ -45,10 +46,10 @@ class ConfigController extends AbstractCrudController 'name', 'order', - 'admin.configuration.variables.view', - 'admin.configuration.variables.create', - 'admin.configuration.variables.update', - 'admin.configuration.variables.delete', + AdminResources::CONFIG_VIEW, + AdminResources::CONFIG_CREATE, + AdminResources::CONFIG_UPDATE, + AdminResources::CONFIG_DELETE, TheliaEvents::CONFIG_CREATE, TheliaEvents::CONFIG_UPDATE, @@ -187,7 +188,7 @@ class ConfigController extends AbstractCrudController public function changeValuesAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $variables = $this->getRequest()->get('variable', array()); diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index c3811695f..721c193f0 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Content\ContentAddFolderEvent; use Thelia\Core\Event\Content\ContentCreateEvent; use Thelia\Core\Event\Content\ContentDeleteEvent; @@ -49,10 +50,10 @@ class ContentController extends AbstractCrudController 'manual', 'content_order', - 'admin.content.default', - 'admin.content.create', - 'admin.content.update', - 'admin.content.delete', + AdminResources::CONTENT_VIEW, + AdminResources::CONTENT_CREATE, + AdminResources::CONTENT_UPDATE, + AdminResources::CONTENT_DELETE, TheliaEvents::CONTENT_CREATE, TheliaEvents::CONTENT_UPDATE, @@ -70,7 +71,7 @@ class ContentController extends AbstractCrudController public function addAdditionalFolderAction() { // Check current user authorization - if (null !== $response = $this->checkAuth('admin.content.update')) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $folder_id = intval($this->getRequest()->request->get('additional_folder_id')); @@ -98,7 +99,7 @@ class ContentController extends AbstractCrudController public function removeAdditionalFolderAction() { // Check current user authorization - if (null !== $response = $this->checkAuth('admin.content.update')) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $folder_id = intval($this->getRequest()->request->get('additional_folder_id')); diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index 91160311f..f3ebf4e42 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Country\CountryCreateEvent; use Thelia\Core\Event\Country\CountryDeleteEvent; use Thelia\Core\Event\Country\CountryToggleDefaultEvent; @@ -46,10 +47,10 @@ class CountryController extends AbstractCrudController 'manual', 'country_order', - 'admin.country.default', - 'admin.country.create', - 'admin.country.update', - 'admin.country.delete', + AdminResources::COUNTRY_VIEW, + AdminResources::COUNTRY_CREATE, + AdminResources::COUNTRY_UPDATE, + AdminResources::COUNTRY_DELETE, TheliaEvents::COUNTRY_CREATE, TheliaEvents::COUNTRY_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index eaecacbda..03a7b7477 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Router; use Thelia\Condition\ConditionFactory; use Thelia\Condition\ConditionManagerInterface; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; @@ -62,7 +63,7 @@ class CouponController extends BaseAdminController */ public function browseAction() { - $this->checkAuth('ADMIN', 'admin.coupon.view'); + $this->checkAuth('ADMIN', AdminResources::COUPON_VIEW); $args['urlReadCoupon'] = $this->getRoute( 'admin.coupon.read', @@ -94,7 +95,7 @@ class CouponController extends BaseAdminController */ public function readAction($couponId) { - $this->checkAuth('ADMIN', 'admin.coupon.read'); + $this->checkAuth('ADMIN', AdminResources::COUPON_VIEW); // Database request repeated in the loop but cached $search = CouponQuery::create(); @@ -122,7 +123,7 @@ class CouponController extends BaseAdminController public function createAction() { // Check current user authorization - $response = $this->checkAuth('admin.coupon.create'); + $response = $this->checkAuth(AdminResources::COUPON_CREATE); if ($response !== null) { return $response; } @@ -170,7 +171,7 @@ class CouponController extends BaseAdminController public function updateAction($couponId) { // Check current user authorization - $response = $this->checkAuth('admin.coupon.update'); + $response = $this->checkAuth(AdminResources::COUPON_UPDATE); if ($response !== null) { return $response; } @@ -277,7 +278,7 @@ var_dump($coupon->getIsRemovingPostage());; */ public function getConditionInputAction($conditionId) { - $this->checkAuth('ADMIN', 'admin.coupon.read'); + $this->checkAuth('ADMIN', AdminResources::COUPON_VIEW); $this->checkXmlHttpRequest(); @@ -307,7 +308,7 @@ var_dump($coupon->getIsRemovingPostage());; */ public function updateConditionsAction($couponId) { - $this->checkAuth('ADMIN', 'admin.coupon.read'); + $this->checkAuth('ADMIN', AdminResources::COUPON_VIEW); $this->checkXmlHttpRequest(); diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 6fd98983b..2510b845c 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Currency\CurrencyDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Currency\CurrencyUpdateEvent; @@ -46,10 +47,10 @@ class CurrencyController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.currencies.view', - 'admin.configuration.currencies.create', - 'admin.configuration.currencies.update', - 'admin.configuration.currencies.delete', + AdminResources::CURRENCY_VIEW, + AdminResources::CURRENCY_CREATE, + AdminResources::CURRENCY_UPDATE, + AdminResources::CURRENCY_DELETE, TheliaEvents::CURRENCY_CREATE, TheliaEvents::CURRENCY_UPDATE, @@ -186,7 +187,7 @@ class CurrencyController extends AbstractCrudController public function updateRatesAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; try { $this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES); @@ -204,7 +205,7 @@ class CurrencyController extends AbstractCrudController public function setDefaultAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $changeEvent = new CurrencyUpdateEvent($this->getRequest()->get('currency_id', 0)); diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index e4d24e9ad..555d2653d 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -26,6 +26,7 @@ namespace Thelia\Controller\Admin; use Propel\Runtime\Exception\PropelException; use Symfony\Component\Form\Form; use Thelia\Core\Event\Address\AddressEvent; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Customer\CustomerAddressEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; @@ -45,13 +46,13 @@ class CustomerController extends BaseAdminController { public function indexAction() { - if (null !== $response = $this->checkAuth("admin.customer.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER_VIEW)) return $response; return $this->render("customers", array("display_customer" => 20)); } public function viewAction($customer_id) { - if (null !== $response = $this->checkAuth("admin.customer.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER_VIEW)) return $response; return $this->render("customer-edit", array( "customer_id" => $customer_id )); @@ -67,7 +68,7 @@ class CustomerController extends BaseAdminController */ public function updateAction($customer_id) { - if (null !== $response = $this->checkAuth("admin.customer.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER_UPDATE)) return $response; $message = false; @@ -123,7 +124,7 @@ class CustomerController extends BaseAdminController public function deleteAction() { - if (null !== $response = $this->checkAuth("admin.customer.delete")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER_DELETE)) return $response; $message = null; diff --git a/core/lib/Thelia/Controller/Admin/FeatureAvController.php b/core/lib/Thelia/Controller/Admin/FeatureAvController.php index e8684ef04..e65fceac0 100644 --- a/core/lib/Thelia/Controller/Admin/FeatureAvController.php +++ b/core/lib/Thelia/Controller/Admin/FeatureAvController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Feature\FeatureAvDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Feature\FeatureAvUpdateEvent; @@ -46,10 +47,10 @@ class FeatureAvController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.features-av.view', - 'admin.configuration.features-av.create', - 'admin.configuration.features-av.update', - 'admin.configuration.features-av.delete', + AdminResources::FEATURE_VIEW, + AdminResources::FEATURE_CREATE, + AdminResources::FEATURE_UPDATE, + AdminResources::FEATURE_DELETE, TheliaEvents::FEATURE_AV_CREATE, TheliaEvents::FEATURE_AV_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/FeatureController.php b/core/lib/Thelia/Controller/Admin/FeatureController.php index a8fde8880..c681a7b61 100644 --- a/core/lib/Thelia/Controller/Admin/FeatureController.php +++ b/core/lib/Thelia/Controller/Admin/FeatureController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Feature\FeatureDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Feature\FeatureUpdateEvent; @@ -50,10 +51,10 @@ class FeatureController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.features.view', - 'admin.configuration.features.create', - 'admin.configuration.features.update', - 'admin.configuration.features.delete', + AdminResources::FEATURE_VIEW, + AdminResources::FEATURE_CREATE, + AdminResources::FEATURE_UPDATE, + AdminResources::FEATURE_DELETE, TheliaEvents::FEATURE_CREATE, TheliaEvents::FEATURE_UPDATE, @@ -253,7 +254,7 @@ class FeatureController extends AbstractCrudController protected function addRemoveFromAllTemplates($eventType) { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.features.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; try { if (null !== $object = $this->getExistingObject()) { diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php index e99b857f7..0c6f51630 100755 --- a/core/lib/Thelia/Controller/Admin/FileController.php +++ b/core/lib/Thelia/Controller/Admin/FileController.php @@ -26,6 +26,7 @@ namespace Thelia\Controller\Admin; use Propel\Runtime\Exception\PropelException; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Response; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent; use Thelia\Core\Event\Document\DocumentDeleteEvent; use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent; @@ -69,7 +70,7 @@ class FileController extends BaseAdminController */ public function saveImageAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.image.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); if ($this->isParentTypeValid($parentType)) { @@ -145,7 +146,7 @@ class FileController extends BaseAdminController */ public function saveDocumentAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.document.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); if ($this->isParentTypeValid($parentType)) { @@ -209,7 +210,7 @@ class FileController extends BaseAdminController */ public function getImageListAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.image.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $args = array('imageType' => $parentType, 'parentId' => $parentId); @@ -226,7 +227,7 @@ class FileController extends BaseAdminController */ public function getDocumentListAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.document.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $args = array('documentType' => $parentType, 'parentId' => $parentId); @@ -243,7 +244,7 @@ class FileController extends BaseAdminController */ public function getImageFormAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.image.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $args = array('imageType' => $parentType, 'parentId' => $parentId); @@ -260,7 +261,7 @@ class FileController extends BaseAdminController */ public function getDocumentFormAjaxAction($parentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.document.save'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $args = array('documentType' => $parentType, 'parentId' => $parentId); @@ -277,7 +278,7 @@ class FileController extends BaseAdminController */ public function viewImageAction($imageId, $parentType) { - if (null !== $response = $this->checkAuth('admin.image.view')) { + if (null !== $response = $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update'))) { return $response; } try { @@ -306,7 +307,7 @@ class FileController extends BaseAdminController */ public function viewDocumentAction($documentId, $parentType) { - if (null !== $response = $this->checkAuth('admin.document.view')) { + if (null !== $response = $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update'))) { return $response; } try { @@ -335,7 +336,7 @@ class FileController extends BaseAdminController */ public function updateImageAction($imageId, $parentType) { - if (null !== $response = $this->checkAuth('admin.image.update')) { + if (null !== $response = $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update'))) { return $response; } @@ -412,7 +413,7 @@ class FileController extends BaseAdminController */ public function updateDocumentAction($documentId, $parentType) { - if (null !== $response = $this->checkAuth('admin.document.update')) { + if (null !== $response = $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update'))) { return $response; } @@ -489,7 +490,7 @@ class FileController extends BaseAdminController */ public function deleteImageAction($imageId, $parentType) { - $this->checkAuth('ADMIN', 'admin.image.delete'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $fileManager = new FileManager($this->container); @@ -532,7 +533,7 @@ class FileController extends BaseAdminController */ public function deleteDocumentAction($documentId, $parentType) { - $this->checkAuth('ADMIN', 'admin.document.delete'); + $this->checkAuth('ADMIN', AdminResources::retrieve($parentType, 'update')); $this->checkXmlHttpRequest(); $fileManager = new FileManager($this->container); diff --git a/core/lib/Thelia/Controller/Admin/FolderController.php b/core/lib/Thelia/Controller/Admin/FolderController.php index 24e2659d9..a5dd5c8eb 100644 --- a/core/lib/Thelia/Controller/Admin/FolderController.php +++ b/core/lib/Thelia/Controller/Admin/FolderController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Folder\FolderCreateEvent; use Thelia\Core\Event\Folder\FolderDeleteEvent; use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent; @@ -47,10 +48,10 @@ class FolderController extends AbstractCrudController 'manual', 'folder_order', - 'admin.folder.default', - 'admin.folder.create', - 'admin.folder.update', - 'admin.folder.delete', + AdminResources::FOLDER_VIEW, + AdminResources::FOLDER_CREATE, + AdminResources::FOLDER_UPDATE, + AdminResources::FOLDER_DELETE, TheliaEvents::FOLDER_CREATE, TheliaEvents::FOLDER_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/LanguageController.php b/core/lib/Thelia/Controller/Admin/LanguageController.php index aa818daad..e6ea4890b 100644 --- a/core/lib/Thelia/Controller/Admin/LanguageController.php +++ b/core/lib/Thelia/Controller/Admin/LanguageController.php @@ -23,6 +23,8 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; + /** * Class LanguageController * @package Thelia\Controller\Admin @@ -32,7 +34,7 @@ class LanguageController extends BaseAdminController { public function defaultAction() { - if (null !== $response = $this->checkAuth("admin.configuration.languages.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE_VIEW)) return $response; return $this->render("languages"); } diff --git a/core/lib/Thelia/Controller/Admin/MailingSystemController.php b/core/lib/Thelia/Controller/Admin/MailingSystemController.php index 89defe01d..7cc1a6727 100644 --- a/core/lib/Thelia/Controller/Admin/MailingSystemController.php +++ b/core/lib/Thelia/Controller/Admin/MailingSystemController.php @@ -23,6 +23,8 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; + /** * Class MailingSystemController * @package Thelia\Controller\Admin @@ -32,7 +34,7 @@ class MailingSystemController extends BaseAdminController { public function defaultAction() { - if (null !== $response = $this->checkAuth("admin.configuration.mailing-system.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::MAILING_SYSTEM_VIEW)) return $response; return $this->render("mailing-system"); } diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index 176fa7de8..71da8b9cf 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Message\MessageDeleteEvent; use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\Message\MessageUpdateEvent; use Thelia\Core\Event\Message\MessageCreateEvent; @@ -44,10 +45,10 @@ class MessageController extends AbstractCrudController null, // no sort order change null, // no sort order change - 'admin.configuration.messages.view', - 'admin.configuration.messages.create', - 'admin.configuration.messages.update', - 'admin.configuration.messages.delete', + AdminResources::MESSAGE_VIEW, + AdminResources::MESSAGE_CREATE, + AdminResources::MESSAGE_UPDATE, + AdminResources::MESSAGE_DELETE, TheliaEvents::MESSAGE_CREATE, TheliaEvents::MESSAGE_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 03691c069..c9430ca41 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -23,6 +23,8 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; + /** * Class ModuleController * @package Thelia\Controller\Admin @@ -32,7 +34,7 @@ class ModuleController extends BaseAdminController { public function indexAction() { - if (null !== $response = $this->checkAuth("admin.module.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::MODULE_VIEW)) return $response; return $this->render("modules", array("display_module" => 20)); } diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php index 1df0679f0..ff1346f58 100644 --- a/core/lib/Thelia/Controller/Admin/OrderController.php +++ b/core/lib/Thelia/Controller/Admin/OrderController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Symfony\Component\HttpFoundation\Response; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Order\OrderAddressEvent; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\PdfEvent; @@ -44,7 +45,7 @@ class OrderController extends BaseAdminController { public function indexAction() { - if (null !== $response = $this->checkAuth("admin.orders.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::ORDER_VIEW)) return $response; return $this->render("orders", array("display_order" => 20)); } @@ -57,7 +58,7 @@ class OrderController extends BaseAdminController public function updateStatus($order_id = null) { - if (null !== $response = $this->checkAuth("admin.order.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::ORDER_UPDATE)) return $response; $message = null; @@ -108,7 +109,7 @@ class OrderController extends BaseAdminController public function updateDeliveryRef($order_id) { - if (null !== $response = $this->checkAuth("admin.order.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::ORDER_UPDATE)) return $response; $message = null; @@ -143,7 +144,7 @@ class OrderController extends BaseAdminController public function updateAddress($order_id) { - if (null !== $response = $this->checkAuth("admin.order.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::ORDER_UPDATE)) return $response; $message = null; @@ -209,7 +210,7 @@ class OrderController extends BaseAdminController protected function generatePdf($order_id, $fileName) { - if (null !== $response = $this->checkAuth("admin.order.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::ORDER_UPDATE)) return $response; $html = $this->renderRaw( diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 4ff40abff..8c56ba55a 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Product\ProductAddCategoryEvent; use Thelia\Core\Event\Product\ProductDeleteCategoryEvent; use Thelia\Core\Event\Product\ProductDeleteEvent; @@ -61,10 +62,10 @@ class ProductController extends AbstractCrudController 'manual', 'product_order', - 'admin.products.default', - 'admin.products.create', - 'admin.products.update', - 'admin.products.delete', + AdminResources::PRODUCT_VIEW, + AdminResources::PRODUCT_CREATE, + AdminResources::PRODUCT_UPDATE, + AdminResources::PRODUCT_DELETE, TheliaEvents::PRODUCT_CREATE, TheliaEvents::PRODUCT_UPDATE, @@ -280,7 +281,7 @@ class ProductController extends AbstractCrudController public function setToggleVisibilityAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $event = new ProductToggleVisibilityEvent($this->getExistingObject()); @@ -356,7 +357,7 @@ class ProductController extends AbstractCrudController { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $content_id = intval($this->getRequest()->get('content_id')); @@ -382,7 +383,7 @@ class ProductController extends AbstractCrudController { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $content_id = intval($this->getRequest()->get('content_id')); @@ -434,7 +435,7 @@ class ProductController extends AbstractCrudController public function addAccessoryAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $accessory_id = intval($this->getRequest()->get('accessory_id')); @@ -459,7 +460,7 @@ class ProductController extends AbstractCrudController public function deleteAccessoryAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $accessory_id = intval($this->getRequest()->get('accessory_id')); @@ -515,7 +516,7 @@ class ProductController extends AbstractCrudController public function setProductTemplateAction($productId) { // Check current user authorization - if (null !== $response = $this->checkAuth('admin.products.update')) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $product = ProductQuery::create()->findPk($productId); @@ -612,7 +613,7 @@ class ProductController extends AbstractCrudController public function addAdditionalCategoryAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $category_id = intval($this->getRequest()->request->get('additional_category_id')); @@ -637,7 +638,7 @@ class ProductController extends AbstractCrudController public function deleteAdditionalCategoryAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $category_id = intval($this->getRequest()->get('additional_category_id')); @@ -734,7 +735,7 @@ class ProductController extends AbstractCrudController public function addCombinationAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $event = new ProductCreateCombinationEvent( $this->getExistingObject(), @@ -759,7 +760,7 @@ class ProductController extends AbstractCrudController public function deleteCombinationAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.products.update")) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $event = new ProductDeleteCombinationEvent( $this->getExistingObject(), diff --git a/core/lib/Thelia/Controller/Admin/ProfileController.php b/core/lib/Thelia/Controller/Admin/ProfileController.php index 619fc0ea3..345093303 100644 --- a/core/lib/Thelia/Controller/Admin/ProfileController.php +++ b/core/lib/Thelia/Controller/Admin/ProfileController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Profile\ProfileEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\ProfileCreationForm; @@ -39,10 +40,10 @@ class ProfileController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.profile.view', - 'admin.configuration.profile.create', - 'admin.configuration.profile.update', - 'admin.configuration.profile.delete', + AdminResources::PRODUCT_VIEW, + AdminResources::PRODUCT_CREATE, + AdminResources::PRODUCT_UPDATE, + AdminResources::PRODUCT_DELETE, TheliaEvents::PROFILE_CREATE, TheliaEvents::PROFILE_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php index d68de4808..f458a4f59 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php +++ b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent; use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent; use Thelia\Core\Event\TheliaEvents; @@ -40,13 +41,13 @@ class ShippingZoneController extends BaseAdminController public function indexAction() { - if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::SHIPPING_ZONE_VIEW)) return $response; return $this->render("shipping-zones", array("display_shipping_zone" => 20)); } public function updateAction($shipping_zones_id) { - if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::SHIPPING_ZONE_VIEW)) return $response; return $this->render("shipping-zones-edit", array( "shipping_zones_id" => $shipping_zones_id )); @@ -57,7 +58,7 @@ class ShippingZoneController extends BaseAdminController */ public function addArea() { - if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::SHIPPING_ZONE_UPDATE)) return $response; $shippingAreaForm = new ShippingZoneAddArea($this->getRequest()); $error_msg = null; @@ -92,7 +93,7 @@ class ShippingZoneController extends BaseAdminController public function removeArea() { - if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::SHIPPING_ZONE_UPDATE)) return $response; $shippingAreaForm = new ShippingZoneRemoveArea($this->getRequest()); $error_msg = null; diff --git a/core/lib/Thelia/Controller/Admin/TaxController.php b/core/lib/Thelia/Controller/Admin/TaxController.php index fd81e4d6c..d0166c9c5 100644 --- a/core/lib/Thelia/Controller/Admin/TaxController.php +++ b/core/lib/Thelia/Controller/Admin/TaxController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Tax\TaxEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\TaxCreationForm; @@ -39,10 +40,10 @@ class TaxController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.tax.view', - 'admin.configuration.tax.create', - 'admin.configuration.tax.update', - 'admin.configuration.tax.delete', + AdminResources::TAX_VIEW, + AdminResources::TAX_CREATE, + AdminResources::TAX_UPDATE, + AdminResources::TAX_DELETE, TheliaEvents::TAX_CREATE, TheliaEvents::TAX_UPDATE, diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index 17381c7a1..eac6a4aa3 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Tax\TaxRuleEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\TaxRuleCreationForm; @@ -40,10 +41,10 @@ class TaxRuleController extends AbstractCrudController 'manual', 'order', - 'admin.configuration.taxrule.view', - 'admin.configuration.taxrule.create', - 'admin.configuration.taxrule.update', - 'admin.configuration.taxrule.delete', + AdminResources::TAX_VIEW, + AdminResources::TAX_CREATE, + AdminResources::TAX_UPDATE, + AdminResources::TAX_DELETE, TheliaEvents::TAX_RULE_CREATE, TheliaEvents::TAX_RULE_UPDATE, @@ -256,7 +257,7 @@ class TaxRuleController extends AbstractCrudController public function processUpdateTaxesAction() { // Check current user authorization - if (null !== $response = $this->checkAuth('admin.configuration.taxrule.update')) return $response; + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; $error_msg = false; diff --git a/core/lib/Thelia/Controller/Admin/TemplateController.php b/core/lib/Thelia/Controller/Admin/TemplateController.php index bdeac9fd2..ba4a1cccf 100644 --- a/core/lib/Thelia/Controller/Admin/TemplateController.php +++ b/core/lib/Thelia/Controller/Admin/TemplateController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\AdminResources; use Thelia\Core\Event\Template\TemplateDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Template\TemplateUpdateEvent; @@ -51,10 +52,10 @@ class TemplateController extends AbstractCrudController null, null, - 'admin.configuration.templates.view', - 'admin.configuration.templates.create', - 'admin.configuration.templates.update', - 'admin.configuration.templates.delete', + AdminResources::TEMPLATE_VIEW, + AdminResources::TEMPLATE_CREATE, + AdminResources::TEMPLATE_UPDATE, + AdminResources::TEMPLATE_DELETE, TheliaEvents::TEMPLATE_CREATE, TheliaEvents::TEMPLATE_UPDATE, @@ -212,7 +213,7 @@ class TemplateController extends AbstractCrudController public function addAttributeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.add")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::TEMPLATE_UPDATE)) return $response; $attribute_id = intval($this->getRequest()->get('attribute_id')); @@ -236,7 +237,7 @@ class TemplateController extends AbstractCrudController public function deleteAttributeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.delete")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::TEMPLATE_UPDATE)) return $response; $event = new TemplateDeleteAttributeEvent( $this->getExistingObject(), @@ -271,7 +272,7 @@ class TemplateController extends AbstractCrudController public function addFeatureAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.template.feature.add")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::TEMPLATE_UPDATE)) return $response; $feature_id = intval($this->getRequest()->get('feature_id')); @@ -295,7 +296,7 @@ class TemplateController extends AbstractCrudController public function deleteFeatureAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.template.feature.delete")) return $response; + if (null !== $response = $this->checkAuth(AdminResources::TEMPLATE_UPDATE)) return $response; $event = new TemplateDeleteFeatureEvent( $this->getExistingObject(), diff --git a/core/lib/Thelia/Controller/Admin/AdminProfileController.php b/core/lib/Thelia/Core/Security/Exception/RessourceException.php similarity index 80% rename from core/lib/Thelia/Controller/Admin/AdminProfileController.php rename to core/lib/Thelia/Core/Security/Exception/RessourceException.php index 91f3f2031..27343bd16 100644 --- a/core/lib/Thelia/Controller/Admin/AdminProfileController.php +++ b/core/lib/Thelia/Core/Security/Exception/RessourceException.php @@ -21,19 +21,19 @@ /* */ /*************************************************************************************/ -namespace Thelia\Controller\Admin; +namespace Thelia\Core\Security\Exception; -/** - * Class AdminProfileController - * @package Thelia\Controller\Admin - * @author Manuel Raynaud - */ -class AdminProfileController extends BaseAdminController +class ResourceException extends \RuntimeException { - public function defaultAction() + const UNKNOWN_EXCEPTION = 0; + + const RESOURCE_NOT_FOUND = 404; + + public function __construct($message, $code = null, $previous = null) { - if (null !== $response = $this->checkAuth("admin.admin-profile.view")) return $response; - return $this->render("admin-profiles", array("display_admin_profile" => 20)); + if ($code === null) { + $code = self::UNKNOWN_EXCEPTION; + } + parent::__construct($message, $code, $previous); } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Security/Resource/AdminResources.php b/core/lib/Thelia/Core/Security/Resource/AdminResources.php new file mode 100644 index 000000000..f23d26a4e --- /dev/null +++ b/core/lib/Thelia/Core/Security/Resource/AdminResources.php @@ -0,0 +1,167 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Core\Security\Exception\ResourceException; + +/** + * + * This class contains all Thelia admin resources + * + * @author Etienne roudeix + */ +final class AdminResources +{ + static private $selfReflection = null; + + static public function retrieve($name, $action) + { + $contantName = strtoupper($name . '_' . $action); + + if(null === self::$selfReflection) { + self::$selfReflection = new \ReflectionClass(__CLASS__); + } + + if(self::$selfReflection->hasConstant($contantName)) { + return self::$selfReflection->getConstant($contantName); + } else { + throw new ResourceException(sprintf('Resource `%s` not found', $contantName), ResourceException::RESOURCE_NOT_FOUND); + } + } + + const ADDRESS_VIEW = "admin.address.view"; + const ADDRESS_CREATE = "admin.address.create"; + const ADDRESS_UPDATE = "admin.address.update"; + const ADDRESS_DELETE = "admin.address.delete"; + + const ADMIN_VIEW = "admin.configuration.admin.view"; + const ADMIN_CREATE = "admin.configuration.admin.create"; + const ADMIN_UPDATE = "admin.configuration.admin.update"; + const ADMIN_DELETE = "admin.configuration.admin.delete"; + + const AREA_VIEW = "admin.configuration.area.view"; + const AREA_CREATE = "admin.configuration.area.create"; + const AREA_UPDATE = "admin.configuration.area.update"; + const AREA_DELETE = "admin.configuration.area.delete"; + + const ATTRIBUTE_VIEW = "admin.configuration.attribute.view"; + const ATTRIBUTE_CREATE = "admin.configuration.attribute.create"; + const ATTRIBUTE_UPDATE = "admin.configuration.attribute.update"; + const ATTRIBUTE_DELETE = "admin.configuration.attribute.delete"; + + const CATEGORY_VIEW = "admin.category.view"; + const CATEGORY_CREATE = "admin.category.create"; + const CATEGORY_UPDATE = "admin.category.update"; + const CATEGORY_DELETE = "admin.category.delete"; + + const CONFIG_VIEW = "admin.configuration.view"; + const CONFIG_CREATE = "admin.configuration.create"; + const CONFIG_UPDATE = "admin.configuration.update"; + const CONFIG_DELETE = "admin.configuration.delete"; + + const CONTENT_VIEW = "admin.content.view"; + const CONTENT_CREATE = "admin.content.create"; + const CONTENT_UPDATE = "admin.content.update"; + const CONTENT_DELETE = "admin.content.delete"; + + const COUNTRY_VIEW = "admin.configuration.country.view"; + const COUNTRY_CREATE = "admin.configuration.country.create"; + const COUNTRY_UPDATE = "admin.configuration.country.update"; + const COUNTRY_DELETE = "admin.configuration.country.delete"; + + const COUPON_VIEW = "admin.coupon.view"; + const COUPON_CREATE = "admin.coupon.create"; + const COUPON_UPDATE = "admin.coupon.update"; + const COUPON_DELETE = "admin.coupon.delete"; + + const CURRENCY_VIEW = "admin.configuration.currency.view"; + const CURRENCY_CREATE = "admin.configuration.currency.create"; + const CURRENCY_UPDATE = "admin.configuration.currency.update"; + const CURRENCY_DELETE = "admin.configuration.currency.delete"; + + const CUSTOMER_VIEW = "admin.customer.view"; + const CUSTOMER_CREATE = "admin.customer.create"; + const CUSTOMER_UPDATE = "admin.customer.update"; + const CUSTOMER_DELETE = "admin.customer.delete"; + + const FEATURE_VIEW = "admin.configuration.feature.view"; + const FEATURE_CREATE = "admin.configuration.feature.create"; + const FEATURE_UPDATE = "admin.configuration.feature.update"; + const FEATURE_DELETE = "admin.configuration.feature.delete"; + + const FOLDER_VIEW = "admin.folder.view"; + const FOLDER_CREATE = "admin.folder.create"; + const FOLDER_UPDATE = "admin.folder.update"; + const FOLDER_DELETE = "admin.folder.delete"; + + const LANGUAGE_VIEW = "admin.configuration.language.view"; + const LANGUAGE_CREATE = "admin.configuration.language.create"; + const LANGUAGE_UPDATE = "admin.configuration.language.update"; + const LANGUAGE_DELETE = "admin.configuration.language.delete"; + + const MAILING_SYSTEM_VIEW = "admin.configuration.mailing-system.view"; + const MAILING_SYSTEM_CREATE = "admin.configuration.mailing-system.create"; + const MAILING_SYSTEM_UPDATE = "admin.configuration.mailing-system.update"; + const MAILING_SYSTEM_DELETE = "admin.configuration.mailing-system.delete"; + + const MESSAGE_VIEW = "admin.configuration.message.view"; + const MESSAGE_CREATE = "admin.configuration.message.create"; + const MESSAGE_UPDATE = "admin.configuration.message.update"; + const MESSAGE_DELETE = "admin.configuration.message.delete"; + + const MODULE_VIEW = "admin.configuration.module.view"; + const MODULE_CREATE = "admin.configuration.module.create"; + const MODULE_UPDATE = "admin.configuration.module.update"; + const MODULE_DELETE = "admin.configuration.module.delete"; + + const ORDER_VIEW = "admin.order.view"; + const ORDER_CREATE = "admin.order.create"; + const ORDER_UPDATE = "admin.order.update"; + const ORDER_DELETE = "admin.order.delete"; + + const PRODUCT_VIEW = "admin.product.view"; + const PRODUCT_CREATE = "admin.product.create"; + const PRODUCT_UPDATE = "admin.product.update"; + const PRODUCT_DELETE = "admin.product.delete"; + + const PROFILE_VIEW = "admin.configuration.profile.view"; + const PROFILE_CREATE = "admin.configuration.profile.create"; + const PROFILE_UPDATE = "admin.configuration.profile.update"; + const PROFILE_DELETE = "admin.configuration.profile.delete"; + + const SHIPPING_ZONE_VIEW = "admin.configuration.shipping-zone.view"; + const SHIPPING_ZONE_CREATE = "admin.configuration.shipping-zone.create"; + const SHIPPING_ZONE_UPDATE = "admin.configuration.shipping-zone.update"; + const SHIPPING_ZONE_DELETE = "admin.configuration.shipping-zone.delete"; + + const TAX_VIEW = "admin.configuration.tax.view"; + const TAX_CREATE = "admin.configuration.tax.create"; + const TAX_UPDATE = "admin.configuration.tax.update"; + const TAX_DELETE = "admin.configuration.tax.delete"; + + const TEMPLATE_VIEW = "admin.configuration.template.view"; + const TEMPLATE_CREATE = "admin.configuration.template.create"; + const TEMPLATE_UPDATE = "admin.configuration.template.update"; + const TEMPLATE_DELETE = "admin.configuration.template.delete"; +} diff --git a/core/lib/Thelia/Core/Template/Loop/Admin.php b/core/lib/Thelia/Core/Template/Loop/Admin.php new file mode 100755 index 000000000..fe4b280ad --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Admin.php @@ -0,0 +1,104 @@ +. */ +/* */ +/*************************************************************************************/ + +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\AdminQuery; +use Thelia\Type; +use Thelia\Type\BooleanOrBothType; + +/** + * + * Admin loop + * + * + * Class Admin + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class Admin extends BaseI18nLoop +{ + public $timestampable = true; + + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createIntListTypeArgument('profile') + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = AdminQuery::create(); + + $id = $this->getId(); + + if (null !== $id) { + $search->filterById($id, Criteria::IN); + } + + $profile = $this->getProfile(); + + if (null !== $profile) { + $search->filterByProfileId($profile, Criteria::IN); + } + + $search->orderByFirstname(Criteria::ASC); + + /* perform search */ + $features = $this->search($search, $pagination); + + $loopResult = new LoopResult($features); + + foreach ($features as $feature) { + $loopResultRow = new LoopResultRow($loopResult, $feature, $this->versionable, $this->timestampable, $this->countable); + $loopResultRow->set("ID", $feature->getId()) + ->set("PROFILE",$feature->getProfileId()) + ->set("FIRSTNAME",$feature->getFirstname()) + ->set("LASTNAME",$feature->getLastname()) + ->set("LOGIN",$feature->getLogin()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/core/lib/Thelia/Core/Template/Loop/Profile.php b/core/lib/Thelia/Core/Template/Loop/Profile.php index 02c6a6893..a7a2e170e 100755 --- a/core/lib/Thelia/Core/Template/Loop/Profile.php +++ b/core/lib/Thelia/Core/Template/Loop/Profile.php @@ -32,8 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Model\ProfileQuery; -use Thelia\Model\ProductQuery; -use Thelia\Type\TypeCollection; use Thelia\Type; use Thelia\Type\BooleanOrBothType; diff --git a/core/lib/Thelia/Model/AdminProfile.php b/core/lib/Thelia/Model/AdminProfile.php deleted file mode 100644 index 767333c22..000000000 --- a/core/lib/Thelia/Model/AdminProfile.php +++ /dev/null @@ -1,10 +0,0 @@ -id; } + /** + * Get the [profile_id] column value. + * + * @return int + */ + public function getProfileId() + { + + return $this->profile_id; + } + /** * Get the [firstname] column value. * @@ -574,6 +570,31 @@ abstract class Admin implements ActiveRecordInterface return $this; } // setId() + /** + * Set the value of [profile_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Admin The current object (for fluent API support) + */ + public function setProfileId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->profile_id !== $v) { + $this->profile_id = $v; + $this->modifiedColumns[] = AdminTableMap::PROFILE_ID; + } + + if ($this->aProfile !== null && $this->aProfile->getId() !== $v) { + $this->aProfile = null; + } + + + return $this; + } // setProfileId() + /** * Set the value of [firstname] column. * @@ -824,37 +845,40 @@ abstract class Admin implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : AdminTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AdminTableMap::translateFieldName('Firstname', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AdminTableMap::translateFieldName('ProfileId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->profile_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AdminTableMap::translateFieldName('Firstname', TableMap::TYPE_PHPNAME, $indexType)]; $this->firstname = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AdminTableMap::translateFieldName('Lastname', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AdminTableMap::translateFieldName('Lastname', TableMap::TYPE_PHPNAME, $indexType)]; $this->lastname = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AdminTableMap::translateFieldName('Login', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AdminTableMap::translateFieldName('Login', TableMap::TYPE_PHPNAME, $indexType)]; $this->login = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AdminTableMap::translateFieldName('Password', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AdminTableMap::translateFieldName('Password', TableMap::TYPE_PHPNAME, $indexType)]; $this->password = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AdminTableMap::translateFieldName('Algo', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AdminTableMap::translateFieldName('Algo', TableMap::TYPE_PHPNAME, $indexType)]; $this->algo = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AdminTableMap::translateFieldName('Salt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $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('RememberMeToken', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $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)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $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)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $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 ? 10 + $startcol : AdminTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : AdminTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -867,7 +891,7 @@ abstract class Admin implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 11; // 11 = AdminTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 12; // 12 = AdminTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Admin object", 0, $e); @@ -889,6 +913,9 @@ abstract class Admin implements ActiveRecordInterface */ public function ensureConsistency() { + if ($this->aProfile !== null && $this->profile_id !== $this->aProfile->getId()) { + $this->aProfile = null; + } } // ensureConsistency /** @@ -928,9 +955,7 @@ abstract class Admin implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->collAdminProfiles = null; - - $this->collProfiles = null; + $this->aProfile = null; } // if (deep) } @@ -1053,6 +1078,18 @@ abstract class Admin implements ActiveRecordInterface 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->aProfile !== null) { + if ($this->aProfile->isModified() || $this->aProfile->isNew()) { + $affectedRows += $this->aProfile->save($con); + } + $this->setProfile($this->aProfile); + } + if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { @@ -1064,50 +1101,6 @@ abstract class Admin implements ActiveRecordInterface $this->resetModified(); } - if ($this->profilesScheduledForDeletion !== null) { - if (!$this->profilesScheduledForDeletion->isEmpty()) { - $pks = array(); - $pk = $this->getPrimaryKey(); - foreach ($this->profilesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($remotePk, $pk); - } - - AdminProfileQuery::create() - ->filterByPrimaryKeys($pks) - ->delete($con); - $this->profilesScheduledForDeletion = null; - } - - foreach ($this->getProfiles() as $profile) { - if ($profile->isModified()) { - $profile->save($con); - } - } - } elseif ($this->collProfiles) { - foreach ($this->collProfiles as $profile) { - if ($profile->isModified()) { - $profile->save($con); - } - } - } - - if ($this->adminProfilesScheduledForDeletion !== null) { - if (!$this->adminProfilesScheduledForDeletion->isEmpty()) { - \Thelia\Model\AdminProfileQuery::create() - ->filterByPrimaryKeys($this->adminProfilesScheduledForDeletion->getPrimaryKeys(false)) - ->delete($con); - $this->adminProfilesScheduledForDeletion = null; - } - } - - if ($this->collAdminProfiles !== null) { - foreach ($this->collAdminProfiles as $referrerFK) { - if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { - $affectedRows += $referrerFK->save($con); - } - } - } - $this->alreadyInSave = false; } @@ -1137,6 +1130,9 @@ abstract class Admin implements ActiveRecordInterface if ($this->isColumnModified(AdminTableMap::ID)) { $modifiedColumns[':p' . $index++] = 'ID'; } + if ($this->isColumnModified(AdminTableMap::PROFILE_ID)) { + $modifiedColumns[':p' . $index++] = 'PROFILE_ID'; + } if ($this->isColumnModified(AdminTableMap::FIRSTNAME)) { $modifiedColumns[':p' . $index++] = 'FIRSTNAME'; } @@ -1181,6 +1177,9 @@ abstract class Admin implements ActiveRecordInterface case 'ID': $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); break; + case 'PROFILE_ID': + $stmt->bindValue($identifier, $this->profile_id, PDO::PARAM_INT); + break; case 'FIRSTNAME': $stmt->bindValue($identifier, $this->firstname, PDO::PARAM_STR); break; @@ -1277,33 +1276,36 @@ abstract class Admin implements ActiveRecordInterface return $this->getId(); break; case 1: - return $this->getFirstname(); + return $this->getProfileId(); break; case 2: - return $this->getLastname(); + return $this->getFirstname(); break; case 3: - return $this->getLogin(); + return $this->getLastname(); break; case 4: - return $this->getPassword(); + return $this->getLogin(); break; case 5: - return $this->getAlgo(); + return $this->getPassword(); break; case 6: - return $this->getSalt(); + return $this->getAlgo(); break; case 7: - return $this->getRememberMeToken(); + return $this->getSalt(); break; case 8: - return $this->getRememberMeSerial(); + return $this->getRememberMeToken(); break; case 9: - return $this->getCreatedAt(); + return $this->getRememberMeSerial(); break; case 10: + return $this->getCreatedAt(); + break; + case 11: return $this->getUpdatedAt(); break; default: @@ -1336,16 +1338,17 @@ abstract class Admin implements ActiveRecordInterface $keys = AdminTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), - $keys[1] => $this->getFirstname(), - $keys[2] => $this->getLastname(), - $keys[3] => $this->getLogin(), - $keys[4] => $this->getPassword(), - $keys[5] => $this->getAlgo(), - $keys[6] => $this->getSalt(), - $keys[7] => $this->getRememberMeToken(), - $keys[8] => $this->getRememberMeSerial(), - $keys[9] => $this->getCreatedAt(), - $keys[10] => $this->getUpdatedAt(), + $keys[1] => $this->getProfileId(), + $keys[2] => $this->getFirstname(), + $keys[3] => $this->getLastname(), + $keys[4] => $this->getLogin(), + $keys[5] => $this->getPassword(), + $keys[6] => $this->getAlgo(), + $keys[7] => $this->getSalt(), + $keys[8] => $this->getRememberMeToken(), + $keys[9] => $this->getRememberMeSerial(), + $keys[10] => $this->getCreatedAt(), + $keys[11] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1353,8 +1356,8 @@ abstract class Admin implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->collAdminProfiles) { - $result['AdminProfiles'] = $this->collAdminProfiles->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->aProfile) { + $result['Profile'] = $this->aProfile->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } } @@ -1394,33 +1397,36 @@ abstract class Admin implements ActiveRecordInterface $this->setId($value); break; case 1: - $this->setFirstname($value); + $this->setProfileId($value); break; case 2: - $this->setLastname($value); + $this->setFirstname($value); break; case 3: - $this->setLogin($value); + $this->setLastname($value); break; case 4: - $this->setPassword($value); + $this->setLogin($value); break; case 5: - $this->setAlgo($value); + $this->setPassword($value); break; case 6: - $this->setSalt($value); + $this->setAlgo($value); break; case 7: - $this->setRememberMeToken($value); + $this->setSalt($value); break; case 8: - $this->setRememberMeSerial($value); + $this->setRememberMeToken($value); break; case 9: - $this->setCreatedAt($value); + $this->setRememberMeSerial($value); break; case 10: + $this->setCreatedAt($value); + break; + case 11: $this->setUpdatedAt($value); break; } // switch() @@ -1448,16 +1454,17 @@ abstract class Admin implements ActiveRecordInterface $keys = AdminTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setFirstname($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setLastname($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setLogin($arr[$keys[3]]); - 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->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]]); + if (array_key_exists($keys[1], $arr)) $this->setProfileId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setFirstname($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setLastname($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setLogin($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setPassword($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setAlgo($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setSalt($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setRememberMeToken($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setRememberMeSerial($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setCreatedAt($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setUpdatedAt($arr[$keys[11]]); } /** @@ -1470,6 +1477,7 @@ abstract class Admin implements ActiveRecordInterface $criteria = new Criteria(AdminTableMap::DATABASE_NAME); if ($this->isColumnModified(AdminTableMap::ID)) $criteria->add(AdminTableMap::ID, $this->id); + if ($this->isColumnModified(AdminTableMap::PROFILE_ID)) $criteria->add(AdminTableMap::PROFILE_ID, $this->profile_id); if ($this->isColumnModified(AdminTableMap::FIRSTNAME)) $criteria->add(AdminTableMap::FIRSTNAME, $this->firstname); if ($this->isColumnModified(AdminTableMap::LASTNAME)) $criteria->add(AdminTableMap::LASTNAME, $this->lastname); if ($this->isColumnModified(AdminTableMap::LOGIN)) $criteria->add(AdminTableMap::LOGIN, $this->login); @@ -1543,6 +1551,7 @@ abstract class Admin implements ActiveRecordInterface */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { + $copyObj->setProfileId($this->getProfileId()); $copyObj->setFirstname($this->getFirstname()); $copyObj->setLastname($this->getLastname()); $copyObj->setLogin($this->getLogin()); @@ -1553,20 +1562,6 @@ abstract class Admin implements ActiveRecordInterface $copyObj->setRememberMeSerial($this->getRememberMeSerial()); $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->getAdminProfiles() as $relObj) { - if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addAdminProfile($relObj->copy($deepCopy)); - } - } - - } // if ($deepCopy) - if ($makeNew) { $copyObj->setNew(true); $copyObj->setId(NULL); // this is a auto-increment column, so set to default value @@ -1595,449 +1590,55 @@ abstract class Admin implements ActiveRecordInterface 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. + * Declares an association between this object and a ChildProfile object. * - * @param string $relationName The name of the relation to initialize - * @return void - */ - public function initRelation($relationName) - { - if ('AdminProfile' == $relationName) { - return $this->initAdminProfiles(); - } - } - - /** - * Clears out the collAdminProfiles 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 addAdminProfiles() - */ - public function clearAdminProfiles() - { - $this->collAdminProfiles = null; // important to set this to NULL since that means it is uninitialized - } - - /** - * Reset is the collAdminProfiles collection loaded partially. - */ - public function resetPartialAdminProfiles($v = true) - { - $this->collAdminProfilesPartial = $v; - } - - /** - * Initializes the collAdminProfiles collection. - * - * By default this just sets the collAdminProfiles collection to an empty array (like clearcollAdminProfiles()); - * 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 initAdminProfiles($overrideExisting = true) - { - if (null !== $this->collAdminProfiles && !$overrideExisting) { - return; - } - $this->collAdminProfiles = new ObjectCollection(); - $this->collAdminProfiles->setModel('\Thelia\Model\AdminProfile'); - } - - /** - * Gets an array of ChildAdminProfile 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 ChildAdmin 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|ChildAdminProfile[] List of ChildAdminProfile objects + * @param ChildProfile $v + * @return \Thelia\Model\Admin The current object (for fluent API support) * @throws PropelException */ - public function getAdminProfiles($criteria = null, ConnectionInterface $con = null) + public function setProfile(ChildProfile $v = null) { - $partial = $this->collAdminProfilesPartial && !$this->isNew(); - if (null === $this->collAdminProfiles || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAdminProfiles) { - // return empty collection - $this->initAdminProfiles(); - } else { - $collAdminProfiles = ChildAdminProfileQuery::create(null, $criteria) - ->filterByAdmin($this) - ->find($con); - - if (null !== $criteria) { - if (false !== $this->collAdminProfilesPartial && count($collAdminProfiles)) { - $this->initAdminProfiles(false); - - foreach ($collAdminProfiles as $obj) { - if (false == $this->collAdminProfiles->contains($obj)) { - $this->collAdminProfiles->append($obj); - } - } - - $this->collAdminProfilesPartial = true; - } - - $collAdminProfiles->getInternalIterator()->rewind(); - - return $collAdminProfiles; - } - - if ($partial && $this->collAdminProfiles) { - foreach ($this->collAdminProfiles as $obj) { - if ($obj->isNew()) { - $collAdminProfiles[] = $obj; - } - } - } - - $this->collAdminProfiles = $collAdminProfiles; - $this->collAdminProfilesPartial = false; - } - } - - return $this->collAdminProfiles; - } - - /** - * Sets a collection of AdminProfile 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 $adminProfiles A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildAdmin The current object (for fluent API support) - */ - public function setAdminProfiles(Collection $adminProfiles, ConnectionInterface $con = null) - { - $adminProfilesToDelete = $this->getAdminProfiles(new Criteria(), $con)->diff($adminProfiles); - - - //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->adminProfilesScheduledForDeletion = clone $adminProfilesToDelete; - - foreach ($adminProfilesToDelete as $adminProfileRemoved) { - $adminProfileRemoved->setAdmin(null); - } - - $this->collAdminProfiles = null; - foreach ($adminProfiles as $adminProfile) { - $this->addAdminProfile($adminProfile); - } - - $this->collAdminProfiles = $adminProfiles; - $this->collAdminProfilesPartial = false; - - return $this; - } - - /** - * Returns the number of related AdminProfile objects. - * - * @param Criteria $criteria - * @param boolean $distinct - * @param ConnectionInterface $con - * @return int Count of related AdminProfile objects. - * @throws PropelException - */ - public function countAdminProfiles(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) - { - $partial = $this->collAdminProfilesPartial && !$this->isNew(); - if (null === $this->collAdminProfiles || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAdminProfiles) { - return 0; - } - - if ($partial && !$criteria) { - return count($this->getAdminProfiles()); - } - - $query = ChildAdminProfileQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByAdmin($this) - ->count($con); - } - - return count($this->collAdminProfiles); - } - - /** - * Method called to associate a ChildAdminProfile object to this object - * through the ChildAdminProfile foreign key attribute. - * - * @param ChildAdminProfile $l ChildAdminProfile - * @return \Thelia\Model\Admin The current object (for fluent API support) - */ - public function addAdminProfile(ChildAdminProfile $l) - { - if ($this->collAdminProfiles === null) { - $this->initAdminProfiles(); - $this->collAdminProfilesPartial = true; - } - - if (!in_array($l, $this->collAdminProfiles->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddAdminProfile($l); - } - - return $this; - } - - /** - * @param AdminProfile $adminProfile The adminProfile object to add. - */ - protected function doAddAdminProfile($adminProfile) - { - $this->collAdminProfiles[]= $adminProfile; - $adminProfile->setAdmin($this); - } - - /** - * @param AdminProfile $adminProfile The adminProfile object to remove. - * @return ChildAdmin The current object (for fluent API support) - */ - public function removeAdminProfile($adminProfile) - { - if ($this->getAdminProfiles()->contains($adminProfile)) { - $this->collAdminProfiles->remove($this->collAdminProfiles->search($adminProfile)); - if (null === $this->adminProfilesScheduledForDeletion) { - $this->adminProfilesScheduledForDeletion = clone $this->collAdminProfiles; - $this->adminProfilesScheduledForDeletion->clear(); - } - $this->adminProfilesScheduledForDeletion[]= clone $adminProfile; - $adminProfile->setAdmin(null); - } - - return $this; - } - - - /** - * If this collection has already been initialized with - * an identical criteria, it returns the collection. - * Otherwise if this Admin is new, it will return - * an empty collection; or if this Admin has previously - * been saved, it will retrieve related AdminProfiles 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 Admin. - * - * @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|ChildAdminProfile[] List of ChildAdminProfile objects - */ - public function getAdminProfilesJoinProfile($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) - { - $query = ChildAdminProfileQuery::create(null, $criteria); - $query->joinWith('Profile', $joinBehavior); - - return $this->getAdminProfiles($query, $con); - } - - /** - * Clears out the collProfiles 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 addProfiles() - */ - public function clearProfiles() - { - $this->collProfiles = null; // important to set this to NULL since that means it is uninitialized - $this->collProfilesPartial = null; - } - - /** - * Initializes the collProfiles collection. - * - * By default this just sets the collProfiles collection to an empty collection (like clearProfiles()); - * 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 initProfiles() - { - $this->collProfiles = new ObjectCollection(); - $this->collProfiles->setModel('\Thelia\Model\Profile'); - } - - /** - * Gets a collection of ChildProfile objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 ChildAdmin 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|ChildProfile[] List of ChildProfile objects - */ - public function getProfiles($criteria = null, ConnectionInterface $con = null) - { - if (null === $this->collProfiles || null !== $criteria) { - if ($this->isNew() && null === $this->collProfiles) { - // return empty collection - $this->initProfiles(); - } else { - $collProfiles = ChildProfileQuery::create(null, $criteria) - ->filterByAdmin($this) - ->find($con); - if (null !== $criteria) { - return $collProfiles; - } - $this->collProfiles = $collProfiles; - } - } - - return $this->collProfiles; - } - - /** - * Sets a collection of Profile objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 $profiles A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildAdmin The current object (for fluent API support) - */ - public function setProfiles(Collection $profiles, ConnectionInterface $con = null) - { - $this->clearProfiles(); - $currentProfiles = $this->getProfiles(); - - $this->profilesScheduledForDeletion = $currentProfiles->diff($profiles); - - foreach ($profiles as $profile) { - if (!$currentProfiles->contains($profile)) { - $this->doAddProfile($profile); - } - } - - $this->collProfiles = $profiles; - - return $this; - } - - /** - * Gets the number of ChildProfile objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 ChildProfile objects - */ - public function countProfiles($criteria = null, $distinct = false, ConnectionInterface $con = null) - { - if (null === $this->collProfiles || null !== $criteria) { - if ($this->isNew() && null === $this->collProfiles) { - return 0; - } else { - $query = ChildProfileQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByAdmin($this) - ->count($con); - } + if ($v === null) { + $this->setProfileId(NULL); } else { - return count($this->collProfiles); - } - } - - /** - * Associate a ChildProfile object to this object - * through the admin_profile cross reference table. - * - * @param ChildProfile $profile The ChildAdminProfile object to relate - * @return ChildAdmin The current object (for fluent API support) - */ - public function addProfile(ChildProfile $profile) - { - if ($this->collProfiles === null) { - $this->initProfiles(); + $this->setProfileId($v->getId()); } - if (!$this->collProfiles->contains($profile)) { // only add it if the **same** object is not already associated - $this->doAddProfile($profile); - $this->collProfiles[] = $profile; + $this->aProfile = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildProfile object, it will not be re-added. + if ($v !== null) { + $v->addAdmin($this); } + return $this; } - /** - * @param Profile $profile The profile object to add. - */ - protected function doAddProfile($profile) - { - $adminProfile = new ChildAdminProfile(); - $adminProfile->setProfile($profile); - $this->addAdminProfile($adminProfile); - // set the back reference to this object directly as using provided method either results - // in endless loop or in multiple relations - if (!$profile->getAdmins()->contains($this)) { - $foreignCollection = $profile->getAdmins(); - $foreignCollection[] = $this; - } - } /** - * Remove a ChildProfile object to this object - * through the admin_profile cross reference table. + * Get the associated ChildProfile object * - * @param ChildProfile $profile The ChildAdminProfile object to relate - * @return ChildAdmin The current object (for fluent API support) + * @param ConnectionInterface $con Optional Connection object. + * @return ChildProfile The associated ChildProfile object. + * @throws PropelException */ - public function removeProfile(ChildProfile $profile) + public function getProfile(ConnectionInterface $con = null) { - if ($this->getProfiles()->contains($profile)) { - $this->collProfiles->remove($this->collProfiles->search($profile)); - - if (null === $this->profilesScheduledForDeletion) { - $this->profilesScheduledForDeletion = clone $this->collProfiles; - $this->profilesScheduledForDeletion->clear(); - } - - $this->profilesScheduledForDeletion[] = $profile; + if ($this->aProfile === null && ($this->profile_id !== null)) { + $this->aProfile = ChildProfileQuery::create()->findPk($this->profile_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->aProfile->addAdmins($this); + */ } - return $this; + return $this->aProfile; } /** @@ -2046,6 +1647,7 @@ abstract class Admin implements ActiveRecordInterface public function clear() { $this->id = null; + $this->profile_id = null; $this->firstname = null; $this->lastname = null; $this->login = null; @@ -2075,26 +1677,9 @@ abstract class Admin implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { - if ($this->collAdminProfiles) { - foreach ($this->collAdminProfiles as $o) { - $o->clearAllReferences($deep); - } - } - if ($this->collProfiles) { - foreach ($this->collProfiles as $o) { - $o->clearAllReferences($deep); - } - } } // if ($deep) - if ($this->collAdminProfiles instanceof Collection) { - $this->collAdminProfiles->clearIterator(); - } - $this->collAdminProfiles = null; - if ($this->collProfiles instanceof Collection) { - $this->collProfiles->clearIterator(); - } - $this->collProfiles = null; + $this->aProfile = null; } /** diff --git a/core/lib/Thelia/Model/Base/AdminProfile.php b/core/lib/Thelia/Model/Base/AdminProfile.php deleted file mode 100644 index f34daefce..000000000 --- a/core/lib/Thelia/Model/Base/AdminProfile.php +++ /dev/null @@ -1,1508 +0,0 @@ -modifiedColumns); - } - - /** - * Has specified column been modified? - * - * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID - * @return boolean True if $col has been modified. - */ - public function isColumnModified($col) - { - return in_array($col, $this->modifiedColumns); - } - - /** - * Get the columns that have been modified in this object. - * @return array A unique list of the modified column names for this object. - */ - public function getModifiedColumns() - { - return array_unique($this->modifiedColumns); - } - - /** - * Returns whether the object has ever been saved. This will - * be false, if the object was retrieved from storage or was created - * and then saved. - * - * @return boolean 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 AdminProfile instance. If - * obj is an instance of AdminProfile, delegates to - * equals(AdminProfile). Otherwise, returns false. - * - * @param mixed $obj The object to compare to. - * @return boolean 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 - * - * @return array - */ - public function getVirtualColumns() - { - return $this->virtualColumns; - } - - /** - * Checks the existence of a virtual column in this object - * - * @param string $name The virtual column name - * @return boolean - */ - public function hasVirtualColumn($name) - { - return array_key_exists($name, $this->virtualColumns); - } - - /** - * Get the value of a virtual column in this object - * - * @param string $name The virtual column name - * @return mixed - * - * @throws PropelException - */ - 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 AdminProfile 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 AdminProfile The current object, for fluid interface - */ - public function importFrom($parser, $data) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); - - return $this; - } - - /** - * 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 [profile_id] column value. - * - * @return int - */ - public function getProfileId() - { - - return $this->profile_id; - } - - /** - * Get the [admin_id] column value. - * - * @return int - */ - public function getAdminId() - { - - return $this->admin_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 instanceof \DateTime ? $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 instanceof \DateTime ? $this->updated_at->format($format) : null; - } - } - - /** - * Set the value of [id] column. - * - * @param int $v new value - * @return \Thelia\Model\AdminProfile 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[] = AdminProfileTableMap::ID; - } - - - return $this; - } // setId() - - /** - * Set the value of [profile_id] column. - * - * @param int $v new value - * @return \Thelia\Model\AdminProfile The current object (for fluent API support) - */ - public function setProfileId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->profile_id !== $v) { - $this->profile_id = $v; - $this->modifiedColumns[] = AdminProfileTableMap::PROFILE_ID; - } - - if ($this->aProfile !== null && $this->aProfile->getId() !== $v) { - $this->aProfile = null; - } - - - return $this; - } // setProfileId() - - /** - * Set the value of [admin_id] column. - * - * @param int $v new value - * @return \Thelia\Model\AdminProfile The current object (for fluent API support) - */ - public function setAdminId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->admin_id !== $v) { - $this->admin_id = $v; - $this->modifiedColumns[] = AdminProfileTableMap::ADMIN_ID; - } - - if ($this->aAdmin !== null && $this->aAdmin->getId() !== $v) { - $this->aAdmin = null; - } - - - return $this; - } // setAdminId() - - /** - * 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\AdminProfile 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[] = AdminProfileTableMap::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\AdminProfile 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[] = AdminProfileTableMap::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 : AdminProfileTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - $this->id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AdminProfileTableMap::translateFieldName('ProfileId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->profile_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AdminProfileTableMap::translateFieldName('AdminId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->admin_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AdminProfileTableMap::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 : AdminProfileTableMap::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 = AdminProfileTableMap::NUM_HYDRATE_COLUMNS. - - } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\AdminProfile 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->aProfile !== null && $this->profile_id !== $this->aProfile->getId()) { - $this->aProfile = null; - } - if ($this->aAdmin !== null && $this->admin_id !== $this->aAdmin->getId()) { - $this->aAdmin = 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(AdminProfileTableMap::DATABASE_NAME); - } - - // We don't need to alter the object instance pool; we're just modifying this instance - // already in the pool. - - $dataFetcher = ChildAdminProfileQuery::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->aProfile = null; - $this->aAdmin = null; - } // if (deep) - } - - /** - * Removes this object from datastore and sets delete attribute. - * - * @param ConnectionInterface $con - * @return void - * @throws PropelException - * @see AdminProfile::setDeleted() - * @see AdminProfile::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(AdminProfileTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - try { - $deleteQuery = ChildAdminProfileQuery::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(AdminProfileTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - $isInsert = $this->isNew(); - try { - $ret = $this->preSave($con); - if ($isInsert) { - $ret = $ret && $this->preInsert($con); - // timestampable behavior - if (!$this->isColumnModified(AdminProfileTableMap::CREATED_AT)) { - $this->setCreatedAt(time()); - } - if (!$this->isColumnModified(AdminProfileTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } else { - $ret = $ret && $this->preUpdate($con); - // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(AdminProfileTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } - if ($ret) { - $affectedRows = $this->doSave($con); - if ($isInsert) { - $this->postInsert($con); - } else { - $this->postUpdate($con); - } - $this->postSave($con); - AdminProfileTableMap::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->aProfile !== null) { - if ($this->aProfile->isModified() || $this->aProfile->isNew()) { - $affectedRows += $this->aProfile->save($con); - } - $this->setProfile($this->aProfile); - } - - if ($this->aAdmin !== null) { - if ($this->aAdmin->isModified() || $this->aAdmin->isNew()) { - $affectedRows += $this->aAdmin->save($con); - } - $this->setAdmin($this->aAdmin); - } - - 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[] = AdminProfileTableMap::ID; - if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . AdminProfileTableMap::ID . ')'); - } - - // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(AdminProfileTableMap::ID)) { - $modifiedColumns[':p' . $index++] = 'ID'; - } - if ($this->isColumnModified(AdminProfileTableMap::PROFILE_ID)) { - $modifiedColumns[':p' . $index++] = 'PROFILE_ID'; - } - if ($this->isColumnModified(AdminProfileTableMap::ADMIN_ID)) { - $modifiedColumns[':p' . $index++] = 'ADMIN_ID'; - } - if ($this->isColumnModified(AdminProfileTableMap::CREATED_AT)) { - $modifiedColumns[':p' . $index++] = 'CREATED_AT'; - } - if ($this->isColumnModified(AdminProfileTableMap::UPDATED_AT)) { - $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; - } - - $sql = sprintf( - 'INSERT INTO admin_profile (%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 'PROFILE_ID': - $stmt->bindValue($identifier, $this->profile_id, PDO::PARAM_INT); - break; - case 'ADMIN_ID': - $stmt->bindValue($identifier, $this->admin_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 = AdminProfileTableMap::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->getProfileId(); - break; - case 2: - return $this->getAdminId(); - 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['AdminProfile'][serialize($this->getPrimaryKey())])) { - return '*RECURSION*'; - } - $alreadyDumpedObjects['AdminProfile'][serialize($this->getPrimaryKey())] = true; - $keys = AdminProfileTableMap::getFieldNames($keyType); - $result = array( - $keys[0] => $this->getId(), - $keys[1] => $this->getProfileId(), - $keys[2] => $this->getAdminId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), - ); - $virtualColumns = $this->virtualColumns; - foreach ($virtualColumns as $key => $virtualColumn) { - $result[$key] = $virtualColumn; - } - - if ($includeForeignObjects) { - if (null !== $this->aProfile) { - $result['Profile'] = $this->aProfile->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); - } - if (null !== $this->aAdmin) { - $result['Admin'] = $this->aAdmin->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 = AdminProfileTableMap::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->setProfileId($value); - break; - case 2: - $this->setAdminId($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 = AdminProfileTableMap::getFieldNames($keyType); - - if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setProfileId($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setAdminId($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(AdminProfileTableMap::DATABASE_NAME); - - if ($this->isColumnModified(AdminProfileTableMap::ID)) $criteria->add(AdminProfileTableMap::ID, $this->id); - if ($this->isColumnModified(AdminProfileTableMap::PROFILE_ID)) $criteria->add(AdminProfileTableMap::PROFILE_ID, $this->profile_id); - if ($this->isColumnModified(AdminProfileTableMap::ADMIN_ID)) $criteria->add(AdminProfileTableMap::ADMIN_ID, $this->admin_id); - if ($this->isColumnModified(AdminProfileTableMap::CREATED_AT)) $criteria->add(AdminProfileTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(AdminProfileTableMap::UPDATED_AT)) $criteria->add(AdminProfileTableMap::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(AdminProfileTableMap::DATABASE_NAME); - $criteria->add(AdminProfileTableMap::ID, $this->id); - $criteria->add(AdminProfileTableMap::PROFILE_ID, $this->profile_id); - $criteria->add(AdminProfileTableMap::ADMIN_ID, $this->admin_id); - - 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->getProfileId(); - $pks[2] = $this->getAdminId(); - - 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->setProfileId($keys[1]); - $this->setAdminId($keys[2]); - } - - /** - * Returns true if the primary key for this object is null. - * @return boolean - */ - public function isPrimaryKeyNull() - { - - return (null === $this->getId()) && (null === $this->getProfileId()) && (null === $this->getAdminId()); - } - - /** - * 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\AdminProfile (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->setProfileId($this->getProfileId()); - $copyObj->setAdminId($this->getAdminId()); - $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\AdminProfile 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 ChildProfile object. - * - * @param ChildProfile $v - * @return \Thelia\Model\AdminProfile The current object (for fluent API support) - * @throws PropelException - */ - public function setProfile(ChildProfile $v = null) - { - if ($v === null) { - $this->setProfileId(NULL); - } else { - $this->setProfileId($v->getId()); - } - - $this->aProfile = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildProfile object, it will not be re-added. - if ($v !== null) { - $v->addAdminProfile($this); - } - - - return $this; - } - - - /** - * Get the associated ChildProfile object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildProfile The associated ChildProfile object. - * @throws PropelException - */ - public function getProfile(ConnectionInterface $con = null) - { - if ($this->aProfile === null && ($this->profile_id !== null)) { - $this->aProfile = ChildProfileQuery::create()->findPk($this->profile_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->aProfile->addAdminProfiles($this); - */ - } - - return $this->aProfile; - } - - /** - * Declares an association between this object and a ChildAdmin object. - * - * @param ChildAdmin $v - * @return \Thelia\Model\AdminProfile The current object (for fluent API support) - * @throws PropelException - */ - public function setAdmin(ChildAdmin $v = null) - { - if ($v === null) { - $this->setAdminId(NULL); - } else { - $this->setAdminId($v->getId()); - } - - $this->aAdmin = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildAdmin object, it will not be re-added. - if ($v !== null) { - $v->addAdminProfile($this); - } - - - return $this; - } - - - /** - * Get the associated ChildAdmin object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildAdmin The associated ChildAdmin object. - * @throws PropelException - */ - public function getAdmin(ConnectionInterface $con = null) - { - if ($this->aAdmin === null && ($this->admin_id !== null)) { - $this->aAdmin = ChildAdminQuery::create()->findPk($this->admin_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->aAdmin->addAdminProfiles($this); - */ - } - - return $this->aAdmin; - } - - /** - * Clears the current object and sets all attributes to their default values - */ - public function clear() - { - $this->id = null; - $this->profile_id = null; - $this->admin_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->aProfile = null; - $this->aAdmin = null; - } - - /** - * Return the string representation of this object - * - * @return string - */ - public function __toString() - { - return (string) $this->exportTo(AdminProfileTableMap::DEFAULT_STRING_FORMAT); - } - - // timestampable behavior - - /** - * Mark the current object so that the update date doesn't get updated during next save - * - * @return ChildAdminProfile The current object (for fluent API support) - */ - public function keepUpdateDateUnchanged() - { - $this->modifiedColumns[] = AdminProfileTableMap::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/AdminProfileQuery.php b/core/lib/Thelia/Model/Base/AdminProfileQuery.php deleted file mode 100644 index b29c82808..000000000 --- a/core/lib/Thelia/Model/Base/AdminProfileQuery.php +++ /dev/null @@ -1,778 +0,0 @@ -setModelAlias($modelAlias); - } - if ($criteria instanceof Criteria) { - $query->mergeWith($criteria); - } - - return $query; - } - - /** - * Find object by primary key. - * Propel uses the instance pool to skip the database if the object exists. - * Go fast if the query is untouched. - * - * - * $obj = $c->findPk(array(12, 34, 56), $con); - * - * - * @param array[$id, $profile_id, $admin_id] $key Primary key to use for the query - * @param ConnectionInterface $con an optional connection object - * - * @return ChildAdminProfile|array|mixed the result, formatted by the current formatter - */ - public function findPk($key, $con = null) - { - if ($key === null) { - return null; - } - if ((null !== ($obj = AdminProfileTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))))) && !$this->formatter) { - // the object is already in the instance pool - return $obj; - } - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(AdminProfileTableMap::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 ChildAdminProfile A model object, or null if the key is not found - */ - protected function findPkSimple($key, $con) - { - $sql = 'SELECT ID, PROFILE_ID, ADMIN_ID, CREATED_AT, UPDATED_AT FROM admin_profile WHERE ID = :p0 AND PROFILE_ID = :p1 AND ADMIN_ID = :p2'; - try { - $stmt = $con->prepare($sql); - $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); - $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); - $stmt->bindValue(':p2', $key[2], 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 ChildAdminProfile(); - $obj->hydrate($row); - AdminProfileTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))); - } - $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 ChildAdminProfile|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 ChildAdminProfileQuery The current query, for fluid interface - */ - public function filterByPrimaryKey($key) - { - $this->addUsingAlias(AdminProfileTableMap::ID, $key[0], Criteria::EQUAL); - $this->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $key[1], Criteria::EQUAL); - $this->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $key[2], 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 ChildAdminProfileQuery 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(AdminProfileTableMap::ID, $key[0], Criteria::EQUAL); - $cton1 = $this->getNewCriterion(AdminProfileTableMap::PROFILE_ID, $key[1], Criteria::EQUAL); - $cton0->addAnd($cton1); - $cton2 = $this->getNewCriterion(AdminProfileTableMap::ADMIN_ID, $key[2], Criteria::EQUAL); - $cton0->addAnd($cton2); - $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 - * - * - * @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 ChildAdminProfileQuery 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(AdminProfileTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($id['max'])) { - $this->addUsingAlias(AdminProfileTableMap::ID, $id['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AdminProfileTableMap::ID, $id, $comparison); - } - - /** - * Filter the query on the profile_id column - * - * Example usage: - * - * $query->filterByProfileId(1234); // WHERE profile_id = 1234 - * $query->filterByProfileId(array(12, 34)); // WHERE profile_id IN (12, 34) - * $query->filterByProfileId(array('min' => 12)); // WHERE profile_id > 12 - * - * - * @see filterByProfile() - * - * @param mixed $profileId 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 ChildAdminProfileQuery The current query, for fluid interface - */ - public function filterByProfileId($profileId = null, $comparison = null) - { - if (is_array($profileId)) { - $useMinMax = false; - if (isset($profileId['min'])) { - $this->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $profileId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($profileId['max'])) { - $this->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $profileId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $profileId, $comparison); - } - - /** - * Filter the query on the admin_id column - * - * Example usage: - * - * $query->filterByAdminId(1234); // WHERE admin_id = 1234 - * $query->filterByAdminId(array(12, 34)); // WHERE admin_id IN (12, 34) - * $query->filterByAdminId(array('min' => 12)); // WHERE admin_id > 12 - * - * - * @see filterByAdmin() - * - * @param mixed $adminId 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 ChildAdminProfileQuery The current query, for fluid interface - */ - public function filterByAdminId($adminId = null, $comparison = null) - { - if (is_array($adminId)) { - $useMinMax = false; - if (isset($adminId['min'])) { - $this->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $adminId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($adminId['max'])) { - $this->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $adminId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $adminId, $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 ChildAdminProfileQuery 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(AdminProfileTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($createdAt['max'])) { - $this->addUsingAlias(AdminProfileTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AdminProfileTableMap::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 ChildAdminProfileQuery 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(AdminProfileTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($updatedAt['max'])) { - $this->addUsingAlias(AdminProfileTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(AdminProfileTableMap::UPDATED_AT, $updatedAt, $comparison); - } - - /** - * Filter the query by a related \Thelia\Model\Profile object - * - * @param \Thelia\Model\Profile|ObjectCollection $profile The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function filterByProfile($profile, $comparison = null) - { - if ($profile instanceof \Thelia\Model\Profile) { - return $this - ->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $profile->getId(), $comparison); - } elseif ($profile instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(AdminProfileTableMap::PROFILE_ID, $profile->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByProfile() only accepts arguments of type \Thelia\Model\Profile or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Profile relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function joinProfile($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Profile'); - - // 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, 'Profile'); - } - - return $this; - } - - /** - * Use the Profile relation Profile 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\ProfileQuery A secondary query class using the current class as primary query - */ - public function useProfileQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinProfile($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Profile', '\Thelia\Model\ProfileQuery'); - } - - /** - * Filter the query by a related \Thelia\Model\Admin object - * - * @param \Thelia\Model\Admin|ObjectCollection $admin The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function filterByAdmin($admin, $comparison = null) - { - if ($admin instanceof \Thelia\Model\Admin) { - return $this - ->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $admin->getId(), $comparison); - } elseif ($admin instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(AdminProfileTableMap::ADMIN_ID, $admin->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByAdmin() only accepts arguments of type \Thelia\Model\Admin or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Admin relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function joinAdmin($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Admin'); - - // 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, 'Admin'); - } - - return $this; - } - - /** - * Use the Admin relation Admin 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\AdminQuery A secondary query class using the current class as primary query - */ - public function useAdminQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) - { - return $this - ->joinAdmin($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Admin', '\Thelia\Model\AdminQuery'); - } - - /** - * Exclude object from result - * - * @param ChildAdminProfile $adminProfile Object to remove from the list of results - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function prune($adminProfile = null) - { - if ($adminProfile) { - $this->addCond('pruneCond0', $this->getAliasedColName(AdminProfileTableMap::ID), $adminProfile->getId(), Criteria::NOT_EQUAL); - $this->addCond('pruneCond1', $this->getAliasedColName(AdminProfileTableMap::PROFILE_ID), $adminProfile->getProfileId(), Criteria::NOT_EQUAL); - $this->addCond('pruneCond2', $this->getAliasedColName(AdminProfileTableMap::ADMIN_ID), $adminProfile->getAdminId(), Criteria::NOT_EQUAL); - $this->combine(array('pruneCond0', 'pruneCond1', 'pruneCond2'), Criteria::LOGICAL_OR); - } - - return $this; - } - - /** - * Deletes all rows from the admin_profile 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(AdminProfileTableMap::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). - AdminProfileTableMap::clearInstancePool(); - AdminProfileTableMap::clearRelatedInstancePool(); - - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $affectedRows; - } - - /** - * Performs a DELETE on the database, given a ChildAdminProfile or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or ChildAdminProfile 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(AdminProfileTableMap::DATABASE_NAME); - } - - $criteria = $this; - - // Set the correct dbName - $criteria->setDbName(AdminProfileTableMap::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(); - - - AdminProfileTableMap::removeInstanceFromPool($criteria); - - $affectedRows += ModelCriteria::delete($con); - AdminProfileTableMap::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 ChildAdminProfileQuery The current query, for fluid interface - */ - public function recentlyUpdated($nbDays = 7) - { - return $this->addUsingAlias(AdminProfileTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Filter by the latest created - * - * @param int $nbDays Maximum age of in days - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function recentlyCreated($nbDays = 7) - { - return $this->addUsingAlias(AdminProfileTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Order by update date desc - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function lastUpdatedFirst() - { - return $this->addDescendingOrderByColumn(AdminProfileTableMap::UPDATED_AT); - } - - /** - * Order by update date asc - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function firstUpdatedFirst() - { - return $this->addAscendingOrderByColumn(AdminProfileTableMap::UPDATED_AT); - } - - /** - * Order by create date desc - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function lastCreatedFirst() - { - return $this->addDescendingOrderByColumn(AdminProfileTableMap::CREATED_AT); - } - - /** - * Order by create date asc - * - * @return ChildAdminProfileQuery The current query, for fluid interface - */ - public function firstCreatedFirst() - { - return $this->addAscendingOrderByColumn(AdminProfileTableMap::CREATED_AT); - } - -} // AdminProfileQuery diff --git a/core/lib/Thelia/Model/Base/AdminQuery.php b/core/lib/Thelia/Model/Base/AdminQuery.php index 26ec46381..d9f032544 100644 --- a/core/lib/Thelia/Model/Base/AdminQuery.php +++ b/core/lib/Thelia/Model/Base/AdminQuery.php @@ -22,6 +22,7 @@ use Thelia\Model\Map\AdminTableMap; * * * @method ChildAdminQuery orderById($order = Criteria::ASC) Order by the id column + * @method ChildAdminQuery orderByProfileId($order = Criteria::ASC) Order by the profile_id column * @method ChildAdminQuery orderByFirstname($order = Criteria::ASC) Order by the firstname column * @method ChildAdminQuery orderByLastname($order = Criteria::ASC) Order by the lastname column * @method ChildAdminQuery orderByLogin($order = Criteria::ASC) Order by the login column @@ -34,6 +35,7 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdminQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildAdminQuery groupById() Group by the id column + * @method ChildAdminQuery groupByProfileId() Group by the profile_id column * @method ChildAdminQuery groupByFirstname() Group by the firstname column * @method ChildAdminQuery groupByLastname() Group by the lastname column * @method ChildAdminQuery groupByLogin() Group by the login column @@ -49,14 +51,15 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdminQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query * @method ChildAdminQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildAdminQuery leftJoinAdminProfile($relationAlias = null) Adds a LEFT JOIN clause to the query using the AdminProfile relation - * @method ChildAdminQuery rightJoinAdminProfile($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AdminProfile relation - * @method ChildAdminQuery innerJoinAdminProfile($relationAlias = null) Adds a INNER JOIN clause to the query using the AdminProfile relation + * @method ChildAdminQuery leftJoinProfile($relationAlias = null) Adds a LEFT JOIN clause to the query using the Profile relation + * @method ChildAdminQuery rightJoinProfile($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Profile relation + * @method ChildAdminQuery innerJoinProfile($relationAlias = null) Adds a INNER JOIN clause to the query using the Profile relation * * @method ChildAdmin findOne(ConnectionInterface $con = null) Return the first ChildAdmin matching the query * @method ChildAdmin findOneOrCreate(ConnectionInterface $con = null) Return the first ChildAdmin matching the query, or a new ChildAdmin object populated from the query conditions when no match is found * * @method ChildAdmin findOneById(int $id) Return the first ChildAdmin filtered by the id column + * @method ChildAdmin findOneByProfileId(int $profile_id) Return the first ChildAdmin filtered by the profile_id column * @method ChildAdmin findOneByFirstname(string $firstname) Return the first ChildAdmin filtered by the firstname column * @method ChildAdmin findOneByLastname(string $lastname) Return the first ChildAdmin filtered by the lastname column * @method ChildAdmin findOneByLogin(string $login) Return the first ChildAdmin filtered by the login column @@ -69,6 +72,7 @@ use Thelia\Model\Map\AdminTableMap; * @method ChildAdmin findOneByUpdatedAt(string $updated_at) Return the first ChildAdmin filtered by the updated_at column * * @method array findById(int $id) Return ChildAdmin objects filtered by the id column + * @method array findByProfileId(int $profile_id) Return ChildAdmin objects filtered by the profile_id column * @method array findByFirstname(string $firstname) Return ChildAdmin objects filtered by the firstname column * @method array findByLastname(string $lastname) Return ChildAdmin objects filtered by the lastname column * @method array findByLogin(string $login) Return ChildAdmin objects filtered by the login column @@ -167,7 +171,7 @@ abstract class AdminQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, FIRSTNAME, LASTNAME, LOGIN, PASSWORD, ALGO, SALT, REMEMBER_ME_TOKEN, REMEMBER_ME_SERIAL, CREATED_AT, UPDATED_AT FROM admin WHERE ID = :p0'; + $sql = 'SELECT ID, PROFILE_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); @@ -297,6 +301,49 @@ abstract class AdminQuery extends ModelCriteria return $this->addUsingAlias(AdminTableMap::ID, $id, $comparison); } + /** + * Filter the query on the profile_id column + * + * Example usage: + * + * $query->filterByProfileId(1234); // WHERE profile_id = 1234 + * $query->filterByProfileId(array(12, 34)); // WHERE profile_id IN (12, 34) + * $query->filterByProfileId(array('min' => 12)); // WHERE profile_id > 12 + * + * + * @see filterByProfile() + * + * @param mixed $profileId 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 ChildAdminQuery The current query, for fluid interface + */ + public function filterByProfileId($profileId = null, $comparison = null) + { + if (is_array($profileId)) { + $useMinMax = false; + if (isset($profileId['min'])) { + $this->addUsingAlias(AdminTableMap::PROFILE_ID, $profileId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($profileId['max'])) { + $this->addUsingAlias(AdminTableMap::PROFILE_ID, $profileId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AdminTableMap::PROFILE_ID, $profileId, $comparison); + } + /** * Filter the query on the firstname column * @@ -616,40 +663,42 @@ abstract class AdminQuery extends ModelCriteria } /** - * Filter the query by a related \Thelia\Model\AdminProfile object + * Filter the query by a related \Thelia\Model\Profile object * - * @param \Thelia\Model\AdminProfile|ObjectCollection $adminProfile the related object to use as filter + * @param \Thelia\Model\Profile|ObjectCollection $profile The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildAdminQuery The current query, for fluid interface */ - public function filterByAdminProfile($adminProfile, $comparison = null) + public function filterByProfile($profile, $comparison = null) { - if ($adminProfile instanceof \Thelia\Model\AdminProfile) { + if ($profile instanceof \Thelia\Model\Profile) { return $this - ->addUsingAlias(AdminTableMap::ID, $adminProfile->getAdminId(), $comparison); - } elseif ($adminProfile instanceof ObjectCollection) { + ->addUsingAlias(AdminTableMap::PROFILE_ID, $profile->getId(), $comparison); + } elseif ($profile instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + return $this - ->useAdminProfileQuery() - ->filterByPrimaryKeys($adminProfile->getPrimaryKeys()) - ->endUse(); + ->addUsingAlias(AdminTableMap::PROFILE_ID, $profile->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { - throw new PropelException('filterByAdminProfile() only accepts arguments of type \Thelia\Model\AdminProfile or Collection'); + throw new PropelException('filterByProfile() only accepts arguments of type \Thelia\Model\Profile or Collection'); } } /** - * Adds a JOIN clause to the query using the AdminProfile relation + * Adds a JOIN clause to the query using the Profile relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildAdminQuery The current query, for fluid interface */ - public function joinAdminProfile($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinProfile($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('AdminProfile'); + $relationMap = $tableMap->getRelation('Profile'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -664,14 +713,14 @@ abstract class AdminQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'AdminProfile'); + $this->addJoinObject($join, 'Profile'); } return $this; } /** - * Use the AdminProfile relation AdminProfile object + * Use the Profile relation Profile object * * @see useQuery() * @@ -679,30 +728,13 @@ abstract class AdminQuery 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\AdminProfileQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ProfileQuery A secondary query class using the current class as primary query */ - public function useAdminProfileQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useProfileQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this - ->joinAdminProfile($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'AdminProfile', '\Thelia\Model\AdminProfileQuery'); - } - - /** - * Filter the query by a related Profile object - * using the admin_profile table as cross reference - * - * @param Profile $profile the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAdminQuery The current query, for fluid interface - */ - public function filterByProfile($profile, $comparison = Criteria::EQUAL) - { - return $this - ->useAdminProfileQuery() - ->filterByProfile($profile, $comparison) - ->endUse(); + ->joinProfile($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Profile', '\Thelia\Model\ProfileQuery'); } /** diff --git a/core/lib/Thelia/Model/Base/Profile.php b/core/lib/Thelia/Model/Base/Profile.php index 4dbd37408..2f75899d2 100644 --- a/core/lib/Thelia/Model/Base/Profile.php +++ b/core/lib/Thelia/Model/Base/Profile.php @@ -18,8 +18,6 @@ use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\Admin as ChildAdmin; -use Thelia\Model\AdminProfile as ChildAdminProfile; -use Thelia\Model\AdminProfileQuery as ChildAdminProfileQuery; use Thelia\Model\AdminQuery as ChildAdminQuery; use Thelia\Model\Profile as ChildProfile; use Thelia\Model\ProfileI18n as ChildProfileI18n; @@ -92,10 +90,10 @@ abstract class Profile implements ActiveRecordInterface protected $updated_at; /** - * @var ObjectCollection|ChildAdminProfile[] Collection to store aggregation of ChildAdminProfile objects. + * @var ObjectCollection|ChildAdmin[] Collection to store aggregation of ChildAdmin objects. */ - protected $collAdminProfiles; - protected $collAdminProfilesPartial; + protected $collAdmins; + protected $collAdminsPartial; /** * @var ObjectCollection|ChildProfileResource[] Collection to store aggregation of ChildProfileResource objects. @@ -115,11 +113,6 @@ abstract class Profile implements ActiveRecordInterface protected $collProfileI18ns; protected $collProfileI18nsPartial; - /** - * @var ChildAdmin[] Collection to store aggregation of ChildAdmin objects. - */ - protected $collAdmins; - /** * @var ChildResource[] Collection to store aggregation of ChildResource objects. */ @@ -147,12 +140,6 @@ abstract class Profile implements ActiveRecordInterface */ protected $currentTranslations; - /** - * An array of objects scheduled for deletion. - * @var ObjectCollection - */ - protected $adminsScheduledForDeletion = null; - /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -163,7 +150,7 @@ abstract class Profile implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $adminProfilesScheduledForDeletion = null; + protected $adminsScheduledForDeletion = null; /** * An array of objects scheduled for deletion. @@ -710,7 +697,7 @@ abstract class Profile implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->collAdminProfiles = null; + $this->collAdmins = null; $this->collProfileResources = null; @@ -718,7 +705,6 @@ abstract class Profile implements ActiveRecordInterface $this->collProfileI18ns = null; - $this->collAdmins = null; $this->collResources = null; } // if (deep) } @@ -853,33 +839,6 @@ abstract class Profile implements ActiveRecordInterface $this->resetModified(); } - if ($this->adminsScheduledForDeletion !== null) { - if (!$this->adminsScheduledForDeletion->isEmpty()) { - $pks = array(); - $pk = $this->getPrimaryKey(); - foreach ($this->adminsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { - $pks[] = array($pk, $remotePk); - } - - AdminProfileQuery::create() - ->filterByPrimaryKeys($pks) - ->delete($con); - $this->adminsScheduledForDeletion = null; - } - - foreach ($this->getAdmins() as $admin) { - if ($admin->isModified()) { - $admin->save($con); - } - } - } elseif ($this->collAdmins) { - foreach ($this->collAdmins as $admin) { - if ($admin->isModified()) { - $admin->save($con); - } - } - } - if ($this->resourcesScheduledForDeletion !== null) { if (!$this->resourcesScheduledForDeletion->isEmpty()) { $pks = array(); @@ -907,17 +866,18 @@ abstract class Profile implements ActiveRecordInterface } } - if ($this->adminProfilesScheduledForDeletion !== null) { - if (!$this->adminProfilesScheduledForDeletion->isEmpty()) { - \Thelia\Model\AdminProfileQuery::create() - ->filterByPrimaryKeys($this->adminProfilesScheduledForDeletion->getPrimaryKeys(false)) - ->delete($con); - $this->adminProfilesScheduledForDeletion = null; + if ($this->adminsScheduledForDeletion !== null) { + if (!$this->adminsScheduledForDeletion->isEmpty()) { + foreach ($this->adminsScheduledForDeletion as $admin) { + // need to save related object because we set the relation to null + $admin->save($con); + } + $this->adminsScheduledForDeletion = null; } } - if ($this->collAdminProfiles !== null) { - foreach ($this->collAdminProfiles as $referrerFK) { + if ($this->collAdmins !== null) { + foreach ($this->collAdmins as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } @@ -1150,8 +1110,8 @@ abstract class Profile implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->collAdminProfiles) { - $result['AdminProfiles'] = $this->collAdminProfiles->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collAdmins) { + $result['Admins'] = $this->collAdmins->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collProfileResources) { $result['ProfileResources'] = $this->collProfileResources->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); @@ -1323,9 +1283,9 @@ abstract class Profile implements ActiveRecordInterface // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); - foreach ($this->getAdminProfiles() as $relObj) { + foreach ($this->getAdmins() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addAdminProfile($relObj->copy($deepCopy)); + $copyObj->addAdmin($relObj->copy($deepCopy)); } } @@ -1388,8 +1348,8 @@ abstract class Profile implements ActiveRecordInterface */ public function initRelation($relationName) { - if ('AdminProfile' == $relationName) { - return $this->initAdminProfiles(); + if ('Admin' == $relationName) { + return $this->initAdmins(); } if ('ProfileResource' == $relationName) { return $this->initProfileResources(); @@ -1403,31 +1363,31 @@ abstract class Profile implements ActiveRecordInterface } /** - * Clears out the collAdminProfiles collection + * Clears out the collAdmins 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 addAdminProfiles() + * @see addAdmins() */ - public function clearAdminProfiles() + public function clearAdmins() { - $this->collAdminProfiles = null; // important to set this to NULL since that means it is uninitialized + $this->collAdmins = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collAdminProfiles collection loaded partially. + * Reset is the collAdmins collection loaded partially. */ - public function resetPartialAdminProfiles($v = true) + public function resetPartialAdmins($v = true) { - $this->collAdminProfilesPartial = $v; + $this->collAdminsPartial = $v; } /** - * Initializes the collAdminProfiles collection. + * Initializes the collAdmins collection. * - * By default this just sets the collAdminProfiles collection to an empty array (like clearcollAdminProfiles()); + * By default this just sets the collAdmins collection to an empty array (like clearcollAdmins()); * 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. * @@ -1436,17 +1396,17 @@ abstract class Profile implements ActiveRecordInterface * * @return void */ - public function initAdminProfiles($overrideExisting = true) + public function initAdmins($overrideExisting = true) { - if (null !== $this->collAdminProfiles && !$overrideExisting) { + if (null !== $this->collAdmins && !$overrideExisting) { return; } - $this->collAdminProfiles = new ObjectCollection(); - $this->collAdminProfiles->setModel('\Thelia\Model\AdminProfile'); + $this->collAdmins = new ObjectCollection(); + $this->collAdmins->setModel('\Thelia\Model\Admin'); } /** - * Gets an array of ChildAdminProfile objects which contain a foreign key that references this object. + * Gets an array of ChildAdmin 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. @@ -1456,112 +1416,109 @@ abstract class Profile implements ActiveRecordInterface * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildAdminProfile[] List of ChildAdminProfile objects + * @return Collection|ChildAdmin[] List of ChildAdmin objects * @throws PropelException */ - public function getAdminProfiles($criteria = null, ConnectionInterface $con = null) + public function getAdmins($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collAdminProfilesPartial && !$this->isNew(); - if (null === $this->collAdminProfiles || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAdminProfiles) { + $partial = $this->collAdminsPartial && !$this->isNew(); + if (null === $this->collAdmins || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAdmins) { // return empty collection - $this->initAdminProfiles(); + $this->initAdmins(); } else { - $collAdminProfiles = ChildAdminProfileQuery::create(null, $criteria) + $collAdmins = ChildAdminQuery::create(null, $criteria) ->filterByProfile($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collAdminProfilesPartial && count($collAdminProfiles)) { - $this->initAdminProfiles(false); + if (false !== $this->collAdminsPartial && count($collAdmins)) { + $this->initAdmins(false); - foreach ($collAdminProfiles as $obj) { - if (false == $this->collAdminProfiles->contains($obj)) { - $this->collAdminProfiles->append($obj); + foreach ($collAdmins as $obj) { + if (false == $this->collAdmins->contains($obj)) { + $this->collAdmins->append($obj); } } - $this->collAdminProfilesPartial = true; + $this->collAdminsPartial = true; } - $collAdminProfiles->getInternalIterator()->rewind(); + $collAdmins->getInternalIterator()->rewind(); - return $collAdminProfiles; + return $collAdmins; } - if ($partial && $this->collAdminProfiles) { - foreach ($this->collAdminProfiles as $obj) { + if ($partial && $this->collAdmins) { + foreach ($this->collAdmins as $obj) { if ($obj->isNew()) { - $collAdminProfiles[] = $obj; + $collAdmins[] = $obj; } } } - $this->collAdminProfiles = $collAdminProfiles; - $this->collAdminProfilesPartial = false; + $this->collAdmins = $collAdmins; + $this->collAdminsPartial = false; } } - return $this->collAdminProfiles; + return $this->collAdmins; } /** - * Sets a collection of AdminProfile objects related by a one-to-many relationship + * Sets a collection of Admin 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 $adminProfiles A Propel collection. + * @param Collection $admins A Propel collection. * @param ConnectionInterface $con Optional connection object * @return ChildProfile The current object (for fluent API support) */ - public function setAdminProfiles(Collection $adminProfiles, ConnectionInterface $con = null) + public function setAdmins(Collection $admins, ConnectionInterface $con = null) { - $adminProfilesToDelete = $this->getAdminProfiles(new Criteria(), $con)->diff($adminProfiles); + $adminsToDelete = $this->getAdmins(new Criteria(), $con)->diff($admins); - //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->adminProfilesScheduledForDeletion = clone $adminProfilesToDelete; + $this->adminsScheduledForDeletion = $adminsToDelete; - foreach ($adminProfilesToDelete as $adminProfileRemoved) { - $adminProfileRemoved->setProfile(null); + foreach ($adminsToDelete as $adminRemoved) { + $adminRemoved->setProfile(null); } - $this->collAdminProfiles = null; - foreach ($adminProfiles as $adminProfile) { - $this->addAdminProfile($adminProfile); + $this->collAdmins = null; + foreach ($admins as $admin) { + $this->addAdmin($admin); } - $this->collAdminProfiles = $adminProfiles; - $this->collAdminProfilesPartial = false; + $this->collAdmins = $admins; + $this->collAdminsPartial = false; return $this; } /** - * Returns the number of related AdminProfile objects. + * Returns the number of related Admin objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related AdminProfile objects. + * @return int Count of related Admin objects. * @throws PropelException */ - public function countAdminProfiles(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countAdmins(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collAdminProfilesPartial && !$this->isNew(); - if (null === $this->collAdminProfiles || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collAdminProfiles) { + $partial = $this->collAdminsPartial && !$this->isNew(); + if (null === $this->collAdmins || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collAdmins) { return 0; } if ($partial && !$criteria) { - return count($this->getAdminProfiles()); + return count($this->getAdmins()); } - $query = ChildAdminProfileQuery::create(null, $criteria); + $query = ChildAdminQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } @@ -1571,83 +1528,58 @@ abstract class Profile implements ActiveRecordInterface ->count($con); } - return count($this->collAdminProfiles); + return count($this->collAdmins); } /** - * Method called to associate a ChildAdminProfile object to this object - * through the ChildAdminProfile foreign key attribute. + * Method called to associate a ChildAdmin object to this object + * through the ChildAdmin foreign key attribute. * - * @param ChildAdminProfile $l ChildAdminProfile + * @param ChildAdmin $l ChildAdmin * @return \Thelia\Model\Profile The current object (for fluent API support) */ - public function addAdminProfile(ChildAdminProfile $l) + public function addAdmin(ChildAdmin $l) { - if ($this->collAdminProfiles === null) { - $this->initAdminProfiles(); - $this->collAdminProfilesPartial = true; + if ($this->collAdmins === null) { + $this->initAdmins(); + $this->collAdminsPartial = true; } - if (!in_array($l, $this->collAdminProfiles->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddAdminProfile($l); + if (!in_array($l, $this->collAdmins->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddAdmin($l); } return $this; } /** - * @param AdminProfile $adminProfile The adminProfile object to add. + * @param Admin $admin The admin object to add. */ - protected function doAddAdminProfile($adminProfile) + protected function doAddAdmin($admin) { - $this->collAdminProfiles[]= $adminProfile; - $adminProfile->setProfile($this); + $this->collAdmins[]= $admin; + $admin->setProfile($this); } /** - * @param AdminProfile $adminProfile The adminProfile object to remove. + * @param Admin $admin The admin object to remove. * @return ChildProfile The current object (for fluent API support) */ - public function removeAdminProfile($adminProfile) + public function removeAdmin($admin) { - if ($this->getAdminProfiles()->contains($adminProfile)) { - $this->collAdminProfiles->remove($this->collAdminProfiles->search($adminProfile)); - if (null === $this->adminProfilesScheduledForDeletion) { - $this->adminProfilesScheduledForDeletion = clone $this->collAdminProfiles; - $this->adminProfilesScheduledForDeletion->clear(); + if ($this->getAdmins()->contains($admin)) { + $this->collAdmins->remove($this->collAdmins->search($admin)); + if (null === $this->adminsScheduledForDeletion) { + $this->adminsScheduledForDeletion = clone $this->collAdmins; + $this->adminsScheduledForDeletion->clear(); } - $this->adminProfilesScheduledForDeletion[]= clone $adminProfile; - $adminProfile->setProfile(null); + $this->adminsScheduledForDeletion[]= $admin; + $admin->setProfile(null); } return $this; } - - /** - * If this collection has already been initialized with - * an identical criteria, it returns the collection. - * Otherwise if this Profile is new, it will return - * an empty collection; or if this Profile has previously - * been saved, it will retrieve related AdminProfiles 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 Profile. - * - * @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|ChildAdminProfile[] List of ChildAdminProfile objects - */ - public function getAdminProfilesJoinAdmin($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) - { - $query = ChildAdminProfileQuery::create(null, $criteria); - $query->joinWith('Admin', $joinBehavior); - - return $this->getAdminProfiles($query, $con); - } - /** * Clears out the collProfileResources collection * @@ -2362,189 +2294,6 @@ abstract class Profile implements ActiveRecordInterface return $this; } - /** - * Clears out the collAdmins 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 addAdmins() - */ - public function clearAdmins() - { - $this->collAdmins = null; // important to set this to NULL since that means it is uninitialized - $this->collAdminsPartial = null; - } - - /** - * Initializes the collAdmins collection. - * - * By default this just sets the collAdmins collection to an empty collection (like clearAdmins()); - * 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 initAdmins() - { - $this->collAdmins = new ObjectCollection(); - $this->collAdmins->setModel('\Thelia\Model\Admin'); - } - - /** - * Gets a collection of ChildAdmin objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 ChildProfile 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|ChildAdmin[] List of ChildAdmin objects - */ - public function getAdmins($criteria = null, ConnectionInterface $con = null) - { - if (null === $this->collAdmins || null !== $criteria) { - if ($this->isNew() && null === $this->collAdmins) { - // return empty collection - $this->initAdmins(); - } else { - $collAdmins = ChildAdminQuery::create(null, $criteria) - ->filterByProfile($this) - ->find($con); - if (null !== $criteria) { - return $collAdmins; - } - $this->collAdmins = $collAdmins; - } - } - - return $this->collAdmins; - } - - /** - * Sets a collection of Admin objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 $admins A Propel collection. - * @param ConnectionInterface $con Optional connection object - * @return ChildProfile The current object (for fluent API support) - */ - public function setAdmins(Collection $admins, ConnectionInterface $con = null) - { - $this->clearAdmins(); - $currentAdmins = $this->getAdmins(); - - $this->adminsScheduledForDeletion = $currentAdmins->diff($admins); - - foreach ($admins as $admin) { - if (!$currentAdmins->contains($admin)) { - $this->doAddAdmin($admin); - } - } - - $this->collAdmins = $admins; - - return $this; - } - - /** - * Gets the number of ChildAdmin objects related by a many-to-many relationship - * to the current object by way of the admin_profile 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 ChildAdmin objects - */ - public function countAdmins($criteria = null, $distinct = false, ConnectionInterface $con = null) - { - if (null === $this->collAdmins || null !== $criteria) { - if ($this->isNew() && null === $this->collAdmins) { - return 0; - } else { - $query = ChildAdminQuery::create(null, $criteria); - if ($distinct) { - $query->distinct(); - } - - return $query - ->filterByProfile($this) - ->count($con); - } - } else { - return count($this->collAdmins); - } - } - - /** - * Associate a ChildAdmin object to this object - * through the admin_profile cross reference table. - * - * @param ChildAdmin $admin The ChildAdminProfile object to relate - * @return ChildProfile The current object (for fluent API support) - */ - public function addAdmin(ChildAdmin $admin) - { - if ($this->collAdmins === null) { - $this->initAdmins(); - } - - if (!$this->collAdmins->contains($admin)) { // only add it if the **same** object is not already associated - $this->doAddAdmin($admin); - $this->collAdmins[] = $admin; - } - - return $this; - } - - /** - * @param Admin $admin The admin object to add. - */ - protected function doAddAdmin($admin) - { - $adminProfile = new ChildAdminProfile(); - $adminProfile->setAdmin($admin); - $this->addAdminProfile($adminProfile); - // set the back reference to this object directly as using provided method either results - // in endless loop or in multiple relations - if (!$admin->getProfiles()->contains($this)) { - $foreignCollection = $admin->getProfiles(); - $foreignCollection[] = $this; - } - } - - /** - * Remove a ChildAdmin object to this object - * through the admin_profile cross reference table. - * - * @param ChildAdmin $admin The ChildAdminProfile object to relate - * @return ChildProfile The current object (for fluent API support) - */ - public function removeAdmin(ChildAdmin $admin) - { - if ($this->getAdmins()->contains($admin)) { - $this->collAdmins->remove($this->collAdmins->search($admin)); - - if (null === $this->adminsScheduledForDeletion) { - $this->adminsScheduledForDeletion = clone $this->collAdmins; - $this->adminsScheduledForDeletion->clear(); - } - - $this->adminsScheduledForDeletion[] = $admin; - } - - return $this; - } - /** * Clears out the collResources collection * @@ -2756,8 +2505,8 @@ abstract class Profile implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { - if ($this->collAdminProfiles) { - foreach ($this->collAdminProfiles as $o) { + if ($this->collAdmins) { + foreach ($this->collAdmins as $o) { $o->clearAllReferences($deep); } } @@ -2776,11 +2525,6 @@ abstract class Profile implements ActiveRecordInterface $o->clearAllReferences($deep); } } - if ($this->collAdmins) { - foreach ($this->collAdmins as $o) { - $o->clearAllReferences($deep); - } - } if ($this->collResources) { foreach ($this->collResources as $o) { $o->clearAllReferences($deep); @@ -2792,10 +2536,10 @@ abstract class Profile implements ActiveRecordInterface $this->currentLocale = 'en_US'; $this->currentTranslations = null; - if ($this->collAdminProfiles instanceof Collection) { - $this->collAdminProfiles->clearIterator(); + if ($this->collAdmins instanceof Collection) { + $this->collAdmins->clearIterator(); } - $this->collAdminProfiles = null; + $this->collAdmins = null; if ($this->collProfileResources instanceof Collection) { $this->collProfileResources->clearIterator(); } @@ -2808,10 +2552,6 @@ abstract class Profile implements ActiveRecordInterface $this->collProfileI18ns->clearIterator(); } $this->collProfileI18ns = null; - if ($this->collAdmins instanceof Collection) { - $this->collAdmins->clearIterator(); - } - $this->collAdmins = null; if ($this->collResources instanceof Collection) { $this->collResources->clearIterator(); } diff --git a/core/lib/Thelia/Model/Base/ProfileQuery.php b/core/lib/Thelia/Model/Base/ProfileQuery.php index 6f9995b71..7937776c5 100644 --- a/core/lib/Thelia/Model/Base/ProfileQuery.php +++ b/core/lib/Thelia/Model/Base/ProfileQuery.php @@ -36,9 +36,9 @@ use Thelia\Model\Map\ProfileTableMap; * @method ChildProfileQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query * @method ChildProfileQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildProfileQuery leftJoinAdminProfile($relationAlias = null) Adds a LEFT JOIN clause to the query using the AdminProfile relation - * @method ChildProfileQuery rightJoinAdminProfile($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AdminProfile relation - * @method ChildProfileQuery innerJoinAdminProfile($relationAlias = null) Adds a INNER JOIN clause to the query using the AdminProfile relation + * @method ChildProfileQuery leftJoinAdmin($relationAlias = null) Adds a LEFT JOIN clause to the query using the Admin relation + * @method ChildProfileQuery rightJoinAdmin($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Admin relation + * @method ChildProfileQuery innerJoinAdmin($relationAlias = null) Adds a INNER JOIN clause to the query using the Admin relation * * @method ChildProfileQuery leftJoinProfileResource($relationAlias = null) Adds a LEFT JOIN clause to the query using the ProfileResource relation * @method ChildProfileQuery rightJoinProfileResource($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProfileResource relation @@ -398,40 +398,40 @@ abstract class ProfileQuery extends ModelCriteria } /** - * Filter the query by a related \Thelia\Model\AdminProfile object + * Filter the query by a related \Thelia\Model\Admin object * - * @param \Thelia\Model\AdminProfile|ObjectCollection $adminProfile the related object to use as filter + * @param \Thelia\Model\Admin|ObjectCollection $admin the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildProfileQuery The current query, for fluid interface */ - public function filterByAdminProfile($adminProfile, $comparison = null) + public function filterByAdmin($admin, $comparison = null) { - if ($adminProfile instanceof \Thelia\Model\AdminProfile) { + if ($admin instanceof \Thelia\Model\Admin) { return $this - ->addUsingAlias(ProfileTableMap::ID, $adminProfile->getProfileId(), $comparison); - } elseif ($adminProfile instanceof ObjectCollection) { + ->addUsingAlias(ProfileTableMap::ID, $admin->getProfileId(), $comparison); + } elseif ($admin instanceof ObjectCollection) { return $this - ->useAdminProfileQuery() - ->filterByPrimaryKeys($adminProfile->getPrimaryKeys()) + ->useAdminQuery() + ->filterByPrimaryKeys($admin->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByAdminProfile() only accepts arguments of type \Thelia\Model\AdminProfile or Collection'); + throw new PropelException('filterByAdmin() only accepts arguments of type \Thelia\Model\Admin or Collection'); } } /** - * Adds a JOIN clause to the query using the AdminProfile relation + * Adds a JOIN clause to the query using the Admin relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildProfileQuery The current query, for fluid interface */ - public function joinAdminProfile($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinAdmin($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('AdminProfile'); + $relationMap = $tableMap->getRelation('Admin'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -446,14 +446,14 @@ abstract class ProfileQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'AdminProfile'); + $this->addJoinObject($join, 'Admin'); } return $this; } /** - * Use the AdminProfile relation AdminProfile object + * Use the Admin relation Admin object * * @see useQuery() * @@ -461,13 +461,13 @@ abstract class ProfileQuery 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\AdminProfileQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\AdminQuery A secondary query class using the current class as primary query */ - public function useAdminProfileQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useAdminQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this - ->joinAdminProfile($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'AdminProfile', '\Thelia\Model\AdminProfileQuery'); + ->joinAdmin($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Admin', '\Thelia\Model\AdminQuery'); } /** @@ -689,23 +689,6 @@ abstract class ProfileQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ProfileI18n', '\Thelia\Model\ProfileI18nQuery'); } - /** - * Filter the query by a related Admin object - * using the admin_profile table as cross reference - * - * @param Admin $admin the related object to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildProfileQuery The current query, for fluid interface - */ - public function filterByAdmin($admin, $comparison = Criteria::EQUAL) - { - return $this - ->useAdminProfileQuery() - ->filterByAdmin($admin, $comparison) - ->endUse(); - } - /** * Filter the query by a related Resource object * using the profile_resource table as cross reference diff --git a/core/lib/Thelia/Model/Map/AdminProfileTableMap.php b/core/lib/Thelia/Model/Map/AdminProfileTableMap.php deleted file mode 100644 index a6407c8e2..000000000 --- a/core/lib/Thelia/Model/Map/AdminProfileTableMap.php +++ /dev/null @@ -1,509 +0,0 @@ - array('Id', 'ProfileId', 'AdminId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'profileId', 'adminId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AdminProfileTableMap::ID, AdminProfileTableMap::PROFILE_ID, AdminProfileTableMap::ADMIN_ID, AdminProfileTableMap::CREATED_AT, AdminProfileTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'PROFILE_ID', 'ADMIN_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'profile_id', 'admin_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, 'ProfileId' => 1, 'AdminId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'profileId' => 1, 'adminId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(AdminProfileTableMap::ID => 0, AdminProfileTableMap::PROFILE_ID => 1, AdminProfileTableMap::ADMIN_ID => 2, AdminProfileTableMap::CREATED_AT => 3, AdminProfileTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'PROFILE_ID' => 1, 'ADMIN_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'profile_id' => 1, 'admin_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('admin_profile'); - $this->setPhpName('AdminProfile'); - $this->setClassName('\\Thelia\\Model\\AdminProfile'); - $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(true); - $this->setIsCrossRef(true); - // columns - $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addForeignPrimaryKey('PROFILE_ID', 'ProfileId', 'INTEGER' , 'profile', 'ID', true, null, null); - $this->addForeignPrimaryKey('ADMIN_ID', 'AdminId', 'INTEGER' , 'admin', '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('Profile', '\\Thelia\\Model\\Profile', RelationMap::MANY_TO_ONE, array('profile_id' => 'id', ), 'CASCADE', 'RESTRICT'); - $this->addRelation('Admin', '\\Thelia\\Model\\Admin', RelationMap::MANY_TO_ONE, array('admin_id' => 'id', ), 'CASCADE', 'RESTRICT'); - } // buildRelations() - - /** - * - * Gets the list of behaviors registered for this table - * - * @return array Associative array (name => parameters) of behaviors - */ - public function getBehaviors() - { - return array( - 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), - ); - } // getBehaviors() - - /** - * 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\AdminProfile $obj A \Thelia\Model\AdminProfile 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->getProfileId(), (string) $obj->getAdminId())); - } // 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\AdminProfile object or a primary key value. - */ - public static function removeInstanceFromPool($value) - { - if (Propel::isInstancePoolingEnabled() && null !== $value) { - if (is_object($value) && $value instanceof \Thelia\Model\AdminProfile) { - $key = serialize(array((string) $value->getId(), (string) $value->getProfileId(), (string) $value->getAdminId())); - - } elseif (is_array($value) && count($value) === 3) { - // assume we've been passed a primary key"; - $key = serialize(array((string) $value[0], (string) $value[1], (string) $value[2])); - } elseif ($value instanceof Criteria) { - self::$instances = []; - - return; - } else { - $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\AdminProfile 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('ProfileId', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 2 + $offset : static::translateFieldName('AdminId', 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('ProfileId', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 2 + $offset : static::translateFieldName('AdminId', 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 ? AdminProfileTableMap::CLASS_DEFAULT : AdminProfileTableMap::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 (AdminProfile object, last column rank) - */ - public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - $key = AdminProfileTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = AdminProfileTableMap::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 + AdminProfileTableMap::NUM_HYDRATE_COLUMNS; - } else { - $cls = AdminProfileTableMap::OM_CLASS; - $obj = new $cls(); - $col = $obj->hydrate($row, $offset, false, $indexType); - AdminProfileTableMap::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 = AdminProfileTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = AdminProfileTableMap::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; - AdminProfileTableMap::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(AdminProfileTableMap::ID); - $criteria->addSelectColumn(AdminProfileTableMap::PROFILE_ID); - $criteria->addSelectColumn(AdminProfileTableMap::ADMIN_ID); - $criteria->addSelectColumn(AdminProfileTableMap::CREATED_AT); - $criteria->addSelectColumn(AdminProfileTableMap::UPDATED_AT); - } else { - $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.PROFILE_ID'); - $criteria->addSelectColumn($alias . '.ADMIN_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(AdminProfileTableMap::DATABASE_NAME)->getTable(AdminProfileTableMap::TABLE_NAME); - } - - /** - * Add a TableMap instance to the database for this tableMap class. - */ - public static function buildTableMap() - { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(AdminProfileTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(AdminProfileTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new AdminProfileTableMap()); - } - } - - /** - * Performs a DELETE on the database, given a AdminProfile or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or AdminProfile 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(AdminProfileTableMap::DATABASE_NAME); - } - - if ($values instanceof Criteria) { - // rename for clarity - $criteria = $values; - } elseif ($values instanceof \Thelia\Model\AdminProfile) { // 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(AdminProfileTableMap::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(AdminProfileTableMap::ID, $value[0]); - $criterion->addAnd($criteria->getNewCriterion(AdminProfileTableMap::PROFILE_ID, $value[1])); - $criterion->addAnd($criteria->getNewCriterion(AdminProfileTableMap::ADMIN_ID, $value[2])); - $criteria->addOr($criterion); - } - } - - $query = AdminProfileQuery::create()->mergeWith($criteria); - - if ($values instanceof Criteria) { AdminProfileTableMap::clearInstancePool(); - } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { AdminProfileTableMap::removeInstanceFromPool($singleval); - } - } - - return $query->delete($con); - } - - /** - * Deletes all rows from the admin_profile 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 AdminProfileQuery::create()->doDeleteAll($con); - } - - /** - * Performs an INSERT on the database, given a AdminProfile or Criteria object. - * - * @param mixed $criteria Criteria or AdminProfile 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(AdminProfileTableMap::DATABASE_NAME); - } - - if ($criteria instanceof Criteria) { - $criteria = clone $criteria; // rename for clarity - } else { - $criteria = $criteria->buildCriteria(); // build Criteria from AdminProfile object - } - - if ($criteria->containsKey(AdminProfileTableMap::ID) && $criteria->keyContainsValue(AdminProfileTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.AdminProfileTableMap::ID.')'); - } - - - // Set the correct dbName - $query = AdminProfileQuery::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; - } - -} // AdminProfileTableMap -// This is the static code needed to register the TableMap for this table with the main Propel class. -// -AdminProfileTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/AdminTableMap.php b/core/lib/Thelia/Model/Map/AdminTableMap.php index edc2bcee3..4217f9de2 100644 --- a/core/lib/Thelia/Model/Map/AdminTableMap.php +++ b/core/lib/Thelia/Model/Map/AdminTableMap.php @@ -57,7 +57,7 @@ class AdminTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 11; + const NUM_COLUMNS = 12; /** * The number of lazy-loaded columns @@ -67,13 +67,18 @@ class AdminTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 11; + const NUM_HYDRATE_COLUMNS = 12; /** * the column name for the ID field */ const ID = 'admin.ID'; + /** + * the column name for the PROFILE_ID field + */ + const PROFILE_ID = 'admin.PROFILE_ID'; + /** * the column name for the FIRSTNAME field */ @@ -136,12 +141,12 @@ class AdminTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - 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, ) + self::TYPE_PHPNAME => array('Id', 'ProfileId', 'Firstname', 'Lastname', 'Login', 'Password', 'Algo', 'Salt', 'RememberMeToken', 'RememberMeSerial', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'profileId', 'firstname', 'lastname', 'login', 'password', 'algo', 'salt', 'rememberMeToken', 'rememberMeSerial', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AdminTableMap::ID, AdminTableMap::PROFILE_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', 'PROFILE_ID', 'FIRSTNAME', 'LASTNAME', 'LOGIN', 'PASSWORD', 'ALGO', 'SALT', 'REMEMBER_ME_TOKEN', 'REMEMBER_ME_SERIAL', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'profile_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, 11, ) ); /** @@ -151,12 +156,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, '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, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ProfileId' => 1, 'Firstname' => 2, 'Lastname' => 3, 'Login' => 4, 'Password' => 5, 'Algo' => 6, 'Salt' => 7, 'RememberMeToken' => 8, 'RememberMeSerial' => 9, 'CreatedAt' => 10, 'UpdatedAt' => 11, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'profileId' => 1, 'firstname' => 2, 'lastname' => 3, 'login' => 4, 'password' => 5, 'algo' => 6, 'salt' => 7, 'rememberMeToken' => 8, 'rememberMeSerial' => 9, 'createdAt' => 10, 'updatedAt' => 11, ), + self::TYPE_COLNAME => array(AdminTableMap::ID => 0, AdminTableMap::PROFILE_ID => 1, AdminTableMap::FIRSTNAME => 2, AdminTableMap::LASTNAME => 3, AdminTableMap::LOGIN => 4, AdminTableMap::PASSWORD => 5, AdminTableMap::ALGO => 6, AdminTableMap::SALT => 7, AdminTableMap::REMEMBER_ME_TOKEN => 8, AdminTableMap::REMEMBER_ME_SERIAL => 9, AdminTableMap::CREATED_AT => 10, AdminTableMap::UPDATED_AT => 11, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PROFILE_ID' => 1, 'FIRSTNAME' => 2, 'LASTNAME' => 3, 'LOGIN' => 4, 'PASSWORD' => 5, 'ALGO' => 6, 'SALT' => 7, 'REMEMBER_ME_TOKEN' => 8, 'REMEMBER_ME_SERIAL' => 9, 'CREATED_AT' => 10, 'UPDATED_AT' => 11, ), + self::TYPE_FIELDNAME => array('id' => 0, 'profile_id' => 1, 'firstname' => 2, 'lastname' => 3, 'login' => 4, 'password' => 5, 'algo' => 6, 'salt' => 7, 'remember_me_token' => 8, 'remember_me_serial' => 9, 'created_at' => 10, 'updated_at' => 11, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ); /** @@ -176,6 +181,7 @@ class AdminTableMap extends TableMap $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('PROFILE_ID', 'ProfileId', 'INTEGER', 'profile', 'ID', false, null, null); $this->addColumn('FIRSTNAME', 'Firstname', 'VARCHAR', true, 100, null); $this->addColumn('LASTNAME', 'Lastname', 'VARCHAR', true, 100, null); $this->addColumn('LOGIN', 'Login', 'VARCHAR', true, 100, null); @@ -193,8 +199,7 @@ class AdminTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('AdminProfile', '\\Thelia\\Model\\AdminProfile', RelationMap::ONE_TO_MANY, array('id' => 'admin_id', ), 'CASCADE', 'RESTRICT', 'AdminProfiles'); - $this->addRelation('Profile', '\\Thelia\\Model\\Profile', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Profiles'); + $this->addRelation('Profile', '\\Thelia\\Model\\Profile', RelationMap::MANY_TO_ONE, array('profile_id' => 'id', ), 'RESTRICT', 'RESTRICT'); } // buildRelations() /** @@ -209,15 +214,6 @@ class AdminTableMap extends TableMap 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), ); } // getBehaviors() - /** - * Method to invalidate the instance pool of all tables related to admin * 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. - AdminProfileTableMap::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. @@ -358,6 +354,7 @@ class AdminTableMap extends TableMap { if (null === $alias) { $criteria->addSelectColumn(AdminTableMap::ID); + $criteria->addSelectColumn(AdminTableMap::PROFILE_ID); $criteria->addSelectColumn(AdminTableMap::FIRSTNAME); $criteria->addSelectColumn(AdminTableMap::LASTNAME); $criteria->addSelectColumn(AdminTableMap::LOGIN); @@ -370,6 +367,7 @@ class AdminTableMap extends TableMap $criteria->addSelectColumn(AdminTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.PROFILE_ID'); $criteria->addSelectColumn($alias . '.FIRSTNAME'); $criteria->addSelectColumn($alias . '.LASTNAME'); $criteria->addSelectColumn($alias . '.LOGIN'); diff --git a/core/lib/Thelia/Model/Map/ProductTableMap.php b/core/lib/Thelia/Model/Map/ProductTableMap.php index 59ac236ac..273ed7382 100644 --- a/core/lib/Thelia/Model/Map/ProductTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductTableMap.php @@ -202,7 +202,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('TaxRule', '\\Thelia\\Model\\TaxRule', RelationMap::MANY_TO_ONE, array('tax_rule_id' => 'id', ), 'RESTRICT', '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'); diff --git a/core/lib/Thelia/Model/Map/ProfileTableMap.php b/core/lib/Thelia/Model/Map/ProfileTableMap.php index 076da402c..293c662ba 100644 --- a/core/lib/Thelia/Model/Map/ProfileTableMap.php +++ b/core/lib/Thelia/Model/Map/ProfileTableMap.php @@ -160,11 +160,10 @@ class ProfileTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('AdminProfile', '\\Thelia\\Model\\AdminProfile', RelationMap::ONE_TO_MANY, array('id' => 'profile_id', ), 'CASCADE', 'RESTRICT', 'AdminProfiles'); + $this->addRelation('Admin', '\\Thelia\\Model\\Admin', RelationMap::ONE_TO_MANY, array('id' => 'profile_id', ), 'RESTRICT', 'RESTRICT', 'Admins'); $this->addRelation('ProfileResource', '\\Thelia\\Model\\ProfileResource', RelationMap::ONE_TO_MANY, array('id' => 'profile_id', ), 'CASCADE', 'RESTRICT', 'ProfileResources'); $this->addRelation('ProfileModule', '\\Thelia\\Model\\ProfileModule', RelationMap::ONE_TO_MANY, array('id' => 'profile_id', ), 'CASCADE', 'CASCADE', 'ProfileModules'); $this->addRelation('ProfileI18n', '\\Thelia\\Model\\ProfileI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ProfileI18ns'); - $this->addRelation('Admin', '\\Thelia\\Model\\Admin', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Admins'); $this->addRelation('Resource', '\\Thelia\\Model\\Resource', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Resources'); } // buildRelations() @@ -188,7 +187,6 @@ class ProfileTableMap 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. - AdminProfileTableMap::clearInstancePool(); ProfileResourceTableMap::clearInstancePool(); ProfileModuleTableMap::clearInstancePool(); ProfileI18nTableMap::clearInstancePool(); diff --git a/core/lib/Thelia/Model/Map/TaxRuleTableMap.php b/core/lib/Thelia/Model/Map/TaxRuleTableMap.php index ccc41e013..4f1cea73b 100644 --- a/core/lib/Thelia/Model/Map/TaxRuleTableMap.php +++ b/core/lib/Thelia/Model/Map/TaxRuleTableMap.php @@ -160,7 +160,7 @@ class TaxRuleTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::ONE_TO_MANY, array('id' => 'tax_rule_id', ), 'SET NULL', 'RESTRICT', 'Products'); + $this->addRelation('Product', '\\Thelia\\Model\\Product', RelationMap::ONE_TO_MANY, array('id' => 'tax_rule_id', ), 'RESTRICT', 'RESTRICT', 'Products'); $this->addRelation('TaxRuleCountry', '\\Thelia\\Model\\TaxRuleCountry', RelationMap::ONE_TO_MANY, array('id' => 'tax_rule_id', ), 'CASCADE', 'RESTRICT', 'TaxRuleCountries'); $this->addRelation('TaxRuleI18n', '\\Thelia\\Model\\TaxRuleI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'TaxRuleI18ns'); } // buildRelations() @@ -185,7 +185,6 @@ class TaxRuleTableMap 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. - ProductTableMap::clearInstancePool(); TaxRuleCountryTableMap::clearInstancePool(); TaxRuleI18nTableMap::clearInstancePool(); } diff --git a/install/thelia.sql b/install/thelia.sql index b6445e3b1..545e235cd 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -50,7 +50,7 @@ CREATE TABLE `product` FOREIGN KEY (`tax_rule_id`) REFERENCES `tax_rule` (`id`) ON UPDATE RESTRICT - ON DELETE SET NULL, + ON DELETE RESTRICT, CONSTRAINT `fk_product_template` FOREIGN KEY (`template_id`) REFERENCES `template` (`id`) @@ -971,6 +971,7 @@ DROP TABLE IF EXISTS `admin`; CREATE TABLE `admin` ( `id` INTEGER NOT NULL AUTO_INCREMENT, + `profile_id` INTEGER, `firstname` VARCHAR(100) NOT NULL, `lastname` VARCHAR(100) NOT NULL, `login` VARCHAR(100) NOT NULL, @@ -981,35 +982,13 @@ CREATE TABLE `admin` `remember_me_serial` VARCHAR(255), `created_at` DATETIME, `updated_at` DATETIME, - PRIMARY KEY (`id`) -) ENGINE=InnoDB; - --- --------------------------------------------------------------------- --- admin_profile --- --------------------------------------------------------------------- - -DROP TABLE IF EXISTS `admin_profile`; - -CREATE TABLE `admin_profile` -( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `profile_id` INTEGER NOT NULL, - `admin_id` INTEGER NOT NULL, - `created_at` DATETIME, - `updated_at` DATETIME, - PRIMARY KEY (`id`,`profile_id`,`admin_id`), - INDEX `idx_admin_profile_profile_id` (`profile_id`), - INDEX `idx_admin_profile_admin_id` (`admin_id`), - CONSTRAINT `fk_admin_profile_profile_id` + PRIMARY KEY (`id`), + INDEX `fk_admin_profile_id` (`profile_id`), + CONSTRAINT `fk_admin_profile_id` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`) ON UPDATE RESTRICT - ON DELETE CASCADE, - CONSTRAINT `fk_admin_profile_admin_id` - FOREIGN KEY (`admin_id`) - REFERENCES `admin` (`id`) - ON UPDATE RESTRICT - ON DELETE CASCADE + ON DELETE RESTRICT ) ENGINE=InnoDB; -- --------------------------------------------------------------------- diff --git a/local/config/schema.xml b/local/config/schema.xml index 1e4d1ab84..e5ff3b31d 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -755,6 +755,7 @@ + @@ -763,12 +764,11 @@ - - + - +
diff --git a/templates/admin/default/includes/generic-warning-dialog.html b/templates/admin/default/includes/generic-warning-dialog.html new file mode 100755 index 000000000..95157e62f --- /dev/null +++ b/templates/admin/default/includes/generic-warning-dialog.html @@ -0,0 +1,34 @@ +{* + +A generic modal creation dialog template. Parameters + + dialog_id = the dialog id attribute + dialog_title = the dialog title + dialog_body = the dialog body. In most cases, this is a creation form + + dialog_ok_label = The OK button label. Default OK + + ok_button_id (optionnal) = the id of the OK button +*} + diff --git a/templates/admin/default/profile-edit.html b/templates/admin/default/profile-edit.html index 1c6d2e9a8..b2d5fd2a4 100644 --- a/templates/admin/default/profile-edit.html +++ b/templates/admin/default/profile-edit.html @@ -25,6 +25,10 @@
+
+ {$CODE} +
+
@@ -171,6 +173,15 @@ form_action = {url path='/admin/configuration/profiles/delete'} form_content = {$smarty.capture.profile_delete_dialog nofilter} } + +{include + file = "includes/generic-warning-dialog.html" + + dialog_id = "profile_cannot_delete_dialog" + dialog_title = {intl l="You can't delete this profile"} + dialog_body = {intl l="They are some administrator which are linked to this profile. Please edit/remove them before deleting this profile."} +} + {/block} {block name="javascript-initialization"}