diff --git a/composer.json b/composer.json index 30dd5a10d..8617bfe3b 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,9 @@ "symfony/yaml" : "2.2.*", "symfony-cmf/routing": "1.0.0" }, + "require-dev" : { + "fzaninotto/faker": "dev-master" + }, "minimum-stability": "stable", "config" : { "vendor-dir" : "core/vendor", diff --git a/composer.lock b/composer.lock index a266b1c29..4b7adeb60 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,9 @@ { - "hash": "05d2d7252b42f45fd8415a6c47087d97", + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "01f45cf9b2249fce35b127051f36f68d", "packages": [ { "name": "ezyang/htmlpurifier", @@ -762,7 +766,51 @@ } ], "packages-dev": [ - + { + "name": "fzaninotto/faker", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/fzaninotto/Faker.git", + "reference": "a9c1c8b76abe4622b285dcd7aa342cab9dfb6de6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/a9c1c8b76abe4622b285dcd7aa342cab9dfb6de6", + "reference": "a9c1c8b76abe4622b285dcd7aa342cab9dfb6de6", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Faker": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2013-04-23 12:35:55" + } ], "aliases": [ @@ -770,7 +818,8 @@ "minimum-stability": "stable", "stability-flags": { "ezyang/htmlpurifier": 20, - "ircmaxell/password-compat": 20 + "ircmaxell/password-compat": 20, + "fzaninotto/faker": 20 }, "platform": { "php": ">=5.3.7" diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml new file mode 100644 index 000000000..fa309cd2b --- /dev/null +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 2e4304ed5..7fe23edc9 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -12,87 +12,16 @@ - - Symfony\Component\Routing\RequestContext - Thelia\Routing\NullUrlGenerator - Symfony\Cmf\Component\Routing\DynamicRouter - Symfony\Cmf\Component\Routing\ChainRouter - Symfony\Component\Routing\Router - + - - - - - - - - - - - - - - - - - - - - - - - %thelia.core_dir%/Config/Resources/ - - - - - - - - - routing.xml - - %kernel.cache_dir% - %kernel.debug% - - - - - - - - - - - -255 - - - - 0 - - - - - - - - - - - - - - - diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index 95dbfb17b..d40d28a2f 100644 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -1,8 +1,75 @@ - + xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> - - \ No newline at end of file + + Symfony\Component\Routing\RequestContext + Thelia\Routing\NullUrlGenerator + Symfony\Cmf\Component\Routing\DynamicRouter + Symfony\Cmf\Component\Routing\ChainRouter + Symfony\Component\Routing\Router + + + + + + + + + + + + + + + + + + + + + + + + + + %thelia.core_dir%/Config/Resources/routing + + + + + + + + + routing.xml + + %kernel.cache_dir% + %kernel.debug% + + + + + + + + + + + -255 + + + + 0 + + + + + + + + + + \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/admin_routing.xml b/core/lib/Thelia/Config/Resources/routing/admin_routing.xml similarity index 100% rename from core/lib/Thelia/Config/Resources/admin_routing.xml rename to core/lib/Thelia/Config/Resources/routing/admin_routing.xml diff --git a/core/lib/Thelia/Config/Resources/routing/routing.xml b/core/lib/Thelia/Config/Resources/routing/routing.xml new file mode 100644 index 000000000..95dbfb17b --- /dev/null +++ b/core/lib/Thelia/Config/Resources/routing/routing.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 1860af69c..69e3515f5 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -107,6 +107,8 @@ class Thelia extends Kernel $loader = new XmlFileLoader($container, new FileLocator(THELIA_ROOT . "/core/lib/Thelia/Config/Resources")); $loader->load("config.xml"); + $loader->load("routing.xml"); + $loader->load("action.xml"); $modules = \Thelia\Model\ModuleQuery::getActivated(); diff --git a/core/lib/Thelia/Model/AttributeAvDesc.php b/core/lib/Thelia/Model/AttributeAvDesc.php deleted file mode 100644 index a2da9e747..000000000 --- a/core/lib/Thelia/Model/AttributeAvDesc.php +++ /dev/null @@ -1,21 +0,0 @@ -findOneByName($search); - + return $value ? $value->getValue() : $default; } } diff --git a/core/lib/Thelia/Model/ContentDesc.php b/core/lib/Thelia/Model/ContentDesc.php deleted file mode 100644 index 2c3f48a7b..000000000 --- a/core/lib/Thelia/Model/ContentDesc.php +++ /dev/null @@ -1,21 +0,0 @@ -setClassname('Thelia\\Model\\Accessory'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(false); + $this->setIsCrossRef(true); // columns $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('product_id', 'ProductId', 'INTEGER', 'product', 'id', true, null, null); diff --git a/core/lib/Thelia/Model/map/AdminGroupTableMap.php b/core/lib/Thelia/Model/map/AdminGroupTableMap.php index 1898040fe..3304ac244 100644 --- a/core/lib/Thelia/Model/map/AdminGroupTableMap.php +++ b/core/lib/Thelia/Model/map/AdminGroupTableMap.php @@ -41,10 +41,11 @@ class AdminGroupTableMap extends TableMap $this->setClassname('Thelia\\Model\\AdminGroup'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); + $this->setIsCrossRef(true); // columns $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); - $this->addForeignKey('group_id', 'GroupId', 'INTEGER', 'group', 'id', false, null, null); - $this->addForeignKey('admin_id', 'AdminId', 'INTEGER', 'admin', 'id', false, null, null); + $this->addForeignPrimaryKey('group_id', 'GroupId', 'INTEGER' , 'group', '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); // validators diff --git a/core/lib/Thelia/Model/map/AdminTableMap.php b/core/lib/Thelia/Model/map/AdminTableMap.php index 1d679ddda..0ba007494 100644 --- a/core/lib/Thelia/Model/map/AdminTableMap.php +++ b/core/lib/Thelia/Model/map/AdminTableMap.php @@ -60,6 +60,7 @@ class AdminTableMap extends TableMap public function buildRelations() { $this->addRelation('AdminGroup', 'Thelia\\Model\\AdminGroup', RelationMap::ONE_TO_MANY, array('id' => 'admin_id', ), 'CASCADE', 'RESTRICT', 'AdminGroups'); + $this->addRelation('Group', 'Thelia\\Model\\Group', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Groups'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/AttributeCategoryTableMap.php b/core/lib/Thelia/Model/map/AttributeCategoryTableMap.php index 435c7ed14..3d21de5f7 100644 --- a/core/lib/Thelia/Model/map/AttributeCategoryTableMap.php +++ b/core/lib/Thelia/Model/map/AttributeCategoryTableMap.php @@ -41,6 +41,7 @@ class AttributeCategoryTableMap extends TableMap $this->setClassname('Thelia\\Model\\AttributeCategory'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); + $this->setIsCrossRef(true); // columns $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('category_id', 'CategoryId', 'INTEGER', 'category', 'id', true, null, null); diff --git a/core/lib/Thelia/Model/map/AttributeTableMap.php b/core/lib/Thelia/Model/map/AttributeTableMap.php index 78c47d3c7..edd977a3f 100644 --- a/core/lib/Thelia/Model/map/AttributeTableMap.php +++ b/core/lib/Thelia/Model/map/AttributeTableMap.php @@ -58,6 +58,7 @@ class AttributeTableMap extends TableMap $this->addRelation('AttributeCombination', 'Thelia\\Model\\AttributeCombination', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeCombinations'); $this->addRelation('AttributeCategory', 'Thelia\\Model\\AttributeCategory', RelationMap::ONE_TO_MANY, array('id' => 'attribute_id', ), 'CASCADE', 'RESTRICT', 'AttributeCategorys'); $this->addRelation('AttributeI18n', 'Thelia\\Model\\AttributeI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'AttributeI18ns'); + $this->addRelation('Category', 'Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categorys'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/CategoryTableMap.php b/core/lib/Thelia/Model/map/CategoryTableMap.php index 1440f4683..3f2f93bcd 100644 --- a/core/lib/Thelia/Model/map/CategoryTableMap.php +++ b/core/lib/Thelia/Model/map/CategoryTableMap.php @@ -69,6 +69,9 @@ class CategoryTableMap extends TableMap $this->addRelation('Rewriting', 'Thelia\\Model\\Rewriting', RelationMap::ONE_TO_MANY, array('id' => 'category_id', ), 'CASCADE', 'RESTRICT', 'Rewritings'); $this->addRelation('CategoryI18n', 'Thelia\\Model\\CategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CategoryI18ns'); $this->addRelation('CategoryVersion', 'Thelia\\Model\\CategoryVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CategoryVersions'); + $this->addRelation('Product', 'Thelia\\Model\\Product', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Products'); + $this->addRelation('Feature', 'Thelia\\Model\\Feature', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Features'); + $this->addRelation('Attribute', 'Thelia\\Model\\Attribute', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Attributes'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/ContentFolderTableMap.php b/core/lib/Thelia/Model/map/ContentFolderTableMap.php index 9ea3be3c2..00d702e1d 100644 --- a/core/lib/Thelia/Model/map/ContentFolderTableMap.php +++ b/core/lib/Thelia/Model/map/ContentFolderTableMap.php @@ -41,6 +41,7 @@ class ContentFolderTableMap extends TableMap $this->setClassname('Thelia\\Model\\ContentFolder'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(false); + $this->setIsCrossRef(true); // columns $this->addForeignPrimaryKey('content_id', 'ContentId', 'INTEGER' , 'content', 'id', true, null, null); $this->addForeignPrimaryKey('folder_id', 'FolderId', 'INTEGER' , 'folder', 'id', true, null, null); diff --git a/core/lib/Thelia/Model/map/ContentTableMap.php b/core/lib/Thelia/Model/map/ContentTableMap.php index a18f1a4e6..803533d39 100644 --- a/core/lib/Thelia/Model/map/ContentTableMap.php +++ b/core/lib/Thelia/Model/map/ContentTableMap.php @@ -65,6 +65,7 @@ class ContentTableMap extends TableMap $this->addRelation('ContentFolder', 'Thelia\\Model\\ContentFolder', RelationMap::ONE_TO_MANY, array('id' => 'content_id', ), 'CASCADE', 'RESTRICT', 'ContentFolders'); $this->addRelation('ContentI18n', 'Thelia\\Model\\ContentI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ContentI18ns'); $this->addRelation('ContentVersion', 'Thelia\\Model\\ContentVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ContentVersions'); + $this->addRelation('Folder', 'Thelia\\Model\\Folder', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Folders'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/FeatureCategoryTableMap.php b/core/lib/Thelia/Model/map/FeatureCategoryTableMap.php index 63dc296c6..88efccc97 100644 --- a/core/lib/Thelia/Model/map/FeatureCategoryTableMap.php +++ b/core/lib/Thelia/Model/map/FeatureCategoryTableMap.php @@ -41,6 +41,7 @@ class FeatureCategoryTableMap extends TableMap $this->setClassname('Thelia\\Model\\FeatureCategory'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); + $this->setIsCrossRef(true); // columns $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('feature_id', 'FeatureId', 'INTEGER', 'feature', 'id', true, null, null); diff --git a/core/lib/Thelia/Model/map/FeatureTableMap.php b/core/lib/Thelia/Model/map/FeatureTableMap.php index 4790256e8..af23df32e 100644 --- a/core/lib/Thelia/Model/map/FeatureTableMap.php +++ b/core/lib/Thelia/Model/map/FeatureTableMap.php @@ -59,6 +59,7 @@ class FeatureTableMap extends TableMap $this->addRelation('FeatureProd', 'Thelia\\Model\\FeatureProd', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureProds'); $this->addRelation('FeatureCategory', 'Thelia\\Model\\FeatureCategory', RelationMap::ONE_TO_MANY, array('id' => 'feature_id', ), 'CASCADE', 'RESTRICT', 'FeatureCategorys'); $this->addRelation('FeatureI18n', 'Thelia\\Model\\FeatureI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'FeatureI18ns'); + $this->addRelation('Category', 'Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categorys'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/FolderTableMap.php b/core/lib/Thelia/Model/map/FolderTableMap.php index 5345d1715..083d2c77d 100644 --- a/core/lib/Thelia/Model/map/FolderTableMap.php +++ b/core/lib/Thelia/Model/map/FolderTableMap.php @@ -66,6 +66,7 @@ class FolderTableMap extends TableMap $this->addRelation('ContentFolder', 'Thelia\\Model\\ContentFolder', RelationMap::ONE_TO_MANY, array('id' => 'folder_id', ), 'CASCADE', 'RESTRICT', 'ContentFolders'); $this->addRelation('FolderI18n', 'Thelia\\Model\\FolderI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'FolderI18ns'); $this->addRelation('FolderVersion', 'Thelia\\Model\\FolderVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'FolderVersions'); + $this->addRelation('Content', 'Thelia\\Model\\Content', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Contents'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/GroupResourceTableMap.php b/core/lib/Thelia/Model/map/GroupResourceTableMap.php index 87270194e..b434456af 100644 --- a/core/lib/Thelia/Model/map/GroupResourceTableMap.php +++ b/core/lib/Thelia/Model/map/GroupResourceTableMap.php @@ -41,10 +41,11 @@ class GroupResourceTableMap extends TableMap $this->setClassname('Thelia\\Model\\GroupResource'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); + $this->setIsCrossRef(true); // columns $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); - $this->addForeignKey('group_id', 'GroupId', 'INTEGER', 'group', 'id', true, null, null); - $this->addForeignKey('resource_id', 'ResourceId', 'INTEGER', 'resource', 'id', true, null, null); + $this->addForeignPrimaryKey('group_id', 'GroupId', 'INTEGER' , 'group', 'id', true, null, null); + $this->addForeignPrimaryKey('resource_id', 'ResourceId', 'INTEGER' , 'resource', 'id', true, null, null); $this->addColumn('read', 'Read', 'TINYINT', false, null, 0); $this->addColumn('write', 'Write', 'TINYINT', false, null, 0); $this->addColumn('created_at', 'CreatedAt', 'TIMESTAMP', false, null, null); diff --git a/core/lib/Thelia/Model/map/GroupTableMap.php b/core/lib/Thelia/Model/map/GroupTableMap.php index ffe90f241..fa5480a6d 100644 --- a/core/lib/Thelia/Model/map/GroupTableMap.php +++ b/core/lib/Thelia/Model/map/GroupTableMap.php @@ -58,6 +58,8 @@ class GroupTableMap extends TableMap $this->addRelation('GroupResource', 'Thelia\\Model\\GroupResource', RelationMap::ONE_TO_MANY, array('id' => 'group_id', ), 'CASCADE', 'RESTRICT', 'GroupResources'); $this->addRelation('GroupModule', 'Thelia\\Model\\GroupModule', RelationMap::ONE_TO_MANY, array('id' => 'group_id', ), 'CASCADE', 'CASCADE', 'GroupModules'); $this->addRelation('GroupI18n', 'Thelia\\Model\\GroupI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'GroupI18ns'); + $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() /** diff --git a/core/lib/Thelia/Model/map/ProductCategoryTableMap.php b/core/lib/Thelia/Model/map/ProductCategoryTableMap.php index f6234eb51..59c67b32b 100644 --- a/core/lib/Thelia/Model/map/ProductCategoryTableMap.php +++ b/core/lib/Thelia/Model/map/ProductCategoryTableMap.php @@ -41,6 +41,7 @@ class ProductCategoryTableMap extends TableMap $this->setClassname('Thelia\\Model\\ProductCategory'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(false); + $this->setIsCrossRef(true); // columns $this->addForeignPrimaryKey('product_id', 'ProductId', 'INTEGER' , 'product', 'id', true, null, null); $this->addForeignPrimaryKey('category_id', 'CategoryId', 'INTEGER' , 'category', 'id', true, null, null); diff --git a/core/lib/Thelia/Model/map/ProductTableMap.php b/core/lib/Thelia/Model/map/ProductTableMap.php index 382c72f1f..dce837c5b 100644 --- a/core/lib/Thelia/Model/map/ProductTableMap.php +++ b/core/lib/Thelia/Model/map/ProductTableMap.php @@ -79,6 +79,9 @@ class ProductTableMap extends TableMap $this->addRelation('Rewriting', 'Thelia\\Model\\Rewriting', RelationMap::ONE_TO_MANY, array('id' => 'product_id', ), 'CASCADE', 'RESTRICT', 'Rewritings'); $this->addRelation('ProductI18n', 'Thelia\\Model\\ProductI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ProductI18ns'); $this->addRelation('ProductVersion', 'Thelia\\Model\\ProductVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ProductVersions'); + $this->addRelation('Category', 'Thelia\\Model\\Category', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Categorys'); + $this->addRelation('ProductRelatedByAccessory', 'Thelia\\Model\\Product', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'ProductsRelatedByAccessory'); + $this->addRelation('ProductRelatedByProductId', 'Thelia\\Model\\Product', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'ProductsRelatedByProductId'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/map/ResourceTableMap.php b/core/lib/Thelia/Model/map/ResourceTableMap.php index b42065c43..30c99ffc3 100644 --- a/core/lib/Thelia/Model/map/ResourceTableMap.php +++ b/core/lib/Thelia/Model/map/ResourceTableMap.php @@ -56,6 +56,7 @@ class ResourceTableMap extends TableMap { $this->addRelation('GroupResource', 'Thelia\\Model\\GroupResource', RelationMap::ONE_TO_MANY, array('id' => 'resource_id', ), 'CASCADE', 'RESTRICT', 'GroupResources'); $this->addRelation('ResourceI18n', 'Thelia\\Model\\ResourceI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ResourceI18ns'); + $this->addRelation('Group', 'Thelia\\Model\\Group', RelationMap::MANY_TO_MANY, array(), 'CASCADE', 'RESTRICT', 'Groups'); } // buildRelations() /** diff --git a/core/lib/Thelia/Model/om/BaseAdmin.php b/core/lib/Thelia/Model/om/BaseAdmin.php index d1613291f..5bf15b3ff 100644 --- a/core/lib/Thelia/Model/om/BaseAdmin.php +++ b/core/lib/Thelia/Model/om/BaseAdmin.php @@ -20,6 +20,8 @@ use Thelia\Model\AdminGroup; use Thelia\Model\AdminGroupQuery; use Thelia\Model\AdminPeer; use Thelia\Model\AdminQuery; +use Thelia\Model\Group; +use Thelia\Model\GroupQuery; /** * Base class that represents a row from the 'admin' table. @@ -109,6 +111,11 @@ abstract class BaseAdmin extends BaseObject implements Persistent protected $collAdminGroups; protected $collAdminGroupsPartial; + /** + * @var PropelObjectCollection|Group[] Collection to store aggregation of Group objects. + */ + protected $collGroups; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -129,6 +136,12 @@ abstract class BaseAdmin extends BaseObject implements Persistent */ protected $alreadyInClearAllReferencesDeep = false; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $groupsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -591,6 +604,7 @@ abstract class BaseAdmin extends BaseObject implements Persistent $this->collAdminGroups = null; + $this->collGroups = null; } // if (deep) } @@ -726,12 +740,37 @@ abstract class BaseAdmin extends BaseObject implements Persistent $this->resetModified(); } + if ($this->groupsScheduledForDeletion !== null) { + if (!$this->groupsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->groupsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + AdminGroupQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->groupsScheduledForDeletion = null; + } + + foreach ($this->getGroups() as $group) { + if ($group->isModified()) { + $group->save($con); + } + } + } elseif ($this->collGroups) { + foreach ($this->collGroups as $group) { + if ($group->isModified()) { + $group->save($con); + } + } + } + if ($this->adminGroupsScheduledForDeletion !== null) { if (!$this->adminGroupsScheduledForDeletion->isEmpty()) { - foreach ($this->adminGroupsScheduledForDeletion as $adminGroup) { - // need to save related object because we set the relation to null - $adminGroup->save($con); - } + AdminGroupQuery::create() + ->filterByPrimaryKeys($this->adminGroupsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); $this->adminGroupsScheduledForDeletion = null; } } @@ -1523,7 +1562,7 @@ abstract class BaseAdmin extends BaseObject implements Persistent $this->adminGroupsScheduledForDeletion = clone $this->collAdminGroups; $this->adminGroupsScheduledForDeletion->clear(); } - $this->adminGroupsScheduledForDeletion[]= $adminGroup; + $this->adminGroupsScheduledForDeletion[]= clone $adminGroup; $adminGroup->setAdmin(null); } @@ -1555,6 +1594,183 @@ abstract class BaseAdmin extends BaseObject implements Persistent return $this->getAdminGroups($query, $con); } + /** + * Clears out the collGroups 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 Admin The current object (for fluent API support) + * @see addGroups() + */ + public function clearGroups() + { + $this->collGroups = null; // important to set this to null since that means it is uninitialized + $this->collGroupsPartial = null; + + return $this; + } + + /** + * Initializes the collGroups collection. + * + * By default this just sets the collGroups collection to an empty collection (like clearGroups()); + * 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 initGroups() + { + $this->collGroups = new PropelObjectCollection(); + $this->collGroups->setModel('Group'); + } + + /** + * Gets a collection of Group objects related by a many-to-many relationship + * to the current object by way of the admin_group 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 Admin 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Group[] List of Group objects + */ + public function getGroups($criteria = null, PropelPDO $con = null) + { + if (null === $this->collGroups || null !== $criteria) { + if ($this->isNew() && null === $this->collGroups) { + // return empty collection + $this->initGroups(); + } else { + $collGroups = GroupQuery::create(null, $criteria) + ->filterByAdmin($this) + ->find($con); + if (null !== $criteria) { + return $collGroups; + } + $this->collGroups = $collGroups; + } + } + + return $this->collGroups; + } + + /** + * Sets a collection of Group objects related by a many-to-many relationship + * to the current object by way of the admin_group 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 PropelCollection $groups A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Admin The current object (for fluent API support) + */ + public function setGroups(PropelCollection $groups, PropelPDO $con = null) + { + $this->clearGroups(); + $currentGroups = $this->getGroups(); + + $this->groupsScheduledForDeletion = $currentGroups->diff($groups); + + foreach ($groups as $group) { + if (!$currentGroups->contains($group)) { + $this->doAddGroup($group); + } + } + + $this->collGroups = $groups; + + return $this; + } + + /** + * Gets the number of Group objects related by a many-to-many relationship + * to the current object by way of the admin_group cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Group objects + */ + public function countGroups($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collGroups || null !== $criteria) { + if ($this->isNew() && null === $this->collGroups) { + return 0; + } else { + $query = GroupQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByAdmin($this) + ->count($con); + } + } else { + return count($this->collGroups); + } + } + + /** + * Associate a Group object to this object + * through the admin_group cross reference table. + * + * @param Group $group The AdminGroup object to relate + * @return Admin The current object (for fluent API support) + */ + public function addGroup(Group $group) + { + if ($this->collGroups === null) { + $this->initGroups(); + } + if (!$this->collGroups->contains($group)) { // only add it if the **same** object is not already associated + $this->doAddGroup($group); + + $this->collGroups[]= $group; + } + + return $this; + } + + /** + * @param Group $group The group object to add. + */ + protected function doAddGroup($group) + { + $adminGroup = new AdminGroup(); + $adminGroup->setGroup($group); + $this->addAdminGroup($adminGroup); + } + + /** + * Remove a Group object to this object + * through the admin_group cross reference table. + * + * @param Group $group The AdminGroup object to relate + * @return Admin The current object (for fluent API support) + */ + public function removeGroup(Group $group) + { + if ($this->getGroups()->contains($group)) { + $this->collGroups->remove($this->collGroups->search($group)); + if (null === $this->groupsScheduledForDeletion) { + $this->groupsScheduledForDeletion = clone $this->collGroups; + $this->groupsScheduledForDeletion->clear(); + } + $this->groupsScheduledForDeletion[]= $group; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -1596,6 +1812,11 @@ abstract class BaseAdmin extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collGroups) { + foreach ($this->collGroups as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -1604,6 +1825,10 @@ abstract class BaseAdmin extends BaseObject implements Persistent $this->collAdminGroups->clearIterator(); } $this->collAdminGroups = null; + if ($this->collGroups instanceof PropelCollection) { + $this->collGroups->clearIterator(); + } + $this->collGroups = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseAdminGroup.php b/core/lib/Thelia/Model/om/BaseAdminGroup.php index a20e693a8..98b15fc14 100644 --- a/core/lib/Thelia/Model/om/BaseAdminGroup.php +++ b/core/lib/Thelia/Model/om/BaseAdminGroup.php @@ -862,10 +862,10 @@ abstract class BaseAdminGroup extends BaseObject implements Persistent */ public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['AdminGroup'][$this->getPrimaryKey()])) { + if (isset($alreadyDumpedObjects['AdminGroup'][serialize($this->getPrimaryKey())])) { return '*RECURSION*'; } - $alreadyDumpedObjects['AdminGroup'][$this->getPrimaryKey()] = true; + $alreadyDumpedObjects['AdminGroup'][serialize($this->getPrimaryKey())] = true; $keys = AdminGroupPeer::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), @@ -991,28 +991,38 @@ abstract class BaseAdminGroup extends BaseObject implements Persistent { $criteria = new Criteria(AdminGroupPeer::DATABASE_NAME); $criteria->add(AdminGroupPeer::ID, $this->id); + $criteria->add(AdminGroupPeer::GROUP_ID, $this->group_id); + $criteria->add(AdminGroupPeer::ADMIN_ID, $this->admin_id); return $criteria; } /** - * Returns the primary key for this object (row). - * @return int + * 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() { - return $this->getId(); + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getGroupId(); + $pks[2] = $this->getAdminId(); + + return $pks; } /** - * Generic method to set the primary key (id column). + * Set the [composite] primary key. * - * @param int $key Primary key. + * @param array $keys The elements of the composite key (order must match the order in XML file). * @return void */ - public function setPrimaryKey($key) + public function setPrimaryKey($keys) { - $this->setId($key); + $this->setId($keys[0]); + $this->setGroupId($keys[1]); + $this->setAdminId($keys[2]); } /** @@ -1022,7 +1032,7 @@ abstract class BaseAdminGroup extends BaseObject implements Persistent public function isPrimaryKeyNull() { - return null === $this->getId(); + return (null === $this->getId()) && (null === $this->getGroupId()) && (null === $this->getAdminId()); } /** diff --git a/core/lib/Thelia/Model/om/BaseAdminGroupPeer.php b/core/lib/Thelia/Model/om/BaseAdminGroupPeer.php index 26c18eb8c..42819d8f3 100644 --- a/core/lib/Thelia/Model/om/BaseAdminGroupPeer.php +++ b/core/lib/Thelia/Model/om/BaseAdminGroupPeer.php @@ -311,7 +311,7 @@ abstract class BaseAdminGroupPeer { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { - $key = (string) $obj->getId(); + $key = serialize(array((string) $obj->getId(), (string) $obj->getGroupId(), (string) $obj->getAdminId())); } // if key === null AdminGroupPeer::$instances[$key] = $obj; } @@ -334,10 +334,10 @@ abstract class BaseAdminGroupPeer { if (Propel::isInstancePoolingEnabled() && $value !== null) { if (is_object($value) && $value instanceof AdminGroup) { - $key = (string) $value->getId(); - } elseif (is_scalar($value)) { + $key = serialize(array((string) $value->getId(), (string) $value->getGroupId(), (string) $value->getAdminId())); + } elseif (is_array($value) && count($value) === 3) { // assume we've been passed a primary key - $key = (string) $value; + $key = serialize(array((string) $value[0], (string) $value[1], (string) $value[2])); } else { $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or AdminGroup object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true))); throw $e; @@ -406,11 +406,11 @@ abstract class BaseAdminGroupPeer public static function getPrimaryKeyHashFromRow($row, $startcol = 0) { // If the PK cannot be derived from the row, return null. - if ($row[$startcol] === null) { + if ($row[$startcol] === null && $row[$startcol + 1] === null && $row[$startcol + 2] === null) { return null; } - return (string) $row[$startcol]; + return serialize(array((string) $row[$startcol], (string) $row[$startcol + 1], (string) $row[$startcol + 2])); } /** @@ -425,7 +425,7 @@ abstract class BaseAdminGroupPeer public static function getPrimaryKeyFromRow($row, $startcol = 0) { - return (int) $row[$startcol]; + return array((int) $row[$startcol], (int) $row[$startcol + 1], (int) $row[$startcol + 2]); } /** @@ -1223,6 +1223,22 @@ abstract class BaseAdminGroupPeer $selectCriteria->setPrimaryTableName(AdminGroupPeer::TABLE_NAME); } + $comparison = $criteria->getComparison(AdminGroupPeer::GROUP_ID); + $value = $criteria->remove(AdminGroupPeer::GROUP_ID); + if ($value) { + $selectCriteria->add(AdminGroupPeer::GROUP_ID, $value, $comparison); + } else { + $selectCriteria->setPrimaryTableName(AdminGroupPeer::TABLE_NAME); + } + + $comparison = $criteria->getComparison(AdminGroupPeer::ADMIN_ID); + $value = $criteria->remove(AdminGroupPeer::ADMIN_ID); + if ($value) { + $selectCriteria->add(AdminGroupPeer::ADMIN_ID, $value, $comparison); + } else { + $selectCriteria->setPrimaryTableName(AdminGroupPeer::TABLE_NAME); + } + } else { // $values is AdminGroup object $criteria = $values->buildCriteria(); // gets full criteria $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s) @@ -1297,10 +1313,19 @@ abstract class BaseAdminGroupPeer $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(AdminGroupPeer::DATABASE_NAME); - $criteria->add(AdminGroupPeer::ID, (array) $values, Criteria::IN); - // invalidate the cache for this object(s) - foreach ((array) $values as $singleval) { - AdminGroupPeer::removeInstanceFromPool($singleval); + // 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(AdminGroupPeer::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(AdminGroupPeer::GROUP_ID, $value[1])); + $criterion->addAnd($criteria->getNewCriterion(AdminGroupPeer::ADMIN_ID, $value[2])); + $criteria->addOr($criterion); + // we can invalidate the cache for this single PK + AdminGroupPeer::removeInstanceFromPool($value); } } @@ -1363,58 +1388,30 @@ abstract class BaseAdminGroupPeer } /** - * Retrieve a single object by pkey. - * - * @param int $pk the primary key. - * @param PropelPDO $con the connection to use - * @return AdminGroup + * Retrieve object using using composite pkey values. + * @param int $id + * @param int $group_id + * @param int $admin_id + * @param PropelPDO $con + * @return AdminGroup */ - public static function retrieveByPK($pk, PropelPDO $con = null) - { - - if (null !== ($obj = AdminGroupPeer::getInstanceFromPool((string) $pk))) { - return $obj; + public static function retrieveByPK($id, $group_id, $admin_id, PropelPDO $con = null) { + $_instancePoolKey = serialize(array((string) $id, (string) $group_id, (string) $admin_id)); + if (null !== ($obj = AdminGroupPeer::getInstanceFromPool($_instancePoolKey))) { + return $obj; } if ($con === null) { $con = Propel::getConnection(AdminGroupPeer::DATABASE_NAME, Propel::CONNECTION_READ); } - $criteria = new Criteria(AdminGroupPeer::DATABASE_NAME); - $criteria->add(AdminGroupPeer::ID, $pk); - + $criteria->add(AdminGroupPeer::ID, $id); + $criteria->add(AdminGroupPeer::GROUP_ID, $group_id); + $criteria->add(AdminGroupPeer::ADMIN_ID, $admin_id); $v = AdminGroupPeer::doSelect($criteria, $con); - return !empty($v) > 0 ? $v[0] : null; + return !empty($v) ? $v[0] : null; } - - /** - * Retrieve multiple objects by pkey. - * - * @param array $pks List of primary keys - * @param PropelPDO $con the connection to use - * @return AdminGroup[] - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function retrieveByPKs($pks, PropelPDO $con = null) - { - if ($con === null) { - $con = Propel::getConnection(AdminGroupPeer::DATABASE_NAME, Propel::CONNECTION_READ); - } - - $objs = null; - if (empty($pks)) { - $objs = array(); - } else { - $criteria = new Criteria(AdminGroupPeer::DATABASE_NAME); - $criteria->add(AdminGroupPeer::ID, $pks, Criteria::IN); - $objs = AdminGroupPeer::doSelect($criteria, $con); - } - - return $objs; - } - } // BaseAdminGroupPeer // This is the static code needed to register the TableMap for this table with the main Propel class. diff --git a/core/lib/Thelia/Model/om/BaseAdminGroupQuery.php b/core/lib/Thelia/Model/om/BaseAdminGroupQuery.php index 1f9695bf7..fa37ae6f6 100644 --- a/core/lib/Thelia/Model/om/BaseAdminGroupQuery.php +++ b/core/lib/Thelia/Model/om/BaseAdminGroupQuery.php @@ -50,6 +50,7 @@ use Thelia\Model\Group; * @method AdminGroup findOne(PropelPDO $con = null) Return the first AdminGroup matching the query * @method AdminGroup findOneOrCreate(PropelPDO $con = null) Return the first AdminGroup matching the query, or a new AdminGroup object populated from the query conditions when no match is found * + * @method AdminGroup findOneById(int $id) Return the first AdminGroup filtered by the id column * @method AdminGroup findOneByGroupId(int $group_id) Return the first AdminGroup filtered by the group_id column * @method AdminGroup findOneByAdminId(int $admin_id) Return the first AdminGroup filtered by the admin_id column * @method AdminGroup findOneByCreatedAt(string $created_at) Return the first AdminGroup filtered by the created_at column @@ -107,10 +108,11 @@ abstract class BaseAdminGroupQuery extends ModelCriteria * Go fast if the query is untouched. * * - * $obj = $c->findPk(12, $con); + * $obj = $c->findPk(array(12, 34, 56), $con); * * - * @param mixed $key Primary key to use for the query + * @param array $key Primary key to use for the query + A Primary key composition: [$id, $group_id, $admin_id] * @param PropelPDO $con an optional connection object * * @return AdminGroup|AdminGroup[]|mixed the result, formatted by the current formatter @@ -120,7 +122,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria if ($key === null) { return null; } - if ((null !== ($obj = AdminGroupPeer::getInstanceFromPool((string) $key))) && !$this->formatter) { + if ((null !== ($obj = AdminGroupPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))))) && !$this->formatter) { // the object is alredy in the instance pool return $obj; } @@ -137,20 +139,6 @@ abstract class BaseAdminGroupQuery extends ModelCriteria } } - /** - * Alias of findPk to use instance pooling - * - * @param mixed $key Primary key to use for the query - * @param PropelPDO $con A connection object - * - * @return AdminGroup A model object, or null if the key is not found - * @throws PropelException - */ - public function findOneById($key, $con = null) - { - return $this->findPk($key, $con); - } - /** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. @@ -163,10 +151,12 @@ abstract class BaseAdminGroupQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `id`, `group_id`, `admin_id`, `created_at`, `updated_at` FROM `admin_group` WHERE `id` = :p0'; + $sql = 'SELECT `id`, `group_id`, `admin_id`, `created_at`, `updated_at` FROM `admin_group` WHERE `id` = :p0 AND `group_id` = :p1 AND `admin_id` = :p2'; try { $stmt = $con->prepare($sql); - $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $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); @@ -176,7 +166,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new AdminGroup(); $obj->hydrate($row); - AdminGroupPeer::addInstanceToPool($obj, (string) $key); + AdminGroupPeer::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))); } $stmt->closeCursor(); @@ -205,7 +195,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria /** * Find objects by primary key * - * $objs = $c->findPks(array(12, 56, 832), $con); + * $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 PropelPDO $con an optional connection object @@ -235,8 +225,11 @@ abstract class BaseAdminGroupQuery extends ModelCriteria */ public function filterByPrimaryKey($key) { + $this->addUsingAlias(AdminGroupPeer::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(AdminGroupPeer::GROUP_ID, $key[1], Criteria::EQUAL); + $this->addUsingAlias(AdminGroupPeer::ADMIN_ID, $key[2], Criteria::EQUAL); - return $this->addUsingAlias(AdminGroupPeer::ID, $key, Criteria::EQUAL); + return $this; } /** @@ -248,8 +241,19 @@ abstract class BaseAdminGroupQuery extends ModelCriteria */ public function filterByPrimaryKeys($keys) { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(AdminGroupPeer::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(AdminGroupPeer::GROUP_ID, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $cton2 = $this->getNewCriterion(AdminGroupPeer::ADMIN_ID, $key[2], Criteria::EQUAL); + $cton0->addAnd($cton2); + $this->addOr($cton0); + } - return $this->addUsingAlias(AdminGroupPeer::ID, $keys, Criteria::IN); + return $this; } /** @@ -502,7 +506,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria * * @return AdminGroupQuery The current query, for fluid interface */ - public function joinGroup($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinGroup($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('Group'); @@ -537,7 +541,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria * * @return \Thelia\Model\GroupQuery A secondary query class using the current class as primary query */ - public function useGroupQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useGroupQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinGroup($relationAlias, $joinType) @@ -578,7 +582,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria * * @return AdminGroupQuery The current query, for fluid interface */ - public function joinAdmin($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinAdmin($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('Admin'); @@ -613,7 +617,7 @@ abstract class BaseAdminGroupQuery extends ModelCriteria * * @return \Thelia\Model\AdminQuery A secondary query class using the current class as primary query */ - public function useAdminQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useAdminQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinAdmin($relationAlias, $joinType) @@ -630,7 +634,10 @@ abstract class BaseAdminGroupQuery extends ModelCriteria public function prune($adminGroup = null) { if ($adminGroup) { - $this->addUsingAlias(AdminGroupPeer::ID, $adminGroup->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond0', $this->getAliasedColName(AdminGroupPeer::ID), $adminGroup->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(AdminGroupPeer::GROUP_ID), $adminGroup->getGroupId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond2', $this->getAliasedColName(AdminGroupPeer::ADMIN_ID), $adminGroup->getAdminId(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1', 'pruneCond2'), Criteria::LOGICAL_OR); } return $this; diff --git a/core/lib/Thelia/Model/om/BaseAdminQuery.php b/core/lib/Thelia/Model/om/BaseAdminQuery.php index 7c04fc880..9cce7e496 100644 --- a/core/lib/Thelia/Model/om/BaseAdminQuery.php +++ b/core/lib/Thelia/Model/om/BaseAdminQuery.php @@ -16,6 +16,7 @@ use Thelia\Model\Admin; use Thelia\Model\AdminGroup; use Thelia\Model\AdminPeer; use Thelia\Model\AdminQuery; +use Thelia\Model\Group; /** * Base class that represents a query for the 'admin' table. @@ -597,7 +598,7 @@ abstract class BaseAdminQuery extends ModelCriteria * * @return AdminQuery The current query, for fluid interface */ - public function joinAdminGroup($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinAdminGroup($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('AdminGroup'); @@ -632,13 +633,30 @@ abstract class BaseAdminQuery extends ModelCriteria * * @return \Thelia\Model\AdminGroupQuery A secondary query class using the current class as primary query */ - public function useAdminGroupQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useAdminGroupQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinAdminGroup($relationAlias, $joinType) ->useQuery($relationAlias ? $relationAlias : 'AdminGroup', '\Thelia\Model\AdminGroupQuery'); } + /** + * Filter the query by a related Group object + * using the admin_group table as cross reference + * + * @param Group $group the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return AdminQuery The current query, for fluid interface + */ + public function filterByGroup($group, $comparison = Criteria::EQUAL) + { + return $this + ->useAdminGroupQuery() + ->filterByGroup($group, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseAttribute.php b/core/lib/Thelia/Model/om/BaseAttribute.php index 436edd53d..9deb6fe5e 100644 --- a/core/lib/Thelia/Model/om/BaseAttribute.php +++ b/core/lib/Thelia/Model/om/BaseAttribute.php @@ -26,6 +26,8 @@ use Thelia\Model\AttributeI18n; use Thelia\Model\AttributeI18nQuery; use Thelia\Model\AttributePeer; use Thelia\Model\AttributeQuery; +use Thelia\Model\Category; +use Thelia\Model\CategoryQuery; /** * Base class that represents a row from the 'attribute' table. @@ -103,6 +105,11 @@ abstract class BaseAttribute extends BaseObject implements Persistent protected $collAttributeI18ns; protected $collAttributeI18nsPartial; + /** + * @var PropelObjectCollection|Category[] Collection to store aggregation of Category objects. + */ + protected $collCategorys; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -137,6 +144,12 @@ abstract class BaseAttribute extends BaseObject implements Persistent */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $categorysScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -463,6 +476,7 @@ abstract class BaseAttribute extends BaseObject implements Persistent $this->collAttributeI18ns = null; + $this->collCategorys = null; } // if (deep) } @@ -598,6 +612,32 @@ abstract class BaseAttribute extends BaseObject implements Persistent $this->resetModified(); } + if ($this->categorysScheduledForDeletion !== null) { + if (!$this->categorysScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->categorysScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + AttributeCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->categorysScheduledForDeletion = null; + } + + foreach ($this->getCategorys() as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } elseif ($this->collCategorys) { + foreach ($this->collCategorys as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } + if ($this->attributeAvsScheduledForDeletion !== null) { if (!$this->attributeAvsScheduledForDeletion->isEmpty()) { AttributeAvQuery::create() @@ -2165,6 +2205,183 @@ abstract class BaseAttribute extends BaseObject implements Persistent return $this; } + /** + * Clears out the collCategorys 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 Attribute The current object (for fluent API support) + * @see addCategorys() + */ + public function clearCategorys() + { + $this->collCategorys = null; // important to set this to null since that means it is uninitialized + $this->collCategorysPartial = null; + + return $this; + } + + /** + * Initializes the collCategorys collection. + * + * By default this just sets the collCategorys collection to an empty collection (like clearCategorys()); + * 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 initCategorys() + { + $this->collCategorys = new PropelObjectCollection(); + $this->collCategorys->setModel('Category'); + } + + /** + * Gets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * + * 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 Attribute 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Category[] List of Category objects + */ + public function getCategorys($criteria = null, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + // return empty collection + $this->initCategorys(); + } else { + $collCategorys = CategoryQuery::create(null, $criteria) + ->filterByAttribute($this) + ->find($con); + if (null !== $criteria) { + return $collCategorys; + } + $this->collCategorys = $collCategorys; + } + } + + return $this->collCategorys; + } + + /** + * Sets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * 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 PropelCollection $categorys A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Attribute The current object (for fluent API support) + */ + public function setCategorys(PropelCollection $categorys, PropelPDO $con = null) + { + $this->clearCategorys(); + $currentCategorys = $this->getCategorys(); + + $this->categorysScheduledForDeletion = $currentCategorys->diff($categorys); + + foreach ($categorys as $category) { + if (!$currentCategorys->contains($category)) { + $this->doAddCategory($category); + } + } + + $this->collCategorys = $categorys; + + return $this; + } + + /** + * Gets the number of Category objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Category objects + */ + public function countCategorys($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + return 0; + } else { + $query = CategoryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByAttribute($this) + ->count($con); + } + } else { + return count($this->collCategorys); + } + } + + /** + * Associate a Category object to this object + * through the attribute_category cross reference table. + * + * @param Category $category The AttributeCategory object to relate + * @return Attribute The current object (for fluent API support) + */ + public function addCategory(Category $category) + { + if ($this->collCategorys === null) { + $this->initCategorys(); + } + if (!$this->collCategorys->contains($category)) { // only add it if the **same** object is not already associated + $this->doAddCategory($category); + + $this->collCategorys[]= $category; + } + + return $this; + } + + /** + * @param Category $category The category object to add. + */ + protected function doAddCategory($category) + { + $attributeCategory = new AttributeCategory(); + $attributeCategory->setCategory($category); + $this->addAttributeCategory($attributeCategory); + } + + /** + * Remove a Category object to this object + * through the attribute_category cross reference table. + * + * @param Category $category The AttributeCategory object to relate + * @return Attribute The current object (for fluent API support) + */ + public function removeCategory(Category $category) + { + if ($this->getCategorys()->contains($category)) { + $this->collCategorys->remove($this->collCategorys->search($category)); + if (null === $this->categorysScheduledForDeletion) { + $this->categorysScheduledForDeletion = clone $this->collCategorys; + $this->categorysScheduledForDeletion->clear(); + } + $this->categorysScheduledForDeletion[]= $category; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2216,6 +2433,11 @@ abstract class BaseAttribute extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collCategorys) { + foreach ($this->collCategorys as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -2240,6 +2462,10 @@ abstract class BaseAttribute extends BaseObject implements Persistent $this->collAttributeI18ns->clearIterator(); } $this->collAttributeI18ns = null; + if ($this->collCategorys instanceof PropelCollection) { + $this->collCategorys->clearIterator(); + } + $this->collCategorys = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseAttributeQuery.php b/core/lib/Thelia/Model/om/BaseAttributeQuery.php index a3bbab373..50ffbe964 100644 --- a/core/lib/Thelia/Model/om/BaseAttributeQuery.php +++ b/core/lib/Thelia/Model/om/BaseAttributeQuery.php @@ -19,6 +19,7 @@ use Thelia\Model\AttributeCombination; use Thelia\Model\AttributeI18n; use Thelia\Model\AttributePeer; use Thelia\Model\AttributeQuery; +use Thelia\Model\Category; /** * Base class that represents a query for the 'attribute' table. @@ -724,6 +725,23 @@ abstract class BaseAttributeQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'AttributeI18n', '\Thelia\Model\AttributeI18nQuery'); } + /** + * Filter the query by a related Category object + * using the attribute_category table as cross reference + * + * @param Category $category the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return AttributeQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = Criteria::EQUAL) + { + return $this + ->useAttributeCategoryQuery() + ->filterByCategory($category, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseCategory.php b/core/lib/Thelia/Model/om/BaseCategory.php index 468766eea..f28b3b513 100644 --- a/core/lib/Thelia/Model/om/BaseCategory.php +++ b/core/lib/Thelia/Model/om/BaseCategory.php @@ -15,8 +15,10 @@ use \PropelDateTime; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Attribute; use Thelia\Model\AttributeCategory; use Thelia\Model\AttributeCategoryQuery; +use Thelia\Model\AttributeQuery; use Thelia\Model\Category; use Thelia\Model\CategoryI18n; use Thelia\Model\CategoryI18nQuery; @@ -29,12 +31,16 @@ use Thelia\Model\ContentAssoc; use Thelia\Model\ContentAssocQuery; use Thelia\Model\Document; use Thelia\Model\DocumentQuery; +use Thelia\Model\Feature; use Thelia\Model\FeatureCategory; use Thelia\Model\FeatureCategoryQuery; +use Thelia\Model\FeatureQuery; use Thelia\Model\Image; use Thelia\Model\ImageQuery; +use Thelia\Model\Product; use Thelia\Model\ProductCategory; use Thelia\Model\ProductCategoryQuery; +use Thelia\Model\ProductQuery; use Thelia\Model\Rewriting; use Thelia\Model\RewritingQuery; @@ -181,6 +187,21 @@ abstract class BaseCategory extends BaseObject implements Persistent protected $collCategoryVersions; protected $collCategoryVersionsPartial; + /** + * @var PropelObjectCollection|Product[] Collection to store aggregation of Product objects. + */ + protected $collProducts; + + /** + * @var PropelObjectCollection|Feature[] Collection to store aggregation of Feature objects. + */ + protected $collFeatures; + + /** + * @var PropelObjectCollection|Attribute[] Collection to store aggregation of Attribute objects. + */ + protected $collAttributes; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -223,6 +244,24 @@ abstract class BaseCategory extends BaseObject implements Persistent */ protected $enforceVersion = false; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $productsScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $featuresScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $attributesScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -838,6 +877,9 @@ abstract class BaseCategory extends BaseObject implements Persistent $this->collCategoryVersions = null; + $this->collProducts = null; + $this->collFeatures = null; + $this->collAttributes = null; } // if (deep) } @@ -985,6 +1027,84 @@ abstract class BaseCategory extends BaseObject implements Persistent $this->resetModified(); } + if ($this->productsScheduledForDeletion !== null) { + if (!$this->productsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->productsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + ProductCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->productsScheduledForDeletion = null; + } + + foreach ($this->getProducts() as $product) { + if ($product->isModified()) { + $product->save($con); + } + } + } elseif ($this->collProducts) { + foreach ($this->collProducts as $product) { + if ($product->isModified()) { + $product->save($con); + } + } + } + + if ($this->featuresScheduledForDeletion !== null) { + if (!$this->featuresScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->featuresScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + FeatureCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->featuresScheduledForDeletion = null; + } + + foreach ($this->getFeatures() as $feature) { + if ($feature->isModified()) { + $feature->save($con); + } + } + } elseif ($this->collFeatures) { + foreach ($this->collFeatures as $feature) { + if ($feature->isModified()) { + $feature->save($con); + } + } + } + + if ($this->attributesScheduledForDeletion !== null) { + if (!$this->attributesScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->attributesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + AttributeCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->attributesScheduledForDeletion = null; + } + + foreach ($this->getAttributes() as $attribute) { + if ($attribute->isModified()) { + $attribute->save($con); + } + } + } elseif ($this->collAttributes) { + foreach ($this->collAttributes as $attribute) { + if ($attribute->isModified()) { + $attribute->save($con); + } + } + } + if ($this->productCategorysScheduledForDeletion !== null) { if (!$this->productCategorysScheduledForDeletion->isEmpty()) { ProductCategoryQuery::create() @@ -4202,6 +4322,537 @@ abstract class BaseCategory extends BaseObject implements Persistent return $this; } + /** + * Clears out the collProducts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return Category The current object (for fluent API support) + * @see addProducts() + */ + public function clearProducts() + { + $this->collProducts = null; // important to set this to null since that means it is uninitialized + $this->collProductsPartial = null; + + return $this; + } + + /** + * Initializes the collProducts collection. + * + * By default this just sets the collProducts collection to an empty collection (like clearProducts()); + * 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 initProducts() + { + $this->collProducts = new PropelObjectCollection(); + $this->collProducts->setModel('Product'); + } + + /** + * Gets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this Category 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Product[] List of Product objects + */ + public function getProducts($criteria = null, PropelPDO $con = null) + { + if (null === $this->collProducts || null !== $criteria) { + if ($this->isNew() && null === $this->collProducts) { + // return empty collection + $this->initProducts(); + } else { + $collProducts = ProductQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + if (null !== $criteria) { + return $collProducts; + } + $this->collProducts = $collProducts; + } + } + + return $this->collProducts; + } + + /** + * Sets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param PropelCollection $products A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Category The current object (for fluent API support) + */ + public function setProducts(PropelCollection $products, PropelPDO $con = null) + { + $this->clearProducts(); + $currentProducts = $this->getProducts(); + + $this->productsScheduledForDeletion = $currentProducts->diff($products); + + foreach ($products as $product) { + if (!$currentProducts->contains($product)) { + $this->doAddProduct($product); + } + } + + $this->collProducts = $products; + + return $this; + } + + /** + * Gets the number of Product objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Product objects + */ + public function countProducts($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collProducts || null !== $criteria) { + if ($this->isNew() && null === $this->collProducts) { + return 0; + } else { + $query = ProductQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + } else { + return count($this->collProducts); + } + } + + /** + * Associate a Product object to this object + * through the product_category cross reference table. + * + * @param Product $product The ProductCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function addProduct(Product $product) + { + if ($this->collProducts === null) { + $this->initProducts(); + } + if (!$this->collProducts->contains($product)) { // only add it if the **same** object is not already associated + $this->doAddProduct($product); + + $this->collProducts[]= $product; + } + + return $this; + } + + /** + * @param Product $product The product object to add. + */ + protected function doAddProduct($product) + { + $productCategory = new ProductCategory(); + $productCategory->setProduct($product); + $this->addProductCategory($productCategory); + } + + /** + * Remove a Product object to this object + * through the product_category cross reference table. + * + * @param Product $product The ProductCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function removeProduct(Product $product) + { + if ($this->getProducts()->contains($product)) { + $this->collProducts->remove($this->collProducts->search($product)); + if (null === $this->productsScheduledForDeletion) { + $this->productsScheduledForDeletion = clone $this->collProducts; + $this->productsScheduledForDeletion->clear(); + } + $this->productsScheduledForDeletion[]= $product; + } + + return $this; + } + + /** + * Clears out the collFeatures collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return Category The current object (for fluent API support) + * @see addFeatures() + */ + public function clearFeatures() + { + $this->collFeatures = null; // important to set this to null since that means it is uninitialized + $this->collFeaturesPartial = null; + + return $this; + } + + /** + * Initializes the collFeatures collection. + * + * By default this just sets the collFeatures collection to an empty collection (like clearFeatures()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @return void + */ + public function initFeatures() + { + $this->collFeatures = new PropelObjectCollection(); + $this->collFeatures->setModel('Feature'); + } + + /** + * Gets a collection of Feature objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * + * 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 Category 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Feature[] List of Feature objects + */ + public function getFeatures($criteria = null, PropelPDO $con = null) + { + if (null === $this->collFeatures || null !== $criteria) { + if ($this->isNew() && null === $this->collFeatures) { + // return empty collection + $this->initFeatures(); + } else { + $collFeatures = FeatureQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + if (null !== $criteria) { + return $collFeatures; + } + $this->collFeatures = $collFeatures; + } + } + + return $this->collFeatures; + } + + /** + * Sets a collection of Feature objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param PropelCollection $features A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Category The current object (for fluent API support) + */ + public function setFeatures(PropelCollection $features, PropelPDO $con = null) + { + $this->clearFeatures(); + $currentFeatures = $this->getFeatures(); + + $this->featuresScheduledForDeletion = $currentFeatures->diff($features); + + foreach ($features as $feature) { + if (!$currentFeatures->contains($feature)) { + $this->doAddFeature($feature); + } + } + + $this->collFeatures = $features; + + return $this; + } + + /** + * Gets the number of Feature objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Feature objects + */ + public function countFeatures($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collFeatures || null !== $criteria) { + if ($this->isNew() && null === $this->collFeatures) { + return 0; + } else { + $query = FeatureQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + } else { + return count($this->collFeatures); + } + } + + /** + * Associate a Feature object to this object + * through the feature_category cross reference table. + * + * @param Feature $feature The FeatureCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function addFeature(Feature $feature) + { + if ($this->collFeatures === null) { + $this->initFeatures(); + } + if (!$this->collFeatures->contains($feature)) { // only add it if the **same** object is not already associated + $this->doAddFeature($feature); + + $this->collFeatures[]= $feature; + } + + return $this; + } + + /** + * @param Feature $feature The feature object to add. + */ + protected function doAddFeature($feature) + { + $featureCategory = new FeatureCategory(); + $featureCategory->setFeature($feature); + $this->addFeatureCategory($featureCategory); + } + + /** + * Remove a Feature object to this object + * through the feature_category cross reference table. + * + * @param Feature $feature The FeatureCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function removeFeature(Feature $feature) + { + if ($this->getFeatures()->contains($feature)) { + $this->collFeatures->remove($this->collFeatures->search($feature)); + if (null === $this->featuresScheduledForDeletion) { + $this->featuresScheduledForDeletion = clone $this->collFeatures; + $this->featuresScheduledForDeletion->clear(); + } + $this->featuresScheduledForDeletion[]= $feature; + } + + return $this; + } + + /** + * Clears out the collAttributes collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return Category The current object (for fluent API support) + * @see addAttributes() + */ + public function clearAttributes() + { + $this->collAttributes = null; // important to set this to null since that means it is uninitialized + $this->collAttributesPartial = null; + + return $this; + } + + /** + * Initializes the collAttributes collection. + * + * By default this just sets the collAttributes collection to an empty collection (like clearAttributes()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @return void + */ + public function initAttributes() + { + $this->collAttributes = new PropelObjectCollection(); + $this->collAttributes->setModel('Attribute'); + } + + /** + * Gets a collection of Attribute objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * + * 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 Category 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Attribute[] List of Attribute objects + */ + public function getAttributes($criteria = null, PropelPDO $con = null) + { + if (null === $this->collAttributes || null !== $criteria) { + if ($this->isNew() && null === $this->collAttributes) { + // return empty collection + $this->initAttributes(); + } else { + $collAttributes = AttributeQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + if (null !== $criteria) { + return $collAttributes; + } + $this->collAttributes = $collAttributes; + } + } + + return $this->collAttributes; + } + + /** + * Sets a collection of Attribute objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param PropelCollection $attributes A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Category The current object (for fluent API support) + */ + public function setAttributes(PropelCollection $attributes, PropelPDO $con = null) + { + $this->clearAttributes(); + $currentAttributes = $this->getAttributes(); + + $this->attributesScheduledForDeletion = $currentAttributes->diff($attributes); + + foreach ($attributes as $attribute) { + if (!$currentAttributes->contains($attribute)) { + $this->doAddAttribute($attribute); + } + } + + $this->collAttributes = $attributes; + + return $this; + } + + /** + * Gets the number of Attribute objects related by a many-to-many relationship + * to the current object by way of the attribute_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Attribute objects + */ + public function countAttributes($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collAttributes || null !== $criteria) { + if ($this->isNew() && null === $this->collAttributes) { + return 0; + } else { + $query = AttributeQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + } else { + return count($this->collAttributes); + } + } + + /** + * Associate a Attribute object to this object + * through the attribute_category cross reference table. + * + * @param Attribute $attribute The AttributeCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function addAttribute(Attribute $attribute) + { + if ($this->collAttributes === null) { + $this->initAttributes(); + } + if (!$this->collAttributes->contains($attribute)) { // only add it if the **same** object is not already associated + $this->doAddAttribute($attribute); + + $this->collAttributes[]= $attribute; + } + + return $this; + } + + /** + * @param Attribute $attribute The attribute object to add. + */ + protected function doAddAttribute($attribute) + { + $attributeCategory = new AttributeCategory(); + $attributeCategory->setAttribute($attribute); + $this->addAttributeCategory($attributeCategory); + } + + /** + * Remove a Attribute object to this object + * through the attribute_category cross reference table. + * + * @param Attribute $attribute The AttributeCategory object to relate + * @return Category The current object (for fluent API support) + */ + public function removeAttribute(Attribute $attribute) + { + if ($this->getAttributes()->contains($attribute)) { + $this->collAttributes->remove($this->collAttributes->search($attribute)); + if (null === $this->attributesScheduledForDeletion) { + $this->attributesScheduledForDeletion = clone $this->collAttributes; + $this->attributesScheduledForDeletion->clear(); + } + $this->attributesScheduledForDeletion[]= $attribute; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -4285,6 +4936,21 @@ abstract class BaseCategory extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collProducts) { + foreach ($this->collProducts as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collFeatures) { + foreach ($this->collFeatures as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collAttributes) { + foreach ($this->collAttributes as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -4329,6 +4995,18 @@ abstract class BaseCategory extends BaseObject implements Persistent $this->collCategoryVersions->clearIterator(); } $this->collCategoryVersions = null; + if ($this->collProducts instanceof PropelCollection) { + $this->collProducts->clearIterator(); + } + $this->collProducts = null; + if ($this->collFeatures instanceof PropelCollection) { + $this->collFeatures->clearIterator(); + } + $this->collFeatures = null; + if ($this->collAttributes instanceof PropelCollection) { + $this->collAttributes->clearIterator(); + } + $this->collAttributes = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseCategoryQuery.php b/core/lib/Thelia/Model/om/BaseCategoryQuery.php index ee26f7226..dd7550fae 100644 --- a/core/lib/Thelia/Model/om/BaseCategoryQuery.php +++ b/core/lib/Thelia/Model/om/BaseCategoryQuery.php @@ -12,6 +12,7 @@ use \PropelCollection; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Attribute; use Thelia\Model\AttributeCategory; use Thelia\Model\Category; use Thelia\Model\CategoryI18n; @@ -20,8 +21,10 @@ use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryVersion; use Thelia\Model\ContentAssoc; use Thelia\Model\Document; +use Thelia\Model\Feature; use Thelia\Model\FeatureCategory; use Thelia\Model\Image; +use Thelia\Model\Product; use Thelia\Model\ProductCategory; use Thelia\Model\Rewriting; @@ -1370,6 +1373,57 @@ abstract class BaseCategoryQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'CategoryVersion', '\Thelia\Model\CategoryVersionQuery'); } + /** + * Filter the query by a related Product object + * using the product_category table as cross reference + * + * @param Product $product the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CategoryQuery The current query, for fluid interface + */ + public function filterByProduct($product, $comparison = Criteria::EQUAL) + { + return $this + ->useProductCategoryQuery() + ->filterByProduct($product, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Feature object + * using the feature_category table as cross reference + * + * @param Feature $feature the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CategoryQuery The current query, for fluid interface + */ + public function filterByFeature($feature, $comparison = Criteria::EQUAL) + { + return $this + ->useFeatureCategoryQuery() + ->filterByFeature($feature, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Attribute object + * using the attribute_category table as cross reference + * + * @param Attribute $attribute the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CategoryQuery The current query, for fluid interface + */ + public function filterByAttribute($attribute, $comparison = Criteria::EQUAL) + { + return $this + ->useAttributeCategoryQuery() + ->filterByAttribute($attribute, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseContent.php b/core/lib/Thelia/Model/om/BaseContent.php index ab9d27612..a7fbcb3a4 100644 --- a/core/lib/Thelia/Model/om/BaseContent.php +++ b/core/lib/Thelia/Model/om/BaseContent.php @@ -29,6 +29,8 @@ use Thelia\Model\ContentVersionPeer; use Thelia\Model\ContentVersionQuery; use Thelia\Model\Document; use Thelia\Model\DocumentQuery; +use Thelia\Model\Folder; +use Thelia\Model\FolderQuery; use Thelia\Model\Image; use Thelia\Model\ImageQuery; use Thelia\Model\Rewriting; @@ -153,6 +155,11 @@ abstract class BaseContent extends BaseObject implements Persistent protected $collContentVersions; protected $collContentVersionsPartial; + /** + * @var PropelObjectCollection|Folder[] Collection to store aggregation of Folder objects. + */ + protected $collFolders; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -195,6 +202,12 @@ abstract class BaseContent extends BaseObject implements Persistent */ protected $enforceVersion = false; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $foldersScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -730,6 +743,7 @@ abstract class BaseContent extends BaseObject implements Persistent $this->collContentVersions = null; + $this->collFolders = null; } // if (deep) } @@ -877,6 +891,32 @@ abstract class BaseContent extends BaseObject implements Persistent $this->resetModified(); } + if ($this->foldersScheduledForDeletion !== null) { + if (!$this->foldersScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->foldersScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + ContentFolderQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->foldersScheduledForDeletion = null; + } + + foreach ($this->getFolders() as $folder) { + if ($folder->isModified()) { + $folder->save($con); + } + } + } elseif ($this->collFolders) { + foreach ($this->collFolders as $folder) { + if ($folder->isModified()) { + $folder->save($con); + } + } + } + if ($this->contentAssocsScheduledForDeletion !== null) { if (!$this->contentAssocsScheduledForDeletion->isEmpty()) { foreach ($this->contentAssocsScheduledForDeletion as $contentAssoc) { @@ -3502,6 +3542,183 @@ abstract class BaseContent extends BaseObject implements Persistent return $this; } + /** + * Clears out the collFolders 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 Content The current object (for fluent API support) + * @see addFolders() + */ + public function clearFolders() + { + $this->collFolders = null; // important to set this to null since that means it is uninitialized + $this->collFoldersPartial = null; + + return $this; + } + + /** + * Initializes the collFolders collection. + * + * By default this just sets the collFolders collection to an empty collection (like clearFolders()); + * 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 initFolders() + { + $this->collFolders = new PropelObjectCollection(); + $this->collFolders->setModel('Folder'); + } + + /** + * Gets a collection of Folder objects related by a many-to-many relationship + * to the current object by way of the content_folder 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 Content 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Folder[] List of Folder objects + */ + public function getFolders($criteria = null, PropelPDO $con = null) + { + if (null === $this->collFolders || null !== $criteria) { + if ($this->isNew() && null === $this->collFolders) { + // return empty collection + $this->initFolders(); + } else { + $collFolders = FolderQuery::create(null, $criteria) + ->filterByContent($this) + ->find($con); + if (null !== $criteria) { + return $collFolders; + } + $this->collFolders = $collFolders; + } + } + + return $this->collFolders; + } + + /** + * Sets a collection of Folder objects related by a many-to-many relationship + * to the current object by way of the content_folder 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 PropelCollection $folders A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Content The current object (for fluent API support) + */ + public function setFolders(PropelCollection $folders, PropelPDO $con = null) + { + $this->clearFolders(); + $currentFolders = $this->getFolders(); + + $this->foldersScheduledForDeletion = $currentFolders->diff($folders); + + foreach ($folders as $folder) { + if (!$currentFolders->contains($folder)) { + $this->doAddFolder($folder); + } + } + + $this->collFolders = $folders; + + return $this; + } + + /** + * Gets the number of Folder objects related by a many-to-many relationship + * to the current object by way of the content_folder cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Folder objects + */ + public function countFolders($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collFolders || null !== $criteria) { + if ($this->isNew() && null === $this->collFolders) { + return 0; + } else { + $query = FolderQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByContent($this) + ->count($con); + } + } else { + return count($this->collFolders); + } + } + + /** + * Associate a Folder object to this object + * through the content_folder cross reference table. + * + * @param Folder $folder The ContentFolder object to relate + * @return Content The current object (for fluent API support) + */ + public function addFolder(Folder $folder) + { + if ($this->collFolders === null) { + $this->initFolders(); + } + if (!$this->collFolders->contains($folder)) { // only add it if the **same** object is not already associated + $this->doAddFolder($folder); + + $this->collFolders[]= $folder; + } + + return $this; + } + + /** + * @param Folder $folder The folder object to add. + */ + protected function doAddFolder($folder) + { + $contentFolder = new ContentFolder(); + $contentFolder->setFolder($folder); + $this->addContentFolder($contentFolder); + } + + /** + * Remove a Folder object to this object + * through the content_folder cross reference table. + * + * @param Folder $folder The ContentFolder object to relate + * @return Content The current object (for fluent API support) + */ + public function removeFolder(Folder $folder) + { + if ($this->getFolders()->contains($folder)) { + $this->collFolders->remove($this->collFolders->search($folder)); + if (null === $this->foldersScheduledForDeletion) { + $this->foldersScheduledForDeletion = clone $this->collFolders; + $this->foldersScheduledForDeletion->clear(); + } + $this->foldersScheduledForDeletion[]= $folder; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -3573,6 +3790,11 @@ abstract class BaseContent extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collFolders) { + foreach ($this->collFolders as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -3609,6 +3831,10 @@ abstract class BaseContent extends BaseObject implements Persistent $this->collContentVersions->clearIterator(); } $this->collContentVersions = null; + if ($this->collFolders instanceof PropelCollection) { + $this->collFolders->clearIterator(); + } + $this->collFolders = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseContentQuery.php b/core/lib/Thelia/Model/om/BaseContentQuery.php index 6c86a3bba..5cb162d1a 100644 --- a/core/lib/Thelia/Model/om/BaseContentQuery.php +++ b/core/lib/Thelia/Model/om/BaseContentQuery.php @@ -20,6 +20,7 @@ use Thelia\Model\ContentPeer; use Thelia\Model\ContentQuery; use Thelia\Model\ContentVersion; use Thelia\Model\Document; +use Thelia\Model\Folder; use Thelia\Model\Image; use Thelia\Model\Rewriting; @@ -1133,6 +1134,23 @@ abstract class BaseContentQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ContentVersion', '\Thelia\Model\ContentVersionQuery'); } + /** + * Filter the query by a related Folder object + * using the content_folder table as cross reference + * + * @param Folder $folder the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ContentQuery The current query, for fluid interface + */ + public function filterByFolder($folder, $comparison = Criteria::EQUAL) + { + return $this + ->useContentFolderQuery() + ->filterByFolder($folder, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseFeature.php b/core/lib/Thelia/Model/om/BaseFeature.php index e2d0cb206..6aeaa9410 100644 --- a/core/lib/Thelia/Model/om/BaseFeature.php +++ b/core/lib/Thelia/Model/om/BaseFeature.php @@ -15,6 +15,8 @@ use \PropelDateTime; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Category; +use Thelia\Model\CategoryQuery; use Thelia\Model\Feature; use Thelia\Model\FeatureAv; use Thelia\Model\FeatureAvQuery; @@ -110,6 +112,11 @@ abstract class BaseFeature extends BaseObject implements Persistent protected $collFeatureI18ns; protected $collFeatureI18nsPartial; + /** + * @var PropelObjectCollection|Category[] Collection to store aggregation of Category objects. + */ + protected $collCategorys; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -144,6 +151,12 @@ abstract class BaseFeature extends BaseObject implements Persistent */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $categorysScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -527,6 +540,7 @@ abstract class BaseFeature extends BaseObject implements Persistent $this->collFeatureI18ns = null; + $this->collCategorys = null; } // if (deep) } @@ -662,6 +676,32 @@ abstract class BaseFeature extends BaseObject implements Persistent $this->resetModified(); } + if ($this->categorysScheduledForDeletion !== null) { + if (!$this->categorysScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->categorysScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + FeatureCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->categorysScheduledForDeletion = null; + } + + foreach ($this->getCategorys() as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } elseif ($this->collCategorys) { + foreach ($this->collCategorys as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } + if ($this->featureAvsScheduledForDeletion !== null) { if (!$this->featureAvsScheduledForDeletion->isEmpty()) { FeatureAvQuery::create() @@ -2245,6 +2285,183 @@ abstract class BaseFeature extends BaseObject implements Persistent return $this; } + /** + * Clears out the collCategorys 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 Feature The current object (for fluent API support) + * @see addCategorys() + */ + public function clearCategorys() + { + $this->collCategorys = null; // important to set this to null since that means it is uninitialized + $this->collCategorysPartial = null; + + return $this; + } + + /** + * Initializes the collCategorys collection. + * + * By default this just sets the collCategorys collection to an empty collection (like clearCategorys()); + * 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 initCategorys() + { + $this->collCategorys = new PropelObjectCollection(); + $this->collCategorys->setModel('Category'); + } + + /** + * Gets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * + * 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 Feature 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Category[] List of Category objects + */ + public function getCategorys($criteria = null, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + // return empty collection + $this->initCategorys(); + } else { + $collCategorys = CategoryQuery::create(null, $criteria) + ->filterByFeature($this) + ->find($con); + if (null !== $criteria) { + return $collCategorys; + } + $this->collCategorys = $collCategorys; + } + } + + return $this->collCategorys; + } + + /** + * Sets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * 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 PropelCollection $categorys A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Feature The current object (for fluent API support) + */ + public function setCategorys(PropelCollection $categorys, PropelPDO $con = null) + { + $this->clearCategorys(); + $currentCategorys = $this->getCategorys(); + + $this->categorysScheduledForDeletion = $currentCategorys->diff($categorys); + + foreach ($categorys as $category) { + if (!$currentCategorys->contains($category)) { + $this->doAddCategory($category); + } + } + + $this->collCategorys = $categorys; + + return $this; + } + + /** + * Gets the number of Category objects related by a many-to-many relationship + * to the current object by way of the feature_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Category objects + */ + public function countCategorys($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + return 0; + } else { + $query = CategoryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByFeature($this) + ->count($con); + } + } else { + return count($this->collCategorys); + } + } + + /** + * Associate a Category object to this object + * through the feature_category cross reference table. + * + * @param Category $category The FeatureCategory object to relate + * @return Feature The current object (for fluent API support) + */ + public function addCategory(Category $category) + { + if ($this->collCategorys === null) { + $this->initCategorys(); + } + if (!$this->collCategorys->contains($category)) { // only add it if the **same** object is not already associated + $this->doAddCategory($category); + + $this->collCategorys[]= $category; + } + + return $this; + } + + /** + * @param Category $category The category object to add. + */ + protected function doAddCategory($category) + { + $featureCategory = new FeatureCategory(); + $featureCategory->setCategory($category); + $this->addFeatureCategory($featureCategory); + } + + /** + * Remove a Category object to this object + * through the feature_category cross reference table. + * + * @param Category $category The FeatureCategory object to relate + * @return Feature The current object (for fluent API support) + */ + public function removeCategory(Category $category) + { + if ($this->getCategorys()->contains($category)) { + $this->collCategorys->remove($this->collCategorys->search($category)); + if (null === $this->categorysScheduledForDeletion) { + $this->categorysScheduledForDeletion = clone $this->collCategorys; + $this->categorysScheduledForDeletion->clear(); + } + $this->categorysScheduledForDeletion[]= $category; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2298,6 +2515,11 @@ abstract class BaseFeature extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collCategorys) { + foreach ($this->collCategorys as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -2322,6 +2544,10 @@ abstract class BaseFeature extends BaseObject implements Persistent $this->collFeatureI18ns->clearIterator(); } $this->collFeatureI18ns = null; + if ($this->collCategorys instanceof PropelCollection) { + $this->collCategorys->clearIterator(); + } + $this->collCategorys = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseFeatureQuery.php b/core/lib/Thelia/Model/om/BaseFeatureQuery.php index 2aabaed24..f9b008e05 100644 --- a/core/lib/Thelia/Model/om/BaseFeatureQuery.php +++ b/core/lib/Thelia/Model/om/BaseFeatureQuery.php @@ -12,6 +12,7 @@ use \PropelCollection; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Category; use Thelia\Model\Feature; use Thelia\Model\FeatureAv; use Thelia\Model\FeatureCategory; @@ -770,6 +771,23 @@ abstract class BaseFeatureQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'FeatureI18n', '\Thelia\Model\FeatureI18nQuery'); } + /** + * Filter the query by a related Category object + * using the feature_category table as cross reference + * + * @param Category $category the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return FeatureQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = Criteria::EQUAL) + { + return $this + ->useFeatureCategoryQuery() + ->filterByCategory($category, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseFolder.php b/core/lib/Thelia/Model/om/BaseFolder.php index d5881a5f2..e2fefbb8a 100644 --- a/core/lib/Thelia/Model/om/BaseFolder.php +++ b/core/lib/Thelia/Model/om/BaseFolder.php @@ -15,8 +15,10 @@ use \PropelDateTime; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Content; use Thelia\Model\ContentFolder; use Thelia\Model\ContentFolderQuery; +use Thelia\Model\ContentQuery; use Thelia\Model\Document; use Thelia\Model\DocumentQuery; use Thelia\Model\Folder; @@ -157,6 +159,11 @@ abstract class BaseFolder extends BaseObject implements Persistent protected $collFolderVersions; protected $collFolderVersionsPartial; + /** + * @var PropelObjectCollection|Content[] Collection to store aggregation of Content objects. + */ + protected $collContents; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -199,6 +206,12 @@ abstract class BaseFolder extends BaseObject implements Persistent */ protected $enforceVersion = false; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $contentsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -790,6 +803,7 @@ abstract class BaseFolder extends BaseObject implements Persistent $this->collFolderVersions = null; + $this->collContents = null; } // if (deep) } @@ -937,6 +951,32 @@ abstract class BaseFolder extends BaseObject implements Persistent $this->resetModified(); } + if ($this->contentsScheduledForDeletion !== null) { + if (!$this->contentsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->contentsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + ContentFolderQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->contentsScheduledForDeletion = null; + } + + foreach ($this->getContents() as $content) { + if ($content->isModified()) { + $content->save($con); + } + } + } elseif ($this->collContents) { + foreach ($this->collContents as $content) { + if ($content->isModified()) { + $content->save($con); + } + } + } + if ($this->imagesScheduledForDeletion !== null) { if (!$this->imagesScheduledForDeletion->isEmpty()) { foreach ($this->imagesScheduledForDeletion as $image) { @@ -3288,6 +3328,183 @@ abstract class BaseFolder extends BaseObject implements Persistent return $this; } + /** + * Clears out the collContents 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 Folder The current object (for fluent API support) + * @see addContents() + */ + public function clearContents() + { + $this->collContents = null; // important to set this to null since that means it is uninitialized + $this->collContentsPartial = null; + + return $this; + } + + /** + * Initializes the collContents collection. + * + * By default this just sets the collContents collection to an empty collection (like clearContents()); + * 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 initContents() + { + $this->collContents = new PropelObjectCollection(); + $this->collContents->setModel('Content'); + } + + /** + * Gets a collection of Content objects related by a many-to-many relationship + * to the current object by way of the content_folder 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 Folder 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Content[] List of Content objects + */ + public function getContents($criteria = null, PropelPDO $con = null) + { + if (null === $this->collContents || null !== $criteria) { + if ($this->isNew() && null === $this->collContents) { + // return empty collection + $this->initContents(); + } else { + $collContents = ContentQuery::create(null, $criteria) + ->filterByFolder($this) + ->find($con); + if (null !== $criteria) { + return $collContents; + } + $this->collContents = $collContents; + } + } + + return $this->collContents; + } + + /** + * Sets a collection of Content objects related by a many-to-many relationship + * to the current object by way of the content_folder 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 PropelCollection $contents A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Folder The current object (for fluent API support) + */ + public function setContents(PropelCollection $contents, PropelPDO $con = null) + { + $this->clearContents(); + $currentContents = $this->getContents(); + + $this->contentsScheduledForDeletion = $currentContents->diff($contents); + + foreach ($contents as $content) { + if (!$currentContents->contains($content)) { + $this->doAddContent($content); + } + } + + $this->collContents = $contents; + + return $this; + } + + /** + * Gets the number of Content objects related by a many-to-many relationship + * to the current object by way of the content_folder cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Content objects + */ + public function countContents($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collContents || null !== $criteria) { + if ($this->isNew() && null === $this->collContents) { + return 0; + } else { + $query = ContentQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByFolder($this) + ->count($con); + } + } else { + return count($this->collContents); + } + } + + /** + * Associate a Content object to this object + * through the content_folder cross reference table. + * + * @param Content $content The ContentFolder object to relate + * @return Folder The current object (for fluent API support) + */ + public function addContent(Content $content) + { + if ($this->collContents === null) { + $this->initContents(); + } + if (!$this->collContents->contains($content)) { // only add it if the **same** object is not already associated + $this->doAddContent($content); + + $this->collContents[]= $content; + } + + return $this; + } + + /** + * @param Content $content The content object to add. + */ + protected function doAddContent($content) + { + $contentFolder = new ContentFolder(); + $contentFolder->setContent($content); + $this->addContentFolder($contentFolder); + } + + /** + * Remove a Content object to this object + * through the content_folder cross reference table. + * + * @param Content $content The ContentFolder object to relate + * @return Folder The current object (for fluent API support) + */ + public function removeContent(Content $content) + { + if ($this->getContents()->contains($content)) { + $this->collContents->remove($this->collContents->search($content)); + if (null === $this->contentsScheduledForDeletion) { + $this->contentsScheduledForDeletion = clone $this->collContents; + $this->contentsScheduledForDeletion->clear(); + } + $this->contentsScheduledForDeletion[]= $content; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -3356,6 +3573,11 @@ abstract class BaseFolder extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collContents) { + foreach ($this->collContents as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -3388,6 +3610,10 @@ abstract class BaseFolder extends BaseObject implements Persistent $this->collFolderVersions->clearIterator(); } $this->collFolderVersions = null; + if ($this->collContents instanceof PropelCollection) { + $this->collContents->clearIterator(); + } + $this->collContents = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseFolderQuery.php b/core/lib/Thelia/Model/om/BaseFolderQuery.php index ed380cd16..82fa87ec1 100644 --- a/core/lib/Thelia/Model/om/BaseFolderQuery.php +++ b/core/lib/Thelia/Model/om/BaseFolderQuery.php @@ -12,6 +12,7 @@ use \PropelCollection; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Content; use Thelia\Model\ContentFolder; use Thelia\Model\Document; use Thelia\Model\Folder; @@ -1133,6 +1134,23 @@ abstract class BaseFolderQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'FolderVersion', '\Thelia\Model\FolderVersionQuery'); } + /** + * Filter the query by a related Content object + * using the content_folder table as cross reference + * + * @param Content $content the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return FolderQuery The current query, for fluid interface + */ + public function filterByContent($content, $comparison = Criteria::EQUAL) + { + return $this + ->useContentFolderQuery() + ->filterByContent($content, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseGroup.php b/core/lib/Thelia/Model/om/BaseGroup.php index a8a53dba7..0f300ced6 100644 --- a/core/lib/Thelia/Model/om/BaseGroup.php +++ b/core/lib/Thelia/Model/om/BaseGroup.php @@ -15,8 +15,10 @@ use \PropelDateTime; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Admin; use Thelia\Model\AdminGroup; use Thelia\Model\AdminGroupQuery; +use Thelia\Model\AdminQuery; use Thelia\Model\Group; use Thelia\Model\GroupI18n; use Thelia\Model\GroupI18nQuery; @@ -26,6 +28,8 @@ use Thelia\Model\GroupPeer; use Thelia\Model\GroupQuery; use Thelia\Model\GroupResource; use Thelia\Model\GroupResourceQuery; +use Thelia\Model\Resource; +use Thelia\Model\ResourceQuery; /** * Base class that represents a row from the 'group' table. @@ -103,6 +107,16 @@ abstract class BaseGroup extends BaseObject implements Persistent protected $collGroupI18ns; protected $collGroupI18nsPartial; + /** + * @var PropelObjectCollection|Admin[] Collection to store aggregation of Admin objects. + */ + protected $collAdmins; + + /** + * @var PropelObjectCollection|Resource[] Collection to store aggregation of Resource objects. + */ + protected $collResources; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -137,6 +151,18 @@ abstract class BaseGroup extends BaseObject implements Persistent */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $adminsScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $resourcesScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -463,6 +489,8 @@ abstract class BaseGroup extends BaseObject implements Persistent $this->collGroupI18ns = null; + $this->collAdmins = null; + $this->collResources = null; } // if (deep) } @@ -598,12 +626,63 @@ abstract class BaseGroup extends BaseObject implements Persistent $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); + } + AdminGroupQuery::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(); + $pk = $this->getPrimaryKey(); + foreach ($this->resourcesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + GroupResourceQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->resourcesScheduledForDeletion = null; + } + + foreach ($this->getResources() as $resource) { + if ($resource->isModified()) { + $resource->save($con); + } + } + } elseif ($this->collResources) { + foreach ($this->collResources as $resource) { + if ($resource->isModified()) { + $resource->save($con); + } + } + } + if ($this->adminGroupsScheduledForDeletion !== null) { if (!$this->adminGroupsScheduledForDeletion->isEmpty()) { - foreach ($this->adminGroupsScheduledForDeletion as $adminGroup) { - // need to save related object because we set the relation to null - $adminGroup->save($con); - } + AdminGroupQuery::create() + ->filterByPrimaryKeys($this->adminGroupsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); $this->adminGroupsScheduledForDeletion = null; } } @@ -1426,7 +1505,7 @@ abstract class BaseGroup extends BaseObject implements Persistent $this->adminGroupsScheduledForDeletion = clone $this->collAdminGroups; $this->adminGroupsScheduledForDeletion->clear(); } - $this->adminGroupsScheduledForDeletion[]= $adminGroup; + $this->adminGroupsScheduledForDeletion[]= clone $adminGroup; $adminGroup->setGroup(null); } @@ -2166,6 +2245,360 @@ abstract class BaseGroup extends BaseObject implements Persistent 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 Group The current object (for fluent API support) + * @see addAdmins() + */ + public function clearAdmins() + { + $this->collAdmins = null; // important to set this to null since that means it is uninitialized + $this->collAdminsPartial = null; + + return $this; + } + + /** + * 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 PropelObjectCollection(); + $this->collAdmins->setModel('Admin'); + } + + /** + * Gets a collection of Admin objects related by a many-to-many relationship + * to the current object by way of the admin_group 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 Group 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Admin[] List of Admin objects + */ + public function getAdmins($criteria = null, PropelPDO $con = null) + { + if (null === $this->collAdmins || null !== $criteria) { + if ($this->isNew() && null === $this->collAdmins) { + // return empty collection + $this->initAdmins(); + } else { + $collAdmins = AdminQuery::create(null, $criteria) + ->filterByGroup($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_group 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 PropelCollection $admins A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Group The current object (for fluent API support) + */ + public function setAdmins(PropelCollection $admins, PropelPDO $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 Admin objects related by a many-to-many relationship + * to the current object by way of the admin_group cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Admin objects + */ + public function countAdmins($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collAdmins || null !== $criteria) { + if ($this->isNew() && null === $this->collAdmins) { + return 0; + } else { + $query = AdminQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByGroup($this) + ->count($con); + } + } else { + return count($this->collAdmins); + } + } + + /** + * Associate a Admin object to this object + * through the admin_group cross reference table. + * + * @param Admin $admin The AdminGroup object to relate + * @return Group The current object (for fluent API support) + */ + public function addAdmin(Admin $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) + { + $adminGroup = new AdminGroup(); + $adminGroup->setAdmin($admin); + $this->addAdminGroup($adminGroup); + } + + /** + * Remove a Admin object to this object + * through the admin_group cross reference table. + * + * @param Admin $admin The AdminGroup object to relate + * @return Group The current object (for fluent API support) + */ + public function removeAdmin(Admin $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 + * + * 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 Group The current object (for fluent API support) + * @see addResources() + */ + public function clearResources() + { + $this->collResources = null; // important to set this to null since that means it is uninitialized + $this->collResourcesPartial = null; + + return $this; + } + + /** + * Initializes the collResources collection. + * + * By default this just sets the collResources collection to an empty collection (like clearResources()); + * 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 initResources() + { + $this->collResources = new PropelObjectCollection(); + $this->collResources->setModel('Resource'); + } + + /** + * Gets a collection of Resource objects related by a many-to-many relationship + * to the current object by way of the group_resource 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 Group 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Resource[] List of Resource objects + */ + public function getResources($criteria = null, PropelPDO $con = null) + { + if (null === $this->collResources || null !== $criteria) { + if ($this->isNew() && null === $this->collResources) { + // return empty collection + $this->initResources(); + } else { + $collResources = ResourceQuery::create(null, $criteria) + ->filterByGroup($this) + ->find($con); + if (null !== $criteria) { + return $collResources; + } + $this->collResources = $collResources; + } + } + + return $this->collResources; + } + + /** + * Sets a collection of Resource objects related by a many-to-many relationship + * to the current object by way of the group_resource 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 PropelCollection $resources A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Group The current object (for fluent API support) + */ + public function setResources(PropelCollection $resources, PropelPDO $con = null) + { + $this->clearResources(); + $currentResources = $this->getResources(); + + $this->resourcesScheduledForDeletion = $currentResources->diff($resources); + + foreach ($resources as $resource) { + if (!$currentResources->contains($resource)) { + $this->doAddResource($resource); + } + } + + $this->collResources = $resources; + + return $this; + } + + /** + * Gets the number of Resource objects related by a many-to-many relationship + * to the current object by way of the group_resource cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Resource objects + */ + public function countResources($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collResources || null !== $criteria) { + if ($this->isNew() && null === $this->collResources) { + return 0; + } else { + $query = ResourceQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByGroup($this) + ->count($con); + } + } else { + return count($this->collResources); + } + } + + /** + * Associate a Resource object to this object + * through the group_resource cross reference table. + * + * @param Resource $resource The GroupResource object to relate + * @return Group The current object (for fluent API support) + */ + public function addResource(Resource $resource) + { + if ($this->collResources === null) { + $this->initResources(); + } + if (!$this->collResources->contains($resource)) { // only add it if the **same** object is not already associated + $this->doAddResource($resource); + + $this->collResources[]= $resource; + } + + return $this; + } + + /** + * @param Resource $resource The resource object to add. + */ + protected function doAddResource($resource) + { + $groupResource = new GroupResource(); + $groupResource->setResource($resource); + $this->addGroupResource($groupResource); + } + + /** + * Remove a Resource object to this object + * through the group_resource cross reference table. + * + * @param Resource $resource The GroupResource object to relate + * @return Group The current object (for fluent API support) + */ + public function removeResource(Resource $resource) + { + if ($this->getResources()->contains($resource)) { + $this->collResources->remove($this->collResources->search($resource)); + if (null === $this->resourcesScheduledForDeletion) { + $this->resourcesScheduledForDeletion = clone $this->collResources; + $this->resourcesScheduledForDeletion->clear(); + } + $this->resourcesScheduledForDeletion[]= $resource; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2217,6 +2650,16 @@ abstract class BaseGroup extends BaseObject implements Persistent $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); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -2241,6 +2684,14 @@ abstract class BaseGroup extends BaseObject implements Persistent $this->collGroupI18ns->clearIterator(); } $this->collGroupI18ns = null; + if ($this->collAdmins instanceof PropelCollection) { + $this->collAdmins->clearIterator(); + } + $this->collAdmins = null; + if ($this->collResources instanceof PropelCollection) { + $this->collResources->clearIterator(); + } + $this->collResources = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseGroupQuery.php b/core/lib/Thelia/Model/om/BaseGroupQuery.php index d868338df..5c9695e10 100644 --- a/core/lib/Thelia/Model/om/BaseGroupQuery.php +++ b/core/lib/Thelia/Model/om/BaseGroupQuery.php @@ -12,6 +12,7 @@ use \PropelCollection; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Admin; use Thelia\Model\AdminGroup; use Thelia\Model\Group; use Thelia\Model\GroupI18n; @@ -19,6 +20,7 @@ use Thelia\Model\GroupModule; use Thelia\Model\GroupPeer; use Thelia\Model\GroupQuery; use Thelia\Model\GroupResource; +use Thelia\Model\Resource; /** * Base class that represents a query for the 'group' table. @@ -447,7 +449,7 @@ abstract class BaseGroupQuery extends ModelCriteria * * @return GroupQuery The current query, for fluid interface */ - public function joinAdminGroup($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function joinAdminGroup($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('AdminGroup'); @@ -482,7 +484,7 @@ abstract class BaseGroupQuery extends ModelCriteria * * @return \Thelia\Model\AdminGroupQuery A secondary query class using the current class as primary query */ - public function useAdminGroupQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + public function useAdminGroupQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinAdminGroup($relationAlias, $joinType) @@ -711,6 +713,40 @@ abstract class BaseGroupQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'GroupI18n', '\Thelia\Model\GroupI18nQuery'); } + /** + * Filter the query by a related Admin object + * using the admin_group 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 GroupQuery The current query, for fluid interface + */ + public function filterByAdmin($admin, $comparison = Criteria::EQUAL) + { + return $this + ->useAdminGroupQuery() + ->filterByAdmin($admin, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Resource object + * using the group_resource table as cross reference + * + * @param Resource $resource the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return GroupQuery The current query, for fluid interface + */ + public function filterByResource($resource, $comparison = Criteria::EQUAL) + { + return $this + ->useGroupResourceQuery() + ->filterByResource($resource, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseGroupResource.php b/core/lib/Thelia/Model/om/BaseGroupResource.php index 055228992..589b76550 100644 --- a/core/lib/Thelia/Model/om/BaseGroupResource.php +++ b/core/lib/Thelia/Model/om/BaseGroupResource.php @@ -988,10 +988,10 @@ abstract class BaseGroupResource extends BaseObject implements Persistent */ public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['GroupResource'][$this->getPrimaryKey()])) { + if (isset($alreadyDumpedObjects['GroupResource'][serialize($this->getPrimaryKey())])) { return '*RECURSION*'; } - $alreadyDumpedObjects['GroupResource'][$this->getPrimaryKey()] = true; + $alreadyDumpedObjects['GroupResource'][serialize($this->getPrimaryKey())] = true; $keys = GroupResourcePeer::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), @@ -1129,28 +1129,38 @@ abstract class BaseGroupResource extends BaseObject implements Persistent { $criteria = new Criteria(GroupResourcePeer::DATABASE_NAME); $criteria->add(GroupResourcePeer::ID, $this->id); + $criteria->add(GroupResourcePeer::GROUP_ID, $this->group_id); + $criteria->add(GroupResourcePeer::RESOURCE_ID, $this->resource_id); return $criteria; } /** - * Returns the primary key for this object (row). - * @return int + * 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() { - return $this->getId(); + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getGroupId(); + $pks[2] = $this->getResourceId(); + + return $pks; } /** - * Generic method to set the primary key (id column). + * Set the [composite] primary key. * - * @param int $key Primary key. + * @param array $keys The elements of the composite key (order must match the order in XML file). * @return void */ - public function setPrimaryKey($key) + public function setPrimaryKey($keys) { - $this->setId($key); + $this->setId($keys[0]); + $this->setGroupId($keys[1]); + $this->setResourceId($keys[2]); } /** @@ -1160,7 +1170,7 @@ abstract class BaseGroupResource extends BaseObject implements Persistent public function isPrimaryKeyNull() { - return null === $this->getId(); + return (null === $this->getId()) && (null === $this->getGroupId()) && (null === $this->getResourceId()); } /** diff --git a/core/lib/Thelia/Model/om/BaseGroupResourcePeer.php b/core/lib/Thelia/Model/om/BaseGroupResourcePeer.php index 5ebff6eb1..5c8fba516 100644 --- a/core/lib/Thelia/Model/om/BaseGroupResourcePeer.php +++ b/core/lib/Thelia/Model/om/BaseGroupResourcePeer.php @@ -321,7 +321,7 @@ abstract class BaseGroupResourcePeer { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { - $key = (string) $obj->getId(); + $key = serialize(array((string) $obj->getId(), (string) $obj->getGroupId(), (string) $obj->getResourceId())); } // if key === null GroupResourcePeer::$instances[$key] = $obj; } @@ -344,10 +344,10 @@ abstract class BaseGroupResourcePeer { if (Propel::isInstancePoolingEnabled() && $value !== null) { if (is_object($value) && $value instanceof GroupResource) { - $key = (string) $value->getId(); - } elseif (is_scalar($value)) { + $key = serialize(array((string) $value->getId(), (string) $value->getGroupId(), (string) $value->getResourceId())); + } elseif (is_array($value) && count($value) === 3) { // assume we've been passed a primary key - $key = (string) $value; + $key = serialize(array((string) $value[0], (string) $value[1], (string) $value[2])); } else { $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or GroupResource object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true))); throw $e; @@ -416,11 +416,11 @@ abstract class BaseGroupResourcePeer public static function getPrimaryKeyHashFromRow($row, $startcol = 0) { // If the PK cannot be derived from the row, return null. - if ($row[$startcol] === null) { + if ($row[$startcol] === null && $row[$startcol + 1] === null && $row[$startcol + 2] === null) { return null; } - return (string) $row[$startcol]; + return serialize(array((string) $row[$startcol], (string) $row[$startcol + 1], (string) $row[$startcol + 2])); } /** @@ -435,7 +435,7 @@ abstract class BaseGroupResourcePeer public static function getPrimaryKeyFromRow($row, $startcol = 0) { - return (int) $row[$startcol]; + return array((int) $row[$startcol], (int) $row[$startcol + 1], (int) $row[$startcol + 2]); } /** @@ -1233,6 +1233,22 @@ abstract class BaseGroupResourcePeer $selectCriteria->setPrimaryTableName(GroupResourcePeer::TABLE_NAME); } + $comparison = $criteria->getComparison(GroupResourcePeer::GROUP_ID); + $value = $criteria->remove(GroupResourcePeer::GROUP_ID); + if ($value) { + $selectCriteria->add(GroupResourcePeer::GROUP_ID, $value, $comparison); + } else { + $selectCriteria->setPrimaryTableName(GroupResourcePeer::TABLE_NAME); + } + + $comparison = $criteria->getComparison(GroupResourcePeer::RESOURCE_ID); + $value = $criteria->remove(GroupResourcePeer::RESOURCE_ID); + if ($value) { + $selectCriteria->add(GroupResourcePeer::RESOURCE_ID, $value, $comparison); + } else { + $selectCriteria->setPrimaryTableName(GroupResourcePeer::TABLE_NAME); + } + } else { // $values is GroupResource object $criteria = $values->buildCriteria(); // gets full criteria $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s) @@ -1307,10 +1323,19 @@ abstract class BaseGroupResourcePeer $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(GroupResourcePeer::DATABASE_NAME); - $criteria->add(GroupResourcePeer::ID, (array) $values, Criteria::IN); - // invalidate the cache for this object(s) - foreach ((array) $values as $singleval) { - GroupResourcePeer::removeInstanceFromPool($singleval); + // 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(GroupResourcePeer::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(GroupResourcePeer::GROUP_ID, $value[1])); + $criterion->addAnd($criteria->getNewCriterion(GroupResourcePeer::RESOURCE_ID, $value[2])); + $criteria->addOr($criterion); + // we can invalidate the cache for this single PK + GroupResourcePeer::removeInstanceFromPool($value); } } @@ -1373,58 +1398,30 @@ abstract class BaseGroupResourcePeer } /** - * Retrieve a single object by pkey. - * - * @param int $pk the primary key. - * @param PropelPDO $con the connection to use - * @return GroupResource + * Retrieve object using using composite pkey values. + * @param int $id + * @param int $group_id + * @param int $resource_id + * @param PropelPDO $con + * @return GroupResource */ - public static function retrieveByPK($pk, PropelPDO $con = null) - { - - if (null !== ($obj = GroupResourcePeer::getInstanceFromPool((string) $pk))) { - return $obj; + public static function retrieveByPK($id, $group_id, $resource_id, PropelPDO $con = null) { + $_instancePoolKey = serialize(array((string) $id, (string) $group_id, (string) $resource_id)); + if (null !== ($obj = GroupResourcePeer::getInstanceFromPool($_instancePoolKey))) { + return $obj; } if ($con === null) { $con = Propel::getConnection(GroupResourcePeer::DATABASE_NAME, Propel::CONNECTION_READ); } - $criteria = new Criteria(GroupResourcePeer::DATABASE_NAME); - $criteria->add(GroupResourcePeer::ID, $pk); - + $criteria->add(GroupResourcePeer::ID, $id); + $criteria->add(GroupResourcePeer::GROUP_ID, $group_id); + $criteria->add(GroupResourcePeer::RESOURCE_ID, $resource_id); $v = GroupResourcePeer::doSelect($criteria, $con); - return !empty($v) > 0 ? $v[0] : null; + return !empty($v) ? $v[0] : null; } - - /** - * Retrieve multiple objects by pkey. - * - * @param array $pks List of primary keys - * @param PropelPDO $con the connection to use - * @return GroupResource[] - * @throws PropelException Any exceptions caught during processing will be - * rethrown wrapped into a PropelException. - */ - public static function retrieveByPKs($pks, PropelPDO $con = null) - { - if ($con === null) { - $con = Propel::getConnection(GroupResourcePeer::DATABASE_NAME, Propel::CONNECTION_READ); - } - - $objs = null; - if (empty($pks)) { - $objs = array(); - } else { - $criteria = new Criteria(GroupResourcePeer::DATABASE_NAME); - $criteria->add(GroupResourcePeer::ID, $pks, Criteria::IN); - $objs = GroupResourcePeer::doSelect($criteria, $con); - } - - return $objs; - } - } // BaseGroupResourcePeer // This is the static code needed to register the TableMap for this table with the main Propel class. diff --git a/core/lib/Thelia/Model/om/BaseGroupResourceQuery.php b/core/lib/Thelia/Model/om/BaseGroupResourceQuery.php index d203d3bf0..d6ff84c8b 100644 --- a/core/lib/Thelia/Model/om/BaseGroupResourceQuery.php +++ b/core/lib/Thelia/Model/om/BaseGroupResourceQuery.php @@ -54,6 +54,7 @@ use Thelia\Model\Resource; * @method GroupResource findOne(PropelPDO $con = null) Return the first GroupResource matching the query * @method GroupResource findOneOrCreate(PropelPDO $con = null) Return the first GroupResource matching the query, or a new GroupResource object populated from the query conditions when no match is found * + * @method GroupResource findOneById(int $id) Return the first GroupResource filtered by the id column * @method GroupResource findOneByGroupId(int $group_id) Return the first GroupResource filtered by the group_id column * @method GroupResource findOneByResourceId(int $resource_id) Return the first GroupResource filtered by the resource_id column * @method GroupResource findOneByRead(int $read) Return the first GroupResource filtered by the read column @@ -115,10 +116,11 @@ abstract class BaseGroupResourceQuery extends ModelCriteria * Go fast if the query is untouched. * * - * $obj = $c->findPk(12, $con); + * $obj = $c->findPk(array(12, 34, 56), $con); * * - * @param mixed $key Primary key to use for the query + * @param array $key Primary key to use for the query + A Primary key composition: [$id, $group_id, $resource_id] * @param PropelPDO $con an optional connection object * * @return GroupResource|GroupResource[]|mixed the result, formatted by the current formatter @@ -128,7 +130,7 @@ abstract class BaseGroupResourceQuery extends ModelCriteria if ($key === null) { return null; } - if ((null !== ($obj = GroupResourcePeer::getInstanceFromPool((string) $key))) && !$this->formatter) { + if ((null !== ($obj = GroupResourcePeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))))) && !$this->formatter) { // the object is alredy in the instance pool return $obj; } @@ -145,20 +147,6 @@ abstract class BaseGroupResourceQuery extends ModelCriteria } } - /** - * Alias of findPk to use instance pooling - * - * @param mixed $key Primary key to use for the query - * @param PropelPDO $con A connection object - * - * @return GroupResource A model object, or null if the key is not found - * @throws PropelException - */ - public function findOneById($key, $con = null) - { - return $this->findPk($key, $con); - } - /** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. @@ -171,10 +159,12 @@ abstract class BaseGroupResourceQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `id`, `group_id`, `resource_id`, `read`, `write`, `created_at`, `updated_at` FROM `group_resource` WHERE `id` = :p0'; + $sql = 'SELECT `id`, `group_id`, `resource_id`, `read`, `write`, `created_at`, `updated_at` FROM `group_resource` WHERE `id` = :p0 AND `group_id` = :p1 AND `resource_id` = :p2'; try { $stmt = $con->prepare($sql); - $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $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); @@ -184,7 +174,7 @@ abstract class BaseGroupResourceQuery extends ModelCriteria if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new GroupResource(); $obj->hydrate($row); - GroupResourcePeer::addInstanceToPool($obj, (string) $key); + GroupResourcePeer::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1], (string) $key[2]))); } $stmt->closeCursor(); @@ -213,7 +203,7 @@ abstract class BaseGroupResourceQuery extends ModelCriteria /** * Find objects by primary key * - * $objs = $c->findPks(array(12, 56, 832), $con); + * $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 PropelPDO $con an optional connection object @@ -243,8 +233,11 @@ abstract class BaseGroupResourceQuery extends ModelCriteria */ public function filterByPrimaryKey($key) { + $this->addUsingAlias(GroupResourcePeer::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(GroupResourcePeer::GROUP_ID, $key[1], Criteria::EQUAL); + $this->addUsingAlias(GroupResourcePeer::RESOURCE_ID, $key[2], Criteria::EQUAL); - return $this->addUsingAlias(GroupResourcePeer::ID, $key, Criteria::EQUAL); + return $this; } /** @@ -256,8 +249,19 @@ abstract class BaseGroupResourceQuery extends ModelCriteria */ public function filterByPrimaryKeys($keys) { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(GroupResourcePeer::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(GroupResourcePeer::GROUP_ID, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $cton2 = $this->getNewCriterion(GroupResourcePeer::RESOURCE_ID, $key[2], Criteria::EQUAL); + $cton0->addAnd($cton2); + $this->addOr($cton0); + } - return $this->addUsingAlias(GroupResourcePeer::ID, $keys, Criteria::IN); + return $this; } /** @@ -722,7 +726,10 @@ abstract class BaseGroupResourceQuery extends ModelCriteria public function prune($groupResource = null) { if ($groupResource) { - $this->addUsingAlias(GroupResourcePeer::ID, $groupResource->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond0', $this->getAliasedColName(GroupResourcePeer::ID), $groupResource->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(GroupResourcePeer::GROUP_ID), $groupResource->getGroupId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond2', $this->getAliasedColName(GroupResourcePeer::RESOURCE_ID), $groupResource->getResourceId(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1', 'pruneCond2'), Criteria::LOGICAL_OR); } return $this; diff --git a/core/lib/Thelia/Model/om/BaseProduct.php b/core/lib/Thelia/Model/om/BaseProduct.php index 090bead7a..64068b28b 100644 --- a/core/lib/Thelia/Model/om/BaseProduct.php +++ b/core/lib/Thelia/Model/om/BaseProduct.php @@ -17,6 +17,8 @@ use \PropelObjectCollection; use \PropelPDO; use Thelia\Model\Accessory; use Thelia\Model\AccessoryQuery; +use Thelia\Model\Category; +use Thelia\Model\CategoryQuery; use Thelia\Model\ContentAssoc; use Thelia\Model\ContentAssocQuery; use Thelia\Model\Document; @@ -248,6 +250,21 @@ abstract class BaseProduct extends BaseObject implements Persistent protected $collProductVersions; protected $collProductVersionsPartial; + /** + * @var PropelObjectCollection|Category[] Collection to store aggregation of Category objects. + */ + protected $collCategorys; + + /** + * @var PropelObjectCollection|Product[] Collection to store aggregation of Product objects. + */ + protected $collProductsRelatedByAccessory; + + /** + * @var PropelObjectCollection|Product[] Collection to store aggregation of Product objects. + */ + protected $collProductsRelatedByProductId; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -290,6 +307,24 @@ abstract class BaseProduct extends BaseObject implements Persistent */ protected $enforceVersion = false; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $categorysScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $productsRelatedByAccessoryScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $productsRelatedByProductIdScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -1173,6 +1208,9 @@ abstract class BaseProduct extends BaseObject implements Persistent $this->collProductVersions = null; + $this->collCategorys = null; + $this->collProductsRelatedByAccessory = null; + $this->collProductsRelatedByProductId = null; } // if (deep) } @@ -1332,6 +1370,84 @@ abstract class BaseProduct extends BaseObject implements Persistent $this->resetModified(); } + if ($this->categorysScheduledForDeletion !== null) { + if (!$this->categorysScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->categorysScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + ProductCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->categorysScheduledForDeletion = null; + } + + foreach ($this->getCategorys() as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } elseif ($this->collCategorys) { + foreach ($this->collCategorys as $category) { + if ($category->isModified()) { + $category->save($con); + } + } + } + + if ($this->productsRelatedByAccessoryScheduledForDeletion !== null) { + if (!$this->productsRelatedByAccessoryScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->productsRelatedByAccessoryScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + AccessoryRelatedByProductIdQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->productsRelatedByAccessoryScheduledForDeletion = null; + } + + foreach ($this->getProductsRelatedByAccessory() as $productRelatedByAccessory) { + if ($productRelatedByAccessory->isModified()) { + $productRelatedByAccessory->save($con); + } + } + } elseif ($this->collProductsRelatedByAccessory) { + foreach ($this->collProductsRelatedByAccessory as $productRelatedByAccessory) { + if ($productRelatedByAccessory->isModified()) { + $productRelatedByAccessory->save($con); + } + } + } + + if ($this->productsRelatedByProductIdScheduledForDeletion !== null) { + if (!$this->productsRelatedByProductIdScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->productsRelatedByProductIdScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + AccessoryRelatedByAccessoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->productsRelatedByProductIdScheduledForDeletion = null; + } + + foreach ($this->getProductsRelatedByProductId() as $productRelatedByProductId) { + if ($productRelatedByProductId->isModified()) { + $productRelatedByProductId->save($con); + } + } + } elseif ($this->collProductsRelatedByProductId) { + foreach ($this->collProductsRelatedByProductId as $productRelatedByProductId) { + if ($productRelatedByProductId->isModified()) { + $productRelatedByProductId->save($con); + } + } + } + if ($this->productCategorysScheduledForDeletion !== null) { if (!$this->productCategorysScheduledForDeletion->isEmpty()) { ProductCategoryQuery::create() @@ -5263,6 +5379,537 @@ abstract class BaseProduct extends BaseObject implements Persistent return $this; } + /** + * Clears out the collCategorys 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 Product The current object (for fluent API support) + * @see addCategorys() + */ + public function clearCategorys() + { + $this->collCategorys = null; // important to set this to null since that means it is uninitialized + $this->collCategorysPartial = null; + + return $this; + } + + /** + * Initializes the collCategorys collection. + * + * By default this just sets the collCategorys collection to an empty collection (like clearCategorys()); + * 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 initCategorys() + { + $this->collCategorys = new PropelObjectCollection(); + $this->collCategorys->setModel('Category'); + } + + /** + * Gets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this Product 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Category[] List of Category objects + */ + public function getCategorys($criteria = null, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + // return empty collection + $this->initCategorys(); + } else { + $collCategorys = CategoryQuery::create(null, $criteria) + ->filterByProduct($this) + ->find($con); + if (null !== $criteria) { + return $collCategorys; + } + $this->collCategorys = $collCategorys; + } + } + + return $this->collCategorys; + } + + /** + * Sets a collection of Category objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param PropelCollection $categorys A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Product The current object (for fluent API support) + */ + public function setCategorys(PropelCollection $categorys, PropelPDO $con = null) + { + $this->clearCategorys(); + $currentCategorys = $this->getCategorys(); + + $this->categorysScheduledForDeletion = $currentCategorys->diff($categorys); + + foreach ($categorys as $category) { + if (!$currentCategorys->contains($category)) { + $this->doAddCategory($category); + } + } + + $this->collCategorys = $categorys; + + return $this; + } + + /** + * Gets the number of Category objects related by a many-to-many relationship + * to the current object by way of the product_category cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Category objects + */ + public function countCategorys($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collCategorys || null !== $criteria) { + if ($this->isNew() && null === $this->collCategorys) { + return 0; + } else { + $query = CategoryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByProduct($this) + ->count($con); + } + } else { + return count($this->collCategorys); + } + } + + /** + * Associate a Category object to this object + * through the product_category cross reference table. + * + * @param Category $category The ProductCategory object to relate + * @return Product The current object (for fluent API support) + */ + public function addCategory(Category $category) + { + if ($this->collCategorys === null) { + $this->initCategorys(); + } + if (!$this->collCategorys->contains($category)) { // only add it if the **same** object is not already associated + $this->doAddCategory($category); + + $this->collCategorys[]= $category; + } + + return $this; + } + + /** + * @param Category $category The category object to add. + */ + protected function doAddCategory($category) + { + $productCategory = new ProductCategory(); + $productCategory->setCategory($category); + $this->addProductCategory($productCategory); + } + + /** + * Remove a Category object to this object + * through the product_category cross reference table. + * + * @param Category $category The ProductCategory object to relate + * @return Product The current object (for fluent API support) + */ + public function removeCategory(Category $category) + { + if ($this->getCategorys()->contains($category)) { + $this->collCategorys->remove($this->collCategorys->search($category)); + if (null === $this->categorysScheduledForDeletion) { + $this->categorysScheduledForDeletion = clone $this->collCategorys; + $this->categorysScheduledForDeletion->clear(); + } + $this->categorysScheduledForDeletion[]= $category; + } + + return $this; + } + + /** + * Clears out the collProductsRelatedByAccessory 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 Product The current object (for fluent API support) + * @see addProductsRelatedByAccessory() + */ + public function clearProductsRelatedByAccessory() + { + $this->collProductsRelatedByAccessory = null; // important to set this to null since that means it is uninitialized + $this->collProductsRelatedByAccessoryPartial = null; + + return $this; + } + + /** + * Initializes the collProductsRelatedByAccessory collection. + * + * By default this just sets the collProductsRelatedByAccessory collection to an empty collection (like clearProductsRelatedByAccessory()); + * 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 initProductsRelatedByAccessory() + { + $this->collProductsRelatedByAccessory = new PropelObjectCollection(); + $this->collProductsRelatedByAccessory->setModel('Product'); + } + + /** + * Gets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the accessory 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 Product 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Product[] List of Product objects + */ + public function getProductsRelatedByAccessory($criteria = null, PropelPDO $con = null) + { + if (null === $this->collProductsRelatedByAccessory || null !== $criteria) { + if ($this->isNew() && null === $this->collProductsRelatedByAccessory) { + // return empty collection + $this->initProductsRelatedByAccessory(); + } else { + $collProductsRelatedByAccessory = ProductQuery::create(null, $criteria) + ->filterByProductRelatedByProductId($this) + ->find($con); + if (null !== $criteria) { + return $collProductsRelatedByAccessory; + } + $this->collProductsRelatedByAccessory = $collProductsRelatedByAccessory; + } + } + + return $this->collProductsRelatedByAccessory; + } + + /** + * Sets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the accessory 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 PropelCollection $productsRelatedByAccessory A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Product The current object (for fluent API support) + */ + public function setProductsRelatedByAccessory(PropelCollection $productsRelatedByAccessory, PropelPDO $con = null) + { + $this->clearProductsRelatedByAccessory(); + $currentProductsRelatedByAccessory = $this->getProductsRelatedByAccessory(); + + $this->productsRelatedByAccessoryScheduledForDeletion = $currentProductsRelatedByAccessory->diff($productsRelatedByAccessory); + + foreach ($productsRelatedByAccessory as $productRelatedByAccessory) { + if (!$currentProductsRelatedByAccessory->contains($productRelatedByAccessory)) { + $this->doAddProductRelatedByAccessory($productRelatedByAccessory); + } + } + + $this->collProductsRelatedByAccessory = $productsRelatedByAccessory; + + return $this; + } + + /** + * Gets the number of Product objects related by a many-to-many relationship + * to the current object by way of the accessory cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Product objects + */ + public function countProductsRelatedByAccessory($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collProductsRelatedByAccessory || null !== $criteria) { + if ($this->isNew() && null === $this->collProductsRelatedByAccessory) { + return 0; + } else { + $query = ProductQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByProductRelatedByProductId($this) + ->count($con); + } + } else { + return count($this->collProductsRelatedByAccessory); + } + } + + /** + * Associate a Product object to this object + * through the accessory cross reference table. + * + * @param Product $product The Accessory object to relate + * @return Product The current object (for fluent API support) + */ + public function addProductRelatedByAccessory(Product $product) + { + if ($this->collProductsRelatedByAccessory === null) { + $this->initProductsRelatedByAccessory(); + } + if (!$this->collProductsRelatedByAccessory->contains($product)) { // only add it if the **same** object is not already associated + $this->doAddProductRelatedByAccessory($product); + + $this->collProductsRelatedByAccessory[]= $product; + } + + return $this; + } + + /** + * @param ProductRelatedByAccessory $productRelatedByAccessory The productRelatedByAccessory object to add. + */ + protected function doAddProductRelatedByAccessory($productRelatedByAccessory) + { + $accessory = new Accessory(); + $accessory->setProductRelatedByAccessory($productRelatedByAccessory); + $this->addAccessoryRelatedByProductId($accessory); + } + + /** + * Remove a Product object to this object + * through the accessory cross reference table. + * + * @param Product $product The Accessory object to relate + * @return Product The current object (for fluent API support) + */ + public function removeProductRelatedByAccessory(Product $product) + { + if ($this->getProductsRelatedByAccessory()->contains($product)) { + $this->collProductsRelatedByAccessory->remove($this->collProductsRelatedByAccessory->search($product)); + if (null === $this->productsRelatedByAccessoryScheduledForDeletion) { + $this->productsRelatedByAccessoryScheduledForDeletion = clone $this->collProductsRelatedByAccessory; + $this->productsRelatedByAccessoryScheduledForDeletion->clear(); + } + $this->productsRelatedByAccessoryScheduledForDeletion[]= $product; + } + + return $this; + } + + /** + * Clears out the collProductsRelatedByProductId 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 Product The current object (for fluent API support) + * @see addProductsRelatedByProductId() + */ + public function clearProductsRelatedByProductId() + { + $this->collProductsRelatedByProductId = null; // important to set this to null since that means it is uninitialized + $this->collProductsRelatedByProductIdPartial = null; + + return $this; + } + + /** + * Initializes the collProductsRelatedByProductId collection. + * + * By default this just sets the collProductsRelatedByProductId collection to an empty collection (like clearProductsRelatedByProductId()); + * 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 initProductsRelatedByProductId() + { + $this->collProductsRelatedByProductId = new PropelObjectCollection(); + $this->collProductsRelatedByProductId->setModel('Product'); + } + + /** + * Gets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the accessory 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 Product 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Product[] List of Product objects + */ + public function getProductsRelatedByProductId($criteria = null, PropelPDO $con = null) + { + if (null === $this->collProductsRelatedByProductId || null !== $criteria) { + if ($this->isNew() && null === $this->collProductsRelatedByProductId) { + // return empty collection + $this->initProductsRelatedByProductId(); + } else { + $collProductsRelatedByProductId = ProductQuery::create(null, $criteria) + ->filterByProductRelatedByAccessory($this) + ->find($con); + if (null !== $criteria) { + return $collProductsRelatedByProductId; + } + $this->collProductsRelatedByProductId = $collProductsRelatedByProductId; + } + } + + return $this->collProductsRelatedByProductId; + } + + /** + * Sets a collection of Product objects related by a many-to-many relationship + * to the current object by way of the accessory 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 PropelCollection $productsRelatedByProductId A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Product The current object (for fluent API support) + */ + public function setProductsRelatedByProductId(PropelCollection $productsRelatedByProductId, PropelPDO $con = null) + { + $this->clearProductsRelatedByProductId(); + $currentProductsRelatedByProductId = $this->getProductsRelatedByProductId(); + + $this->productsRelatedByProductIdScheduledForDeletion = $currentProductsRelatedByProductId->diff($productsRelatedByProductId); + + foreach ($productsRelatedByProductId as $productRelatedByProductId) { + if (!$currentProductsRelatedByProductId->contains($productRelatedByProductId)) { + $this->doAddProductRelatedByProductId($productRelatedByProductId); + } + } + + $this->collProductsRelatedByProductId = $productsRelatedByProductId; + + return $this; + } + + /** + * Gets the number of Product objects related by a many-to-many relationship + * to the current object by way of the accessory cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Product objects + */ + public function countProductsRelatedByProductId($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collProductsRelatedByProductId || null !== $criteria) { + if ($this->isNew() && null === $this->collProductsRelatedByProductId) { + return 0; + } else { + $query = ProductQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByProductRelatedByAccessory($this) + ->count($con); + } + } else { + return count($this->collProductsRelatedByProductId); + } + } + + /** + * Associate a Product object to this object + * through the accessory cross reference table. + * + * @param Product $product The Accessory object to relate + * @return Product The current object (for fluent API support) + */ + public function addProductRelatedByProductId(Product $product) + { + if ($this->collProductsRelatedByProductId === null) { + $this->initProductsRelatedByProductId(); + } + if (!$this->collProductsRelatedByProductId->contains($product)) { // only add it if the **same** object is not already associated + $this->doAddProductRelatedByProductId($product); + + $this->collProductsRelatedByProductId[]= $product; + } + + return $this; + } + + /** + * @param ProductRelatedByProductId $productRelatedByProductId The productRelatedByProductId object to add. + */ + protected function doAddProductRelatedByProductId($productRelatedByProductId) + { + $accessory = new Accessory(); + $accessory->setProductRelatedByProductId($productRelatedByProductId); + $this->addAccessoryRelatedByAccessory($accessory); + } + + /** + * Remove a Product object to this object + * through the accessory cross reference table. + * + * @param Product $product The Accessory object to relate + * @return Product The current object (for fluent API support) + */ + public function removeProductRelatedByProductId(Product $product) + { + if ($this->getProductsRelatedByProductId()->contains($product)) { + $this->collProductsRelatedByProductId->remove($this->collProductsRelatedByProductId->search($product)); + if (null === $this->productsRelatedByProductIdScheduledForDeletion) { + $this->productsRelatedByProductIdScheduledForDeletion = clone $this->collProductsRelatedByProductId; + $this->productsRelatedByProductIdScheduledForDeletion->clear(); + } + $this->productsRelatedByProductIdScheduledForDeletion[]= $product; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -5363,6 +6010,21 @@ abstract class BaseProduct extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collCategorys) { + foreach ($this->collCategorys as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collProductsRelatedByAccessory) { + foreach ($this->collProductsRelatedByAccessory as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collProductsRelatedByProductId) { + foreach ($this->collProductsRelatedByProductId as $o) { + $o->clearAllReferences($deep); + } + } if ($this->aTaxRule instanceof Persistent) { $this->aTaxRule->clearAllReferences($deep); } @@ -5418,6 +6080,18 @@ abstract class BaseProduct extends BaseObject implements Persistent $this->collProductVersions->clearIterator(); } $this->collProductVersions = null; + if ($this->collCategorys instanceof PropelCollection) { + $this->collCategorys->clearIterator(); + } + $this->collCategorys = null; + if ($this->collProductsRelatedByAccessory instanceof PropelCollection) { + $this->collProductsRelatedByAccessory->clearIterator(); + } + $this->collProductsRelatedByAccessory = null; + if ($this->collProductsRelatedByProductId instanceof PropelCollection) { + $this->collProductsRelatedByProductId->clearIterator(); + } + $this->collProductsRelatedByProductId = null; $this->aTaxRule = null; } diff --git a/core/lib/Thelia/Model/om/BaseProductQuery.php b/core/lib/Thelia/Model/om/BaseProductQuery.php index 9c2049c5f..1030bcedc 100644 --- a/core/lib/Thelia/Model/om/BaseProductQuery.php +++ b/core/lib/Thelia/Model/om/BaseProductQuery.php @@ -13,6 +13,7 @@ use \PropelException; use \PropelObjectCollection; use \PropelPDO; use Thelia\Model\Accessory; +use Thelia\Model\Category; use Thelia\Model\ContentAssoc; use Thelia\Model\Document; use Thelia\Model\FeatureProd; @@ -1932,6 +1933,57 @@ abstract class BaseProductQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ProductVersion', '\Thelia\Model\ProductVersionQuery'); } + /** + * Filter the query by a related Category object + * using the product_category table as cross reference + * + * @param Category $category the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ProductQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = Criteria::EQUAL) + { + return $this + ->useProductCategoryQuery() + ->filterByCategory($category, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Product object + * using the accessory table as cross reference + * + * @param Product $product the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ProductQuery The current query, for fluid interface + */ + public function filterByProductRelatedByAccessory($product, $comparison = Criteria::EQUAL) + { + return $this + ->useAccessoryRelatedByProductIdQuery() + ->filterByProductRelatedByAccessory($product, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Product object + * using the accessory table as cross reference + * + * @param Product $product the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ProductQuery The current query, for fluid interface + */ + public function filterByProductRelatedByProductId($product, $comparison = Criteria::EQUAL) + { + return $this + ->useAccessoryRelatedByAccessoryQuery() + ->filterByProductRelatedByProductId($product, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/om/BaseResource.php b/core/lib/Thelia/Model/om/BaseResource.php index d58f245f1..9e9c26153 100644 --- a/core/lib/Thelia/Model/om/BaseResource.php +++ b/core/lib/Thelia/Model/om/BaseResource.php @@ -15,6 +15,8 @@ use \PropelDateTime; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Group; +use Thelia\Model\GroupQuery; use Thelia\Model\GroupResource; use Thelia\Model\GroupResourceQuery; use Thelia\Model\Resource; @@ -87,6 +89,11 @@ abstract class BaseResource extends BaseObject implements Persistent protected $collResourceI18ns; protected $collResourceI18nsPartial; + /** + * @var PropelObjectCollection|Group[] Collection to store aggregation of Group objects. + */ + protected $collGroups; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -121,6 +128,12 @@ abstract class BaseResource extends BaseObject implements Persistent */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var PropelObjectCollection + */ + protected $groupsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var PropelObjectCollection @@ -431,6 +444,7 @@ abstract class BaseResource extends BaseObject implements Persistent $this->collResourceI18ns = null; + $this->collGroups = null; } // if (deep) } @@ -566,6 +580,32 @@ abstract class BaseResource extends BaseObject implements Persistent $this->resetModified(); } + if ($this->groupsScheduledForDeletion !== null) { + if (!$this->groupsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->groupsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + GroupResourceQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->groupsScheduledForDeletion = null; + } + + foreach ($this->getGroups() as $group) { + if ($group->isModified()) { + $group->save($con); + } + } + } elseif ($this->collGroups) { + foreach ($this->collGroups as $group) { + if ($group->isModified()) { + $group->save($con); + } + } + } + if ($this->groupResourcesScheduledForDeletion !== null) { if (!$this->groupResourcesScheduledForDeletion->isEmpty()) { GroupResourceQuery::create() @@ -1573,6 +1613,183 @@ abstract class BaseResource extends BaseObject implements Persistent return $this; } + /** + * Clears out the collGroups 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 Resource The current object (for fluent API support) + * @see addGroups() + */ + public function clearGroups() + { + $this->collGroups = null; // important to set this to null since that means it is uninitialized + $this->collGroupsPartial = null; + + return $this; + } + + /** + * Initializes the collGroups collection. + * + * By default this just sets the collGroups collection to an empty collection (like clearGroups()); + * 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 initGroups() + { + $this->collGroups = new PropelObjectCollection(); + $this->collGroups->setModel('Group'); + } + + /** + * Gets a collection of Group objects related by a many-to-many relationship + * to the current object by way of the group_resource 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 Resource 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 PropelPDO $con Optional connection object + * + * @return PropelObjectCollection|Group[] List of Group objects + */ + public function getGroups($criteria = null, PropelPDO $con = null) + { + if (null === $this->collGroups || null !== $criteria) { + if ($this->isNew() && null === $this->collGroups) { + // return empty collection + $this->initGroups(); + } else { + $collGroups = GroupQuery::create(null, $criteria) + ->filterByResource($this) + ->find($con); + if (null !== $criteria) { + return $collGroups; + } + $this->collGroups = $collGroups; + } + } + + return $this->collGroups; + } + + /** + * Sets a collection of Group objects related by a many-to-many relationship + * to the current object by way of the group_resource 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 PropelCollection $groups A Propel collection. + * @param PropelPDO $con Optional connection object + * @return Resource The current object (for fluent API support) + */ + public function setGroups(PropelCollection $groups, PropelPDO $con = null) + { + $this->clearGroups(); + $currentGroups = $this->getGroups(); + + $this->groupsScheduledForDeletion = $currentGroups->diff($groups); + + foreach ($groups as $group) { + if (!$currentGroups->contains($group)) { + $this->doAddGroup($group); + } + } + + $this->collGroups = $groups; + + return $this; + } + + /** + * Gets the number of Group objects related by a many-to-many relationship + * to the current object by way of the group_resource cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param PropelPDO $con Optional connection object + * + * @return int the number of related Group objects + */ + public function countGroups($criteria = null, $distinct = false, PropelPDO $con = null) + { + if (null === $this->collGroups || null !== $criteria) { + if ($this->isNew() && null === $this->collGroups) { + return 0; + } else { + $query = GroupQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByResource($this) + ->count($con); + } + } else { + return count($this->collGroups); + } + } + + /** + * Associate a Group object to this object + * through the group_resource cross reference table. + * + * @param Group $group The GroupResource object to relate + * @return Resource The current object (for fluent API support) + */ + public function addGroup(Group $group) + { + if ($this->collGroups === null) { + $this->initGroups(); + } + if (!$this->collGroups->contains($group)) { // only add it if the **same** object is not already associated + $this->doAddGroup($group); + + $this->collGroups[]= $group; + } + + return $this; + } + + /** + * @param Group $group The group object to add. + */ + protected function doAddGroup($group) + { + $groupResource = new GroupResource(); + $groupResource->setGroup($group); + $this->addGroupResource($groupResource); + } + + /** + * Remove a Group object to this object + * through the group_resource cross reference table. + * + * @param Group $group The GroupResource object to relate + * @return Resource The current object (for fluent API support) + */ + public function removeGroup(Group $group) + { + if ($this->getGroups()->contains($group)) { + $this->collGroups->remove($this->collGroups->search($group)); + if (null === $this->groupsScheduledForDeletion) { + $this->groupsScheduledForDeletion = clone $this->collGroups; + $this->groupsScheduledForDeletion->clear(); + } + $this->groupsScheduledForDeletion[]= $group; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -1614,6 +1831,11 @@ abstract class BaseResource extends BaseObject implements Persistent $o->clearAllReferences($deep); } } + if ($this->collGroups) { + foreach ($this->collGroups as $o) { + $o->clearAllReferences($deep); + } + } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) @@ -1630,6 +1852,10 @@ abstract class BaseResource extends BaseObject implements Persistent $this->collResourceI18ns->clearIterator(); } $this->collResourceI18ns = null; + if ($this->collGroups instanceof PropelCollection) { + $this->collGroups->clearIterator(); + } + $this->collGroups = null; } /** diff --git a/core/lib/Thelia/Model/om/BaseResourceQuery.php b/core/lib/Thelia/Model/om/BaseResourceQuery.php index 33bc2520a..f390091ec 100644 --- a/core/lib/Thelia/Model/om/BaseResourceQuery.php +++ b/core/lib/Thelia/Model/om/BaseResourceQuery.php @@ -12,6 +12,7 @@ use \PropelCollection; use \PropelException; use \PropelObjectCollection; use \PropelPDO; +use Thelia\Model\Group; use Thelia\Model\GroupResource; use Thelia\Model\Resource; use Thelia\Model\ResourceI18n; @@ -553,6 +554,23 @@ abstract class BaseResourceQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ResourceI18n', '\Thelia\Model\ResourceI18nQuery'); } + /** + * Filter the query by a related Group object + * using the group_resource table as cross reference + * + * @param Group $group the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ResourceQuery The current query, for fluid interface + */ + public function filterByGroup($group, $comparison = Criteria::EQUAL) + { + return $this + ->useGroupResourceQuery() + ->filterByGroup($group, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/install/faker.php b/install/faker.php new file mode 100644 index 000000000..b6f803b05 --- /dev/null +++ b/install/faker.php @@ -0,0 +1,67 @@ +beginTransaction(); +try { + //first category + $sweet = new Thelia\Model\Category(); + $sweet->setParent(0); + $sweet->setVisible(1); + $sweet->setPosition(1); + $sweet->setDescription($faker->text(255)); + $sweet->setTitle($faker->bs); + + $sweet->save(); + + //second category + $jeans = new Thelia\Model\Category(); + $jeans->setParent(0); + $jeans->setVisible(1); + $jeans->setPosition(2); + $jeans->setDescription($faker->text(255)); + $jeans->setTitle($faker->bs); + + $jeans->save(); + + for ($i=1; $i <= 5; $i++) { + $product = new \Thelia\Model\Product(); + $product->addCategory($sweet); + $product->setTitle($faker->bs); + $product->setDescription($faker->text(250)); + $product->setStock($faker->randomNumber(1,50)); + $product->setPrice($faker->randomFloat(2, 20, 2500)); + $product->setVisible(1); + $product->setPosition($i); + $product->setRef($faker->text(255)); + $product->save(); + + } + + for ($i=1; $i <= 5; $i++) { + $product = new \Thelia\Model\Product(); + $product->addCategory($jeans); + $product->setTitle($faker->bs); + $product->setDescription($faker->text(250)); + $product->setStock($faker->randomNumber(1,50)); + $product->setPrice($faker->randomFloat(2, 20, 2500)); + $product->setVisible(1); + $product->setPosition($i); + $product->setRef($faker->text(255)); + $product->save(); + + } + + + $con->commit(); +} catch (Exception $e) { + echo "error : ".$e->getMessage(); + $con->rollBack(); +} + + + diff --git a/local/config/schema.xml b/local/config/schema.xml index fa2784ee4..7cfd83230 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -54,7 +54,7 @@ - +
@@ -194,7 +194,7 @@
- +
@@ -293,7 +293,7 @@
- +
@@ -688,7 +688,7 @@
- +
@@ -765,10 +765,10 @@
- +
- - + + @@ -783,10 +783,10 @@
- +
- - + + @@ -795,7 +795,7 @@ - + @@ -922,7 +922,7 @@
- +
diff --git a/local/plugins/Test/Loop/Doobitch.php b/local/plugins/Test/Loop/Doobitch.php index 3aaa507c3..d88780510 100644 --- a/local/plugins/Test/Loop/Doobitch.php +++ b/local/plugins/Test/Loop/Doobitch.php @@ -11,6 +11,7 @@ namespace Test\Loop; use Thelia\Tpex\Element\Loop\BaseLoop; use Thelia\Tpex\Tools; +use Thelia\Model\ProductQuery; class Doobitch extends BaseLoop {