Beispiel #1
0
 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();
 }
Beispiel #2
0
 public function deleteAttribute(TemplateDeleteAttributeEvent $event)
 {
     $attribute_template = AttributeTemplateQuery::create()->filterByAttributeId($event->getAttributeId())->filterByTemplate($event->getTemplate())->findOne();
     if ($attribute_template !== null) {
         $attribute_template->delete();
     }
 }
 public function updateAttributePositionAction()
 {
     // Find attribute_template
     $attributeTemplate = AttributeTemplateQuery::create()->filterByTemplateId($this->getRequest()->get('template_id', null))->filterByAttributeId($this->getRequest()->get('attribute_id', null))->findOne();
     return $this->genericUpdatePositionAction($attributeTemplate, TheliaEvents::TEMPLATE_CHANGE_ATTRIBUTE_POSITION);
 }
Beispiel #4
0
 public function buildModelCriteria()
 {
     $search = AttributeQuery::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);
     }
     $product = $this->getProduct();
     $template = $this->getTemplate();
     $exclude_template = $this->getExcludeTemplate();
     $this->useAttributePosistion = 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(AttributeTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN);
         $this->useAttributePosistion = false;
     } elseif (null !== $exclude_template) {
         // Join with attribute_template table to get position
         $exclude_attributes = AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find();
         $search->joinAttributeTemplate(null, Criteria::LEFT_JOIN)->withColumn(AttributeTemplateTableMap::POSITION, 'position')->filterById($exclude_attributes, Criteria::NOT_IN);
         $this->useAttributePosistion = false;
     }
     $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->useAttributePosistion) {
                     $search->orderByPosition(Criteria::ASC);
                 } else {
                     $search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION);
                 }
                 break;
             case "manual_reverse":
                 if ($this->useAttributePosistion) {
                     $search->orderByPosition(Criteria::DESC);
                 } else {
                     $search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION);
                 }
                 break;
         }
     }
     return $search;
 }
Beispiel #5
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Template is new, it will return
  * an empty collection; or if this Template has previously
  * been saved, it will retrieve related AttributeTemplates 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 Template.
  *
  * @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|ChildAttributeTemplate[] List of ChildAttributeTemplate objects
  */
 public function getAttributeTemplatesJoinAttribute($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildAttributeTemplateQuery::create(null, $criteria);
     $query->joinWith('Attribute', $joinBehavior);
     return $this->getAttributeTemplates($query, $con);
 }
 /**
  * Performs an INSERT on the database, given a AttributeTemplate or Criteria object.
  *
  * @param mixed               $criteria Criteria or AttributeTemplate 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(AttributeTemplateTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from AttributeTemplate object
     }
     if ($criteria->containsKey(AttributeTemplateTableMap::ID) && $criteria->keyContainsValue(AttributeTemplateTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeTemplateTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AttributeTemplateQuery::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 #7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see AttributeTemplate::setDeleted()
  * @see AttributeTemplate::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(AttributeTemplateTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAttributeTemplateQuery::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;
     }
 }
Beispiel #8
0
 public function removeFromAllTemplates(AttributeEvent $event)
 {
     // Delete this attribute from all product templates
     AttributeTemplateQuery::create()->filterByAttribute($event->getAttribute())->delete();
 }