/** * {@inheritdoc} * * @return bool */ public function persist() { // Update word counter $this->wordCounter = NenoHelper::getWordCount($this->getString()); if ($this->contentType == self::DB_STRING) { /* @var $field NenoContentElementField */ $field = $this->element; if ($field instanceof NenoContentElementField) { $this->string = $field->applyFilter($this->string); } } if ($this->getState() == self::TRANSLATED_STATE) { $this->timeCompleted = new DateTime(); } // Ensure JSON string length $this->ensureJsonStringsLength(); // Check if this record is new $isNew = $this->isNew(); if (!$isNew) { // Updating changed time $this->timeChanged = new DateTime(); } // Only execute this task when the translation is new and there are no records about how to find it. if (parent::persist()) { $db = JFactory::getDbo(); $query = $db->getQuery(true); if ($isNew && $this->contentType == self::DB_STRING) { if (!empty($this->sourceElementData)) { $query->insert('#__neno_content_element_fields_x_translations')->columns(array('field_id', 'translation_id', 'value')); $inserted = array(); // Loop through the data foreach ($this->sourceElementData as $sourceData) { /* @var $field NenoContentElementField */ $field = $sourceData['field']; $fieldValue = $sourceData['value']; // Checks if this row has been inserted already if (!in_array($field->getId() . '|' . $this->getId(), $inserted)) { $query->values($field->getId() . ',' . $this->getId() . ',' . $db->quote($fieldValue)); $inserted[] = $field->getId() . '|' . $this->getId(); } } $db->setQuery($query); $db->execute(); } } $query->clear()->delete('#__neno_content_element_translation_x_translation_methods')->where('translation_id = ' . $this->id); $db->setQuery($query); $db->execute(); if (!empty($this->translationMethods)) { $query->clear()->insert('#__neno_content_element_translation_x_translation_methods')->columns(array('translation_id', 'translation_method_id', 'ordering')); foreach ($this->translationMethods as $key => $translationMethod) { $query->values($this->id . ',' . $translationMethod->id . ',' . ($key + 1)); } $db->setQuery($query); $db->execute(); } $this->originalText = $this->loadOriginalText(); if ($this->originalText != '') { $this->updateOriginalText(); } if ($this->state == self::TRANSLATED_STATE) { $this->moveTranslationToTarget(); } return true; } return false; }