diff options
Diffstat (limited to 'Aufgabe06/generated-classes/Base')
| -rw-r--r-- | Aufgabe06/generated-classes/Base/Category.php | 296 | ||||
| -rw-r--r-- | Aufgabe06/generated-classes/Base/CategoryQuery.php | 17 | ||||
| -rw-r--r-- | Aufgabe06/generated-classes/Base/Product.php | 296 | ||||
| -rw-r--r-- | Aufgabe06/generated-classes/Base/ProductQuery.php | 17 |
4 files changed, 626 insertions, 0 deletions
diff --git a/Aufgabe06/generated-classes/Base/Category.php b/Aufgabe06/generated-classes/Base/Category.php index 715d738..b9916f8 100644 --- a/Aufgabe06/generated-classes/Base/Category.php +++ b/Aufgabe06/generated-classes/Base/Category.php @@ -4,8 +4,10 @@ namespace Base; use \Category as ChildCategory; use \CategoryQuery as ChildCategoryQuery; +use \Product as ChildProduct; use \ProductCategory as ChildProductCategory; use \ProductCategoryQuery as ChildProductCategoryQuery; +use \ProductQuery as ChildProductQuery; use \Exception; use \PDO; use Map\CategoryTableMap; @@ -88,6 +90,16 @@ abstract class Category implements ActiveRecordInterface protected $collProductCategoriesPartial; /** + * @var ObjectCollection|ChildProduct[] Cross Collection to store aggregation of ChildProduct objects. + */ + protected $collProducts; + + /** + * @var bool + */ + protected $collProductsPartial; + + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. * @@ -97,6 +109,12 @@ abstract class Category implements ActiveRecordInterface /** * An array of objects scheduled for deletion. + * @var ObjectCollection|ChildProduct[] + */ + protected $productsScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. * @var ObjectCollection|ChildProductCategory[] */ protected $productCategoriesScheduledForDeletion = null; @@ -523,6 +541,7 @@ abstract class Category implements ActiveRecordInterface $this->collProductCategories = null; + $this->collProducts = null; } // if (deep) } @@ -633,6 +652,35 @@ abstract class Category implements ActiveRecordInterface $this->resetModified(); } + if ($this->productsScheduledForDeletion !== null) { + if (!$this->productsScheduledForDeletion->isEmpty()) { + $pks = array(); + foreach ($this->productsScheduledForDeletion as $entry) { + $entryPk = []; + + $entryPk[1] = $this->getId(); + $entryPk[0] = $entry->getId(); + $pks[] = $entryPk; + } + + \ProductCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + + $this->productsScheduledForDeletion = null; + } + + } + + if ($this->collProducts) { + foreach ($this->collProducts as $product) { + if (!$product->isDeleted() && ($product->isNew() || $product->isModified())) { + $product->save($con); + } + } + } + + if ($this->productCategoriesScheduledForDeletion !== null) { if (!$this->productCategoriesScheduledForDeletion->isEmpty()) { \ProductCategoryQuery::create() @@ -1352,6 +1400,248 @@ abstract class Category implements ActiveRecordInterface } /** + * Clears out the collProducts collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addProducts() + */ + public function clearProducts() + { + $this->collProducts = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Initializes the collProducts crossRef 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 ObjectCollection(); + $this->collProductsPartial = true; + + $this->collProducts->setModel('\Product'); + } + + /** + * Checks if the collProducts collection is loaded. + * + * @return bool + */ + public function isProductsLoaded() + { + return null !== $this->collProducts; + } + + /** + * Gets a collection of ChildProduct 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 ChildCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildProduct[] List of ChildProduct objects + */ + public function getProducts(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collProductsPartial && !$this->isNew(); + if (null === $this->collProducts || null !== $criteria || $partial) { + if ($this->isNew()) { + // return empty collection + if (null === $this->collProducts) { + $this->initProducts(); + } + } else { + + $query = ChildProductQuery::create(null, $criteria) + ->filterByCategory($this); + $collProducts = $query->find($con); + if (null !== $criteria) { + return $collProducts; + } + + if ($partial && $this->collProducts) { + //make sure that already added objects gets added to the list of the database. + foreach ($this->collProducts as $obj) { + if (!$collProducts->contains($obj)) { + $collProducts[] = $obj; + } + } + } + + $this->collProducts = $collProducts; + $this->collProductsPartial = false; + } + } + + 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 Collection $products A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function setProducts(Collection $products, ConnectionInterface $con = null) + { + $this->clearProducts(); + $currentProducts = $this->getProducts(); + + $productsScheduledForDeletion = $currentProducts->diff($products); + + foreach ($productsScheduledForDeletion as $toDelete) { + $this->removeProduct($toDelete); + } + + foreach ($products as $product) { + if (!$currentProducts->contains($product)) { + $this->doAddProduct($product); + } + } + + $this->collProductsPartial = false; + $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 ConnectionInterface $con Optional connection object + * + * @return int the number of related Product objects + */ + public function countProducts(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collProductsPartial && !$this->isNew(); + if (null === $this->collProducts || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collProducts) { + return 0; + } else { + + if ($partial && !$criteria) { + return count($this->getProducts()); + } + + $query = ChildProductQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + } else { + return count($this->collProducts); + } + } + + /** + * Associate a ChildProduct to this object + * through the product_category cross reference table. + * + * @param ChildProduct $product + * @return ChildCategory The current object (for fluent API support) + */ + public function addProduct(ChildProduct $product) + { + if ($this->collProducts === null) { + $this->initProducts(); + } + + if (!$this->getProducts()->contains($product)) { + // only add it if the **same** object is not already associated + $this->collProducts->push($product); + $this->doAddProduct($product); + } + + return $this; + } + + /** + * + * @param ChildProduct $product + */ + protected function doAddProduct(ChildProduct $product) + { + $productCategory = new ChildProductCategory(); + + $productCategory->setProduct($product); + + $productCategory->setCategory($this); + + $this->addProductCategory($productCategory); + + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$product->isCategoriesLoaded()) { + $product->initCategories(); + $product->getCategories()->push($this); + } elseif (!$product->getCategories()->contains($this)) { + $product->getCategories()->push($this); + } + + } + + /** + * Remove product of this object + * through the product_category cross reference table. + * + * @param ChildProduct $product + * @return ChildCategory The current object (for fluent API support) + */ + public function removeProduct(ChildProduct $product) + { + if ($this->getProducts()->contains($product)) { $productCategory = new ChildProductCategory(); + + $productCategory->setProduct($product); + if ($product->isCategoriesLoaded()) { + //remove the back reference if available + $product->getCategories()->removeObject($this); + } + + $productCategory->setCategory($this); + $this->removeProductCategory(clone $productCategory); + $productCategory->clear(); + + $this->collProducts->remove($this->collProducts->search($product)); + + if (null === $this->productsScheduledForDeletion) { + $this->productsScheduledForDeletion = clone $this->collProducts; + $this->productsScheduledForDeletion->clear(); + } + + $this->productsScheduledForDeletion->push($product); + } + + + return $this; + } + + /** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). @@ -1384,9 +1674,15 @@ abstract class Category implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collProducts) { + foreach ($this->collProducts as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) $this->collProductCategories = null; + $this->collProducts = null; } /** diff --git a/Aufgabe06/generated-classes/Base/CategoryQuery.php b/Aufgabe06/generated-classes/Base/CategoryQuery.php index 46f1727..4711525 100644 --- a/Aufgabe06/generated-classes/Base/CategoryQuery.php +++ b/Aufgabe06/generated-classes/Base/CategoryQuery.php @@ -411,6 +411,23 @@ abstract class CategoryQuery extends ModelCriteria } /** + * 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 ChildCategoryQuery The current query, for fluid interface + */ + public function filterByProduct($product, $comparison = Criteria::EQUAL) + { + return $this + ->useProductCategoryQuery() + ->filterByProduct($product, $comparison) + ->endUse(); + } + + /** * Exclude object from result * * @param ChildCategory $category Object to remove from the list of results diff --git a/Aufgabe06/generated-classes/Base/Product.php b/Aufgabe06/generated-classes/Base/Product.php index 870e1c4..6bcf48d 100644 --- a/Aufgabe06/generated-classes/Base/Product.php +++ b/Aufgabe06/generated-classes/Base/Product.php @@ -2,6 +2,8 @@ namespace Base; +use \Category as ChildCategory; +use \CategoryQuery as ChildCategoryQuery; use \Product as ChildProduct; use \ProductCategory as ChildProductCategory; use \ProductCategoryQuery as ChildProductCategoryQuery; @@ -106,6 +108,16 @@ abstract class Product implements ActiveRecordInterface protected $collProductCategoriesPartial; /** + * @var ObjectCollection|ChildCategory[] Cross Collection to store aggregation of ChildCategory objects. + */ + protected $collCategories; + + /** + * @var bool + */ + protected $collCategoriesPartial; + + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. * @@ -115,6 +127,12 @@ abstract class Product implements ActiveRecordInterface /** * An array of objects scheduled for deletion. + * @var ObjectCollection|ChildCategory[] + */ + protected $categoriesScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. * @var ObjectCollection|ChildProductCategory[] */ protected $productCategoriesScheduledForDeletion = null; @@ -640,6 +658,7 @@ abstract class Product implements ActiveRecordInterface $this->collProductCategories = null; + $this->collCategories = null; } // if (deep) } @@ -750,6 +769,35 @@ abstract class Product implements ActiveRecordInterface $this->resetModified(); } + if ($this->categoriesScheduledForDeletion !== null) { + if (!$this->categoriesScheduledForDeletion->isEmpty()) { + $pks = array(); + foreach ($this->categoriesScheduledForDeletion as $entry) { + $entryPk = []; + + $entryPk[0] = $this->getId(); + $entryPk[1] = $entry->getId(); + $pks[] = $entryPk; + } + + \ProductCategoryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + + $this->categoriesScheduledForDeletion = null; + } + + } + + if ($this->collCategories) { + foreach ($this->collCategories as $category) { + if (!$category->isDeleted() && ($category->isNew() || $category->isModified())) { + $category->save($con); + } + } + } + + if ($this->productCategoriesScheduledForDeletion !== null) { if (!$this->productCategoriesScheduledForDeletion->isEmpty()) { \ProductCategoryQuery::create() @@ -1529,6 +1577,248 @@ abstract class Product implements ActiveRecordInterface } /** + * Clears out the collCategories collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCategories() + */ + public function clearCategories() + { + $this->collCategories = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Initializes the collCategories crossRef collection. + * + * By default this just sets the collCategories collection to an empty collection (like clearCategories()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @return void + */ + public function initCategories() + { + $this->collCategories = new ObjectCollection(); + $this->collCategoriesPartial = true; + + $this->collCategories->setModel('\Category'); + } + + /** + * Checks if the collCategories collection is loaded. + * + * @return bool + */ + public function isCategoriesLoaded() + { + return null !== $this->collCategories; + } + + /** + * Gets a collection of ChildCategory 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 ChildProduct is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildCategory[] List of ChildCategory objects + */ + public function getCategories(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCategoriesPartial && !$this->isNew(); + if (null === $this->collCategories || null !== $criteria || $partial) { + if ($this->isNew()) { + // return empty collection + if (null === $this->collCategories) { + $this->initCategories(); + } + } else { + + $query = ChildCategoryQuery::create(null, $criteria) + ->filterByProduct($this); + $collCategories = $query->find($con); + if (null !== $criteria) { + return $collCategories; + } + + if ($partial && $this->collCategories) { + //make sure that already added objects gets added to the list of the database. + foreach ($this->collCategories as $obj) { + if (!$collCategories->contains($obj)) { + $collCategories[] = $obj; + } + } + } + + $this->collCategories = $collCategories; + $this->collCategoriesPartial = false; + } + } + + return $this->collCategories; + } + + /** + * 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 Collection $categories A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildProduct The current object (for fluent API support) + */ + public function setCategories(Collection $categories, ConnectionInterface $con = null) + { + $this->clearCategories(); + $currentCategories = $this->getCategories(); + + $categoriesScheduledForDeletion = $currentCategories->diff($categories); + + foreach ($categoriesScheduledForDeletion as $toDelete) { + $this->removeCategory($toDelete); + } + + foreach ($categories as $category) { + if (!$currentCategories->contains($category)) { + $this->doAddCategory($category); + } + } + + $this->collCategoriesPartial = false; + $this->collCategories = $categories; + + 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 ConnectionInterface $con Optional connection object + * + * @return int the number of related Category objects + */ + public function countCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCategoriesPartial && !$this->isNew(); + if (null === $this->collCategories || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategories) { + return 0; + } else { + + if ($partial && !$criteria) { + return count($this->getCategories()); + } + + $query = ChildCategoryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByProduct($this) + ->count($con); + } + } else { + return count($this->collCategories); + } + } + + /** + * Associate a ChildCategory to this object + * through the product_category cross reference table. + * + * @param ChildCategory $category + * @return ChildProduct The current object (for fluent API support) + */ + public function addCategory(ChildCategory $category) + { + if ($this->collCategories === null) { + $this->initCategories(); + } + + if (!$this->getCategories()->contains($category)) { + // only add it if the **same** object is not already associated + $this->collCategories->push($category); + $this->doAddCategory($category); + } + + return $this; + } + + /** + * + * @param ChildCategory $category + */ + protected function doAddCategory(ChildCategory $category) + { + $productCategory = new ChildProductCategory(); + + $productCategory->setCategory($category); + + $productCategory->setProduct($this); + + $this->addProductCategory($productCategory); + + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$category->isProductsLoaded()) { + $category->initProducts(); + $category->getProducts()->push($this); + } elseif (!$category->getProducts()->contains($this)) { + $category->getProducts()->push($this); + } + + } + + /** + * Remove category of this object + * through the product_category cross reference table. + * + * @param ChildCategory $category + * @return ChildProduct The current object (for fluent API support) + */ + public function removeCategory(ChildCategory $category) + { + if ($this->getCategories()->contains($category)) { $productCategory = new ChildProductCategory(); + + $productCategory->setCategory($category); + if ($category->isProductsLoaded()) { + //remove the back reference if available + $category->getProducts()->removeObject($this); + } + + $productCategory->setProduct($this); + $this->removeProductCategory(clone $productCategory); + $productCategory->clear(); + + $this->collCategories->remove($this->collCategories->search($category)); + + if (null === $this->categoriesScheduledForDeletion) { + $this->categoriesScheduledForDeletion = clone $this->collCategories; + $this->categoriesScheduledForDeletion->clear(); + } + + $this->categoriesScheduledForDeletion->push($category); + } + + + return $this; + } + + /** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). @@ -1564,9 +1854,15 @@ abstract class Product implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCategories) { + foreach ($this->collCategories as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) $this->collProductCategories = null; + $this->collCategories = null; } /** diff --git a/Aufgabe06/generated-classes/Base/ProductQuery.php b/Aufgabe06/generated-classes/Base/ProductQuery.php index 84c59aa..0665619 100644 --- a/Aufgabe06/generated-classes/Base/ProductQuery.php +++ b/Aufgabe06/generated-classes/Base/ProductQuery.php @@ -549,6 +549,23 @@ abstract class ProductQuery extends ModelCriteria } /** + * 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 ChildProductQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = Criteria::EQUAL) + { + return $this + ->useProductCategoryQuery() + ->filterByCategory($category, $comparison) + ->endUse(); + } + + /** * Exclude object from result * * @param ChildProduct $product Object to remove from the list of results |
