} } else { $object->setName($data); } break; case 'delete': if (!is_null($object->getLabel()) && $object->getLabel() !== $data) { unset($object); } break; default: // ... } } elseif ('insert' === $method) { $object = new \XLite\Model\LanguageLabel(); $object->setName($oldKey); $object->setLabel($data); } if (isset($object)) { $objects[$method][] = $object; } } } foreach ($objects as $method => $labels) { \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->{$method . 'InBatch'}($labels); } // Update config options $config = array('insert' => array(), 'update' => array('General' => array('decimal_delim' => array('Currency decimal separator', 'Decimal separator for float values'), 'redirect_to_cart' => array('Redirect customer to cart when adding a product', 'Redirect customer to the cart page after a product is added to cart'), 'shop_closed' => array('Check this to close the shop temporarily', 'Close the shop temporarily'), 'thousand_delim' => array('Currency thousands separator', 'Thousands separator for float values'))), 'delete' => array()); $objects = array(); foreach ($config as $method => $tmp) { foreach ($tmp as $category => $data) {
/** * Add label * * @return void */ protected function doActionAdd() { $name = substr(\XLite\Core\Request::getInstance()->name, 0, 255); $label = \XLite\Core\Request::getInstance()->label; $codeDefault = $codeInterface = static::getDefaultLanguage(); if (!$name) { \XLite\Core\TopMessage::addError('The text label has not been added, because its name has not been specified'); } elseif (\XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->findOneByName($name)) { \XLite\Core\TopMessage::addError('The text label has not been added, because such a text label already exists'); } elseif (!isset($label[$codeDefault]) || !$label[$codeDefault]) { \XLite\Core\TopMessage::addError('The text label has not been added, because its translation to the default application language has not been specified'); } elseif (!isset($label[$codeInterface]) || !$label[$codeInterface]) { \XLite\Core\TopMessage::addError('The text label has not been added, because its translation to the default interface language has not been specified'); } else { $lbl = new \XLite\Model\LanguageLabel(); $lbl->setName($name); foreach ($label as $code => $text) { if (!empty($text)) { $lbl->setEditLanguage($code)->setLabel($text); } } \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->insert($lbl); \XLite\Core\Translation::getInstance()->reset(); \XLite\Core\TopMessage::addInfo('The text label has been added successfully'); } }
/** * Update label with data from import rows * * @param array $rows Import data rows * * @return void */ protected function updateLanguageLabel($rows) { static $c; if (!isset($c)) { $c = 0; } $toDelete = array(); $toUpdate = array(); foreach ($rows as $row) { $c++; $log = array(); $log['code'] = $row[static::LNG_IMPORT_FIELD_CODE]; $log['name'] = $row[static::LNG_IMPORT_FIELD_NAME]; $log['action'] = ''; $log['counter'] = $c; // Find the label $label = \XLite\Core\Database::getRepo('XLite\\Model\\LanguageLabel')->findOneBy(array('name' => $row[static::LNG_IMPORT_FIELD_NAME])); if (!$label && !empty($row[static::LNG_IMPORT_FIELD_LABEL])) { $log['action'] = 'create label '; $label = new \XLite\Model\LanguageLabel(); $label->setName($row[static::LNG_IMPORT_FIELD_NAME]); \XLite\Core\Database::getRepo('XLite\\Model\\LanguageLabel')->insert($label); } elseif ($label && empty($row[static::LNG_IMPORT_FIELD_LABEL])) { $log['action'] = 'delete label'; $translation = $label->getTranslation($row[static::LNG_IMPORT_FIELD_CODE]); $toDelete[] = $translation; } if (!empty($row[static::LNG_IMPORT_FIELD_LABEL])) { $log['action'] .= 'update label'; $label->setEditLanguage($row[static::LNG_IMPORT_FIELD_CODE])->setLabel($row[static::LNG_IMPORT_FIELD_LABEL]); $toUpdate[] = $label; } // Uncomment the line below to log all import operations // \XLite\Logger::logCustom('lng_import', $log); } if ($toUpdate) { \XLite\Core\Database::getRepo('XLite\\Model\\LanguageLabel')->updateInBatch($toUpdate); } if ($toDelete) { \XLite\Core\Database::getRepo('XLite\\Model\\LanguageLabel')->deleteInBatch($toDelete); } }
/** * Add label * * @return void */ protected function doActionAdd() { $requestData = \XLite\Core\Request::getInstance()->getNonFilteredData(); $name = substr($requestData['name'], 0, 255); $label = $requestData['label']; if (!$name) { $this->valid = false; \XLite\Core\TopMessage::addError('The text label has not been added, because its name has not been specified'); } elseif (\XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->findOneByName($name)) { $this->valid = false; \XLite\Core\TopMessage::addError('The text label has not been added, because such a text label already exists'); } else { $lbl = new \XLite\Model\LanguageLabel(); $lbl->setName($name); foreach ($label as $code => $text) { if (!empty($text)) { $lbl->setEditLanguage($code)->setLabel($text); } } $lbl = \XLite\Core\Database::getRepo('\\XLite\\Model\\LanguageLabel')->insert($lbl); if ($lbl && $lbl->getLabelId()) { // Save added label ID in session $addedLabels = \XLite\Core\Session::getInstance()->added_labels; if (is_array($addedLabels)) { array_push($addedLabels, $lbl->getLabelId()); } else { $addedLabels = array($lbl->getLabelId()); } \XLite\Core\Session::getInstance()->added_labels = $addedLabels; $this->setHardRedirect(); } \XLite\Core\Translation::getInstance()->reset(); \XLite\Core\TopMessage::addInfo('The text label has been added successfully'); } }