public function buildModelCriteria() { $product = $this->getProduct(); $category = $this->getCategory(); if ($product === null && $category === null) { throw new \InvalidArgumentException('You have to provide either `product` or `category` argument in associated_content loop'); } if ($product !== null) { /** @var ProductAssociatedContentQuery $search */ $search = ProductAssociatedContentQuery::create(); $search->filterByProductId($product, Criteria::EQUAL); } elseif ($category !== null) { /** @var CategoryAssociatedContentQuery $search */ $search = CategoryAssociatedContentQuery::create(); $search->filterByCategoryId($category, Criteria::EQUAL); } $excludeProduct = $this->getExcludeProduct(); // If we have to filter by product, find all products assigned to this product, and filter by found IDs if (null !== $excludeProduct) { // Exclude all contents related to the given product $search->filterById(ProductAssociatedContentQuery::create()->filterByProductId($excludeProduct)->select('product_id')->find(), Criteria::NOT_IN); } $excludeCategory = $this->getExcludeCategory(); // If we have to filter by category, find all contents assigned to this category, and filter by found IDs if (null !== $excludeCategory) { // Exclure tous les attribut qui sont attachés aux templates indiqués $search->filterById(CategoryAssociatedContentQuery::create()->filterByProductId($excludeCategory)->select('category_id')->find(), Criteria::NOT_IN); } $order = $this->getOrder(); $orderByAssociatedContent = array_search('associated_content', $order); $orderByAssociatedContentReverse = array_search('associated_content_reverse', $order); if ($orderByAssociatedContent !== false) { $search->orderByPosition(Criteria::ASC); $order[$orderByAssociatedContent] = 'given_id'; $this->args->get('order')->setValue(implode(',', $order)); } if ($orderByAssociatedContentReverse !== false) { $search->orderByPosition(Criteria::DESC); $order[$orderByAssociatedContentReverse] = 'given_id'; $this->args->get('order')->setValue(implode(',', $order)); } $associatedContents = $this->search($search); $associatedContentIdList = array(0); $this->contentPosition = $this->contentId = array(); foreach ($associatedContents as $associatedContent) { $associatedContentId = $associatedContent->getContentId(); array_push($associatedContentIdList, $associatedContentId); $this->contentPosition[$associatedContentId] = $associatedContent->getPosition(); $this->contentId[$associatedContentId] = $associatedContent->getId(); } $receivedIdList = $this->getId(); /* if an Id list is receive, loop will only match accessories from this list */ if ($receivedIdList === null) { $this->args->get('id')->setValue(implode(',', $associatedContentIdList)); } else { $this->args->get('id')->setValue(implode(',', array_intersect($receivedIdList, $associatedContentIdList))); } return parent::buildModelCriteria(); }
/** * @param Lang $lang * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria */ public function buildDataSet(Lang $lang) { $locale = $this->locale = $lang->getLocale(); /** * Join objects */ $urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); $productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN); $query = ProductAssociatedContentQuery::create()->useProductQuery()->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_REF", ProductTableMap::REF)->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)->addAsColumn("product_seo_TITLE", ProductI18nTableMap::META_TITLE)->addAsColumn("product_seo_META_DESCRIPTION", ProductI18nTableMap::META_DESCRIPTION)->addAsColumn("product_seo_META_KEYWORDS", ProductI18nTableMap::META_KEYWORDS)->endUse()->addJoinObject($urlJoin, "rewriting_url_join")->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW . " = ?", (new Product())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", "ISNULL(" . RewritingUrlTableMap::REDIRECTED . ")")->addAsColumn("product_URL", RewritingUrlTableMap::URL)->select(["product_REF", "product_VISIBLE", "product_i18n_TITLE", "product_URL", "product_seo_TITLE", "product_seo_META_DESCRIPTION", "product_seo_META_KEYWORDS"]); return $query; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Content is new, it will return * an empty collection; or if this Content has previously * been saved, it will retrieve related ProductAssociatedContents from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Content. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return Collection|ChildProductAssociatedContent[] List of ChildProductAssociatedContent objects */ public function getProductAssociatedContentsJoinProduct($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildProductAssociatedContentQuery::create(null, $criteria); $query->joinWith('Product', $joinBehavior); return $this->getProductAssociatedContents($query, $con); }
/** * Performs an INSERT on the database, given a ProductAssociatedContent or Criteria object. * * @param mixed $criteria Criteria or ProductAssociatedContent object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(ProductAssociatedContentTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ProductAssociatedContent object } if ($criteria->containsKey(ProductAssociatedContentTableMap::ID) && $criteria->keyContainsValue(ProductAssociatedContentTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductAssociatedContentTableMap::ID . ')'); } // Set the correct dbName $query = ProductAssociatedContentQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
// Create localized version for content generation $localizedFaker = []; foreach ($localeList as $locale) { $localizedFaker[$locale] = Faker\Factory::create($locale); } $con = \Propel\Runtime\Propel::getConnection(Thelia\Model\Map\ProductTableMap::DATABASE_NAME); $con->beginTransaction(); // Intialize URL management $url = new Thelia\Tools\URL(); $currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne(); //\Thelia\Log\Tlog::getInstance()->setLevel(\Thelia\Log\Tlog::ERROR); try { $stmt = $con->prepare("SET foreign_key_checks = 0"); $stmt->execute(); echo "Clearing tables\n"; Model\ProductAssociatedContentQuery::create()->deleteAll(); Model\CategoryAssociatedContentQuery::create()->deleteAll(); Model\FeatureProductQuery::create()->deleteAll(); Model\AttributeCombinationQuery::create()->deleteAll(); Model\FeatureQuery::create()->deleteAll(); Model\FeatureI18nQuery::create()->deleteAll(); Model\FeatureAvQuery::create()->deleteAll(); Model\FeatureAvI18nQuery::create()->deleteAll(); Model\AttributeQuery::create()->deleteAll(); Model\AttributeI18nQuery::create()->deleteAll(); Model\AttributeAvQuery::create()->deleteAll(); Model\AttributeAvI18nQuery::create()->deleteAll(); Model\CategoryQuery::create()->deleteAll(); Model\CategoryI18nQuery::create()->deleteAll(); Model\ProductQuery::create()->deleteAll(); Model\ProductI18nQuery::create()->deleteAll();
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ProductAssociatedContent::setDeleted() * @see ProductAssociatedContent::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(ProductAssociatedContentTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildProductAssociatedContentQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Update related content position */ public function updateContentPositionAction() { $content = ProductAssociatedContentQuery::create()->findPk($this->getRequest()->get('content_id', null)); return $this->genericUpdatePositionAction($content, TheliaEvents::PRODUCT_UPDATE_CONTENT_POSITION); }
/** * @depends testCloneFeatureCombination * @param ProductCloneEvent $event * @return ProductCloneEvent */ public function testCloneAssociatedContent(ProductCloneEvent $event) { // Call function to test $action = new Product(); $action->cloneAssociatedContent($event); // Get products' associated contents $originalProductAssocConts = ProductAssociatedContentQuery::create()->findByProductId($event->getOriginalProduct()->getId()); $cloneProductAssocConts = ProductAssociatedContentQuery::create()->filterByProductId($event->getClonedProduct()->getId())->count(); $this->assertEquals(count($originalProductAssocConts), $cloneProductAssocConts, 'There must be the same quantity of associated contents'); // Check clone product's associated contents foreach ($originalProductAssocConts as $originalProductAssocCont) { $cloneProductAssocCont = ProductAssociatedContentQuery::create()->filterByProductId($event->getClonedProduct()->getId())->filterByPosition($originalProductAssocCont->getPosition())->findOneByContentId($originalProductAssocCont->getContentId()); $this->assertInstanceOf('Thelia\\Model\\ProductAssociatedContent', $cloneProductAssocCont, 'Instance of clone product associated content must be Thelia\\Model\\ProductAssociatedContent'); $this->assertEquals($event->getClonedProduct()->getId(), $cloneProductAssocCont->getProductId(), 'ProductID must be equal'); $this->assertEquals($originalProductAssocCont->getContentId(), $cloneProductAssocCont->getContentId(), 'ContentID must be equal'); $this->assertEquals($originalProductAssocCont->getPosition(), $cloneProductAssocCont->getPosition(), 'Position must be equal'); } return $event; }
/** * Changes position, selecting absolute ou relative change. * * @param ProductChangePositionEvent $event */ public function updateContentPosition(UpdatePositionEvent $event) { return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event); }
/** * Changes position, selecting absolute ou relative change. * * @param UpdatePositionEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher * @return Object */ public function updateContentPosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher) { return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event, $dispatcher); }