コード例 #1
0
 protected function getExistingObject()
 {
     $featureAv = FeatureAvQuery::create()->findOneById($this->getRequest()->get('featureav_id', 0));
     if (null !== $featureAv) {
         $featureAv->setLocale($this->getCurrentEditionLocale());
     }
     return $featureAv;
 }
コード例 #2
0
ファイル: FeaturesImport.php プロジェクト: JumBay/ImportT1
 public function preImport()
 {
     FeatureQuery::create()->deleteAll();
     FeatureAvQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->feat_corresp = new CorrespondanceTable(CorrespondanceTable::FEATURES, $this->t1db);
     $this->feat_corresp->reset();
     $this->feat_av_corresp = new CorrespondanceTable(CorrespondanceTable::FEATURES_AV, $this->t1db);
     $this->feat_av_corresp->reset();
 }
コード例 #3
0
 public function buildModelCriteria()
 {
     $search = FeatureAvQuery::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);
     }
     $feature = $this->getFeature();
     if (null !== $feature) {
         $search->filterByFeatureId($feature, Criteria::IN);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha-reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "manual_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     // We do not consider here Free Text values, so be sure that the features values we will get
     // are not free text ones, e.g. are not defined as free-text feature values in the
     // feature_product table.
     // We are doig here something like
     //    SELECT * FROM `feature_av`
     //    WHERE feature_av.FEATURE_ID IN ('7')
     //    AND feature_av.ID not in (
     //        select feature_av_id from feature_product
     //        where feature_id = `feature_av`.feature_id
     //        and feature_av_id = `feature_av`.id
     //        and free_text_value = 1
     //    )
     $search->where(FeatureAvTableMap::ID . ' NOT IN (
          SELECT ' . FeatureProductTableMap::FEATURE_AV_ID . ' 
          FROM ' . FeatureProductTableMap::TABLE_NAME . '
          WHERE ' . FeatureProductTableMap::FREE_TEXT_VALUE . ' = 1
     )');
     return $search;
 }
コード例 #4
0
 public function buildModelCriteria()
 {
     $search = FeatureAvQuery::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);
     }
     $feature = $this->getFeature();
     if (null !== $feature) {
         $search->filterByFeatureId($feature, Criteria::IN);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha-reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "manual_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
コード例 #5
0
ファイル: FeatureAv.php プロジェクト: vigourouxjulien/thelia
 /**
  * Changes position, selecting absolute ou relative change.
  *
  * @param UpdatePositionEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $this->genericUpdatePosition(FeatureAvQuery::create(), $event, $dispatcher);
 }
コード例 #6
0
ファイル: FeatureAv.php プロジェクト: margery/thelia
 /**
  * Changes position, selecting absolute ou relative change.
  *
  * @param UpdatePositionEvent $event
  */
 public function updatePosition(UpdatePositionEvent $event)
 {
     $this->genericUpdatePosition(FeatureAvQuery::create(), $event);
 }
コード例 #7
0
ファイル: FeatureAvI18n.php プロジェクト: margery/thelia
 /**
  * Get the associated ChildFeatureAv object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildFeatureAv The associated ChildFeatureAv object.
  * @throws PropelException
  */
 public function getFeatureAv(ConnectionInterface $con = null)
 {
     if ($this->aFeatureAv === null && $this->id !== null) {
         $this->aFeatureAv = ChildFeatureAvQuery::create()->findPk($this->id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aFeatureAv->addFeatureAvI18ns($this);
            */
     }
     return $this->aFeatureAv;
 }
コード例 #8
0
ファイル: faker.php プロジェクト: hadesain/thelia
$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();
    Model\ContentI18nQuery::create()->deleteAll();
コード例 #9
0
ファイル: Feature.php プロジェクト: margery/thelia
 /**
  * Returns the number of related FeatureAv objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related FeatureAv objects.
  * @throws PropelException
  */
 public function countFeatureAvs(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collFeatureAvsPartial && !$this->isNew();
     if (null === $this->collFeatureAvs || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collFeatureAvs) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getFeatureAvs());
         }
         $query = ChildFeatureAvQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByFeature($this)->count($con);
     }
     return count($this->collFeatureAvs);
 }
