private static function getJoinsFromSqlVariables($textWithVars, $currentDoJoin, $currentDoCountJoin, $alternativeDb, $reportModule, $reportTable, &$joinVariables, &$reportTableCustomJoin, &$processedJoinsFromSqlKeys) { $sqlFormulaJoins = ""; $isNonCrmDatabase = $alternativeDb !== false ? true : false; $beanItems = asol_ReportsUtils::getItemVariables($textWithVars); foreach ($beanItems as $beanItem) { if ($beanItem['item'] == '${this}') { continue; } $beanField = null; $tmpBeanItem = substr(substr($beanItem['item'], 2), 0, -1); $beanValues = explode("->", $tmpBeanItem); $beanValues = count($beanValues) == 1 ? explode("->", $tmpBeanItem) : $beanValues; if (count($beanValues) == 2) { if ($beanValues[0] == "bean_cstm") { $reportTableCustomJoin = true; } } else { if (count($beanValues) == 3) { $usedModules = explode("::", $beanValues[0]); $usedKeys = explode("::", $beanValues[1]); $mainFieldKey = $usedKeys[0]; foreach ($usedModules as $usedIndex => $usedModule) { if ($isNonCrmDatabase) { if (isset($processedJoinsFromSqlKeys[$usedModule])) { $relatedLinkKey = $processedJoinsFromSqlKeys[$usedModule]; } else { $mainPK = asol_Report::getSelectionResults("SHOW KEYS FROM " . $usedModule . " WHERE Key_name = 'PRIMARY'", null, true, $alternativeDb); $relatedLinkKey = $processedJoinsFromSqlKeys[$usedModule] = $mainPK[0]['Column_name']; } $mainTable = $usedIndex >= 1 ? $usedModules[$usedIndex - 1] : $reportTable; $mainKey = $usedKeys[$usedIndex]; $relatedTable = $usedModule; $relatedKey = $relatedLinkKey; $parentKey = $usedIndex >= 1 ? $usedKeys[$usedIndex - 1] : null; $joinTable = null; $isMainCustom = false; $isRelatedCustom = false; } else { $bean = BeanFactory::newBean($usedModule); $relatedInfo = asol_Report::getReportsRelatedFields($bean, $usedKeys[$usedIndex]); if (isset($processedJoinsFromSqlKeys[$usedModules[$usedIndex - 1]])) { $previousTable = $processedJoinsFromSqlKeys[$usedModules[$usedIndex - 1]]; } else { $previousTable = $processedJoinsFromSqlKeys[$usedModules[$usedIndex - 1]] = BeanFactory::newBean(BeanFactory::getObjectName($usedModules[$usedIndex - 1]))->table_name; } if (isset($processedJoinsFromSqlKeys[$usedModule])) { $currentTable = $processedJoinsFromSqlKeys[$usedModule]; } else { $currentTable = $processedJoinsFromSqlKeys[$usedModule] = BeanFactory::newBean($usedModule)->table_name; } $mainTable = $usedIndex >= 1 ? $previousTable : $reportTable; $mainKey = $usedKeys[$usedIndex]; $relatedTable = $currentTable; $relatedKey = 'id'; $parentKey = $usedIndex >= 1 ? $usedKeys[$usedIndex - 1] : null; $joinTable = null; $isMainCustom = isset($relatedInfo['custom_module']); $isRelatedCustom = $isCustomTable; } $storedKey = $mainKey . '.' . $relatedTable; $hasRelatedCustom = $joinVariables[$mainFieldKey][$usedIndex][$storedKey]['isRelatedCustom']; if (!empty($mainKey) && $hasRelatedCustom !== true) { $currentDoJoin = $currentDoJoin || $joinVariables[$mainFieldKey][$usedIndex][$storedKey]['doJoin']; $currentDoCountJoin = $currentDoCountJoin || $joinVariables[$mainFieldKey][$usedIndex][$storedKey]['doCountJoin']; $joinVariables[$mainFieldKey][$usedIndex][$storedKey] = array('mainTable' => $mainTable, 'mainKey' => $mainKey, 'relatedTable' => $relatedTable, 'relatedKey' => $relatedKey, 'parentKey' => $parentKey, 'joinTable' => $joinTable, 'isMainCustom' => $isMainCustom, 'isRelatedCustom' => $isRelatedCustom, 'avoidAlias' => false, 'doJoin' => $currentDoJoin, 'doCountJoin' => $currentDoCountJoin); } } } } } }