Beispiel #1
0
 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;
 }
Beispiel #2
0
$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();
    Model\AdminQuery::create()->deleteAll();
    Model\FolderQuery::create()->deleteAll();
    Model\FolderI18nQuery::create()->deleteAll();
    Model\ContentQuery::create()->deleteAll();
Beispiel #3
0
 /**
  * Performs an INSERT on the database, given a FeatureI18n or Criteria object.
  *
  * @param mixed               $criteria Criteria or FeatureI18n 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(FeatureI18nTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from FeatureI18n object
     }
     // Set the correct dbName
     $query = FeatureI18nQuery::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;
 }
Beispiel #4
0
 /**
  * Remove the translation for a given locale
  *
  * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
  * @param     ConnectionInterface $con an optional connection object
  *
  * @return    ChildFeature The current object (for fluent API support)
  */
 public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!$this->isNew()) {
         ChildFeatureI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->delete($con);
     }
     if (isset($this->currentTranslations[$locale])) {
         unset($this->currentTranslations[$locale]);
     }
     foreach ($this->collFeatureI18ns as $key => $translation) {
         if ($translation->getLocale() == $locale) {
             unset($this->collFeatureI18ns[$key]);
             break;
         }
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see FeatureI18n::setDeleted()
  * @see FeatureI18n::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(FeatureI18nTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildFeatureI18nQuery::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;
     }
 }