Пример #1
0
 /**
  * @param string $xml
  * @param bool $refreshCache
  * @param bool $importOnlyActivePluginPrefix
  * @param bool $updateValues
  * @return bool
  */
 public function importPrefix($xml, $refreshCache = false, $importOnlyActivePluginPrefix = false, $updateValues = false)
 {
     if (false === ($prefixesXml = $xml->xpath("/prefix"))) {
         return false;
     }
     $languageTag = (string) $prefixesXml[0]->attributes()->language_tag;
     $prefixName = strval($prefixesXml[0]->attributes()->name);
     if ($importOnlyActivePluginPrefix && !in_array($prefixName, $this->getExceptionPrefixes())) {
         $plugin = BOL_PluginService::getInstance()->findPluginByKey($prefixName);
         if (empty($plugin)) {
             return false;
         }
     }
     if (null === ($language = $this->findByTag($languageTag))) {
         $language = new BOL_Language();
         $language->setTag($languageTag)->setLabel((string) $prefixesXml[0]->attributes()->language_label)->setOrder($this->findMaxOrder() + 1)->setStatus('inactive');
         $language->setRtl((string) $prefixesXml[0]->attributes()->language_rtl);
         $this->save($language);
     }
     if (null === ($prefix = $this->findPrefix($prefixName))) {
         $prefix = new BOL_LanguagePrefix();
         $prefix->setPrefix($prefixName)->setLabel(strval($prefixesXml[0]->attributes()->label));
         $this->savePrefix($prefix);
     }
     $keysXml = $prefixesXml[0]->xpath('child::key');
     foreach ($keysXml as $keyXml) {
         if (null === ($key = $this->findKey((string) $prefixesXml[0]->attributes()->name, (string) $keyXml->attributes()->name))) {
             $key = new BOL_LanguageKey();
             $key->setKey((string) $keyXml->attributes()->name);
             $key->setPrefixId($prefix->getId());
             $this->saveKey($key);
         }
         $valueDto = $this->findValue($language->getId(), $key->getId());
         if ($valueDto !== null && !$updateValues) {
             continue;
         }
         if ($valueDto === null) {
             $valueDto = new BOL_LanguageValue();
             $valueDto->setLanguageId($language->getId());
             $valueDto->setKeyId($key->getId());
         }
         $valueDto->setValue((string) $keyXml->value);
         $this->saveValue($valueDto, false);
     }
     if ($refreshCache) {
         $this->generateCache($language->getId());
     }
 }
Пример #2
0
 public function importPrefix($xml, $refreshCache = false)
 {
     if (false === ($prefixesXml = $xml->xpath("/prefix"))) {
         return false;
     }
     $service = $this;
     $languageTag = (string) $prefixesXml[0]->attributes()->language_tag;
     if (null === ($language = $service->findByTag($languageTag))) {
         $language = new BOL_Language();
         $language->setTag($languageTag)->setLabel((string) $prefixesXml[0]->attributes()->language_label)->setOrder($service->findMaxOrder() + 1)->setStatus('inactive');
         $language->setRtl((string) $prefixesXml[0]->attributes()->language_rtl);
         $service->save($language);
     }
     if (null === ($prefix = $service->findPrefix((string) $prefixesXml[0]->attributes()->name))) {
         $prefix = new BOL_LanguagePrefix();
         $prefix->setPrefix(strval($prefixesXml[0]->attributes()->name))->setLabel(strval($prefixesXml[0]->attributes()->label));
         $service->savePrefix($prefix);
     }
     $keysXml = $prefixesXml[0]->xpath('child::key');
     foreach ($keysXml as $keyXml) {
         if (null === ($key = $service->findKey((string) $prefixesXml[0]->attributes()->name, (string) $keyXml->attributes()->name))) {
             $key = new BOL_LanguageKey();
             $key->setKey((string) $keyXml->attributes()->name)->setPrefixId($prefix->getId());
             $service->saveKey($key);
         }
         if (null === ($value = $service->findValue($language->getId(), $key->getId()))) {
             $value = new BOL_LanguageValue();
             $value->setLanguageId($language->getId())->setKeyId($key->getId())->setValue((string) $keyXml->value);
             $service->saveValue($value, false);
         }
         if ($refreshCache) {
             $this->generateCache($language->getId());
         }
     }
 }