/** * This method will be executed once the content is save * * @param string $context Save context * @param JTable $content JTable class of the content * @param bool $isNew If the record is new or not * * @return void */ public function onContentAfterSave($context, $content, $isNew) { // If the user has create a new menu item, let's create it. if ($context == 'com_menus.item' && $isNew) { NenoHelper::createMenuStructure(); } elseif ($content instanceof JTable) { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $tableName = $content->getTableName(); /* @var $table NenoContentElementTable */ $table = NenoContentElementTable::load(array('table_name' => $tableName), false); if (!empty($table)) { // If the record has changed the state to 'Trashed' if (isset($content->state) && $content->state == -2) { $primaryKeys = $content->getPrimaryKey(); $this->trashTranslations($table, array($content->{$primaryKeys[0]})); } else { $fields = $table->getFields(false, true); /* @var $field NenoContentElementField */ foreach ($fields as $field) { if ($field->isTranslatable()) { $primaryKeyData = array(); foreach ($content->getPrimaryKey() as $primaryKeyName => $primaryKeyValue) { $primaryKeyData[$primaryKeyName] = $primaryKeyValue; } $field->persistTranslations($primaryKeyData); } } $languages = NenoHelper::getLanguages(false); $defaultLanguage = NenoSettings::get('source_language'); foreach ($languages as $language) { if ($language->lang_code != $defaultLanguage) { $shadowTable = $db->generateShadowTableName($tableName, $language->lang_code); $properties = $content->getProperties(); $query = 'REPLACE INTO ' . $db->quoteName($shadowTable) . ' (' . implode(',', $db->quoteName(array_keys($properties))) . ') VALUES(' . implode(',', $db->quote($properties)) . ')'; $db->setQuery($query); $db->execute(); } } } } } }