Added easy translation export and import feature, to allow translation to be done via an exel spreadsheet

This commit is contained in:
2018-01-18 01:14:43 +02:00
parent d00603355b
commit 189a8723ac
53 changed files with 2462 additions and 1482 deletions

View File

@@ -1534,7 +1534,7 @@ class Get
// set custom import scripts
if (isset($view->add_custom_import) && $view->add_custom_import == 1)
{
$addImportArray = array('php_import_ext', 'php_import_display', 'php_import', 'php_import_setdata', 'php_import_save', 'html_import_view');
$addImportArray = array('php_import_ext', 'php_import_display', 'php_import', 'php_import_setdata', 'php_import_save', 'php_import_headers', 'html_import_view');
foreach ($addImportArray as $importScripter)
{
if (isset($view->$importScripter) && strlen($view->$importScripter) > 0)

View File

@@ -8104,32 +8104,34 @@ class Interpretation extends Fields
$query .= PHP_EOL . "\t\treturn false;";
$query .= PHP_EOL . "\t}";
$query .= PHP_EOL . PHP_EOL . "\t/**";
$query .= PHP_EOL . "\t* Method to get header.";
$query .= PHP_EOL . "\t*";
$query .= PHP_EOL . "\t* @return mixed An array of data items on success, false on failure.";
$query .= PHP_EOL . "\t*/";
$query .= PHP_EOL . "\tpublic function getExImPortHeaders()";
$query .= PHP_EOL . "\t{";
$query .= PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Get a db connection.";
$query .= PHP_EOL . "\t\t\$db = JFactory::getDbo();";
$query .= PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " get the columns";
$query .= PHP_EOL . "\t\t\$columns = \$db->getTableColumns(" . '"#__' . $this->fileContentStatic['###component###'] . '_' . $viewName_single . '");';
$query .= PHP_EOL . "\t\tif (" . $this->fileContentStatic['###Component###'] . "Helper::checkArray(\$columns))";
$query .= PHP_EOL . "\t\t{";
$query .= PHP_EOL . "\t\t\t//" . $this->setLine(__LINE__) . " remove the headers you don't import/export.";
$query .= PHP_EOL . "\t\t\tunset(\$columns['asset_id']);";
$query .= PHP_EOL . "\t\t\tunset(\$columns['checked_out']);";
$query .= PHP_EOL . "\t\t\tunset(\$columns['checked_out_time']);";
$query .= PHP_EOL . "\t\t\t\$headers = new stdClass();";
$query .= PHP_EOL . "\t\t\tforeach (\$columns as \$column => \$type)";
$query .= PHP_EOL . "\t\t\t{";
$query .= PHP_EOL . "\t\t\t\t\$headers->{\$column} = \$column;";
$query .= PHP_EOL . "\t\t\t}";
$query .= PHP_EOL . "\t\t\treturn \$headers;";
$query .= PHP_EOL . "\t\t}";
$query .= PHP_EOL . "\t\treturn false;";
$query .= PHP_EOL . "\t}";
// set some placeholders just incase
if (!isset($this->placeholders['###view###']) && !isset($this->placeholders['[[[view]]]']))
{
$this->placeholders['###view###'] = $viewName_single;
$this->placeholders['[[[view]]]'] = $viewName_single;
$_viewSet = true;
}
if (!isset($this->placeholders['###views###']) && !isset($this->placeholders['[[[views]]]']))
{
$this->placeholders['###views###'] = $viewName_list;
$this->placeholders['[[[views]]]'] = $viewName_list;
$_viewsSet = true;
}
// add getExImPortHeaders
$query .= $this->getCustomScriptBuilder('php_import_headers', 'import_' . $viewName_list, PHP_EOL . PHP_EOL, null, true);
// remove place holders if not needed (to not be suprized)
if (isset($_viewSet))
{
unset($this->placeholders['###view###']);
unset($this->placeholders['[[[view]]]']);
}
if (isset($_viewsSet))
{
unset($this->placeholders['###views###']);
unset($this->placeholders['[[[views]]]']);
}
}
return $query;
}

View File

@@ -938,7 +938,7 @@ abstract class ComponentbuilderHelper
public static function getImportScripts($type, $fieldName = false)
{
// if field name is pased the convert to type
// if field name is passed the convert to type
if ($fieldName)
{
$fieldNames = array(
@@ -947,7 +947,8 @@ abstract class ComponentbuilderHelper
'php_import_save' => 'save',
'html_import_view' => 'view',
'php_import' => 'import',
'php_import_ext' => 'ext'
'php_import_ext' => 'ext',
'php_import_headers' => 'headers'
);
// first check if the field name is found
if (isset($fieldNames[$type]))
@@ -1047,6 +1048,36 @@ abstract class ComponentbuilderHelper
$script['setdata'][] = "\t\treturn false;";
$script['setdata'][] = "\t}";
}
elseif ('headers' === $type)
{
$script['headers'] = array();
$script['headers'][] = "\t/**";
$script['headers'][] = "\t* Method to get header.";
$script['headers'][] = "\t*";
$script['headers'][] = "\t* @return mixed An array of data items on success, false on failure.";
$script['headers'][] = "\t*/";
$script['headers'][] = "\tpublic function getExImPortHeaders()";
$script['headers'][] = "\t{";
$script['headers'][] = "\t\t// Get a db connection.";
$script['headers'][] = "\t\t\$db = JFactory::getDbo();";
$script['headers'][] = "\t\t// get the columns";
$script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__###-#-#-component###_###-#-#-view###\");";
$script['headers'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$columns))";
$script['headers'][] = "\t\t{";
$script['headers'][] = "\t\t\t// remove the headers you don't import/export.";
$script['headers'][] = "\t\t\tunset(\$columns['asset_id']);";
$script['headers'][] = "\t\t\tunset(\$columns['checked_out']);";
$script['headers'][] = "\t\t\tunset(\$columns['checked_out_time']);";
$script['headers'][] = "\t\t\t\$headers = new stdClass();";
$script['headers'][] = "\t\t\tforeach (\$columns as \$column => \$type)";
$script['headers'][] = "\t\t\t{";
$script['headers'][] = "\t\t\t\t\$headers->{\$column} = \$column;";
$script['headers'][] = "\t\t\t}";
$script['headers'][] = "\t\t\treturn \$headers;";
$script['headers'][] = "\t\t}";
$script['headers'][] = "\t\treturn false;";
$script['headers'][] = "\t}";
}
elseif ('save' === $type)
{
$script['save'] = array();