Exemple #1
0
 /**
  * Save translation as completed
  *
  * @return void
  */
 public function saveAllAsCompleted()
 {
     // Get input and turn it into an array with objects
     $input = $this->input;
     $stringsJson = $input->get('strings', '', 'RAW');
     $strings = json_decode($stringsJson);
     // Create an array to hold info about the translations
     $messages = array();
     if (!empty($strings) && count($strings) > 0) {
         $checkedStrings = array();
         foreach ($strings as $string) {
             $string->text = NenoHelper::cleanXssString($string->text);
             // Save the translation
             if ($this->saveTranslation($string->translation_id, $string->text, NenoContentElementTranslation::TRANSLATED_STATE)) {
                 /* @var $translation NenoContentElementTranslation */
                 $translation = NenoContentElementTranslation::load($string->translation_id, false);
                 // Check for number of same translations to offer consolidation
                 // Only check for one string once
                 $counter = 0;
                 $originalText = $translation->getOriginalText();
                 if (in_array(strtolower(trim($originalText)), $checkedStrings) === false) {
                     $checkedStrings[] = strtolower(trim($originalText));
                     $model = $this->getModel();
                     $counter = $model->getSimilarTranslationsCounter($string->translation_id, $translation->getLanguage(), $originalText);
                 }
                 // If we found matches prepare data to return
                 $message = array();
                 if ($counter != 0) {
                     $message['translation_id'] = $string->translation_id;
                     $message['message'] = '<div><input type="checkbox" class="consolidate-checkbox" value="' . $string->translation_id . '" checked="checked"> ' . JText::sprintf('COM_NENO_EDITOR_CONSOLIDATE_MESSAGE', $counter, NenoHelper::html2text($originalText, 200), NenoHelper::html2text($string->text, 200)) . '</div>';
                     $message['counter'] = $counter;
                 }
                 if (!empty($message)) {
                     $messages[] = $message;
                 }
             }
         }
     }
     // Echo any messages
     if (count($messages) > 0) {
         echo json_encode($messages);
     }
     JFactory::getApplication()->close();
 }