Esempio n. 1
0
 public function actionTranslate()
 {
     if (!Yii::app()->request->isPostRequest) {
         throw new CHttpException(403, 'Forbidden');
     }
     if (empty($_POST) || !array_key_exists('form', $_POST) || !array_key_exists('text_id', $_POST['form']) || !array_key_exists('text_translate', $_POST['form']) || !is_array($_POST['form']['text_translate'])) {
         throw new CHttpException(403, 'Forbidden');
     }
     $text = Translate::model()->findByPk($_POST['form']['text_id']);
     if ($text == NULL) {
         throw new CHttpException(403, 'Forbidden');
     }
     $isChange = FALSE;
     $textTranslated = $_POST['form']['text_translate'];
     $langs = Langs::model()->findAll();
     foreach ($langs as $lang) {
         if (array_key_exists($lang->alias, $textTranslated)) {
             $translateLang = TranslateLang::model()->find('translate__id=:translate__id AND lang=:lang', array(':translate__id' => $text->id, ':lang' => $lang->alias));
             if ($translateLang == NULL) {
                 $translateLang = new TranslateLang();
                 $translateLang->translate__id = $text->id;
                 $translateLang->lang = $lang->alias;
             }
             if ($translateLang->translate != $textTranslated[$translateLang->lang]) {
                 $isChange = TRUE;
                 $translateLang->translate = $textTranslated[$translateLang->lang];
                 if (!$translateLang->save()) {
                     Yii::trace('TRANSLATE EDIT SAVE FATAL ERROR. CODE#1: ' . var_export($translateLang->getErrors(), TRUE));
                     throw new CException('Ошибка сохранения перевода', E_USER_ERROR);
                 }
             }
         }
     }
     if ((bool) $isChange) {
         if ($text->object_type == Translate::OBJECT_TYPE_STATIC_JAVASCRIPT) {
             Translate::fileRegenerateJavascript();
         } else {
             Translate::fileRegenerate();
         }
     }
     echo CJSON::encode(array('result' => $isChange, 'texts' => $textTranslated));
 }
Esempio n. 2
0
 public static function langRestore($id)
 {
     $deleteLang = self::model()->findByPk($id);
     if ($deleteLang == NULL) {
         Yii::app()->user->setFlash('error', 'Удаленный язык не найден');
         return FALSE;
     }
     if ((bool) $deleteLang->is_restored) {
         Yii::app()->user->setFlash('error', 'Удаленный язык уже восстановлен');
         return FALSE;
     }
     $langExist = Langs::model()->findByPk($deleteLang->lang__id);
     if ($langExist != NULL) {
         Yii::app()->user->setFlash('error', 'Удаленный язык уже восстановлен');
         return FALSE;
     }
     $langExist = Langs::model()->find('alias=:alias', array(':alias' => $deleteLang->alias));
     if ($langExist != NULL) {
         Yii::app()->user->setFlash('error', 'Язык с псевдонимом удаленного языка уже создан');
         return FALSE;
     }
     $restoreLang = new Langs();
     $restoreLang->id = $deleteLang->lang__id;
     $restoreLang->alias = $deleteLang->alias;
     $restoreLang->is_default = $deleteLang->is_default;
     $restoreLang->is_enabled = $deleteLang->is_enabled;
     $restoreLang->attachment__id_active = $deleteLang->attachment__id_active;
     $restoreLang->attachment__id_nonactive = $deleteLang->attachment__id_nonactive;
     $restoreLangLang = new LangsLang();
     $restoreLangLang->lang = Yii::app()->language;
     $restoreLangLang->langs__id = $deleteLang->lang__id;
     $restoreLangLang->title = $deleteLang->title;
     $deleteLang->is_restored = (int) TRUE;
     if (!$restoreLang->save()) {
         Yii::trace('RESTORING LANG FATAL ERROR. CODE#1: ' . var_export($restoreLang->getErrors(), TRUE));
         throw new CException('Ошибка восстановления языка', E_USER_ERROR);
     }
     if (!$restoreLangLang->save()) {
         Yii::trace('RESTORING LANG FATAL ERROR. CODE#2: ' . var_export($restoreLangLang->getErrors(), TRUE));
         throw new CException('Ошибка восстановления языка', E_USER_ERROR);
     }
     if (!$deleteLang->save()) {
         Yii::trace('RESTORING LANG FATAL ERROR. CODE#2: ' . var_export($deleteLang->getErrors(), TRUE));
         throw new CException('Ошибка восстановления языка', E_USER_ERROR);
     }
     Yii::app()->user->setFlash('success', 'Язык успешно восстановлен');
     return TRUE;
 }
Esempio n. 3
0
 public static function fileRegenerateJavascript()
 {
     $path = Yii::app()->basePath . '/../js/translate/app_translate.js';
     $directory = Yii::app()->basePath . '/../js/translate';
     if (!file_exists($directory)) {
         if (!mkdir($directory, self::FILE_MODE, true)) {
             trigger_error('Не удалось создать директорию для хранения транслита. Проверьте права.', E_USER_ERROR);
         }
         @chmod($directory, self::FILE_MODE);
     }
     $langsModel = Langs::model()->findAll();
     $result = array();
     foreach ($langsModel as $langModel) {
         $translatesLang = TranslateLang::model()->findAll(array('condition' => 'lang=:lang AND text != ""', 'params' => array(':lang' => $langModel->alias), 'with' => array('translateModel' => array('joinType' => 'INNER JOIN', 'condition' => 'object_type=:object_type_javascript', 'params' => array(':object_type_javascript' => self::OBJECT_TYPE_STATIC_JAVASCRIPT)))));
         foreach ($translatesLang as $translate) {
             $result[$translate->lang . '_' . $translate->translateModel->text] = $translate->translate;
         }
     }
     $predata = 'var app_js_translate = new Object;' . "\n";
     $body = '';
     foreach ($result as $key => $dataset) {
         $body .= "\t" . "app_js_translate['" . $key . "']" . "\t" . '=' . "\t" . "'" . $dataset . "';" . "\n";
     }
     file_put_contents($path, $predata . $body);
 }