Added the new language feature to the export and import of Components, so that their related translations can also be linked to the exported package.

This commit is contained in:
Llewellyn van der Merwe 2017-04-06 22:40:22 +01:00
parent 2f90f9359c
commit d113d7b91b
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
22 changed files with 205 additions and 40 deletions

View File

@ -109,7 +109,7 @@ Component Builder is mapped as a component in itself on my local development env
+ *Version*: 2.4.2 + *Version*: 2.4.2
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **105639** + *Line count*: **105804**
+ *File count*: **639** + *File count*: **639**
+ *Folder count*: **115** + *Folder count*: **115**

View File

@ -109,7 +109,7 @@ Component Builder is mapped as a component in itself on my local development env
+ *Version*: 2.4.2 + *Version*: 2.4.2
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **105639** + *Line count*: **105804**
+ *File count*: **639** + *File count*: **639**
+ *Folder count*: **115** + *Folder count*: **115**

View File

@ -9,8 +9,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_component.css @subpackage joomla_component.css

View File

@ -9,8 +9,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_components.css @subpackage joomla_components.css

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_component.php @subpackage joomla_component.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_components.php @subpackage joomla_components.php

View File

@ -9,8 +9,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_component.js @subpackage joomla_component.js

View File

@ -691,6 +691,16 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
{ {
return false; return false;
} }
// we then store the languages
if (!$this->saveSmartItems($data, 'language', $db, $user, $today))
{
return false;
}
// we then store the language translations
if (!$this->saveSmartItems($data, 'language_translation', $db, $user, $today))
{
return false;
}
// we then store the custom_code // we then store the custom_code
if (!$this->saveSmartItems($data, 'custom_code', $db, $user, $today)) if (!$this->saveSmartItems($data, 'custom_code', $db, $user, $today))
{ {
@ -845,6 +855,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
// okay we have it local (check if the version is newer) // okay we have it local (check if the version is newer)
if ($this->forceUpdate == 1 || $dbDate > $localDate) if ($this->forceUpdate == 1 || $dbDate > $localDate)
{ {
// add some local values to item to combine
if ($type === 'language_translation')
{
$item->localComponents = $local->components;
$item->localTranslation = $local->translation;
}
// make sure we have the correct ID set // make sure we have the correct ID set
$item->id = $local->id; $item->id = $local->id;
// yes it is newer, lets update (or is being forced) // yes it is newer, lets update (or is being forced)
@ -1416,6 +1432,87 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
} }
} }
break; break;
case 'language_translation':
// update the component ID where needed
if (isset($item->components) && ComponentbuilderHelper::checkJson($item->components))
{
$components = json_decode($item->components, true);
foreach ($components as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the components
if (isset($this->newID['joomla_component'][$id]))
{
$components[$nr] = $this->newID['joomla_component'][$id];
}
else
{
unset($components[$nr]);
}
}
}
// load the local components if found
if (isset($item->localComponents) && ComponentbuilderHelper::checkJson($item->localComponents))
{
if (!isset($components))
{
$components= array();
}
$localComponents = json_decode($item->localComponents, true);
foreach ($localComponents as $lid)
{
if (!is_numeric($lid))
{
continue;
}
// add if not already there
if (!in_array($lid, $components))
{
$components[] = $lid;
}
}
}
// remove the localComponents
if (isset($item->localComponents))
{
unset($item->localComponents);
}
// load it back
if (isset($components) && ComponentbuilderHelper::checkArray($components))
{
// load it back
$item->components = json_encode(array_values($components));
}
// merge the translations where needed
if (isset($item->translation) && isset($item->localTranslation)
&& ComponentbuilderHelper::checkJson($item->translation)
&& ComponentbuilderHelper::checkJson($item->localTranslation))
{
$translations = json_decode($item->translation, true);
$localTranslations = json_decode($item->localTranslation, true);
foreach ($localTranslations['translation'] as $nr => $value)
{
if (!in_array($value, $translations['translation']))
{
$translations['translation'][] = $value;
$translations['language'][] = $localTranslations['language'][$nr];
}
}
$item->translation = json_encode($translations);
}
elseif (isset($item->localTranslation) && ComponentbuilderHelper::checkJson($item->localTranslation))
{
$item->translation = $item->localTranslation;
}
// remove the localTranslation
if (isset($item->localTranslation))
{
unset($item->localTranslation);
}
break;
} }
// final action prep // final action prep
switch($action) switch($action)
@ -1829,6 +1926,14 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$retryAgain = 2; $retryAgain = 2;
} }
break; break;
case 'language_translation':
// get by English translation since there should just be one
$getter = 'entranslation';
break;
case 'language':
// get by language tag since there should just be one
$getter = 'langtag';
break;
default: default:
// can't be found so return false // can't be found so return false
return false; return false;

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_component.php @subpackage joomla_component.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_components.php @subpackage joomla_components.php
@ -213,6 +213,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
$this->setData($user, $db, 'site_view', $item->addsite_views, 'siteview'); $this->setData($user, $db, 'site_view', $item->addsite_views, 'siteview');
// set the custom code ID's // set the custom code ID's
$this->setCustomCodeIds($item, 'joomla_component'); $this->setCustomCodeIds($item, 'joomla_component');
// set the language strings for this component
$this->setLanguageTranslation($user, $db, $item->id);
// load to global object // load to global object
$this->smartExport['joomla_component'][$item->id] = $item; $this->smartExport['joomla_component'][$item->id] = $item;
} }
@ -882,6 +884,64 @@ class ComponentbuilderModelJoomla_components extends JModelList
} }
} }
/**
* Set the language strings for this component
*
* @param int $id The component id
*
* @return void
*
*/
protected function setLanguageTranslation(&$user, &$db, &$id)
{
// Create a new query object.
$query = $db->getQuery(true);
$query->select(array('a.*'));
$query->from('#__componentbuilder_language_translation AS a');
// Implement View Level Access
if (!$user->authorise('core.options', 'com_componentbuilder'))
{
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('a.access IN (' . $groups . ')');
}
// Order the results by ordering
$query->order('a.ordering ASC');
// Load the items
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
$items = $db->loadObjectList();
// check if we have items
if (ComponentbuilderHelper::checkArray($items))
{
if (!isset($this->smartExport['language_translation']))
{
$this->smartExport['language_translation'] = array();
}
foreach ($items as $item)
{
if (!isset($this->smartExport['language_translation'][$item->id]) && ComponentbuilderHelper::checkJson($item->components))
{
$components = json_decode($item->components, true);
if (in_array($id, $components))
{
// load to global object
$this->smartExport['language_translation'][$item->id] = $item;
// add languages
if (isset($item->translation))
{
$this->setData($user, $db, 'language', $item->translation, 'language');
}
}
}
}
}
}
}
/** /**
* Get the package name * Get the package name
* *

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage joomla_component.php @subpackage joomla_component.php

View File

@ -9,8 +9,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage submitbutton.js @subpackage submitbutton.js

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage edit.php @subpackage edit.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage view.html.php @subpackage view.html.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default.php @subpackage default.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_batch_body.php @subpackage default_batch_body.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_batch_footer.php @subpackage default_batch_footer.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_body.php @subpackage default_body.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_foot.php @subpackage default_foot.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_head.php @subpackage default_head.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage default_toolbar.php @subpackage default_toolbar.php

View File

@ -10,8 +10,8 @@
|_| |_|
/-------------------------------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 318 of this MVC @version @update number 329 of this MVC
@build 5th April, 2017 @build 6th April, 2017
@created 6th May, 2015 @created 6th May, 2015
@package Component Builder @package Component Builder
@subpackage view.html.php @subpackage view.html.php