/**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \Thelia\Model\FeatureAvI18n $obj A \Thelia\Model\FeatureAvI18n object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Beispiel #2
0
 /**
  * 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);
 }
Beispiel #3
0
 /**
  * Filter the query by a related \Thelia\Model\FeatureAvI18n object
  *
  * @param \Thelia\Model\FeatureAvI18n|ObjectCollection $featureAvI18n  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildFeatureAvQuery The current query, for fluid interface
  */
 public function filterByFeatureAvI18n($featureAvI18n, $comparison = null)
 {
     if ($featureAvI18n instanceof \Thelia\Model\FeatureAvI18n) {
         return $this->addUsingAlias(FeatureAvTableMap::ID, $featureAvI18n->getId(), $comparison);
     } elseif ($featureAvI18n instanceof ObjectCollection) {
         return $this->useFeatureAvI18nQuery()->filterByPrimaryKeys($featureAvI18n->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByFeatureAvI18n() only accepts arguments of type \\Thelia\\Model\\FeatureAvI18n or Collection');
     }
 }
Beispiel #4
0
 /**
  * Exclude object from result
  *
  * @param   ChildFeatureAvI18n $featureAvI18n Object to remove from the list of results
  *
  * @return ChildFeatureAvI18nQuery The current query, for fluid interface
  */
 public function prune($featureAvI18n = null)
 {
     if ($featureAvI18n) {
         $this->addCond('pruneCond0', $this->getAliasedColName(FeatureAvI18nTableMap::ID), $featureAvI18n->getId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(FeatureAvI18nTableMap::LOCALE), $featureAvI18n->getLocale(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Returns the current 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 ChildFeatureAvI18n */
 public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!isset($this->currentTranslations[$locale])) {
         if (null !== $this->collFeatureAvI18ns) {
             foreach ($this->collFeatureAvI18ns as $translation) {
                 if ($translation->getLocale() == $locale) {
                     $this->currentTranslations[$locale] = $translation;
                     return $translation;
                 }
             }
         }
         if ($this->isNew()) {
             $translation = new ChildFeatureAvI18n();
             $translation->setLocale($locale);
         } else {
             $translation = ChildFeatureAvI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->findOneOrCreate($con);
             $this->currentTranslations[$locale] = $translation;
         }
         $this->addFeatureAvI18n($translation);
     }
     return $this->currentTranslations[$locale];
 }