Ejemplo n.º 1
0
 public function addAttribute(TemplateAddAttributeEvent $event)
 {
     if (null === AttributeTemplateQuery::create()->filterByAttributeId($event->getAttributeId())->filterByTemplate($event->getTemplate())->findOne()) {
         $attribute_template = new AttributeTemplate();
         $attribute_template->setAttributeId($event->getAttributeId())->setTemplate($event->getTemplate())->save();
     }
 }
Ejemplo n.º 2
0
 protected function doAddToAllTemplates(AttributeModel $attribute)
 {
     $templates = TemplateQuery::create()->find();
     foreach ($templates as $template) {
         $attribute_template = new AttributeTemplate();
         if (null === AttributeTemplateQuery::create()->filterByAttribute($attribute)->filterByTemplate($template)->findOne()) {
             $attribute_template->setAttribute($attribute)->setTemplate($template)->save();
         }
     }
 }
Ejemplo n.º 3
0
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from rubrique order by parent asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     /*
             $hdl = $this->t1db
                 ->query(
                     sprintf(
                         "select * from rubrique order by parent asc limit %d, %d",
                         intval($startRecord),
                         $this->getChunkSize()
                     )
                 );
     */
     $image_import = new CategoryImageImport($this->dispatcher, $this->t1db);
     $document_import = new CategoryDocumentImport($this->dispatcher, $this->t1db);
     while ($hdl && ($rubrique = $this->t1db->fetch_object($hdl))) {
         echo "r={$rubrique->id}";
         $count++;
         try {
             $this->cat_corresp->getT2($rubrique->id);
             Tlog::getInstance()->warning("Category ID={$rubrique->id} already imported.");
             continue;
         } catch (ImportException $ex) {
             // Okay, the category was not imported.
         }
         try {
             $event = new CategoryCreateEvent();
             $idx = 0;
             $descs = $this->t1db->query_list("select * from rubriquedesc where rubrique = ? order by lang asc", array($rubrique->id));
             foreach ($descs as $objdesc) {
                 $lang = $this->getT2Lang($objdesc->lang);
                 // A title is required to create the rewritten URL
                 if (empty($objdesc->titre)) {
                     $objdesc->titre = sprintf("Untitled-%d-%s", $objdesc->id, $lang->getCode());
                 }
                 $parent = $rubrique->parent > 0 ? $rubrique->parent + 1000000 : 0;
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setParent($parent)->setVisible($rubrique->ligne == 1 ? true : false);
                     $this->dispatcher->dispatch(TheliaEvents::CATEGORY_CREATE, $event);
                     $category_id = $event->getCategory()->getId();
                     // Update position
                     // ---------------
                     $update_position_event = new UpdatePositionEvent($category_id, UpdatePositionEvent::POSITION_ABSOLUTE, $rubrique->classement);
                     $this->dispatcher->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $update_position_event);
                     Tlog::getInstance()->info("Created category {$category_id} from {$objdesc->titre} ({$rubrique->id})");
                     $this->cat_corresp->addEntry($rubrique->id, $category_id);
                     // Create a product template if this categorie has declinaisons and/or caracteristiques
                     // ------------------------------------------------------------------------------------
                     $tpl_update = null;
                     $feature_list = $this->t1db->query_list("select caracteristique from rubcaracteristique where rubrique={$rubrique->id}");
                     $attribute_list = $this->t1db->query_list("select declinaison from rubdeclinaison where rubrique={$rubrique->id}");
                     if (!empty($attribute_list) || !empty($feature_list)) {
                         $tpl_create = new TemplateCreateEvent();
                         $tpl_create->setLocale($lang->getLocale())->setTemplateName($objdesc->titre . " (generated by import)");
                         $this->dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $tpl_create);
                         $tpl_id = $tpl_create->getTemplate()->getId();
                         $tpl_update = new TemplateUpdateEvent($tpl_id);
                         foreach ($attribute_list as $attr) {
                             try {
                                 $attribute_template = new AttributeTemplate();
                                 $id = $this->attr_corresp->getT2($attr->declinaison);
                                 $attribute_template->setAttributeId($id)->setTemplateId($tpl_id)->save();
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to create template attribute for T1 caractéristique {$attr->declinaison} : ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         foreach ($feature_list as $feat) {
                             try {
                                 $feature_template = new FeatureTemplate();
                                 $id = $this->feat_corresp->getT2($feat->caracteristique);
                                 $feature_template->setFeatureId($id)->setTemplateId($tpl_id)->save();
                             } catch (\Exception $ex) {
                                 Tlog::getInstance()->addError("Failed to create template feature for T1 declinaison {$feat->caracteristique} : ", $ex->getMessage());
                                 $errors++;
                             }
                         }
                         $this->tpl_corresp->addEntry($rubrique->id, $tpl_id);
                     }
                     // Import related content
                     // ----------------------
                     $contents = $this->t1db->query_list("select * from contenuassoc where objet=? and type=0 order by classement", array($rubrique->id));
                     // type: 1 = produit, 0=rubrique
                     foreach ($contents as $content) {
                         try {
                             $content_event = new CategoryAddContentEvent($event->getCategory(), $this->content_corresp->getT2($content->contenu));
                             $this->dispatcher->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $content_event);
                         } catch (\Exception $ex) {
                             Tlog::getInstance()->addError("Failed to create associated content {$content->contenu} for category {$category_id}: ", $ex->getMessage());
                             $errors++;
                         }
                     }
                     // Import images and documents
                     // ---------------------------
                     $image_import->importMedia($rubrique->id, $category_id);
                     $document_import->importMedia($rubrique->id, $category_id);
                 }
                 // Update the newly created category
                 $update_event = new CategoryUpdateEvent($category_id);
                 $update_event->setTitle($objdesc->titre)->setParent($parent)->setLocale($lang->getLocale())->setVisible($rubrique->ligne == 1 ? true : false)->setChapo($objdesc->chapo)->setDescription($objdesc->description)->setPostscriptum($objdesc->postscriptum);
                 $this->dispatcher->dispatch(TheliaEvents::CATEGORY_UPDATE, $update_event);
                 // Create a product template name in this language
                 // -----------------------------------------------
                 if ($tpl_update !== null) {
                     $tpl_update->setLocale($lang->getLocale())->setTemplateName($objdesc->titre . " (generated by import)");
                     $this->dispatcher->dispatch(TheliaEvents::TEMPLATE_UPDATE, $tpl_update);
                 }
                 // Update the rewritten URL
                 $this->updateRewrittenUrl($event->getCategory(), $lang->getLocale(), $objdesc->lang, "rubrique", "%id_rubrique={$rubrique->id}");
                 $idx++;
             }
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError("Failed to import category ID={$rubrique->id}: ", $ex->getMessage());
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }
Ejemplo n.º 4
0
 /**
  * @param    Attribute $attribute The attribute object to add.
  */
 protected function doAddAttribute($attribute)
 {
     $attributeTemplate = new ChildAttributeTemplate();
     $attributeTemplate->setAttribute($attribute);
     $this->addAttributeTemplate($attributeTemplate);
     // set the back reference to this object directly as using provided method either results
     // in endless loop or in multiple relations
     if (!$attribute->getTemplates()->contains($this)) {
         $foreignCollection = $attribute->getTemplates();
         $foreignCollection[] = $this;
     }
 }
Ejemplo n.º 5
0
 /**
  * Exclude object from result
  *
  * @param   ChildAttributeTemplate $attributeTemplate Object to remove from the list of results
  *
  * @return ChildAttributeTemplateQuery The current query, for fluid interface
  */
 public function prune($attributeTemplate = null)
 {
     if ($attributeTemplate) {
         $this->addUsingAlias(AttributeTemplateTableMap::ID, $attributeTemplate->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Filter the query by a related \Thelia\Model\AttributeTemplate object
  *
  * @param \Thelia\Model\AttributeTemplate|ObjectCollection $attributeTemplate  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildTemplateQuery The current query, for fluid interface
  */
 public function filterByAttributeTemplate($attributeTemplate, $comparison = null)
 {
     if ($attributeTemplate instanceof \Thelia\Model\AttributeTemplate) {
         return $this->addUsingAlias(TemplateTableMap::ID, $attributeTemplate->getTemplateId(), $comparison);
     } elseif ($attributeTemplate instanceof ObjectCollection) {
         return $this->useAttributeTemplateQuery()->filterByPrimaryKeys($attributeTemplate->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByAttributeTemplate() only accepts arguments of type \\Thelia\\Model\\AttributeTemplate or Collection');
     }
 }