コード例 #10
0
ファイル: Product.php プロジェクト: savvagee/thelia
 /**
  * Update the value of a product feature.
  *
  * @param FeatureProductUpdateEvent $event
  */
 public function updateFeatureProductValue(FeatureProductUpdateEvent $event)
 {
     // Prepare the FeatureAv's ID
     $featureAvId = $event->getFeatureValue();
     // Search for existing FeatureProduct
     $featureProductQuery = FeatureProductQuery::create()->filterByProductId($event->getProductId())->filterByFeatureId($event->getFeatureId());
     // If it's not a free text value, we can filter by the event's featureValue (which is an ID)
     if ($event->getFeatureValue() !== null && $event->getIsTextValue() === false) {
         $featureProductQuery->filterByFeatureAvId($featureAvId);
     }
     $featureProduct = $featureProductQuery->findOne();
     // If the FeatureProduct does not exist, create it
     if ($featureProduct === null) {
         $featureProduct = new FeatureProduct();
         $featureProduct->setDispatcher($event->getDispatcher())->setProductId($event->getProductId())->setFeatureId($event->getFeatureId());
         // If it's a free text value, create a FeatureAv to handle i18n
         if ($event->getIsTextValue() === true) {
             $featureProduct->setFreeTextValue(true);
             $createFeatureAvEvent = new FeatureAvCreateEvent();
             $createFeatureAvEvent->setFeatureId($event->getFeatureId())->setLocale($event->getLocale())->setTitle($event->getFeatureValue());
             $event->getDispatcher()->dispatch(TheliaEvents::FEATURE_AV_CREATE, $createFeatureAvEvent);
             $featureAvId = $createFeatureAvEvent->getFeatureAv()->getId();
         }
     } elseif ($featureProduct !== null && $event->getIsTextValue() === true) {
         // Get the FeatureAv
         $freeTextFeatureAv = FeatureAvQuery::create()->filterByFeatureProduct($featureProduct)->findOneByFeatureId($event->getFeatureId());
         // Get the FeatureAvI18n by locale
         $freeTextFeatureAvI18n = FeatureAvI18nQuery::create()->filterById($freeTextFeatureAv->getId())->findOneByLocale($event->getLocale());
         // Nothing found for this lang and the new value is not empty : create FeatureAvI18n
         if ($freeTextFeatureAvI18n === null && !empty($featureAvId)) {
             $featureAvI18n = new FeatureAvI18n();
             $featureAvI18n->setId($freeTextFeatureAv->getId())->setLocale($event->getLocale())->setTitle($event->getFeatureValue())->save();
             $featureAvId = $featureAvI18n->getId();
         } elseif ($freeTextFeatureAvI18n !== null && empty($featureAvId)) {
             $freeTextFeatureAvI18n->delete();
             // Check if there are still some FeatureAvI18n for this FeatureAv
             $freeTextFeatureAvI18ns = FeatureAvI18nQuery::create()->findById($freeTextFeatureAv->getId());
             // If there are no more FeatureAvI18ns for this FeatureAv, remove the corresponding FeatureProduct & FeatureAv
             if (count($freeTextFeatureAvI18ns) == 0) {
                 $deleteFeatureProductEvent = new FeatureProductDeleteEvent($event->getProductId(), $event->getFeatureId());
                 $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $deleteFeatureProductEvent);
                 $deleteFeatureAvEvent = new FeatureAvDeleteEvent($freeTextFeatureAv->getId());
                 $event->getDispatcher()->dispatch(TheliaEvents::FEATURE_AV_DELETE, $deleteFeatureAvEvent);
                 return;
             }
         } elseif ($freeTextFeatureAvI18n !== null && !empty($featureAvId)) {
             $freeTextFeatureAvI18n->setTitle($featureAvId);
             $freeTextFeatureAvI18n->save();
             $featureAvId = $freeTextFeatureAvI18n->getId();
         }
     } else {
         $featureAvId = $event->getFeatureValue();
     }
     $featureProduct->setFeatureAvId($featureAvId);
     $featureProduct->save();
     $event->setFeatureProduct($featureProduct);
 }
コード例 #11
0
ファイル: FeatureAvTableMap.php プロジェクト: margery/thelia
 /**
  * Performs an INSERT on the database, given a FeatureAv or Criteria object.
  *
  * @param mixed               $criteria Criteria or FeatureAv 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(FeatureAvTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from FeatureAv object
     }
     if ($criteria->containsKey(FeatureAvTableMap::ID) && $criteria->keyContainsValue(FeatureAvTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureAvTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = FeatureAvQuery::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;
 }
コード例 #12
0
ファイル: FeatureAv.php プロジェクト: margery/thelia
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see FeatureAv::setDeleted()
  * @see FeatureAv::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(FeatureAvTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildFeatureAvQuery::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;
     }
 }