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(); }
public function preImport() { // Delete table before proceeding ProductQuery::create()->deleteAll(); CategoryQuery::create()->deleteAll(); FeatureTemplateQuery::create()->deleteAll(); AttributeTemplateQuery::create()->deleteAll(); TemplateQuery::create()->deleteAll(); CategoryImageQuery::create()->deleteAll(); CategoryDocumentQuery::create()->deleteAll(); CategoryAssociatedContentQuery::create()->deleteAll(); // Create T1 <-> T2 IDs correspondance tables $this->cat_corresp->reset(); $this->tpl_corresp->reset(); }
/** * 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 CategoryAssociatedContents 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|ChildCategoryAssociatedContent[] List of ChildCategoryAssociatedContent objects */ public function getCategoryAssociatedContentsJoinCategory($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildCategoryAssociatedContentQuery::create(null, $criteria); $query->joinWith('Category', $joinBehavior); return $this->getCategoryAssociatedContents($query, $con); }
public function getAvailableRelatedContentAction($categoryId, $folderId) { $result = array(); $folders = FolderQuery::create()->filterById($folderId)->find(); if ($folders !== null) { $list = ContentQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->filterByFolder($folders, Criteria::IN)->filterById(CategoryAssociatedContentQuery::create()->select('content_id')->findByCategoryId($categoryId), Criteria::NOT_IN)->find(); if ($list !== null) { foreach ($list as $item) { $result[] = array('id' => $item->getId(), 'title' => $item->getTitle()); } } } return $this->jsonResponse(json_encode($result)); }
$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(); Model\CustomerQuery::create()->deleteAll();
public function removeContent(CategoryDeleteContentEvent $event) { $content = CategoryAssociatedContentQuery::create()->filterByContentId($event->getContentId())->filterByCategory($event->getCategory())->findOne(); if ($content !== null) { $content->setDispatcher($event->getDispatcher())->delete(); } }
/** * Performs an INSERT on the database, given a CategoryAssociatedContent or Criteria object. * * @param mixed $criteria Criteria or CategoryAssociatedContent 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(CategoryAssociatedContentTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from CategoryAssociatedContent object } if ($criteria->containsKey(CategoryAssociatedContentTableMap::ID) && $criteria->keyContainsValue(CategoryAssociatedContentTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CategoryAssociatedContentTableMap::ID . ')'); } // Set the correct dbName $query = CategoryAssociatedContentQuery::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; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see CategoryAssociatedContent::setDeleted() * @see CategoryAssociatedContent::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(CategoryAssociatedContentTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildCategoryAssociatedContentQuery::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; } }