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(); }
public function deleteFeature(TemplateDeleteFeatureEvent $event) { $feature_template = FeatureTemplateQuery::create()->filterByFeatureId($event->getFeatureId())->filterByTemplate($event->getTemplate())->findOne(); if ($feature_template !== null) { $feature_template->delete(); } }
public function buildModelCriteria() { $search = FeatureQuery::create(); /* manage translations */ $this->configureI18nProcessing($search); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $exclude = $this->getExclude(); if (null !== $exclude) { $search->filterById($exclude, Criteria::NOT_IN); } $visible = $this->getVisible(); if ($visible != BooleanOrBothType::ANY) { $search->filterByVisible($visible); } $product = $this->getProduct(); $template = $this->getTemplate(); $exclude_template = $this->getExcludeTemplate(); $this->useFeaturePosition = true; if (null !== $product) { // Find all template assigned to the products. $products = ProductQuery::create()->findById($product); // Ignore if the product cannot be found. if ($products !== null) { // Create template array if ($template == null) { $template = array(); } foreach ($products as $product) { $tpl_id = $product->getTemplateId(); if (!is_null($tpl_id)) { $template[] = $tpl_id; } } } // franck@cqfdev.fr - 05/12/2013 : if the given product has no template // or if the product cannot be found, do not return anything. if (empty($template)) { return null; } } if (!empty($template)) { // Join with feature_template table to get position $search->withColumn(FeatureTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN); $this->useFeaturePosition = false; } if (null !== $exclude_template) { $exclude_features = FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find(); $search->filterById($exclude_features, Criteria::NOT_IN); } $title = $this->getTitle(); if (null !== $title) { //find all feature that match exactly this title and find with all locales. $features = FeatureI18nQuery::create()->filterByTitle($title, Criteria::LIKE)->select('id')->find(); if ($features) { $search->filterById($features, Criteria::IN); } } $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case "id": $search->orderById(Criteria::ASC); break; case "id_reverse": $search->orderById(Criteria::DESC); break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha-reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual": if ($this->useFeaturePosition) { $search->orderByPosition(Criteria::ASC); } else { $search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION); } break; case "manual_reverse": if ($this->useFeaturePosition) { $search->orderByPosition(Criteria::DESC); } else { $search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION); } break; } } return $search; }
/** * Performs an INSERT on the database, given a FeatureTemplate or Criteria object. * * @param mixed $criteria Criteria or FeatureTemplate 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(FeatureTemplateTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from FeatureTemplate object } if ($criteria->containsKey(FeatureTemplateTableMap::ID) && $criteria->keyContainsValue(FeatureTemplateTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureTemplateTableMap::ID . ')'); } // Set the correct dbName $query = FeatureTemplateQuery::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; }
public function removeFromAllTemplates(FeatureEvent $event) { // Delete this feature from all product templates FeatureTemplateQuery::create()->filterByFeature($event->getFeature())->delete(); }
/** * Update product attributes and features */ public function updateAttributesAndFeaturesAction($productId) { $product = ProductQuery::create()->findPk($productId); if ($product != null) { $featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($product->getTemplateId())->find(); if ($featureTemplate !== null) { // Get all features for the template attached to this product $allFeatures = FeatureQuery::create()->filterByFeatureTemplate($featureTemplate)->find(); $updatedFeatures = array(); // Update all features values, starting with feature av. values $featureValues = $this->getRequest()->get('feature_value', array()); foreach ($featureValues as $featureId => $featureValueList) { // Delete all features av. for this feature. $event = new FeatureProductDeleteEvent($productId, $featureId); $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event); // Add then all selected values foreach ($featureValueList as $featureValue) { $event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue); $this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event); } $updatedFeatures[] = $featureId; } // Update then features text values $featureTextValues = $this->getRequest()->get('feature_text_value', array()); foreach ($featureTextValues as $featureId => $featureValue) { // Check if a FeatureProduct exists for this product and this feature (for another lang) $freeTextFeatureProduct = FeatureProductQuery::create()->filterByProductId($productId)->filterByFreeTextValue(true)->findOneByFeatureId($featureId); // If no corresponding FeatureProduct exists AND if the feature_text_value is empty, do nothing if (is_null($freeTextFeatureProduct) && empty($featureValue)) { continue; } $event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue, true); $event->setLocale($this->getCurrentEditionLocale()); $this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event); $updatedFeatures[] = $featureId; } // Delete features which don't have any values /** @var Feature $feature */ foreach ($allFeatures as $feature) { if (!in_array($feature->getId(), $updatedFeatures)) { $event = new FeatureProductDeleteEvent($productId, $feature->getId()); $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event); } } } } // If we have to stay on the same page, do not redirect to the successUrl, // just redirect to the edit page again. if ($this->getRequest()->get('save_mode') == 'stay') { return $this->redirectToEditionTemplate($this->getRequest()); } // Redirect to the category/product list return $this->redirectToListTemplate(); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Feature is new, it will return * an empty collection; or if this Feature has previously * been saved, it will retrieve related FeatureTemplates 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 Feature. * * @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|ChildFeatureTemplate[] List of ChildFeatureTemplate objects */ public function getFeatureTemplatesJoinTemplate($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildFeatureTemplateQuery::create(null, $criteria); $query->joinWith('Template', $joinBehavior); return $this->getFeatureTemplates($query, $con); }
public function updateFeaturePositionAction() { // Find feature_template $featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($this->getRequest()->get('template_id', null))->filterByFeatureId($this->getRequest()->get('feature_id', null))->findOne(); return $this->genericUpdatePositionAction($featureTemplate, TheliaEvents::TEMPLATE_CHANGE_FEATURE_POSITION); }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see FeatureTemplate::setDeleted() * @see FeatureTemplate::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(FeatureTemplateTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildFeatureTemplateQuery::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; } }