diff options
Diffstat (limited to 'Aufgabe06/generated-classes/Base/Category.php')
| -rw-r--r-- | Aufgabe06/generated-classes/Base/Category.php | 296 |
1 files changed, 296 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; } /** |
