/** * Function to translate a section object * @param array $rows * @param array $ids * @param string $reference_table * @param JFLanguage $language * @param string $refTablePrimaryKey * @param array $tableArray * @param string $querySQL * @param boolean $allowfallback */ public static function translateListWithIDs(&$rows, $ids, $reference_table, $language, $refTablePrimaryKey = "id", &$tableArray, $querySQL, $allowfallback = true) { $params = JComponentHelper::getParams('com_falang'); //print " translateListWithIDs for ids=$ids refTablePrimaryKey=$refTablePrimaryKey<br>" ; //$debug = $config->get("debug") == 1 ? true : false; //if we use association we have to remove the :alias in the id's //new since 1.3.3 // JLanguageAssociations::isEnabled() only since Joomla 3.2 $pos = strpos($ids, ':'); if ($pos !== false) { return; } if (!isset($language) || $language == '') { $lang = JFactory::getLanguage(); $language = $lang->getTag(); } $db = JFactory::getDBO(); // setup falang pluginds $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('falang'); if ($reference_table == "falang_content") { return; // I can't translate myself ;-) } $results = $dispatcher->trigger('onBeforeTranslation', array(&$rows, &$ids, $reference_table, $language, $refTablePrimaryKey, &$tableArray, $querySQL, $allowfallback)); // if onBeforeTranslation has cleaned out the list then just return at this point if (strlen($ids) == 0) { return; } // find reference table alias $reftableAlias = $reference_table; for ($i = 0; $i < $tableArray["fieldCount"]; $i++) { if (!array_key_exists($i, $tableArray["fieldTableAliasData"])) { continue; } if ($tableArray["fieldTableAliasData"][$i]["tableName"] == $reference_table && $tableArray["fieldTableAliasData"][$i]["fieldNameAlias"] == $refTablePrimaryKey) { $reftableAlias = $tableArray["fieldTableAliasData"][$i]["tableNameAlias"]; break; } } // NASTY KLUDGE TO DEAL WITH SQL CONSTRUCTION IN contact.php, weblinks.php where multiple tables to be translated all use "id" which gets dropped! etc. $currentRow = current($rows); // must not check on catid>0 since this would be uncategorised items if ($reference_table == 'categories' && count($rows) > 0 && isset($currentRow->catid)) { $reftableAlias = $tableArray["tableAliases"]["categories"]; } if ($reference_table == 'sections' && count($rows) > 0 && isset($currentRow->sectionid)) { $reftableAlias = $tableArray["tableAliases"]["sections"]; } if ($params->get('debug')) { echo "<p><strong>Falang debug (new):</strong><br>" . "reference_table={$reference_table}<br>" . "{$refTablePrimaryKey} IN({$ids})<br>" . "language={$language}<br>" . (count($rows) > 0 ? "class=" . get_class(current($rows)) : "") . "</p>"; } static $languages; if (!isset($languages)) { $jfm = FalangManager::getInstance(); $languages = $jfm->getLanguagesIndexedByCode(); } // process fallback language $fallbacklanguage = false; $fallbackrows = array(); $idarray = explode(",", $ids); $fallbackids = array(); if (isset($languages[$language]) && $languages[$language]->fallback_code != "") { $fallbacklanguage = $languages[$language]->fallback_code; if (!array_key_exists($fallbacklanguage, $languages)) { $allowfallback = false; } } if (!$fallbacklanguage) { $allowfallback = false; } if (isset($ids) && $reference_table != '') { //TODO Params for published ? //$user = JFactory::getUser(); //$published = $user->authorise('core.publish', 'com_falang') ? "\n AND falang_content.published=1" : ""; //$published = ($user->get('id')<21)?"\n AND falang_content.published=1":""; $published = "\n\tAND falang_content.published=1"; $sql = "SELECT falang_content.reference_field, falang_content.value, falang_content.reference_id, falang_content.original_value " . "\nFROM #__falang_content AS falang_content" . "\nWHERE falang_content.language_id=" . $languages[$language]->lang_id . $published . "\n AND falang_content.reference_id IN({$ids})" . "\n AND falang_content.reference_table='{$reference_table}'"; $db->setQuery($sql); //$translations = $db->loadObjectList('',false); $translations = $db->loadObjectList('', 'stdClass', false); if (count($translations) > 0) { $fieldmap = null; foreach (array_keys($rows) as $key) { $row_to_translate = $rows[$key]; $rowTranslationExists = false; //print_r ($row_to_translate); print"<br>"; if (isset($row_to_translate->{$refTablePrimaryKey})) { foreach ($translations as $row) { if ($row->reference_id != $row_to_translate->{$refTablePrimaryKey}) { continue; } // TODO - consider building array for refFields. Some queries may have multiple aliases e.g. SELECT a.*, a.field as fieldalias $refField = $row->reference_field; // adjust refField for aliases (make sure the field is from the same table!). // I could reduce the calculation by building an array of translation reference fields against their mapping number // but this refinement can wait! $fieldmatch = false; // This is used to confirm the field is from the correct table for ($i = 0; $i < $tableArray["fieldCount"]; $i++) { if (!array_key_exists($i, $tableArray["fieldTableAliasData"])) { continue; } // look for fields from the correct table with the correct name if ($tableArray["fieldTableAliasData"][$i]["tableName"] == $reference_table && $tableArray["fieldTableAliasData"][$i]["fieldName"] == $refField && $tableArray["fieldTableAliasData"][$i]["tableNameAlias"] == $reftableAlias) { $refField = $tableArray["fieldTableAliasData"][$i]["fieldNameAlias"]; $fieldmatch = true; break; } } $fieldIndex = $i; if ($fieldmatch && isset($row->reference_id) && $row->reference_id == $row_to_translate->{$refTablePrimaryKey} && $fieldIndex <= $tableArray["fieldCount"]) { if (is_subclass_of($row_to_translate, 'mosDBTable')) { $row_to_translate->set($row->reference_field, $row->value); } else { $row_to_translate->{$refField} = $row->value; } $rowTranslationExists = true; //print_r( $row_to_translate);print"<br>"; } } if (!$rowTranslationExists) { if ($allowfallback && isset($rows[$key]->{$refTablePrimaryKey})) { $fallbackrows[$key] = $rows[$key]; $fallbackids[$key] = $rows[$key]->{$refTablePrimaryKey}; } else { $results = $dispatcher->trigger('onMissingTranslation', array(&$row_to_translate, $language, $reference_table, $tableArray, $querySQL)); //JoomFish::processMissingTranslation($row_to_translate, $language,$reference_table); } } } } } else { foreach (array_keys($rows) as $key) { if ($allowfallback && isset($rows[$key]->{$refTablePrimaryKey})) { $fallbackrows[$key] = $rows[$key]; $fallbackids[$key] = $rows[$key]->{$refTablePrimaryKey}; } else { $results = $dispatcher->trigger('onMissingTranslation', array(&$rows[$key], $language, $reference_table, $tableArray, $querySQL)); //JoomFish::processMissingTranslation($rows[$key], $language,$reference_table); } } } if ($allowfallback && count($fallbackrows) > 0) { $fallbackids = implode($fallbackids, ","); Falang::translateListWithIDs($fallbackrows, $fallbackids, $reference_table, $fallbacklanguage, $refTablePrimaryKey, $tableArray, $querySQL, false); } $dispatcher->trigger('onAfterTranslation', array(&$rows, $ids, $reference_table, $language, $refTablePrimaryKey, $tableArray, $querySQL, $allowfallback)); } }
function loadObjectList($key = '', $class = 'stdClass', $translate = true, $language = null) { //sbou //sbou TODO check r�cursive pb //$jfManager = FalangManager::getInstance(); if (!$translate) { $this->_skipSetRefTables = true; $result = parent::loadObjectList($key, empty($class) ? 'stdClass' : $class); $this->_skipSetRefTables = false; return $result; } $result = parent::loadObjectList($key, empty($class) ? 'stdClass' : $class); // if( isset($jfManager)) { // $this->_setLanguage($language); // } // TODO check the impact of this on frontend translation // It does stop Joomfish plugins from working on missing translations e.g. regional content so disable for now // Don't do it for now since translation caching is so effective /* $registry = JFactory::getConfig(); $defaultLang = $registry->getValue("config.defaultlang"); if ($defaultLang == $language){ $translate = false; } */ //sbou TODO this is not the right solution. // if( isset($jfManager)) { if (true) { $doTranslate = false; $tables = $this->getRefTables(); if ($tables == null) { return $result; } // an unstranslatable query to return result as is // if we don't have "fieldTablePairs" then we can't translate if (!array_key_exists("fieldTablePairs", $tables)) { return $result; } foreach ($tables["fieldTablePairs"] as $i => $table) { if ($this->translatedContentAvailable($table)) { $doTranslate = true; break; } } if ($doTranslate) { $pfunc = $this->_profile(); //sbou TODO cache desactived // if ($jfManager->getCfg("transcaching",1)){ if (false) { // cache the results // TODO call based on config //$cache = JFactory::getCache('jfquery'); $cache = $jfManager->getCache($language); $this->orig_limit = $this->limit; $this->orig_offset = $this->offset; $result = $cache->get(array("FaLang", 'translateListCached'), array($result, $language, $this->getRefTables())); $this->orig_limit = 0; $this->orig_offset = 0; } else { $this->orig_limit = $this->limit; $this->orig_offset = $this->offset; Falang::translateList($result, $language, $this->getRefTables()); $this->orig_limit = 0; $this->orig_offset = 0; } $pfunc = $this->_profile($pfunc); } } return $result; }