Exemplo n.º 1
0
 public function translate($language)
 {
     $source_arr = $this->getLanguage();
     if (is_array($source_arr) && isset($source_arr['id'])) {
         $source = $source_arr['id'];
     }
     $target_arr = explode('-', $language);
     $target = $target_arr[0];
     $translations = array();
     $translations = $this->getAllTranslations();
     $translator = new LanguageTranslator('AIzaSyBlwXdmxJZ__ZNScwe4zq5r3qh3ebXb26k');
     if (count($translations)) {
         foreach ($translations as $node) {
             if ($node['language']['id'] == $target) {
                 $slide = new Slide();
                 $slide->slide_id = $node['id'];
                 $slide->createFromIDLite($slide->getLastRevisionID());
                 return $slide->id;
             }
         }
     }
     $old_slide_id = $this->slide_id;
     //for questions
     $this->symbolsToLatex();
     $replace_array = array();
     $replace_array = $this->filterTags();
     $q = $this->content;
     $content = '';
     $translation = $translator->translate($q, $target, $source);
     if ($translation != -1) {
         $tags_back = $this->addTagsBack($translation, $replace_array);
         $content = '<div lang="' . $target . '-x-mtfrom-' . $source . '">' . $tags_back . '</div>';
         $this->language = $language;
         $this->translated_from = $this->slide_id;
         $translated_from_revision = $this->id;
         $this->content = $content;
         $this->description = $this->getDescription();
         $this->latexToSymbols();
         $based_on = NULL;
         $this->slide_id = $this->dbInsert('slide', array('user_id' => $this->user->id, 'description' => $this->description, 'language' => $this->language, 'translated_from' => $this->translated_from, 'translated_from_revision' => $translated_from_revision));
         $new_slide_id = $this->slide_id;
         //for questions
         $this->translateQuestions($old_slide_id, $new_slide_id, $source_arr, $language);
         $this->based_on = NULL;
         $this->id = $this->dbInsert('slide_revision', array('slide' => $this->slide_id, 'content' => $this->content, 'user_id' => $this->user->id, 'comment' => $this->comment, 'based_on' => $based_on, 'note' => $this->note, 'translation_status' => 'google', 'translated_from_revision' => $translated_from_revision));
         return $this->id;
     } else {
         return -1;
     }
 }
Exemplo n.º 2
0
 public function translate($language)
 {
     if (empty($this->default_theme)) {
         $this->default_theme = 2;
     }
     if (empty($this->default_transition)) {
         $this->default_transition = 4;
     }
     $source_arr = $this->getLanguage();
     if (is_array($source_arr) && isset($source_arr['id'])) {
         $source = $source_arr['id'];
     }
     $target_arr = explode('-', $language);
     $target = $target_arr[0];
     $translations_array = array();
     $translated_from_revision = $this->id;
     //                //check if translation already exists
     $translations_array = $this->getAllTranslations();
     $continue = true;
     if (count($translations_array)) {
         //if there are other translations
         $continue = false;
         foreach ($translations_array as $translation) {
             if ($translation['language']['id'] == $target) {
                 //if there is a translation to the same language
                 $this->removeFromQueue($this->id, $language);
                 $new_deck = new Deck();
                 $new_deck->createFromIDLite($translation['last']);
                 //to copy the title, abstract etc.
                 $deck_id = $translation['id'];
                 $based_on = $translation['last'];
                 $title = $new_deck->title;
                 $abstract = $new_deck->abstract;
                 $footer_text = $new_deck->footer_text;
                 $this->id = $this->dbInsert('deck_revision', array('deck_id' => $deck_id, 'title' => $title, 'user_id' => $this->user->id, 'abstract' => $abstract, 'footer_text' => $footer_text, 'comment' => $this->comment, 'visibility' => $this->visibility, 'based_on' => $based_on, 'default_theme' => $this->default_theme, 'default_transition' => $this->default_transition, 'translation_status' => 'in_progress', 'translated_from_revision' => $translated_from_revision));
                 $groups = $this->dbQuery('SELECT * FROM user_group WHERE deck_revision_id=:id', array('id' => $based_on));
                 if (!empty($groups)) {
                     foreach ($groups as $group) {
                         $this->dbInsert('user_group', array('deck_revision_id' => $this->id, 'user_id' => $group['user_id'], 'category' => $group['category']));
                     }
                 }
                 $this->translateContent($this->user->id, $language);
                 $this->dbQuery('UPDATE deck_revision SET translation_status = NULL WHERE id=:id', array('id' => $this->id));
                 $this->dbQuery('UPDATE translation_cronjobs SET future_deck=:future_deck WHERE revision_id=:revision_id AND to_language=:language', array('future_deck' => $this->id, 'language' => $language, 'revision_id' => $translated_from_revision));
                 return $this->id;
             } else {
                 //there is no translations on the same language
                 $continue = true;
             }
         }
     }
     if ($continue) {
         //create new deck
         $this->language = $language;
         $this->translated_from = $this->deck_id;
         $this->translated_from_revision = $this->id;
         $translator = new LanguageTranslator('AIzaSyBlwXdmxJZ__ZNScwe4zq5r3qh3ebXb26k');
         $abstract = '';
         $title = '';
         $footer_text = '';
         $q = $this->title;
         $title = $translator->translate($q, $target, $source);
         if ($title != -1) {
             $q = $this->abstract;
             if ($q) {
                 $abstract = $translator->translate($q, $target, $source);
             }
             $q = $this->footer_text;
             if ($q) {
                 $footer_text = $translator->translate($q, $target, $source);
             }
             $based_on = $this->id;
             $this->deck_id = $this->dbInsert('deck', array('user_id' => $this->user->id, 'language' => $this->language, 'translated_from' => $this->translated_from, 'translated_from_revision' => $this->translated_from_revision));
             $this->id = $this->dbInsert('deck_revision', array('deck_id' => $this->deck_id, 'title' => $title, 'user_id' => $this->user->id, 'abstract' => $abstract, 'footer_text' => $footer_text, 'comment' => $this->comment, 'visibility' => $this->visibility, 'based_on' => NULL, 'default_theme' => $this->default_theme, 'default_transition' => $this->default_transition, 'translation_status' => 'in_progress', 'translated_from_revision' => $translated_from_revision));
             //copy the user groups into the new deck revision
             $groups = $this->dbQuery('SELECT * FROM user_group WHERE deck_revision_id=:id', array('id' => $this->translated_from_revision));
             if (!empty($groups)) {
                 foreach ($groups as $group) {
                     $this->dbInsert('user_group', array('deck_revision_id' => $this->id, 'user_id' => $group['user_id'], 'category' => $group['category']));
                 }
             }
             $this->translateContent($this->user->id, $language);
             $this->dbQuery('UPDATE translation_cronjobs SET future_deck=:future_deck WHERE revision_id=:revision_id AND to_language=:language', array('future_deck' => $this->id, 'language' => $language, 'revision_id' => $this->translated_from_revision));
             $this->dbQuery('UPDATE deck_revision SET translation_status = NULL WHERE id=:id', array('id' => $this->id));
             return $this->id;
         } else {
             return -1;
         }
     }
 }